From e723d72570226e4bd031037713d9ab8d1e5201f4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 13 Jun 2016 14:01:03 +0100 Subject: [PATCH] Move the initialize_data method out of the TNode trait. This reduces the dependency of TNode implementations on layout types. --- components/layout/wrapper.rs | 27 +++++++++++++-------------- components/style/dom.rs | 6 ------ ports/geckolib/wrapper.rs | 18 +++++++++--------- 3 files changed, 22 insertions(+), 29 deletions(-) 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> { 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; diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index b36e8fd7463..7a4125717c5 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -81,6 +81,15 @@ impl<'ln> GeckoNode<'ln> { Gecko_GetNodeData(self.node) as NonOpaqueStyleData } } + + pub fn initialize_data(self) { + unsafe { + if self.get_node_data().is_null() { + let ptr: NonOpaqueStyleData = Box::into_raw(box RefCell::new(PrivateStyleData::new())); + Gecko_SetNodeData(self.node, ptr as *mut ServoNodeData); + } + } + } } #[derive(Clone, Copy)] @@ -132,15 +141,6 @@ impl<'ln> TNode for GeckoNode<'ln> { OpaqueNode(ptr) } - fn initialize_data(self) { - unsafe { - if self.get_node_data().is_null() { - let ptr: NonOpaqueStyleData = Box::into_raw(box RefCell::new(PrivateStyleData::new())); - Gecko_SetNodeData(self.node, ptr as *mut ServoNodeData); - } - } - } - fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option> { if self.opaque() == reflow_root { None