diff options
author | Anthony Ramine <nox@nox.paris> | 2020-04-06 14:42:05 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-04-06 23:06:13 +0200 |
commit | 030a1cf8fb040155ca4c5a414f6e2ca01f7574ad (patch) | |
tree | 675917251fd55babce50e521e0ab28f7538a352c /components/script_layout_interface | |
parent | 88d79fe46d51a1d5416a1c09b795f089d0b4899a (diff) | |
download | servo-030a1cf8fb040155ca4c5a414f6e2ca01f7574ad.tar.gz servo-030a1cf8fb040155ca4c5a414f6e2ca01f7574ad.zip |
Replace OpaqueStyleAndLayoutData by StyleAndOpaqueLayoutData
Diffstat (limited to 'components/script_layout_interface')
-rw-r--r-- | components/script_layout_interface/lib.rs | 39 | ||||
-rw-r--r-- | components/script_layout_interface/wrapper_traits.rs | 18 |
2 files changed, 27 insertions, 30 deletions
diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index 6fb859aa112..651c0815f9f 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -29,12 +29,13 @@ use std::any::Any; use std::sync::atomic::AtomicIsize; use style::data::ElementData; -#[repr(C)] +#[derive(MallocSizeOf)] pub struct StyleData { /// Data that the style system associates with a node. When the /// style system is being used standalone, this is all that hangs /// off the node. This must be first to permit the various /// transmutations between ElementData and PersistentLayoutData. + #[ignore_malloc_size_of = "This probably should not be ignored"] pub element_data: AtomicRefCell<ElementData>, /// Information needed during parallel traversals. @@ -50,37 +51,33 @@ impl StyleData { } } +pub type StyleAndOpaqueLayoutData = StyleAndGenericData<dyn Any + Send + Sync>; + #[derive(MallocSizeOf)] -pub struct OpaqueStyleAndLayoutData { - // NB: We really store a `StyleAndLayoutData` here, so be careful! +pub struct StyleAndGenericData<T> +where + T: ?Sized, +{ + /// The style data. + pub style_data: StyleData, + /// The opaque layout data. #[ignore_malloc_size_of = "Trait objects are hard"] - ptr: Box<dyn Any + Send + Sync>, + pub generic_data: T, } -impl OpaqueStyleAndLayoutData { - #[inline] - pub fn new<T>(value: T) -> Self - where - T: Any + Send + Sync, - { - Self { - ptr: Box::new(value) as Box<dyn Any + Send + Sync>, - } - } - - /// Extremely cursed. +impl StyleAndOpaqueLayoutData { #[inline] - pub fn downcast_ref<T>(&self) -> Option<&T> + pub fn new<T>(style_data: StyleData, layout_data: T) -> Box<Self> where T: Any + Send + Sync, { - self.ptr.downcast_ref() + Box::new(StyleAndGenericData { + style_data, + generic_data: layout_data, + }) } } -#[allow(unsafe_code)] -unsafe impl Send for OpaqueStyleAndLayoutData {} - /// Information that we need stored in each DOM node. #[derive(MallocSizeOf)] pub struct DomParallelInfo { diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 5d7768cbe12..2056129244b 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -7,8 +7,8 @@ use crate::HTMLCanvasData; use crate::HTMLMediaData; use crate::LayoutNodeType; -use crate::OpaqueStyleAndLayoutData; use crate::SVGSVGData; +use crate::StyleAndOpaqueLayoutData; use atomic_refcell::AtomicRef; use gfx_traits::{combine_id_with_fragment_type, ByteIndex, FragmentType}; use html5ever::{LocalName, Namespace}; @@ -79,13 +79,13 @@ impl PseudoElementType { } /// Trait to abstract access to layout data across various data structures. -pub trait GetOpaqueStyleAndLayoutData<'dom> { - fn get_opaque_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData>; +pub trait GetStyleAndOpaqueLayoutData<'dom> { + fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData>; } /// A wrapper so that layout can access only the methods that it should have access to. Layout must /// only ever see these and must never see instances of `LayoutDom`. -pub trait LayoutNode<'dom>: Debug + GetOpaqueStyleAndLayoutData<'dom> + TNode { +pub trait LayoutNode<'dom>: Debug + GetStyleAndOpaqueLayoutData<'dom> + TNode { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>; fn to_threadsafe(&self) -> Self::ConcreteThreadSafeLayoutNode; @@ -93,8 +93,8 @@ pub trait LayoutNode<'dom>: Debug + GetOpaqueStyleAndLayoutData<'dom> + TNode { fn type_id(&self) -> LayoutNodeType; unsafe fn initialize_data(&self); - unsafe fn init_opaque_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData); - unsafe fn take_opaque_style_and_layout_data(&self) -> OpaqueStyleAndLayoutData; + unsafe fn init_style_and_opaque_layout_data(&self, data: Box<StyleAndOpaqueLayoutData>); + unsafe fn take_style_and_opaque_layout_data(&self) -> Box<StyleAndOpaqueLayoutData>; fn rev_children(self) -> LayoutIterator<ReverseChildrenIterator<Self>> { LayoutIterator(ReverseChildrenIterator { @@ -160,7 +160,7 @@ where /// A thread-safe version of `LayoutNode`, used during flow construction. This type of layout /// node does not allow any parents or siblings of nodes to be accessed, to avoid races. pub trait ThreadSafeLayoutNode<'dom>: - Clone + Copy + Debug + GetOpaqueStyleAndLayoutData<'dom> + NodeInfo + PartialEq + Sized + Clone + Copy + Debug + GetStyleAndOpaqueLayoutData<'dom> + NodeInfo + PartialEq + Sized { type ConcreteNode: LayoutNode<'dom, ConcreteThreadSafeLayoutNode = Self>; type ConcreteElement: TElement; @@ -224,7 +224,7 @@ pub trait ThreadSafeLayoutNode<'dom>: .map_or(PseudoElementType::Normal, |el| el.get_pseudo_element_type()) } - fn get_opaque_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData>; + fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData>; fn style(&self, context: &SharedStyleContext) -> Arc<ComputedValues> { if let Some(el) = self.as_element() { @@ -319,7 +319,7 @@ pub trait ThreadSafeLayoutElement<'dom>: + Sized + Debug + ::selectors::Element<Impl = SelectorImpl> - + GetOpaqueStyleAndLayoutData<'dom> + + GetStyleAndOpaqueLayoutData<'dom> { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode< 'dom, |