diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2017-02-08 12:47:45 -0800 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2017-02-10 10:34:27 -0800 |
commit | 095265affec010d2ecb42fa633e46929820b4894 (patch) | |
tree | 35136c175eb5d0fc67beb88d87a07b1e87d36c5b | |
parent | 401a55e172e7ebdbc1045400ec4720a6c3f1cb03 (diff) | |
download | servo-095265affec010d2ecb42fa633e46929820b4894.tar.gz servo-095265affec010d2ecb42fa633e46929820b4894.zip |
Hoist some work out of the tail of compute_style into the caller.
This is really part of the "recalc" rather than the "compute" work. But more to
the point, it lets us early-return on the style-sharing stuff (see the next patch).
-rw-r--r-- | components/style/traversal.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/components/style/traversal.rs b/components/style/traversal.rs index f6e75a2efe8..4c608212653 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -428,7 +428,18 @@ pub fn recalc_style_at<E, D>(traversal: &D, // Compute style for this element if necessary. if compute_self { - inherited_style_changed = compute_style(traversal, traversal_data, context, element, &mut data); + compute_style(traversal, traversal_data, context, element, &mut data); + + // If we're restyling this element to display:none, throw away all style + // data in the subtree, notify the caller to early-return. + let display_none = data.styles().is_display_none(); + if display_none { + debug!("New element style is display:none - clearing data from descendants."); + clear_descendant_data(element, &|e| unsafe { D::clear_element_data(&e) }); + } + + // FIXME(bholley): Compute this accurately from the call to CalcStyleDifference. + inherited_style_changed = true; } // Now that matching and cascading is done, clear the bits corresponding to @@ -452,7 +463,7 @@ pub fn recalc_style_at<E, D>(traversal: &D, // Make sure the dirty descendants bit is not set for the root of a // display:none subtree, even if the style didn't change (since, if - // the style did change, we'd have already cleared it in compute_style). + // the style did change, we'd have already cleared it above). // // This keeps the tree in a valid state without requiring the DOM to // check display:none on the parent when inserting new children (which @@ -464,13 +475,11 @@ pub fn recalc_style_at<E, D>(traversal: &D, } } -// Computes style, returning true if the inherited styles changed for this -// element. fn compute_style<E, D>(_traversal: &D, traversal_data: &mut PerLevelTraversalData, context: &mut StyleContext<E>, element: E, - mut data: &mut AtomicRefMut<ElementData>) -> bool + mut data: &mut AtomicRefMut<ElementData>) where E: TElement, D: DomTraversal<E>, { @@ -546,19 +555,6 @@ fn compute_style<E, D>(_traversal: &D, match_results.relations); } } - - // If we're restyling this element to display:none, throw away all style data - // in the subtree, notify the caller to early-return. - let display_none = data.styles().is_display_none(); - if display_none { - debug!("New element style is display:none - clearing data from descendants."); - clear_descendant_data(element, &|e| unsafe { D::clear_element_data(&e) }); - } - - // FIXME(bholley): Compute this accurately from the call to CalcStyleDifference. - let inherited_styles_changed = true; - - inherited_styles_changed } fn preprocess_children<E, D>(traversal: &D, |