diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/traversal.rs | 9 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 27 | ||||
-rw-r--r-- | components/style/dom.rs | 6 | ||||
-rw-r--r-- | components/style/traversal.rs | 6 |
4 files changed, 21 insertions, 27 deletions
diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 692d956f000..bd07e1f72bb 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -65,7 +65,14 @@ impl<'lc, 'ln> DomTraversalContext<ServoLayoutNode<'ln>> for RecalcStyleAndConst } } - fn process_preorder(&self, node: ServoLayoutNode<'ln>) { recalc_style_at(&self.context, self.root, node); } + fn process_preorder(&self, node: ServoLayoutNode<'ln>) { + // 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); + } + fn process_postorder(&self, node: ServoLayoutNode<'ln>) { construct_flows_at(&self.context, self.root, node); } } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 303c9f76943..3c18e909bae 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -120,6 +120,19 @@ impl<'ln> ServoLayoutNode<'ln> { chain: self.chain, } } + + pub fn initialize_data(self) { + if unsafe { self.borrow_data_unchecked() }.is_none() { + let ptr: NonOpaqueStyleAndLayoutData = + Box::into_raw(box RefCell::new(PrivateLayoutData::new())); + let opaque = OpaqueStyleAndLayoutData { + ptr: unsafe { NonZero::new(ptr as *mut ()) } + }; + unsafe { + self.node.init_style_and_layout_data(opaque); + } + } + } } impl<'ln> TNode for ServoLayoutNode<'ln> { @@ -158,20 +171,6 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { OpaqueNodeMethods::from_jsmanaged(unsafe { self.get_jsmanaged() }) } - fn initialize_data(self) { - let has_data = unsafe { self.borrow_data_unchecked().is_some() }; - if !has_data { - let ptr: NonOpaqueStyleAndLayoutData = - Box::into_raw(box RefCell::new(PrivateLayoutData::new())); - let opaque = OpaqueStyleAndLayoutData { - ptr: unsafe { NonZero::new(ptr as *mut ()) } - }; - unsafe { - self.node.init_style_and_layout_data(opaque); - } - } - } - fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option<ServoLayoutNode<'ln>> { if self.opaque() == reflow_root { None diff --git a/components/style/dom.rs b/components/style/dom.rs index badd4f31065..7d10b394989 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -86,12 +86,6 @@ pub trait TNode : Sized + Copy + Clone { /// Converts self into an `OpaqueNode`. fn opaque(&self) -> OpaqueNode; - /// Initializes style and layout data for the node. No-op if the data is already - /// initialized. - /// - /// FIXME(pcwalton): Do this as part of fragment building instead of in a traversal. - fn initialize_data(self); - /// While doing a reflow, the node at the root has no parent, as far as we're /// concerned. This method returns `None` at the reflow root. fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option<Self>; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 386af02e5ef..1afdcbb34c7 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -125,12 +125,6 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, where N: TNode, C: StyleContext<'a, <N::ConcreteElement as Element>::Impl>, <N::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues=N::ConcreteComputedValues> + 'a { - // Initialize layout data. - // - // FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML - // parser. - node.initialize_data(); - // Get the parent node. let parent_opt = match node.parent_node() { Some(parent) if parent.is_element() => Some(parent), |