Skip to content

Truly independent web browser

LibWeb: Box the SVG facts of a committed fragment

Andreas Klingc279ff99c8e7
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 1c05e8719e1..048512a59f4 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -34,7 +34,8 @@ pub(crate) struct Fragment {
pub(crate) grid_layout_data: Option<std::sync::Arc<grid_formatting_context::GridLayoutData>>,
pub(crate) flex_layout_data: Option<std::sync::Arc<formatting_context::FlexLayoutData>>,
pub(crate) used_grid_tracks: Option<std::sync::Arc<grid_formatting_context::OwnedUsedGridTracks>>,
- pub(crate) svg: CommittedSvgFacts,
+ /// Boxed, as only SVG boxes have any and the facts are larger than the rest of the fragment's box.
+ pub(crate) svg: Option<Box<CommittedSvgFacts>>,
pub(crate) computed_svg_path: Option<std::sync::Arc<libgfx_rust::path::OwnedPath>>,
pub(crate) svg_text_character_cells: Option<std::sync::Arc<Vec<svg_formatting_context::FfiSvgTextCharacterCell>>>,
pub(crate) has_line_clamp_point: bool,
@@ -88,7 +89,7 @@ impl Fragment {
&& self.grid_layout_data.is_none()
&& self.flex_layout_data.is_none()
&& self.used_grid_tracks.is_none()
- && self.svg == CommittedSvgFacts::default()
+ && self.svg.is_none()
&& self.computed_svg_path.is_none()
&& self.svg_text_character_cells.is_none()
&& !self.has_line_clamp_point
@@ -229,7 +230,7 @@ impl FragmentLink {
grid_layout_data: None,
flex_layout_data: None,
used_grid_tracks: None,
- svg: Default::default(),
+ svg: None,
computed_svg_path: None,
svg_text_character_cells: None,
has_line_clamp_point: false,
@@ -461,7 +462,7 @@ fn snapshot_fragment(
grid_layout_data,
flex_layout_data,
used_grid_tracks,
- svg,
+ svg: (svg != CommittedSvgFacts::default()).then(|| Box::new(svg)),
computed_svg_path,
svg_text_character_cells,
has_line_clamp_point: used.has_line_clamp_point.get(),
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
index 4b685309845..68cbc779f63 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
@@ -180,7 +180,9 @@ pub(crate) fn committed_svg_viewport_transform(
arena: &impl GeometryRead,
slot: NodeSlotId,
) -> Option<svg_formatting_context::FfiAffineTransform> {
- arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.svg.viewport_transform))
+ arena.with_committed_fragment_link(slot, |link| {
+ link.and_then(|link| link.fragment.svg.as_ref()?.viewport_transform)
+ })
}
pub(crate) fn committed_svg_viewport_size(arena: &impl GeometryRead, slot: NodeSlotId) -> used_values::FfiCssPixelSize {
@@ -188,7 +190,7 @@ pub(crate) fn committed_svg_viewport_size(arena: &impl GeometryRead, slot: NodeS
return used_values::FfiCssPixelSize::default();
}
arena.with_committed_fragment_link(slot, |link| {
- link.and_then(|link| link.fragment.svg.viewport_size)
+ link.and_then(|link| link.fragment.svg.as_ref()?.viewport_size)
.unwrap_or_default()
})
}
@@ -197,7 +199,9 @@ pub(crate) fn committed_svg_element_transform(
arena: &impl GeometryRead,
slot: NodeSlotId,
) -> Option<svg_formatting_context::FfiAffineTransform> {
- arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.svg.element_transform))
+ arena.with_committed_fragment_link(slot, |link| {
+ link.and_then(|link| link.fragment.svg.as_ref()?.element_transform)
+ })
}
pub(crate) fn committed_svg_additional_element_transform(
@@ -205,7 +209,7 @@ pub(crate) fn committed_svg_additional_element_transform(
slot: NodeSlotId,
) -> Option<svg_formatting_context::FfiAffineTransform> {
arena.with_committed_fragment_link(slot, |link| {
- link.and_then(|link| link.fragment.svg.additional_element_transform)
+ link.and_then(|link| link.fragment.svg.as_ref()?.additional_element_transform)
})
}
@@ -213,14 +217,16 @@ pub(crate) fn committed_svg_mask_area_facts(
arena: &impl GeometryRead,
slot: NodeSlotId,
) -> Option<svg_formatting_context::SvgMaskAreaFacts> {
- arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.svg.mask_area_facts))
+ arena.with_committed_fragment_link(slot, |link| {
+ link.and_then(|link| link.fragment.svg.as_ref()?.mask_area_facts)
+ })
}
pub(crate) fn committed_svg_view_box(
arena: &impl GeometryRead,
slot: NodeSlotId,
) -> Option<svg_formatting_context::FfiSvgViewBox> {
- arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.svg.view_box))
+ arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.svg.as_ref()?.view_box))
}
pub(crate) fn committed_svg_resource_content_units_are_object_bounding_box(
@@ -228,13 +234,19 @@ pub(crate) fn committed_svg_resource_content_units_are_object_bounding_box(
slot: NodeSlotId,
) -> bool {
arena.with_committed_fragment_link(slot, |link| {
- link.is_some_and(|link| link.fragment.svg.resource_content_units_are_object_bounding_box)
+ link.is_some_and(|link| {
+ link.fragment
+ .svg
+ .as_ref()
+ .is_some_and(|svg| svg.resource_content_units_are_object_bounding_box)
+ })
})
}
pub(crate) fn committed_svg_viewport_percentage_basis(arena: &impl GeometryRead, slot: NodeSlotId) -> CssPixels {
arena.with_committed_fragment_link(slot, |link| {
- link.map_or_else(CssPixels::default, |link| link.fragment.svg.viewport_percentage_basis)
+ link.and_then(|link| link.fragment.svg.as_ref())
+ .map_or_else(CssPixels::default, |svg| svg.viewport_percentage_basis)
})
}