mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #26105 - servo:layout-2020-less-opaque, r=emilio
Make DOM own the style and layout data, in an UnsafeCell
This commit is contained in:
commit
d64f7d427a
21 changed files with 184 additions and 247 deletions
|
@ -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>,
|
||||
|
|
|
@ -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;
|
||||
|
@ -761,7 +761,7 @@ pub fn process_resolved_style_request<'dom>(
|
|||
|
||||
// We call process_resolved_style_request after performing a whole-document
|
||||
// traversal, so in the common case, the element is styled.
|
||||
if element.get_data().is_some() {
|
||||
if element.has_data() {
|
||||
return process_resolved_style_request_internal(node, pseudo, property, layout_root);
|
||||
}
|
||||
|
||||
|
@ -1036,9 +1036,14 @@ fn inner_text_collection_steps<'dom>(
|
|||
_ => child,
|
||||
};
|
||||
|
||||
let element_data = unsafe {
|
||||
node.get_style_and_layout_data()
|
||||
.map(|d| &(*(d.ptr.as_ptr() as *mut StyleData)).element_data)
|
||||
let 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() {
|
||||
|
|
|
@ -39,23 +39,21 @@ use style::selector_parser::RestyleDamage;
|
|||
use style::values::computed::counters::ContentItem;
|
||||
use style::values::generics::counters::Content;
|
||||
|
||||
pub trait LayoutNodeLayoutData {
|
||||
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
|
||||
/// than only the style::data::ElementData.
|
||||
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>>;
|
||||
fn mutate_layout_data(&self) -> Option<AtomicRefMut<LayoutData>>;
|
||||
pub trait LayoutNodeLayoutData<'dom> {
|
||||
fn borrow_layout_data(self) -> Option<AtomicRef<'dom, LayoutData>>;
|
||||
fn mutate_layout_data(self) -> Option<AtomicRefMut<'dom, LayoutData>>;
|
||||
fn flow_debug_id(self) -> usize;
|
||||
}
|
||||
|
||||
impl<'dom, T> LayoutNodeLayoutData for T
|
||||
impl<'dom, T> LayoutNodeLayoutData<'dom> for T
|
||||
where
|
||||
T: GetLayoutData<'dom>,
|
||||
{
|
||||
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>> {
|
||||
fn borrow_layout_data(self) -> Option<AtomicRef<'dom, LayoutData>> {
|
||||
self.get_raw_data().map(|d| d.layout_data.borrow())
|
||||
}
|
||||
|
||||
fn mutate_layout_data(&self) -> Option<AtomicRefMut<LayoutData>> {
|
||||
fn mutate_layout_data(self) -> Option<AtomicRefMut<'dom, LayoutData>> {
|
||||
self.get_raw_data().map(|d| d.layout_data.borrow_mut())
|
||||
}
|
||||
|
||||
|
@ -65,19 +63,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub trait GetRawData {
|
||||
fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
|
||||
pub trait GetRawData<'dom> {
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData>;
|
||||
}
|
||||
|
||||
impl<'dom, T> GetRawData for T
|
||||
impl<'dom, T> GetRawData<'dom> 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 }
|
||||
})
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData> {
|
||||
self.get_style_and_layout_data()
|
||||
.map(|opaque| opaque.downcast_ref().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue