diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 400f27fa44b..f4269ceb7b5 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -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 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::>().into_boxed_slice(); - - longhands::cursor::computed_value::T { images, keyword } - } +<%self:impl_trait style_struct_name="InheritedUI"> <%self:impl_trait style_struct_name="Column" diff --git a/components/style/values/computed/ui.rs b/components/style/values/computed/ui.rs index 21914995951..ae12dfcdae0 100644 --- a/components/style/values/computed/ui.rs +++ b/components/style/values/computed/ui.rs @@ -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; +pub type Cursor = generics::GenericCursor; /// A computed value for item of `image cursors`. -pub type CursorImage = generics::CursorImage; +pub type CursorImage = generics::GenericCursorImage; /// A computed value for `scrollbar-color` property. pub type ScrollbarColor = generics::GenericScrollbarColor; diff --git a/components/style/values/generics/ui.rs b/components/style/values/generics/ui.rs index 945f60fb5dd..6dfbb4a9c94 100644 --- a/components/style/values/generics/ui.rs +++ b/components/style/values/generics/ui.rs @@ -21,19 +21,22 @@ use values::specified::ui::CursorKind; ToResolvedValue, ToShmem, )] -pub struct Cursor { +#[repr(C)] +pub struct GenericCursor { /// The parsed images for the cursor. - pub images: Box<[Image]>, + pub images: crate::OwnedSlice, /// The kind of the cursor [default | help | ...]. pub keyword: CursorKind, } +pub use self::GenericCursor as Cursor; + impl Cursor { /// 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 ToCss for Cursor { ToResolvedValue, ToShmem, )] -pub struct CursorImage { +#[repr(C)] +pub struct GenericCursorImage { /// The url to parse images from. pub url: ImageUrl, - /// The and 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 ToCss for CursorImage { fn to_css(&self, dest: &mut CssWriter) -> 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(()) } diff --git a/components/style/values/specified/ui.rs b/components/style/values/specified/ui.rs index 46272b2ae85..b262347de20 100644 --- a/components/style/values/specified/ui.rs +++ b/components/style/values/specified/ui.rs @@ -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; +pub type Cursor = generics::GenericCursor; /// A specified value for item of `image cursors`. -pub type CursorImage = generics::CursorImage; +pub type CursorImage = generics::GenericCursorImage; impl Parse for Cursor { /// cursor: [ [ ]?]# [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> { - 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 }) } }