From 08ef158d4e1c38935eb18dc57de2b953368e0771 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 4 Apr 2024 09:56:51 +0200 Subject: script: Split style and layout data in DOM nodes (#31985) This change splits the style and layout data in DOM nodes that is populated by style and layout passes. This makes Servo's data design more like Gecko's. This allows: 1. Removing the various `StyleAndLayout` data structures used by layout. 2. Removing the `GetStyleAndLayoutData` and `GetStyleAndOpaqueLayoutData` traits. Accessing style and layout data are now just functions on the `LayoutNode` and `ThreadSafeLayoutNode` traits. 3. Styling now doesn't populate layout data. This is is postponed until layout itself. 4. Allows the DOM wrappers to no longer have to be generic over the layout data. This data was already stored using `std::any::Any` and the new code just makes layout responsible for downcasting. Cleaning up the generic type parameter in the DOM wrappers can happen in a followup change. The main benefit to all of this is that we should be able to remove unsafe creation of `ServoLayoutNode` in layout and `TrustedLayoutNodeAddress` entirely, because `ServoLayoutNode` will be able to be passed directly from script to layout. In addition, this removes one more abstraction layer from the layout DOM wrappers, making the code a lot more understandable. Note: This increases the measured size of DOM types, but the same data is stored. It's simply that before that data was stored behind a heap pointer. --- components/layout/construct.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'components/layout/construct.rs') diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 35d414283f1..522635543fd 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -43,7 +43,7 @@ use style::LocalName; use crate::block::BlockFlow; use crate::context::{with_thread_local_font_context, LayoutContext}; -use crate::data::{LayoutData, LayoutDataFlags}; +use crate::data::{InnerLayoutData, LayoutDataFlags}; use crate::display_list::items::OpaqueNode; use crate::flex::FlexFlow; use crate::floats::FloatKind; @@ -71,14 +71,15 @@ use crate::table_rowgroup::TableRowGroupFlow; use crate::table_wrapper::TableWrapperFlow; use crate::text::TextRunScanner; use crate::traversal::PostorderNodeMutTraversal; -use crate::wrapper::{LayoutNodeLayoutData, TextContent, ThreadSafeLayoutNodeHelpers}; +use crate::wrapper::{TextContent, ThreadSafeLayoutNodeHelpers}; use crate::{parallel, ServoArc}; /// The results of flow construction for a DOM node. -#[derive(Clone)] +#[derive(Clone, Default)] pub enum ConstructionResult { /// This node contributes nothing at all (`display: none`). Alternately, this is what newly /// created nodes have their `ConstructionResult` set to. + #[default] None, /// This node contributed a flow at the proper position in the tree. @@ -1992,7 +1993,7 @@ trait NodeUtils { /// Returns true if this node doesn't render its kids and false otherwise. fn is_replaced_content(&self) -> bool; - fn construction_result_mut(self, layout_data: &mut LayoutData) -> &mut ConstructionResult; + fn construction_result_mut(self, layout_data: &mut InnerLayoutData) -> &mut ConstructionResult; /// Sets the construction result of a flow. fn set_flow_construction_result(self, result: ConstructionResult); @@ -2029,7 +2030,7 @@ where } } - fn construction_result_mut(self, data: &mut LayoutData) -> &mut ConstructionResult { + fn construction_result_mut(self, data: &mut InnerLayoutData) -> &mut ConstructionResult { match self.get_pseudo_element_type() { PseudoElementType::Before => &mut data.before_flow_construction_result, PseudoElementType::After => &mut data.after_flow_construction_result, -- cgit v1.2.3