From 719709f0d5e0b68b0ad731e091b5a7ccedacdaa4 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 9 Jun 2017 13:43:52 +0800 Subject: [PATCH] style: Add TNode::children_and_traversal_children_might_differ. This will be used to optimize out traversing the real DOM children when propagating restyle hints. --- components/script/layout_wrapper.rs | 6 ++++++ components/style/dom.rs | 4 ++++ components/style/gecko/wrapper.rs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index f8ddbc485a1..bd4d74dcfec 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -185,6 +185,12 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { self.children() } + fn children_and_traversal_children_might_differ(&self) -> bool { + // Servo doesn't have to worry about nodes being rearranged in the + // flattened tree like Gecko does (for XBL and Shadow DOM). Yet. + false + } + fn opaque(&self) -> OpaqueNode { unsafe { self.get_jsmanaged().opaque() } } diff --git a/components/style/dom.rs b/components/style/dom.rs index c50a613d253..318068c8aa9 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -126,6 +126,10 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo { /// Get this node's children from the perspective of a restyle traversal. fn traversal_children(&self) -> LayoutIterator; + /// Returns whether `children()` and `traversal_children()` might return + /// iterators over different nodes. + fn children_and_traversal_children_might_differ(&self) -> bool; + /// Converts self into an `OpaqueNode`. fn opaque(&self) -> OpaqueNode; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 70b36aff533..6c70013d481 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -34,6 +34,7 @@ use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement, Gecko_ use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags}; use gecko_bindings::bindings::Gecko_ClassOrClassList; use gecko_bindings::bindings::Gecko_ElementHasAnimations; +use gecko_bindings::bindings::Gecko_ElementHasBindingWithAnonymousContent; use gecko_bindings::bindings::Gecko_ElementHasCSSAnimations; use gecko_bindings::bindings::Gecko_ElementHasCSSTransitions; use gecko_bindings::bindings::Gecko_GetActiveLinkAttrDeclarationBlock; @@ -271,6 +272,10 @@ impl<'ln> TNode for GeckoNode<'ln> { } } + fn children_and_traversal_children_might_differ(&self) -> bool { + self.as_element().map_or(false, |e| unsafe { Gecko_ElementHasBindingWithAnonymousContent(e.0) }) + } + fn opaque(&self) -> OpaqueNode { let ptr: usize = self.0 as *const _ as usize; OpaqueNode(ptr)