Make layout_parent_style be a member of StyleAdjuster. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Wed, 05 Jul 2017 12:00:05 +1000
changeset 604458 1039de49b1cdecbe7a4606ca9d296a0077eb7f0f
parent 604457 26ea03b68c291b52cbe7adb4c36891b7041fcb4d
child 604459 6969081ef1f3f13159da4dbf60d53e4cb74043a6
push id67082
push userxquan@mozilla.com
push dateWed, 05 Jul 2017 23:14:29 +0000
reviewersheycam
milestone56.0a1
Make layout_parent_style be a member of StyleAdjuster. r?heycam MozReview-Commit-ID: 65HPZ4Gk3DZ
servo/components/style/properties/properties.mako.rs
servo/components/style/style_adjuster.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -2911,18 +2911,18 @@ pub fn apply_declarations<'a, F, I>(devi
                 context.device.set_root_font_size(s);
             }
         % endif
     % endfor
 
     let mut style = context.style;
 
     {
-        StyleAdjuster::new(&mut style)
-            .adjust(context.layout_parent_style, flags);
+        StyleAdjuster::new(&mut style, context.layout_parent_style)
+            .adjust(flags);
     }
 
     % if product == "gecko":
         if let Some(ref mut bg) = style.get_background_if_mutated() {
             bg.fill_arrays();
         }
 
         if let Some(ref mut svg) = style.get_svg_if_mutated() {
--- a/servo/components/style/style_adjuster.rs
+++ b/servo/components/style/style_adjuster.rs
@@ -12,23 +12,26 @@ use properties::longhands::display::comp
 use properties::longhands::float::computed_value::T as float;
 use properties::longhands::overflow_x::computed_value::T as overflow;
 use properties::longhands::position::computed_value::T as position;
 
 
 /// An unsized struct that implements all the adjustment methods.
 pub struct StyleAdjuster<'a, 'b: 'a> {
     style: &'a mut StyleBuilder<'b>,
+    layout_parent_style: &'a ComputedValues,
 }
 
 impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     /// Trivially constructs a new StyleAdjuster.
-    pub fn new(style: &'a mut StyleBuilder<'b>) -> Self {
+    pub fn new(style: &'a mut StyleBuilder<'b>,
+               layout_parent_style: &'a ComputedValues) -> Self {
         StyleAdjuster {
-            style: style,
+            style,
+            layout_parent_style,
         }
     }
 
     /// 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.
     ///
@@ -46,31 +49,29 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     fn adjust_for_position(&mut self) {
         if self.style.out_of_flow_positioned() && self.style.floated() {
             self.style.mutate_box().set_float(float::none);
         }
     }
 
     /// Apply the blockification rules based on the table in CSS 2.2 section 9.7.
     /// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo
-    fn blockify_if_necessary(&mut self,
-                             layout_parent_style: &ComputedValues,
-                             flags: CascadeFlags) {
+    fn blockify_if_necessary(&mut self, flags: CascadeFlags) {
         let mut blockify = false;
         macro_rules! blockify_if {
             ($if_what:expr) => {
                 if !blockify {
                     blockify = $if_what;
                 }
             }
         }
 
         if !flags.contains(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) {
             blockify_if!(flags.contains(IS_ROOT_ELEMENT));
-            blockify_if!(layout_parent_style.get_box().clone_display().is_item_container());
+            blockify_if!(self.layout_parent_style.get_box().clone_display().is_item_container());
         }
 
         let is_item_or_root = blockify;
 
         blockify_if!(self.style.floated());
         blockify_if!(self.style.out_of_flow_positioned());
 
         if !blockify {
@@ -128,20 +129,20 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     ///        - If the box has a specified display of inline, its display
     ///          computes to inline-block. [CSS21]
     ///
     /// This matches the adjustment that Gecko does, not exactly following
     /// the spec. See also:
     ///
     /// https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html
     /// https://github.com/servo/servo/issues/15754
-    fn adjust_for_writing_mode(&mut self,
-                               layout_parent_style: &ComputedValues) {
+    fn adjust_for_writing_mode(&mut self) {
         let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode();
-        let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode();
+        let parent_writing_mode =
+            self.layout_parent_style.get_inheritedbox().clone_writing_mode();
 
         if our_writing_mode != parent_writing_mode &&
            self.style.get_box().clone_display() == display::inline {
             self.style.mutate_box().set_display(display::inline_block);
         }
     }
 
     #[cfg(feature = "gecko")]
@@ -189,24 +190,24 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
         }
     }
 
     /// This implements an out-of-date spec. The new spec moves the handling of
     /// this to layout, which Gecko implements but Servo doesn't.
     ///
     /// See https://github.com/servo/servo/issues/15229
     #[cfg(feature = "servo")]
-    fn adjust_for_alignment(&mut self, layout_parent_style: &ComputedValues) {
+    fn adjust_for_alignment(&mut self) {
         use computed_values::align_items::T as align_items;
         use computed_values::align_self::T as align_self;
 
         if self.style.get_position().clone_align_self() == align_self::auto &&
            !self.style.out_of_flow_positioned() {
             let self_align =
-                match layout_parent_style.get_position().clone_align_items() {
+                match self.layout_parent_style.get_position().clone_align_items() {
                     align_items::stretch => align_self::stretch,
                     align_items::baseline => align_self::baseline,
                     align_items::flex_start => align_self::flex_start,
                     align_items::flex_end => align_self::flex_end,
                     align_items::center => align_self::center,
                 };
             self.style.mutate_position().set_align_self(self_align);
         }
@@ -313,33 +314,32 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     }
 
     /// Adjusts the style to account for various fixups that don't fit naturally
     /// into the cascade.
     ///
     /// When comparing to Gecko, this is similar to the work done by
     /// `nsStyleContext::ApplyStyleFixups`.
     pub fn adjust(&mut self,
-                  layout_parent_style: &ComputedValues,
                   flags: CascadeFlags) {
         #[cfg(feature = "gecko")]
         {
             self.adjust_for_prohibited_display_contents(flags);
         }
         self.adjust_for_top_layer();
-        self.blockify_if_necessary(layout_parent_style, flags);
+        self.blockify_if_necessary(flags);
         self.adjust_for_position();
         self.adjust_for_overflow();
         #[cfg(feature = "gecko")]
         {
             self.adjust_for_table_text_align();
             self.adjust_for_contain();
             self.adjust_for_mathvariant();
         }
         #[cfg(feature = "servo")]
         {
-            self.adjust_for_alignment(layout_parent_style);
+            self.adjust_for_alignment();
         }
         self.adjust_for_border_width();
         self.adjust_for_outline();
-        self.adjust_for_writing_mode(layout_parent_style);
+        self.adjust_for_writing_mode();
     }
 }
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1659,17 +1659,17 @@ pub extern "C" fn Servo_ComputedValues_I
     let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style);
 
     let for_text = target == structs::InheritTarget::Text;
     let style = if let Some(reference) = maybe_arc.as_ref() {
         let mut style =
             StyleBuilder::for_inheritance(reference,
                                           &data.default_computed_values());
         if for_text {
-            StyleAdjuster::new(&mut style)
+            StyleAdjuster::new(&mut style, reference)
                 .adjust_for_text();
         }
 
         Arc::new(style.build())
     } else {
         debug_assert!(!for_text);
         data.default_computed_values().clone()
     };