servo: Merge #15710 - Implement gecko glue for clip property (from canaltinova:clip); r=emilio
authorNazım Can Altınova <canaltinova@gmail.com>
Fri, 24 Feb 2017 07:44:48 -0800
changeset 373765 b02bd54b83e26bb80755b67acb493c5567afa022
parent 373764 23114a28082a06937c9ecb104f3b45c8f9f3ab05
child 373766 de5f5cec4080f2a711375c60980cae85f2c067ec
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs15710, 10294, 10316, 1341728
milestone54.0a1
servo: Merge #15710 - Implement gecko glue for clip property (from canaltinova:clip); r=emilio <!-- Please describe your changes on the following line: --> Implemented gecko glue for clip property. Clip property looks slightly different in gecko. `auto` top and left values are preserved as auto in [gecko](http://searchfox.org/mozilla-central/rev/39e4b25a076c59d2e7820297d62319f167871449/layout/style/nsRuleNode.cpp#10294,10316) but converted to 0 in [servo](https://dxr.mozilla.org/servo/rev/65624dbfc28442b58145215f524eb13aeb2cadf6/components/style/values/specified/mod.rs#942). Gecko is setting `NS_STYLE_CLIP_TOP_AUTO` and `NS_STYLE_CLIP_LEFT_AUTO` flags with that information. But I tried this property in stylo build and it is working correctly like this. It looks like it doesn't change the outcome of the property. ~Do we really need to set these flags?~ Manishearth and bz said that auto and 0 values are same. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix [Bug 1341728](https://bugzilla.mozilla.org/show_bug.cgi?id=1341728) <!-- Either: --> - [X] These changes do not require tests because this is stylo side change. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 050d9d909749f5d549b4dfdf69690bd1b5486836
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/effects.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2303,17 +2303,17 @@ fn static_assert() {
     pub fn set__x_span(&mut self, v: longhands::_x_span::computed_value::T) {
         self.gecko.mSpan = v.0
     }
 
     ${impl_simple_copy('_x_span', 'mSpan')}
 </%self:impl_trait>
 
 <%self:impl_trait style_struct_name="Effects"
-                  skip_longhands="box-shadow filter">
+                  skip_longhands="box-shadow clip filter">
     pub fn set_box_shadow(&mut self, v: longhands::box_shadow::computed_value::T) {
 
         self.gecko.mBoxShadow.replace_with_new(v.0.len() as u32);
 
         for (servo, gecko_shadow) in v.0.into_iter()
                                       .zip(self.gecko.mBoxShadow.iter_mut()) {
 
             gecko_shadow.mXOffset = servo.offset_x.0;
@@ -2348,16 +2348,58 @@ fn static_assert() {
                 spread_radius: Au(shadow.mSpread),
                 inset: shadow.mInset,
                 color: Color::RGBA(convert_nscolor_to_rgba(shadow.mColor)),
             }
         }).collect();
         longhands::box_shadow::computed_value::T(buf)
     }
 
+    pub fn set_clip(&mut self, v: longhands::clip::computed_value::T) {
+        use gecko_bindings::structs::NS_STYLE_CLIP_AUTO;
+        use gecko_bindings::structs::NS_STYLE_CLIP_RECT;
+        use gecko_bindings::structs::NS_STYLE_CLIP_RIGHT_AUTO;
+        use gecko_bindings::structs::NS_STYLE_CLIP_BOTTOM_AUTO;
+        use values::Either;
+
+        match v {
+            Either::First(rect) => {
+                self.gecko.mClipFlags = NS_STYLE_CLIP_RECT as u8;
+                self.gecko.mClip.x = rect.left.0;
+                self.gecko.mClip.y = rect.top.0;
+
+                if let Some(bottom) = rect.bottom {
+                    self.gecko.mClip.height = bottom.0 - self.gecko.mClip.y;
+                } else {
+                    self.gecko.mClip.height = 1 << 30; // NS_MAXSIZE
+                    self.gecko.mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO as u8;
+                }
+
+                if let Some(right) = rect.right {
+                    self.gecko.mClip.width = right.0 - self.gecko.mClip.x;
+                } else {
+                    self.gecko.mClip.width = 1 << 30; // NS_MAXSIZE
+                    self.gecko.mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO as u8;
+                }
+            },
+            Either::Second(_auto) => {
+                self.gecko.mClipFlags = NS_STYLE_CLIP_AUTO as u8;
+                self.gecko.mClip.x = 0;
+                self.gecko.mClip.y = 0;
+                self.gecko.mClip.width = 0;
+                self.gecko.mClip.height = 0;
+            }
+        }
+    }
+
+    pub fn copy_clip_from(&mut self, other: &Self) {
+        self.gecko.mClip = other.gecko.mClip;
+        self.gecko.mClipFlags = other.gecko.mClipFlags;
+    }
+
     pub fn set_filter(&mut self, v: longhands::filter::computed_value::T) {
         use properties::longhands::filter::computed_value::Filter::*;
         use gecko_bindings::structs::nsCSSShadowArray;
         use gecko_bindings::structs::nsStyleFilter;
         use gecko_bindings::structs::NS_STYLE_FILTER_BLUR;
         use gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS;
         use gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST;
         use gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE;
--- a/servo/components/style/properties/longhand/effects.mako.rs
+++ b/servo/components/style/properties/longhand/effects.mako.rs
@@ -76,17 +76,16 @@
     }
 </%helpers:vector_longhand>
 
 // FIXME: This prop should be animatable
 ${helpers.predefined_type("clip",
                           "ClipRectOrAuto",
                           "computed::ClipRectOrAuto::auto()",
                           animatable=False,
-                          products="servo",
                           boxed="True",
                           spec="https://drafts.fxtf.org/css-masking/#clip-property")}
 
 // FIXME: This prop should be animatable
 <%helpers:longhand name="filter" animatable="False" extra_prefixes="webkit"
                    spec="https://drafts.fxtf.org/filters/#propdef-filter">
     //pub use self::computed_value::T as SpecifiedValue;
     use cssparser;