Move the initialize_data method out of the TNode trait.

This reduces the dependency of TNode implementations on layout types.
This commit is contained in:
Ms2ger 2016-06-13 14:01:03 +01:00
parent ae5cb0ceb0
commit e723d72570
3 changed files with 22 additions and 29 deletions

View file

@ -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

View file

@ -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>;

View file

@ -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<GeckoNode<'ln>> {
if self.opaque() == reflow_root {
None