aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/dom.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/dom.rs')
-rw-r--r--components/layout/dom.rs38
1 files changed, 29 insertions, 9 deletions
diff --git a/components/layout/dom.rs b/components/layout/dom.rs
index 6db4dbccd41..add4b3ac2d5 100644
--- a/components/layout/dom.rs
+++ b/components/layout/dom.rs
@@ -2,18 +2,21 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+use std::any::Any;
use std::marker::PhantomData;
use std::sync::Arc;
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use base::id::{BrowsingContextId, PipelineId};
use html5ever::{local_name, ns};
+use malloc_size_of_derive::MallocSizeOf;
use pixels::Image;
use script_layout_interface::wrapper_traits::{
LayoutDataTrait, LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
};
use script_layout_interface::{
- HTMLCanvasDataSource, LayoutElementType, LayoutNodeType as ScriptLayoutNodeType,
+ GenericLayoutDataTrait, HTMLCanvasDataSource, LayoutElementType,
+ LayoutNodeType as ScriptLayoutNodeType,
};
use servo_arc::Arc as ServoArc;
use style::properties::ComputedValues;
@@ -31,7 +34,7 @@ use crate::table::TableLevelBox;
use crate::taffy::TaffyItemBox;
/// The data that is stored in each DOM node that is used by layout.
-#[derive(Default)]
+#[derive(Default, MallocSizeOf)]
pub struct InnerDOMLayoutData {
pub(super) self_box: ArcRefCell<Option<LayoutBox>>,
pub(super) pseudo_before_box: ArcRefCell<Option<LayoutBox>>,
@@ -54,10 +57,11 @@ impl InnerDOMLayoutData {
}
/// A box that is stored in one of the `DOMLayoutData` slots.
+#[derive(MallocSizeOf)]
pub(super) enum LayoutBox {
DisplayContents,
BlockLevel(ArcRefCell<BlockLevelBox>),
- InlineLevel(ArcRefCell<InlineItem>),
+ InlineLevel(Vec<ArcRefCell<InlineItem>>),
FlexLevel(ArcRefCell<FlexLevelBox>),
TableLevelBox(TableLevelBox),
TaffyItemBox(ArcRefCell<TaffyItemBox>),
@@ -70,8 +74,10 @@ impl LayoutBox {
LayoutBox::BlockLevel(block_level_box) => {
block_level_box.borrow().invalidate_cached_fragment()
},
- LayoutBox::InlineLevel(inline_item) => {
- inline_item.borrow().invalidate_cached_fragment()
+ LayoutBox::InlineLevel(inline_items) => {
+ for inline_item in inline_items.iter() {
+ inline_item.borrow().invalidate_cached_fragment()
+ }
},
LayoutBox::FlexLevel(flex_level_box) => {
flex_level_box.borrow().invalidate_cached_fragment()
@@ -87,7 +93,10 @@ impl LayoutBox {
match self {
LayoutBox::DisplayContents => vec![],
LayoutBox::BlockLevel(block_level_box) => block_level_box.borrow().fragments(),
- LayoutBox::InlineLevel(inline_item) => inline_item.borrow().fragments(),
+ LayoutBox::InlineLevel(inline_items) => inline_items
+ .iter()
+ .flat_map(|inline_item| inline_item.borrow().fragments())
+ .collect(),
LayoutBox::FlexLevel(flex_level_box) => flex_level_box.borrow().fragments(),
LayoutBox::TaffyItemBox(taffy_item_box) => taffy_item_box.borrow().fragments(),
LayoutBox::TableLevelBox(table_box) => table_box.fragments(),
@@ -98,11 +107,16 @@ impl LayoutBox {
/// A wrapper for [`InnerDOMLayoutData`]. This is necessary to give the entire data
/// structure interior mutability, as we will need to mutate the layout data of
/// non-mutable DOM nodes.
-#[derive(Default)]
+#[derive(Default, MallocSizeOf)]
pub struct DOMLayoutData(AtomicRefCell<InnerDOMLayoutData>);
// The implementation of this trait allows the data to be stored in the DOM.
impl LayoutDataTrait for DOMLayoutData {}
+impl GenericLayoutDataTrait for DOMLayoutData {
+ fn as_any(&self) -> &dyn Any {
+ self
+ }
+}
pub struct BoxSlot<'dom> {
pub(crate) slot: Option<ArcRefCell<Option<LayoutBox>>>,
@@ -255,6 +269,7 @@ where
}
LayoutNode::layout_data(&self)
.unwrap()
+ .as_any()
.downcast_ref::<DOMLayoutData>()
.unwrap()
.0
@@ -262,8 +277,13 @@ where
}
fn layout_data(self) -> Option<AtomicRef<'dom, InnerDOMLayoutData>> {
- LayoutNode::layout_data(&self)
- .map(|data| data.downcast_ref::<DOMLayoutData>().unwrap().0.borrow())
+ LayoutNode::layout_data(&self).map(|data| {
+ data.as_any()
+ .downcast_ref::<DOMLayoutData>()
+ .unwrap()
+ .0
+ .borrow()
+ })
}
fn element_box_slot(&self) -> BoxSlot<'dom> {