style: Move root font size handling outside of the cascade. draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 07 Jul 2017 20:27:42 +0200
changeset 605443 68509badb6f69659e4c806a858823452140ff027
parent 605442 040091fd888b375bf1e55853e8a45342b42bcecf
child 605444 231bb86bd99242194dcc94d327f20a6f10d03dba
child 605653 08432c438c1a011b9a615c36a45277f62f77f3d2
push id67406
push userbmo:emilio+bugs@crisal.io
push dateFri, 07 Jul 2017 18:39:02 +0000
milestone56.0a1
style: Move root font size handling outside of the cascade. And merge it with the rest of the code handling root font-size changes. MozReview-Commit-ID: 3rW1C3mXiMd
servo/components/style/matching.rs
servo/components/style/properties/properties.mako.rs
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -336,17 +336,16 @@ trait PrivateMatchMethods: TElement {
             cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP)
         }
         if cascade_visited.visited_dependent_only() {
             cascade_flags.insert(VISITED_DEPENDENT_ONLY);
         }
         if self.is_native_anonymous() || cascade_target == CascadeTarget::EagerPseudo {
             cascade_flags.insert(PROHIBIT_DISPLAY_CONTENTS);
         } else if self.is_root() {
-            debug_assert!(self.owner_doc_matches_for_testing(shared_context.stylist.device()));
             cascade_flags.insert(IS_ROOT_ELEMENT);
         }
 
         // Grab the inherited values.
         let parent_el;
         let element_and_style; // So parent_el and style_to_inherit_from are known live.
         let style_to_inherit_from = match cascade_target {
             CascadeTarget::Normal => {
@@ -558,19 +557,24 @@ trait PrivateMatchMethods: TElement {
                 // The new root font-size has already been updated on the Device
                 // in properties::apply_declarations.
                 let device = context.shared.stylist.device();
                 let new_font_size = new_values.get_font().clone_font_size();
 
                 // If the root font-size changed since last time, and something
                 // in the document did use rem units, ensure we recascade the
                 // entire tree.
-                if old_values.map_or(false, |v| v.get_font().clone_font_size() != new_font_size) &&
-                   device.used_root_font_size() {
-                    child_cascade_requirement = ChildCascadeRequirement::MustCascadeDescendants;
+                if old_values.map_or(true, |v| v.get_font().clone_font_size() != new_font_size) {
+                    // FIXME(emilio): This can fire when called from a document
+                    // from the bfcache (bug 1376897).
+                    debug_assert!(self.owner_doc_matches_for_testing(device));
+                    device.set_root_font_size(new_font_size);
+                    if device.used_root_font_size() {
+                        child_cascade_requirement = ChildCascadeRequirement::MustCascadeDescendants;
+                    }
                 }
             }
         }
 
         // Set the new computed values.
         let primary_inputs = context.cascade_inputs_mut().primary_mut();
         cascade_visited.set_primary_values(&mut data.styles,
                                            primary_inputs,
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -2896,21 +2896,16 @@ pub fn apply_declarations<'a, F, I>(devi
                                                  inherited_style,
                                                  default_style,
                                                  &mut context,
                                                  &mut cacheable,
                                                  &mut cascade_info,
                                                  error_reporter);
             % endif
             }
-
-            if context.is_root_element {
-                let s = context.style.get_font().clone_font_size();
-                context.device.set_root_font_size(s);
-            }
         % endif
     % endfor
 
     let mut style = context.style;
 
     {
         StyleAdjuster::new(&mut style)
             .adjust(context.layout_parent_style, flags);
@@ -2933,17 +2928,16 @@ pub fn apply_declarations<'a, F, I>(devi
            seen.contains(LonghandId::FontFamily) {
             style.mutate_font().compute_font_hash();
         }
     % endif
 
     style.build()
 }
 
-
 /// See StyleAdjuster::adjust_for_border_width.
 pub fn adjust_border_width(style: &mut StyleBuilder) {
     % for side in ["top", "right", "bottom", "left"]:
         // Like calling to_computed_value, which wouldn't type check.
         if style.get_border().clone_border_${side}_style().none_or_hidden() &&
            style.get_border().border_${side}_has_nonzero_width() {
             style.mutate_border().set_border_${side}_width(Au(0));
         }