From 65a8a8dccb51f0d45eff52aa566a6a900c33c849 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 19 Aug 2016 17:09:41 +0530 Subject: [PATCH] Make most background- properties handle arrays --- components/style/properties/gecko.mako.rs | 121 +++++++++--------- components/style/properties/helpers.mako.rs | 5 +- .../properties/longhand/background.mako.rs | 8 ++ .../sugar/ns_style_auto_array.rs | 5 +- 4 files changed, 72 insertions(+), 67 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 2c7e6f0ea1a..e58727fae67 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -937,6 +937,32 @@ fn static_assert() { +<%def name="simple_background_array_property(name, field_name)"> + pub fn copy_background_${name}_from(&mut self, other: &Self) { + unsafe { + Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, other.gecko.mImage.mLayers.len()); + } + for (layer, other) in self.gecko.mImage.mLayers.iter_mut() + .zip(other.gecko.mImage.mLayers.iter()) + .take(other.gecko.mImage.${field_name}Count) { + layer.${field_name} = other.${field_name}; + } + self.gecko.mImage.${field_name}Count = other.gecko.mImage.${field_name}Count; + } + + pub fn set_background_${name}(&mut self, v: longhands::background_${name}::computed_value::T) { + unsafe { + Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, v.0.len()); + } + + self.gecko.mImage.${field_name}Count = v.0.len() as u32; + for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.mImage.mLayers.iter_mut()) { + geckolayer.${field_name} = { + ${caller.body()} + }; + } + } + // 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. @@ -950,86 +976,57 @@ fn static_assert() { <% impl_color("background_color", "mBackgroundColor", need_clone=True) %> - pub fn copy_background_repeat_from(&mut self, other: &Self) { - self.gecko.mImage.mRepeatCount = cmp::min(1, other.gecko.mImage.mRepeatCount); - self.gecko.mImage.mLayers.mFirstElement.mRepeat = - other.gecko.mImage.mLayers.mFirstElement.mRepeat; - } - - pub fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) { - use properties::longhands::background_repeat::computed_value::T; - use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT}; + <%self:simple_background_array_property name="repeat" field_name="mRepeat"> + use properties::longhands::background_repeat::single_value::computed_value::T; use gecko_bindings::structs::nsStyleImageLayers_Repeat; - let (repeat_x, repeat_y) = match v { - 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, + use gecko_bindings::structs::NS_STYLE_IMAGELAYER_REPEAT_REPEAT; + use gecko_bindings::structs::NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT; + + let (repeat_x, repeat_y) = match servo { + 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::no_repeat => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT, - NS_STYLE_IMAGELAYER_REPEAT_NO_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), }; + nsStyleImageLayers_Repeat { + mXRepeat: repeat_x as u8, + mYRepeat: repeat_y as u8, + } + - self.gecko.mImage.mRepeatCount = 1; - self.gecko.mImage.mLayers.mFirstElement.mRepeat = nsStyleImageLayers_Repeat { - mXRepeat: repeat_x as u8, - mYRepeat: repeat_y as u8, - }; - } + <%self:simple_background_array_property name="clip" field_name="mClip"> + use properties::longhands::background_clip::single_value::computed_value::T; - pub fn copy_background_clip_from(&mut self, other: &Self) { - self.gecko.mImage.mClipCount = cmp::min(1, other.gecko.mImage.mClipCount); - self.gecko.mImage.mLayers.mFirstElement.mClip = - other.gecko.mImage.mLayers.mFirstElement.mClip; - } - - pub fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) { - use 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 { + match servo { 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, - }; - } + } + - pub fn copy_background_origin_from(&mut self, other: &Self) { - self.gecko.mImage.mOriginCount = cmp::min(1, other.gecko.mImage.mOriginCount); - self.gecko.mImage.mLayers.mFirstElement.mOrigin = - other.gecko.mImage.mLayers.mFirstElement.mOrigin; - } + <%self:simple_background_array_property name="origin" field_name="mOrigin"> + use properties::longhands::background_origin::single_value::computed_value::T; - pub fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) { - use properties::longhands::background_origin::computed_value::T; - - self.gecko.mImage.mOriginCount = 1; - self.gecko.mImage.mLayers.mFirstElement.mOrigin = match v { + match servo { 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, - }; - } + } + - pub fn copy_background_attachment_from(&mut self, other: &Self) { - self.gecko.mImage.mAttachmentCount = cmp::min(1, other.gecko.mImage.mAttachmentCount); - self.gecko.mImage.mLayers.mFirstElement.mAttachment = - other.gecko.mImage.mLayers.mFirstElement.mAttachment; - } + <%self:simple_background_array_property name="attachment" field_name="mAttachment"> + use properties::longhands::background_attachment::single_value::computed_value::T; - pub fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) { - use properties::longhands::background_attachment::computed_value::T; - - self.gecko.mImage.mAttachmentCount = 1; - self.gecko.mImage.mLayers.mFirstElement.mAttachment = match v { + match servo { 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, - }; - } + } + pub fn copy_background_position_from(&mut self, other: &Self) { self.gecko.mImage.mPositionXCount = cmp::min(1, other.gecko.mImage.mPositionXCount); diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 1f6ed3125c4..ae08f79b293 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -285,9 +285,6 @@ } -<%def name="maybe_vector_longhand(name, maybe, **kwargs)"> - - <%def name="single_keyword(name, values, vector=False, **kwargs)"> <%call expr="single_keyword_computed(name, values, vector, **kwargs)"> use values::computed::ComputedValueAsSpecified; @@ -304,7 +301,7 @@ 'extra_gecko_values', 'extra_servo_values', ]} %> - + <%def name="inner_body()"> pub use self::computed_value::T as SpecifiedValue; pub mod computed_value { diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index c36e6e63e74..3b72d1cc0ef 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -107,18 +107,26 @@ ${helpers.predefined_type("background-color", "CSSColor", ${helpers.single_keyword("background-repeat", "repeat repeat-x repeat-y no-repeat", + vector=True, + gecko_only=True, animatable=False)} ${helpers.single_keyword("background-attachment", "scroll fixed" + (" local" if product == "gecko" else ""), + vector=True, + gecko_only=True, animatable=False)} ${helpers.single_keyword("background-clip", "border-box padding-box content-box", + vector=True, + gecko_only=True, animatable=False)} ${helpers.single_keyword("background-origin", "padding-box border-box content-box", + vector=True, + gecko_only=True, animatable=False)} <%helpers:longhand name="background-size" animatable="True"> diff --git a/ports/geckolib/gecko_bindings/sugar/ns_style_auto_array.rs b/ports/geckolib/gecko_bindings/sugar/ns_style_auto_array.rs index 43728fd979d..b81aa51df52 100644 --- a/ports/geckolib/gecko_bindings/sugar/ns_style_auto_array.rs +++ b/ports/geckolib/gecko_bindings/sugar/ns_style_auto_array.rs @@ -3,13 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::iter::{once, Chain, Once, IntoIterator}; -use std::slice::IterMut; +use std::slice::{Iter, IterMut}; use structs::nsStyleAutoArray; impl nsStyleAutoArray { pub fn iter_mut(&mut self) -> Chain, IterMut> { once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut()) } + pub fn iter(&self) -> Chain, Iter> { + once(&self.mFirstElement).chain(self.mOtherElements.iter()) + } // Note that often structs containing autoarrays will have // additional member fields that contain the length, which must be kept