Make OpaqueLayoutAndStyleData just a bit less opaque

It now stores a NonNull<dyn Any>.
This commit is contained in:
Anthony Ramine 2020-04-02 13:17:44 +02:00
parent e47e884cc7
commit 4c61baee30
11 changed files with 83 additions and 65 deletions

View file

@ -8,8 +8,7 @@ use script_layout_interface::StyleData;
#[repr(C)]
pub struct StyleAndLayoutData {
/// Data accessed by script_layout_interface. This must be first to allow
/// casting between StyleAndLayoutData and StyleData.
/// The style data associated with a node.
pub style_data: StyleData,
/// The layout data associated with a node.
pub layout_data: AtomicRefCell<LayoutData>,

View file

@ -6,6 +6,7 @@
use crate::construct::ConstructionResult;
use crate::context::LayoutContext;
use crate::data::StyleAndLayoutData;
use crate::display_list::items::{DisplayList, OpaqueNode, ScrollOffsetMap};
use crate::display_list::IndexableText;
use crate::flow::{Flow, GetBaseFlow};
@ -26,7 +27,6 @@ use script_layout_interface::rpc::{OffsetParentResponse, ResolvedStyleResponse,
use script_layout_interface::wrapper_traits::{
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
};
use script_layout_interface::StyleData;
use script_layout_interface::{LayoutElementType, LayoutNodeType};
use script_traits::LayoutMsg as ConstellationMsg;
use script_traits::UntrustedNodeAddress;
@ -1037,8 +1037,13 @@ fn inner_text_collection_steps<'dom>(
};
let element_data = unsafe {
node.get_style_and_layout_data()
.map(|d| &(*(d.ptr.as_ptr() as *mut StyleData)).element_data)
&node.get_style_and_layout_data().as_ref().map(|opaque| {
&opaque
.downcast_ref::<StyleAndLayoutData>()
.unwrap()
.style_data
.element_data
})
};
if element_data.is_none() {

View file

@ -73,7 +73,7 @@ where
// flow construction:
// (1) They child doesn't yet have layout data (preorder traversal initializes it).
// (2) The parent element has restyle damage (so the text flow also needs fixup).
node.get_raw_data().is_none() || !parent_data.damage.is_empty()
(unsafe { node.get_raw_data().is_none() }) || !parent_data.damage.is_empty()
}
fn shared_context(&self) -> &SharedStyleContext {

View file

@ -52,11 +52,11 @@ where
T: GetLayoutData<'dom>,
{
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>> {
self.get_raw_data().map(|d| d.layout_data.borrow())
unsafe { self.get_raw_data().map(|d| d.layout_data.borrow()) }
}
fn mutate_layout_data(&self) -> Option<AtomicRefMut<LayoutData>> {
self.get_raw_data().map(|d| d.layout_data.borrow_mut())
unsafe { self.get_raw_data().map(|d| d.layout_data.borrow_mut()) }
}
fn flow_debug_id(self) -> usize {
@ -66,18 +66,16 @@ where
}
pub trait GetRawData {
fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
}
impl<'dom, T> GetRawData for T
where
T: GetLayoutData<'dom>,
{
fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
self.get_style_and_layout_data().map(|opaque| {
let container = opaque.ptr.as_ptr() as *mut StyleAndLayoutData;
unsafe { &*container }
})
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
self.get_style_and_layout_data()
.map(|opaque| opaque.downcast_ref().unwrap())
}
}
@ -146,7 +144,7 @@ where
debug_assert!(node.is_element());
}
let damage = {
let damage = unsafe {
let data = node.get_raw_data().unwrap();
if !data