servo: Merge #16094 - Bug 1349885: stylo: Simplify computation of float and position (from emilio:simplify-float-pos); r=heycam,upsuper
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 23 Mar 2017 05:35:28 -0700
changeset 399695 95c2c1e23977c9a6bd8748dfda6737a520129574
parent 399694 24d718f4a6c244aad50b982518118e498e0953ed
child 399696 17050f0040ef42bc2a921807702ad731c94fcbf6
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, upsuper
bugs1349885
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16094 - Bug 1349885: stylo: Simplify computation of float and position (from emilio:simplify-float-pos); r=heycam,upsuper Source-Repo: https://github.com/servo/servo Source-Revision: 9d0b481789167a330b614240e73668d7d33632fe
servo/components/style/properties/longhand/box.mako.rs
servo/components/style/properties/properties.mako.rs
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -98,58 +98,23 @@
 </%helpers:longhand>
 
 ${helpers.single_keyword("-moz-top-layer", "none top",
                          gecko_constant_prefix="NS_STYLE_TOP_LAYER",
                          gecko_ffi_name="mTopLayer", need_clone=True,
                          products="gecko", animatable=False, internal=True,
                          spec="Internal (not web-exposed)")}
 
-<%helpers:single_keyword_computed name="position"
-                                  values="static absolute relative fixed"
-                                  need_clone="True"
-                                  extra_gecko_values="sticky"
-                                  animatable="False"
-                                  creates_stacking_context="True"
-                                  abspos_cb="True"
-                                  spec="https://drafts.csswg.org/css-position/#position-property">
-    impl SpecifiedValue {
-        pub fn is_absolutely_positioned_style(&self) -> bool {
-            matches!(*self, SpecifiedValue::absolute | SpecifiedValue::fixed)
-        }
-    }
-
-    use values::HasViewportPercentage;
-    no_viewport_percentage!(SpecifiedValue);
-    impl ToComputedValue for SpecifiedValue {
-        type ComputedValue = computed_value::T;
-
-        #[inline]
-        fn to_computed_value(&self, _context: &Context) -> computed_value::T {
-            % if product == "gecko":
-                // https://fullscreen.spec.whatwg.org/#new-stacking-layer
-                // Any position value other than 'absolute' and 'fixed' are
-                // computed to 'absolute' if the element is in a top layer.
-                if !self.is_absolutely_positioned_style() &&
-                   matches!(_context.style().get_box().clone__moz_top_layer(),
-                            longhands::_moz_top_layer::SpecifiedValue::top) {
-                    SpecifiedValue::absolute
-                } else {
-                    *self
-                }
-            % else:
-                *self
-            % endif
-        }
-        #[inline]
-        fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
-            *computed
-        }
-    }
-</%helpers:single_keyword_computed>
+${helpers.single_keyword("position", "static absolute relative fixed",
+                         need_clone="True",
+                         extra_gecko_values="sticky",
+                         animatable="False",
+                         creates_stacking_context="True",
+                         abspos_cb="True",
+                         spec="https://drafts.csswg.org/css-position/#position-property")}
 
 <%helpers:single_keyword_computed name="float"
                                   values="none left right"
                                   // https://drafts.csswg.org/css-logical-props/#float-clear
                                   extra_specified="inline-start inline-end"
                                   needs_conversion="True"
                                   animatable="False"
                                   need_clone="True"
