diff options
author | Anthony Ramine <nox@nox.paris> | 2020-04-27 11:09:06 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-05-19 15:51:55 +0200 |
commit | 518c0660c6eee711252057bd73f75cd35f3d3215 (patch) | |
tree | 8442faa299ced3e959b6b731c4b26ec073e0fe73 /components/script/dom/node.rs | |
parent | 15db31769cb0172be610fe2d731533c30c40fa76 (diff) | |
download | servo-518c0660c6eee711252057bd73f75cd35f3d3215.tar.gz servo-518c0660c6eee711252057bd73f75cd35f3d3215.zip |
Make Node::style_and_layout_data be a DomRefCell<T>
That way we can use borrow_mut_for_layout and borrow_mut.
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r-- | components/script/dom/node.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index a7eda2e3597..7a75ea51503 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -150,12 +150,9 @@ pub struct Node { /// are this node. ranges: WeakRangeVec, - /// Style+Layout information. Only the layout thread may touch this data. - /// - /// Must be sent back to the layout thread to be destroyed when this - /// node is finalized. - #[ignore_malloc_size_of = "Unsafe cell"] - style_and_layout_data: UnsafeCell<Option<Box<StyleAndOpaqueLayoutData>>>, + /// Style+Layout information. + #[ignore_malloc_size_of = "trait object"] + style_and_layout_data: DomRefCell<Option<Box<StyleAndOpaqueLayoutData>>>, } bitflags! { @@ -1246,21 +1243,18 @@ impl Node { } } - #[allow(unsafe_code)] pub fn style(&self) -> Option<Arc<ComputedValues>> { if !window_from_node(self).layout_reflow(QueryMsg::StyleQuery) { return None; } - unsafe { - (*self.style_and_layout_data.get()).as_ref().map(|data| { - data.style_data - .element_data - .borrow() - .styles - .primary() - .clone() - }) - } + self.style_and_layout_data.borrow().as_ref().map(|data| { + data.style_data + .element_data + .borrow() + .styles + .primary() + .clone() + }) } } @@ -1444,13 +1438,21 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData> { - unsafe { (*self.unsafe_get().style_and_layout_data.get()).as_deref() } + unsafe { + self.unsafe_get() + .style_and_layout_data + .borrow_for_layout() + .as_deref() + } } #[inline] #[allow(unsafe_code)] unsafe fn init_style_and_opaque_layout_data(self, val: Box<StyleAndOpaqueLayoutData>) { - let data = &mut *self.unsafe_get().style_and_layout_data.get(); + let data = self + .unsafe_get() + .style_and_layout_data + .borrow_mut_for_layout(); debug_assert!(data.is_none()); *data = Some(val); } @@ -1458,7 +1460,9 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] unsafe fn take_style_and_opaque_layout_data(self) -> Box<StyleAndOpaqueLayoutData> { - (*self.unsafe_get().style_and_layout_data.get()) + self.unsafe_get() + .style_and_layout_data + .borrow_mut_for_layout() .take() .unwrap() } @@ -1775,7 +1779,7 @@ impl Node { inclusive_descendants_version: Cell::new(0), ranges: WeakRangeVec::new(), - style_and_layout_data: UnsafeCell::new(None), + style_and_layout_data: Default::default(), } } |