diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-08-10 21:02:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-10 21:02:30 -0500 |
commit | 1b2450339c40dbcb65e94a346ea434d45f0edf90 (patch) | |
tree | 5678ca02c5ed91097d523ab523c623bf6fef3408 /components/layout | |
parent | 3c7de6b82165d251e37f699d8f724fba0a0f4556 (diff) | |
parent | 9b8eac000f86badbd0224d1cb5b183c091fe7c1b (diff) | |
download | servo-1b2450339c40dbcb65e94a346ea434d45f0edf90.tar.gz servo-1b2450339c40dbcb65e94a346ea434d45f0edf90.zip |
Auto merge of #12757 - emilio:stylo, r=bholley,pcwalton
stylo: Stop restyling display: none elements, remove the has_changed hack that made us use ReconstructFrame unconditionally.
<!-- Please describe your changes on the following line: -->
---
<!-- 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
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
r? @bholley
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12757)
<!-- Reviewable:end -->
Diffstat (limited to 'components/layout')
-rw-r--r-- | components/layout/animation.rs | 2 | ||||
-rw-r--r-- | components/layout/construct.rs | 8 | ||||
-rw-r--r-- | components/layout/query.rs | 37 | ||||
-rw-r--r-- | components/layout/traversal.rs | 9 |
4 files changed, 47 insertions, 9 deletions
diff --git a/components/layout/animation.rs b/components/layout/animation.rs index 5222d4ba70a..71a388dcf0c 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -135,7 +135,7 @@ pub fn recalc_style_for_animations(context: &SharedLayoutContext, update_style_for_animation(&context.style_context, animation, &mut fragment.style); - damage |= RestyleDamage::compute(Some(&old_style), &fragment.style); + damage |= RestyleDamage::compute(&old_style, &fragment.style); } } }); diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 809ecaa406a..33b88f6b8c0 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -1374,12 +1374,20 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> // We visit the kids first and reset their HAS_NEWLY_CONSTRUCTED_FLOW flags after checking // them. NOTE: Make sure not to bail out early before resetting all the flags! let mut need_to_reconstruct = false; + + // If the node has display: none, it's possible that we haven't even + // styled the children once, so we need to bailout early here. + if node.style(self.style_context()).get_box().clone_display() == display::T::none { + return false; + } + for kid in node.children() { if kid.flags().contains(HAS_NEWLY_CONSTRUCTED_FLOW) { kid.remove_flags(HAS_NEWLY_CONSTRUCTED_FLOW); need_to_reconstruct = true } } + if need_to_reconstruct { return false } diff --git a/components/layout/query.rs b/components/layout/query.rs index ee06f3865ba..d8742973460 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -30,6 +30,7 @@ use std::ops::Deref; use std::sync::{Arc, Mutex}; use string_cache::Atom; use style::computed_values; +use style::context::StyleContext; use style::logical_geometry::{WritingMode, BlockFlowDirection, InlineBaseDirection}; use style::properties::longhands::{display, position}; use style::properties::style_structs; @@ -37,7 +38,7 @@ use style::selector_impl::PseudoElement; use style::selector_matching::Stylist; use style::values::LocalToCss; use style_traits::cursor::Cursor; -use wrapper::ThreadSafeLayoutNodeHelpers; +use wrapper::{LayoutNodeLayoutData, ThreadSafeLayoutNodeHelpers}; /// Mutable data belonging to the LayoutThread. /// @@ -620,11 +621,39 @@ pub fn process_node_scroll_area_request< N: LayoutNode>(requested_node: N, layou } } +/// Ensures that a node's data, and all its parents' is initialized. This is +/// needed to resolve style lazily. +fn ensure_node_data_initialized<N: LayoutNode>(node: &N) { + let mut cur = Some(node.clone()); + while let Some(current) = cur { + if current.borrow_data().is_some() { + break; + } + + current.initialize_data(); + cur = current.parent_node(); + } +} + /// Return the resolved value of property for a given (pseudo)element. /// https://drafts.csswg.org/cssom/#resolved-value -pub fn process_resolved_style_request<N: LayoutNode>( - requested_node: N, pseudo: &Option<PseudoElement>, - property: &Atom, layout_root: &mut FlowRef) -> Option<String> { +pub fn process_resolved_style_request<'a, N, C>(requested_node: N, + style_context: &'a C, + pseudo: &Option<PseudoElement>, + property: &Atom, + layout_root: &mut FlowRef) -> Option<String> + where N: LayoutNode, + C: StyleContext<'a> +{ + use style::traversal::ensure_node_styled; + + // This node might have display: none, or it's style might be not up to + // date, so we might need to do style recalc. + // + // FIXME(emilio): Is a bit shame we have to do this instead of in style. + ensure_node_data_initialized(&requested_node); + ensure_node_styled(requested_node, style_context); + let layout_node = requested_node.to_threadsafe(); let layout_node = match *pseudo { Some(PseudoElement::Before) => layout_node.get_before_pseudo(), diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index f9dcd975f9c..a8c94c52715 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -16,6 +16,7 @@ use std::mem; use style::context::SharedStyleContext; use style::dom::TNode; use style::selector_impl::ServoSelectorImpl; +use style::traversal::RestyleResult; use style::traversal::{DomTraversalContext, remove_from_bloom_filter, recalc_style_at}; use util::opts; use wrapper::{LayoutNodeLayoutData, ThreadSafeLayoutNodeHelpers}; @@ -69,12 +70,12 @@ impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc> } } - fn process_preorder(&self, node: N) { - // FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML - // parser. + fn process_preorder(&self, node: N) -> RestyleResult { + // FIXME(pcwalton): Stop allocating here. Ideally this should just be + // done by the HTML parser. node.initialize_data(); - recalc_style_at(&self.context, self.root, node); + recalc_style_at(&self.context, self.root, node) } fn process_postorder(&self, node: N) { |