mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -22,7 +22,6 @@ use crate::gecko_bindings::bindings::Gecko_CopyConstruct_${style_struct.gecko_ff
|
|||
use crate::gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
|
||||
% endfor
|
||||
use crate::gecko_bindings::bindings::Gecko_CopyCounterStyle;
|
||||
use crate::gecko_bindings::bindings::Gecko_CopyCursorArrayFrom;
|
||||
use crate::gecko_bindings::bindings::Gecko_CopyFontFamilyFrom;
|
||||
use crate::gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
|
||||
use crate::gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
|
||||
|
@ -2263,61 +2262,7 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="InheritedUI" skip_longhands="cursor">
|
||||
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
|
||||
self.gecko.mCursor = v.keyword;
|
||||
unsafe {
|
||||
bindings::Gecko_SetCursorArrayCapacity(&mut *self.gecko, v.images.len());
|
||||
}
|
||||
for i in 0..v.images.len() {
|
||||
unsafe {
|
||||
bindings::Gecko_AppendCursorImage(&mut *self.gecko, &v.images[i].url);
|
||||
}
|
||||
|
||||
match v.images[i].hotspot {
|
||||
Some((x, y)) => {
|
||||
self.gecko.mCursorImages[i].mHaveHotspot = true;
|
||||
self.gecko.mCursorImages[i].mHotspotX = x;
|
||||
self.gecko.mCursorImages[i].mHotspotY = y;
|
||||
},
|
||||
_ => {
|
||||
self.gecko.mCursorImages[i].mHaveHotspot = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_cursor_from(&mut self, other: &Self) {
|
||||
self.gecko.mCursor = other.gecko.mCursor;
|
||||
unsafe {
|
||||
Gecko_CopyCursorArrayFrom(&mut *self.gecko, &*other.gecko);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_cursor(&mut self, other: &Self) {
|
||||
self.copy_cursor_from(other)
|
||||
}
|
||||
|
||||
pub fn clone_cursor(&self) -> longhands::cursor::computed_value::T {
|
||||
use crate::values::computed::ui::CursorImage;
|
||||
|
||||
let keyword = self.gecko.mCursor;
|
||||
|
||||
let images = self.gecko.mCursorImages.iter().map(|gecko_cursor_image| {
|
||||
let url = gecko_cursor_image.mImage.clone();
|
||||
|
||||
let hotspot =
|
||||
if gecko_cursor_image.mHaveHotspot {
|
||||
Some((gecko_cursor_image.mHotspotX, gecko_cursor_image.mHotspotY))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
CursorImage { url, hotspot }
|
||||
}).collect::<Vec<_>>().into_boxed_slice();
|
||||
|
||||
longhands::cursor::computed_value::T { images, keyword }
|
||||
}
|
||||
<%self:impl_trait style_struct_name="InheritedUI">
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Column"
|
||||
|
|
|
@ -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