diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-10-26 12:48:59 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-10-26 12:49:13 +0200 |
commit | 4d4fa69018c25a0f06c971aafa17f9e7c01621fc (patch) | |
tree | 86f183ca582c5d3fedc3f9cfead8defaabbf1b5c /components/layout_thread/dom_wrapper.rs | |
parent | 6c796b50ec273b6320c27e47b44a9bdfba20c26b (diff) | |
download | servo-4d4fa69018c25a0f06c971aafa17f9e7c01621fc.tar.gz servo-4d4fa69018c25a0f06c971aafa17f9e7c01621fc.zip |
style: Introduce a TDocument trait.
This will be useful for querySelector optimizations.
Diffstat (limited to 'components/layout_thread/dom_wrapper.rs')
-rw-r--r-- | components/layout_thread/dom_wrapper.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index fdf93bf66b8..c26b3a57315 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -69,7 +69,7 @@ use style::computed_values::display; use style::context::SharedStyleContext; use style::data::ElementData; use style::dom::{DomChildren, LayoutIterator, NodeInfo, OpaqueNode}; -use style::dom::{TElement, TNode}; +use style::dom::{TDocument, TElement, TNode}; use style::element_state::*; use style::font_metrics::ServoMetricsProvider; use style::properties::{ComputedValues, PropertyDeclarationBlock}; @@ -139,10 +139,6 @@ impl<'ln> ServoLayoutNode<'ln> { self.node.type_id_for_layout() } } - - pub fn as_document(&self) -> Option<ServoLayoutDocument<'ln>> { - self.node.downcast().map(ServoLayoutDocument::from_layout_js) - } } impl<'ln> NodeInfo for ServoLayoutNode<'ln> { @@ -158,6 +154,7 @@ impl<'ln> NodeInfo for ServoLayoutNode<'ln> { } impl<'ln> TNode for ServoLayoutNode<'ln> { + type ConcreteDocument = ServoLayoutDocument<'ln>; type ConcreteElement = ServoLayoutElement<'ln>; fn parent_node(&self) -> Option<Self> { @@ -206,6 +203,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { as_element(self.node) } + fn as_document(&self) -> Option<ServoLayoutDocument<'ln>> { + self.node.downcast().map(ServoLayoutDocument::from_layout_js) + } + fn can_be_fragmented(&self) -> bool { unsafe { self.node.get_flag(CAN_BE_FRAGMENTED) } } @@ -287,11 +288,15 @@ pub struct ServoLayoutDocument<'ld> { chain: PhantomData<&'ld ()>, } -impl<'ld> ServoLayoutDocument<'ld> { - fn as_node(&self) -> ServoLayoutNode<'ld> { +impl<'ld> TDocument for ServoLayoutDocument<'ld> { + type ConcreteNode = ServoLayoutNode<'ld>; + + fn as_node(&self) -> Self::ConcreteNode { ServoLayoutNode::from_layout_js(self.document.upcast()) } +} +impl<'ld> ServoLayoutDocument<'ld> { pub fn root_element(&self) -> Option<ServoLayoutElement<'ld>> { self.as_node().dom_children().flat_map(|n| n.as_element()).next() } |