@@ -159,30 +124,26 @@
                                   spec="https://drafts.csswg.org/css-box/#propdef-float">
     use values::HasViewportPercentage;
     no_viewport_percentage!(SpecifiedValue);
     impl ToComputedValue for SpecifiedValue {
         type ComputedValue = computed_value::T;
 
         #[inline]
         fn to_computed_value(&self, context: &Context) -> computed_value::T {
-            if context.style().get_box().clone_position().is_absolutely_positioned_style() {
-                computed_value::T::none
-            } else {
-                let ltr = context.style().writing_mode.is_bidi_ltr();
-                // https://drafts.csswg.org/css-logical-props/#float-clear
-                match *self {
-                    SpecifiedValue::inline_start if ltr => computed_value::T::left,
-                    SpecifiedValue::inline_start => computed_value::T::right,
-                    SpecifiedValue::inline_end if ltr => computed_value::T::right,
-                    SpecifiedValue::inline_end => computed_value::T::left,
-                    % for value in "none left right".split():
-                        SpecifiedValue::${value} => computed_value::T::${value},
-                    % endfor
-                }
+            let ltr = context.style().writing_mode.is_bidi_ltr();
+            // https://drafts.csswg.org/css-logical-props/#float-clear
+            match *self {
+                SpecifiedValue::inline_start if ltr => computed_value::T::left,
+                SpecifiedValue::inline_start => computed_value::T::right,
+                SpecifiedValue::inline_end if ltr => computed_value::T::right,
+                SpecifiedValue::inline_end => computed_value::T::left,
+                % for value in "none left right".split():
+                    SpecifiedValue::${value} => computed_value::T::${value},
+                % endfor
             }
         }
         #[inline]
         fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
             match *computed {
                 % for value in "none left right".split():
                     computed_value::T::${value} => SpecifiedValue::${value},
                 % endfor
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -1945,16 +1945,17 @@ pub fn cascade(device: &Device,
                        cascade_info,
                        error_reporter,
                        None,
                        flags)
 }
 
 /// NOTE: This function expects the declaration with more priority to appear
 /// first.
+#[allow(unused_mut)] // conditionally compiled code for "position"
 pub fn apply_declarations<'a, F, I>(device: &Device,
                                     is_root_element: bool,
                                     iter_declarations: F,
                                     inherited_style: &ComputedValues,
                                     layout_parent_style: &ComputedValues,
                                     mut cascade_info: Option<<&mut CascadeInfo>,
                                     error_reporter: &ParseErrorReporter,
                                     font_metrics_provider: Option<<&FontMetricsProvider>,
@@ -2045,18 +2046,16 @@ pub fn apply_declarations<'a, F, I>(devi
             // "early" properties then "other".
             //
             // Unfortunately, it’s not easy to check that this
             // classification is correct.
             let is_early_property = matches!(longhand_id,
                 LonghandId::FontSize |
                 LonghandId::FontFamily |
                 LonghandId::Color |
-                LonghandId::Position |
-                LonghandId::Float |
                 LonghandId::TextDecorationLine |
                 LonghandId::WritingMode |
                 LonghandId::Direction
                 % if product == 'gecko':
                     | LonghandId::TextOrientation
                     | LonghandId::AnimationName
                     | LonghandId::TransitionProperty
                 % endif
@@ -2089,19 +2088,34 @@ pub fn apply_declarations<'a, F, I>(devi
         % if category_to_cascade_now == "early":
             let writing_mode = get_writing_mode(context.style.get_inheritedbox());
             context.style.writing_mode = writing_mode;
         % endif
     % endfor
 
     let mut style = context.style;
 
-    let positioned = matches!(style.get_box().clone_position(),
+    let mut positioned = matches!(style.get_box().clone_position(),
         longhands::position::SpecifiedValue::absolute |
         longhands::position::SpecifiedValue::fixed);
+
+    // https://fullscreen.spec.whatwg.org/#new-stacking-layer
+    // Any position value other than 'absolute' and 'fixed' are
+    // computed to 'absolute' if the element is in a top layer.
+    % if product == "gecko":
+        if !positioned &&
+            matches!(style.get_box().clone__moz_top_layer(),
+                     longhands::_moz_top_layer::SpecifiedValue::top) {
+            positioned = true;
+            style.mutate_box().set_position(longhands::position::computed_value::T::absolute);
+        }
+    % endif
+
+    let positioned = positioned; // To ensure it's not mutated further.
+
     let floated = style.get_box().clone_float() != longhands::float::computed_value::T::none;
     let is_item = matches!(context.layout_parent_style.get_box().clone_display(),
         % if product == "gecko":
         computed_values::display::T::grid |
         computed_values::display::T::inline_grid |
         % endif
         computed_values::display::T::flex |
         computed_values::display::T::inline_flex);