mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use cbindgen for cursors.
Pretty straight-forward. Differential Revision: https://phabricator.services.mozilla.com/D63777
This commit is contained in:
parent
787ac98d18
commit
18570bf077
4 changed files with 39 additions and 77 deletions
|
@ -13,10 +13,10 @@ pub use crate::values::specified::ui::CursorKind;
|
|||
pub use crate::values::specified::ui::{MozForceBrokenImageIcon, UserSelect};
|
||||
|
||||
/// A computed value for the `cursor` property.
|
||||
pub type Cursor = generics::Cursor<CursorImage>;
|
||||
pub type Cursor = generics::GenericCursor<CursorImage>;
|
||||
|
||||
/// A computed value for item of `image cursors`.
|
||||
pub type CursorImage = generics::CursorImage<ComputedImageUrl, Number>;
|
||||
pub type CursorImage = generics::GenericCursorImage<ComputedImageUrl, Number>;
|
||||
|
||||
/// A computed value for `scrollbar-color` property.
|
||||
pub type ScrollbarColor = generics::GenericScrollbarColor<Color>;
|
||||
|
|
|
@ -21,19 +21,22 @@ use values::specified::ui::CursorKind;
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct Cursor<Image> {
|
||||
#[repr(C)]
|
||||
pub struct GenericCursor<Image> {
|
||||
/// The parsed images for the cursor.
|
||||
pub images: Box<[Image]>,
|
||||
pub images: crate::OwnedSlice<Image>,
|
||||
/// The kind of the cursor [default | help | ...].
|
||||
pub keyword: CursorKind,
|
||||
}
|
||||
|
||||
pub use self::GenericCursor as Cursor;
|
||||
|
||||
impl<Image> Cursor<Image> {
|
||||
/// Set `cursor` to `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
Self {
|
||||
images: vec![].into_boxed_slice(),
|
||||
images: Default::default(),
|
||||
keyword: CursorKind::Auto,
|
||||
}
|
||||
}
|
||||
|
@ -63,24 +66,31 @@ impl<Image: ToCss> ToCss for Cursor<Image> {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct CursorImage<ImageUrl, Number> {
|
||||
#[repr(C)]
|
||||
pub struct GenericCursorImage<ImageUrl, Number> {
|
||||
/// The url to parse images from.
|
||||
pub url: ImageUrl,
|
||||
/// The <x> and <y> coordinates.
|
||||
pub hotspot: Option<(Number, Number)>,
|
||||
/// Whether the image has a hotspot or not.
|
||||
pub has_hotspot: bool,
|
||||
/// The x coordinate.
|
||||
pub hotspot_x: Number,
|
||||
/// The y coordinate.
|
||||
pub hotspot_y: Number,
|
||||
}
|
||||
|
||||
pub use self::GenericCursorImage as CursorImage;
|
||||
|
||||
impl<ImageUrl: ToCss, Number: ToCss> ToCss for CursorImage<ImageUrl, Number> {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
self.url.to_css(dest)?;
|
||||
if let Some((ref x, ref y)) = self.hotspot {
|
||||
if self.has_hotspot {
|
||||
dest.write_str(" ")?;
|
||||
x.to_css(dest)?;
|
||||
self.hotspot_x.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
y.to_css(dest)?;
|
||||
self.hotspot_y.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ use std::fmt::{self, Write};
|
|||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
||||
/// A specified value for the `cursor` property.
|
||||
pub type Cursor = generics::Cursor<CursorImage>;
|
||||
pub type Cursor = generics::GenericCursor<CursorImage>;
|
||||
|
||||
/// A specified value for item of `image cursors`.
|
||||
pub type CursorImage = generics::CursorImage<SpecifiedImageUrl, Number>;
|
||||
pub type CursorImage = generics::GenericCursorImage<SpecifiedImageUrl, Number>;
|
||||
|
||||
impl Parse for Cursor {
|
||||
/// cursor: [<url> [<number> <number>]?]# [auto | default | ...]
|
||||
|
@ -34,7 +34,7 @@ impl Parse for Cursor {
|
|||
input.expect_comma()?;
|
||||
}
|
||||
Ok(Self {
|
||||
images: images.into_boxed_slice(),
|
||||
images: images.into(),
|
||||
keyword: CursorKind::parse(input)?,
|
||||
})
|
||||
}
|
||||
|
@ -45,13 +45,20 @@ impl Parse for CursorImage {
|
|||
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,
|
||||
},
|
||||
})
|
||||
use crate::Zero;
|
||||
|
||||
let url = SpecifiedImageUrl::parse(context, input)?;
|
||||
let mut has_hotspot = false;
|
||||
let mut hotspot_x = Number::zero();
|
||||
let mut hotspot_y = Number::zero();
|
||||
|
||||
if let Ok(x) = input.try(|input| Number::parse(context, input)) {
|
||||
has_hotspot = true;
|
||||
hotspot_x = x;
|
||||
hotspot_y = Number::parse(context, input)?;
|
||||
}
|
||||
|
||||
Ok(Self { url, has_hotspot, hotspot_x, hotspot_y })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue