From fa6dd1d61b0b516b5ef4f352c5316a48bd86652f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 15 Jun 2016 11:38:17 +0200 Subject: [PATCH 1/2] stylo: Support the rest of the background-xxx P1 properties. We do the same that with background-{image, repeat}, we just use the first element until servo can parse and use a list efficiently. --- .../properties/longhand/background.mako.rs | 2 +- ports/geckolib/properties.mako.rs | 81 ++++++++++++++++--- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index d2e6a090a3b..77be57aa097 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -184,7 +184,7 @@ ${helpers.predefined_type( ${helpers.single_keyword("background-repeat", "repeat repeat-x repeat-y no-repeat")} -${helpers.single_keyword("background-attachment", "scroll fixed")} +${helpers.single_keyword("background-attachment", "scroll fixed" + (" local" if product == "gecko" else ""))} ${helpers.single_keyword("background-clip", "border-box padding-box content-box")} diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 3444403271f..e1336492881 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -384,8 +384,6 @@ impl Debug for ${style_struct.gecko_struct_name} { force_stub = []; # These are currently being shuffled to a different style struct on the gecko side. force_stub += ["backface-visibility", "transform-box", "transform-style"] - # These live in nsStyleImageLayers in gecko. Need to figure out what to do about that. - force_stub += ["background-attachment", "background-clip", "background-origin"]; # These live in an nsFont member in Gecko. Should be straightforward to do manually. force_stub += ["font-kerning", "font-stretch", "font-variant"] # These have unusual representations in gecko. @@ -746,8 +744,14 @@ fn static_assert() { } +// TODO: Gecko accepts lists in most background-related properties. We just use +// the first element (which is the common case), but at some point we want to +// add support for parsing these lists in servo and pushing to nsTArray's. +<% skip_background_longhands = """background-color background-repeat + background-image background-clip + background-origin background-attachment""" %> <%self:impl_trait style_struct_name="Background" - skip_longhands="background-color background-repeat background-image" + skip_longhands="${skip_background_longhands}" skip_additionals="*"> <% impl_color("background_color", "mBackgroundColor") %> @@ -759,18 +763,18 @@ fn static_assert() { } fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) { - use style::properties::longhands::background_repeat::computed_value::T as Computed; + use style::properties::longhands::background_repeat::computed_value::T; use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT}; use gecko_bindings::structs::nsStyleImageLayers_Repeat; let (repeat_x, repeat_y) = match v { - Computed::repeat_x => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT, - NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT), - Computed::repeat_y => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT, - NS_STYLE_IMAGELAYER_REPEAT_REPEAT), - Computed::repeat => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT, - NS_STYLE_IMAGELAYER_REPEAT_REPEAT), - Computed::no_repeat => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT, - NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT), + T::repeat_x => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT, + NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT), + T::repeat_y => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT, + NS_STYLE_IMAGELAYER_REPEAT_REPEAT), + T::repeat => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT, + NS_STYLE_IMAGELAYER_REPEAT_REPEAT), + T::no_repeat => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT, + NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT), }; self.gecko.mImage.mRepeatCount = 1; @@ -780,6 +784,59 @@ fn static_assert() { }; } + fn copy_background_clip_from(&mut self, other: &Self) { + self.gecko.mImage.mClipCount = other.gecko.mImage.mClipCount; + self.gecko.mImage.mLayers.mFirstElement.mClip = + other.gecko.mImage.mLayers.mFirstElement.mClip; + } + + fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) { + use style::properties::longhands::background_clip::computed_value::T; + self.gecko.mImage.mClipCount = 1; + + // TODO: Gecko supports background-clip: text, but just on -webkit- + // prefixed properties. + self.gecko.mImage.mLayers.mFirstElement.mClip = match v { + T::border_box => structs::NS_STYLE_IMAGELAYER_CLIP_BORDER as u8, + T::padding_box => structs::NS_STYLE_IMAGELAYER_CLIP_PADDING as u8, + T::content_box => structs::NS_STYLE_IMAGELAYER_CLIP_CONTENT as u8, + }; + } + + fn copy_background_origin_from(&mut self, other: &Self) { + self.gecko.mImage.mOriginCount = other.gecko.mImage.mOriginCount; + self.gecko.mImage.mLayers.mFirstElement.mOrigin = + other.gecko.mImage.mLayers.mFirstElement.mOrigin; + } + + fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) { + use style::properties::longhands::background_origin::computed_value::T; + + self.gecko.mImage.mOriginCount = 1; + self.gecko.mImage.mLayers.mFirstElement.mOrigin = match v { + T::border_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_BORDER as u8, + T::padding_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_PADDING as u8, + T::content_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_CONTENT as u8, + }; + } + + fn copy_background_attachment_from(&mut self, other: &Self) { + self.gecko.mImage.mAttachmentCount = other.gecko.mImage.mAttachmentCount; + self.gecko.mImage.mLayers.mFirstElement.mAttachment = + other.gecko.mImage.mLayers.mFirstElement.mAttachment; + } + + fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) { + use style::properties::longhands::background_attachment::computed_value::T; + + self.gecko.mImage.mAttachmentCount = 1; + self.gecko.mImage.mLayers.mFirstElement.mAttachment = match v { + T::scroll => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL as u8, + T::fixed => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED as u8, + T::local => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL as u8, + }; + } + fn copy_background_image_from(&mut self, other: &Self) { unsafe { Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage, From 827c71d8ca1bd00e189e5a89d5974b53d3179296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 16 Jun 2016 11:27:37 +0200 Subject: [PATCH 2/2] geckolib: Cap background-xxx properties at 1 --- ports/geckolib/properties.mako.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index e1336492881..a49eeb5ab16 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -757,7 +757,7 @@ fn static_assert() { <% impl_color("background_color", "mBackgroundColor") %> fn copy_background_repeat_from(&mut self, other: &Self) { - self.gecko.mImage.mRepeatCount = other.gecko.mImage.mRepeatCount; + self.gecko.mImage.mRepeatCount = cmp::min(1, other.gecko.mImage.mRepeatCount); self.gecko.mImage.mLayers.mFirstElement.mRepeat = other.gecko.mImage.mLayers.mFirstElement.mRepeat; } @@ -785,7 +785,7 @@ fn static_assert() { } fn copy_background_clip_from(&mut self, other: &Self) { - self.gecko.mImage.mClipCount = other.gecko.mImage.mClipCount; + self.gecko.mImage.mClipCount = cmp::min(1, other.gecko.mImage.mClipCount); self.gecko.mImage.mLayers.mFirstElement.mClip = other.gecko.mImage.mLayers.mFirstElement.mClip; } @@ -804,7 +804,7 @@ fn static_assert() { } fn copy_background_origin_from(&mut self, other: &Self) { - self.gecko.mImage.mOriginCount = other.gecko.mImage.mOriginCount; + self.gecko.mImage.mOriginCount = cmp::min(1, other.gecko.mImage.mOriginCount); self.gecko.mImage.mLayers.mFirstElement.mOrigin = other.gecko.mImage.mLayers.mFirstElement.mOrigin; } @@ -821,7 +821,7 @@ fn static_assert() { } fn copy_background_attachment_from(&mut self, other: &Self) { - self.gecko.mImage.mAttachmentCount = other.gecko.mImage.mAttachmentCount; + self.gecko.mImage.mAttachmentCount = cmp::min(1, other.gecko.mImage.mAttachmentCount); self.gecko.mImage.mLayers.mFirstElement.mAttachment = other.gecko.mImage.mLayers.mFirstElement.mAttachment; }