mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Support calc in cursor.
Bug: 1453258 Reviewed-by: emilio MozReview-Commit-ID: 1ZzxkYboWZg
This commit is contained in:
parent
da43a33fb1
commit
89fba41e1d
3 changed files with 135 additions and 166 deletions
|
@ -8,44 +8,15 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use style_traits::ParseError;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use style_traits::cursor::CursorKind;
|
||||
use values::generics::pointing::CaretColor as GenericCaretColor;
|
||||
use values::generics::pointing as generics;
|
||||
use values::specified::Number;
|
||||
use values::specified::color::Color;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedImageUrl;
|
||||
|
||||
/// The specified value for the `cursor` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-ui/#cursor
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct Cursor(pub CursorKind);
|
||||
|
||||
/// The specified value for the `cursor` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-ui/#cursor
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct Cursor {
|
||||
/// The parsed images for the cursor.
|
||||
pub images: Box<[CursorImage]>,
|
||||
/// The kind of the cursor [default | help | ...].
|
||||
pub keyword: CursorKind,
|
||||
}
|
||||
|
||||
/// The specified value for the `image cursors`.
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct CursorImage {
|
||||
/// The url to parse images from.
|
||||
pub url: SpecifiedImageUrl,
|
||||
/// The <x> and <y> coordinates.
|
||||
pub hotspot: Option<(f32, f32)>,
|
||||
}
|
||||
|
||||
/// A specified value for the `caret-color` property.
|
||||
pub type CaretColor = GenericCaretColor<Color>;
|
||||
pub type CaretColor = generics::CaretColor<Color>;
|
||||
|
||||
impl Parse for CaretColor {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -53,8 +24,63 @@ impl Parse for CaretColor {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(GenericCaretColor::Auto);
|
||||
return Ok(generics::CaretColor::Auto);
|
||||
}
|
||||
Ok(GenericCaretColor::Color(Color::parse(context, input)?))
|
||||
Ok(generics::CaretColor::Color(Color::parse(context, input)?))
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `cursor` property.
|
||||
pub type Cursor = generics::Cursor<CursorImage>;
|
||||
|
||||
/// A specified value for item of `image cursors`.
|
||||
pub type CursorImage = generics::CursorImage<SpecifiedImageUrl, Number>;
|
||||
|
||||
impl Parse for Cursor {
|
||||
/// cursor: [<url> [<number> <number>]?]# [auto | default | ...]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut images = vec![];
|
||||
loop {
|
||||
match input.try(|input| CursorImage::parse(context, input)) {
|
||||
Ok(image) => images.push(image),
|
||||
Err(_) => break,
|
||||
}
|
||||
input.expect_comma()?;
|
||||
}
|
||||
Ok(Self {
|
||||
images: images.into_boxed_slice(),
|
||||
keyword: CursorKind::parse(context, input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for CursorKind {
|
||||
fn parse<'i, 't>(
|
||||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let ident = input.expect_ident()?;
|
||||
CursorKind::from_css_keyword(&ident).map_err(|_| {
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for CursorImage {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(Self {
|
||||
url: SpecifiedImageUrl::parse(context, input)?,
|
||||
hotspot: match input.try(|input| Number::parse(context, input)) {
|
||||
Ok(number) => Some((number, Number::parse(context, input)?)),
|
||||
Err(_) => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue