diff options
Diffstat (limited to 'components/layout/wrapper.rs')
-rw-r--r-- | components/layout/wrapper.rs | 58 |
1 files changed, 14 insertions, 44 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 99f9a4cc54d..c37499a12af 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -33,7 +33,8 @@ use core::nonzero::NonZero; use data::{LayoutDataFlags, PersistentLayoutData}; use script_layout_interface::{OpaqueStyleAndLayoutData, PartialPersistentLayoutData}; -use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; +use script_layout_interface::wrapper_traits::{GetLayoutData, LayoutNode}; +use script_layout_interface::wrapper_traits::{ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use style::atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use style::computed_values::content::{self, ContentItem}; @@ -44,11 +45,10 @@ pub trait LayoutNodeLayoutData { /// than only the style::data::NodeData. fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>>; fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>>; - fn initialize_data(self); fn flow_debug_id(self) -> usize; } -impl<T: LayoutNode> LayoutNodeLayoutData for T { +impl<T: GetLayoutData> LayoutNodeLayoutData for T { fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>> { unsafe { self.get_style_and_layout_data().map(|opaque| { @@ -67,6 +67,16 @@ impl<T: LayoutNode> LayoutNodeLayoutData for T { } } + fn flow_debug_id(self) -> usize { + self.borrow_layout_data().map_or(0, |d| d.flow_construction_result.debug_id()) + } +} + +pub trait LayoutNodeHelpers { + fn initialize_data(self); +} + +impl<T: LayoutNode> LayoutNodeHelpers for T { fn initialize_data(self) { if self.borrow_layout_data().is_none() { let ptr: NonOpaqueStyleAndLayoutData = @@ -77,27 +87,9 @@ impl<T: LayoutNode> LayoutNodeLayoutData for T { self.init_style_and_layout_data(opaque); } } - - fn flow_debug_id(self) -> usize { - self.borrow_layout_data().map_or(0, |d| d.flow_construction_result.debug_id()) - } } pub trait ThreadSafeLayoutNodeHelpers { - fn flow_debug_id(self) -> usize; - - /// Borrows the layout data immutably. Fails on a conflicting borrow. - /// - /// TODO(pcwalton): Make this private. It will let us avoid borrow flag checks in some cases. - #[inline(always)] - fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>>; - - /// Borrows the layout data mutably. Fails on a conflicting borrow. - /// - /// TODO(pcwalton): Make this private. It will let us avoid borrow flag checks in some cases. - #[inline(always)] - fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>>; - /// Returns the layout data flags for this node. fn flags(self) -> LayoutDataFlags; @@ -115,28 +107,6 @@ pub trait ThreadSafeLayoutNodeHelpers { } impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T { - fn flow_debug_id(self) -> usize { - self.borrow_layout_data().map_or(0, |d| d.flow_construction_result.debug_id()) - } - - fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>> { - unsafe { - self.get_style_and_layout_data().map(|opaque| { - let container = *opaque.ptr as NonOpaqueStyleAndLayoutData; - (*container).borrow() - }) - } - } - - fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>> { - unsafe { - self.get_style_and_layout_data().map(|opaque| { - let container = *opaque.ptr as NonOpaqueStyleAndLayoutData; - (*container).borrow_mut() - }) - } - } - fn flags(self) -> LayoutDataFlags { self.borrow_layout_data().as_ref().unwrap().flags } @@ -151,7 +121,7 @@ impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T { fn text_content(&self) -> TextContent { if self.get_pseudo_element_type().is_replaced_content() { - let style = self.resolved_style(); + let style = self.as_element().unwrap().resolved_style(); return match style.as_ref().get_counters().content { content::T::Content(ref value) if !value.is_empty() => { |