LibWeb: Remove should_ensure_creation_of_paintable() SVG hack

The elements this hack was being used for were grouping elements, and
can be properly sized: https://svgwg.org/svg2-draft/struct.html#Groups.

Note: Other than one test change the elements here are already covered
by layout tests.
This commit is contained in:
MacDue 2023-11-12 20:51:23 +00:00 committed by Andreas Kling
parent 9b2b28b612
commit 2248d85894
Notes: sideshowbarker 2024-07-17 08:55:54 +09:00
2 changed files with 24 additions and 24 deletions

View File

@ -10,8 +10,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
TextNode <#text>
SVGSVGBox <svg> at (8,8) content-size 300x150 [SVG] children: inline
TextNode <#text>
Box <use> at (8,8) content-size 0x0 children: inline
Box <symbol#braces> at (8,8) content-size 0x0 [BFC] children: inline
Box <use> at (8,8) content-size 215.625x130.90625 children: inline
Box <symbol#braces> at (92.375,26.75) content-size 131.25x112.15625 [BFC] children: inline
TextNode <#text>
SVGGeometryBox <path> at (92.375,26.75) content-size 131.25x112.15625 children: inline
TextNode <#text>
@ -25,6 +25,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
PaintableWithLines (BlockContainer<DIV>) [8,8 784x150]
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
PaintableBox (Box<use>) [8,8 0x0]
PaintableBox (Box<symbol>#braces) [8,8 0x0]
PaintableBox (Box<use>) [8,8 215.625x130.90625]
PaintableBox (Box<symbol>#braces) [92.375,26.75 131.25x112.15625]
SVGPathPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]

View File

@ -15,6 +15,8 @@
#include <LibWeb/Layout/SVGSVGBox.h>
#include <LibWeb/Layout/SVGTextBox.h>
#include <LibWeb/SVG/SVGForeignObjectElement.h>
#include <LibWeb/SVG/SVGGElement.h>
#include <LibWeb/SVG/SVGMaskElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGSymbolElement.h>
#include <LibWeb/SVG/SVGUseElement.h>
@ -134,16 +136,20 @@ static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio
return viewbox_transform;
}
static bool should_ensure_creation_of_paintable(Node const& node)
static bool is_container_element(Node const& node)
{
if (is<SVGGraphicsBox>(node))
// https://svgwg.org/svg2-draft/struct.html#GroupsOverview
auto* dom_node = node.dom_node();
if (!dom_node)
return false;
if (is<SVG::SVGUseElement>(dom_node))
return true;
if (is<SVG::SVGSymbolElement>(dom_node))
return true;
if (is<SVG::SVGGElement>(dom_node))
return true;
if (is<SVG::SVGMaskElement>(dom_node))
return true;
if (node.dom_node()) {
if (is<SVG::SVGUseElement>(*node.dom_node()))
return true;
if (is<SVG::SVGSymbolElement>(*node.dom_node()))
return true;
}
return false;
}
@ -260,10 +266,6 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
} else if (is<SVGSVGBox>(descendant)) {
SVGFormattingContext nested_context(m_state, static_cast<SVGSVGBox const&>(descendant), this);
nested_context.run(static_cast<SVGSVGBox const&>(descendant), layout_mode, available_space);
} else if (should_ensure_creation_of_paintable(descendant)) {
// NOTE: This hack creates a layout state to ensure the existence of
// a paintable in LayoutState::commit().
m_state.get_mutable(static_cast<NodeWithStyleAndBoxModelMetrics const&>(descendant));
}
return IterationDecision::Continue;
@ -273,10 +275,7 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
// 5.2. Grouping: the g element
// The g element is a container element for grouping together related graphics elements.
box.for_each_in_subtree_of_type<Box>([&](Box const& descendant) {
if (is<SVGGraphicsBox>(descendant) && !is<SVGGeometryBox>(descendant) && !is<SVGTextBox>(descendant)) {
auto const& svg_graphics_box = static_cast<SVGGraphicsBox const&>(descendant);
auto& graphics_box_state = m_state.get_mutable(svg_graphics_box);
if (is_container_element(descendant)) {
Gfx::BoundingBox<CSSPixels> bounding_box;
descendant.for_each_in_subtree_of_type<Box>([&](Box const& child_of_svg_container) {
auto& box_state = m_state.get(child_of_svg_container);
@ -285,10 +284,11 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
return IterationDecision::Continue;
});
graphics_box_state.set_content_x(bounding_box.x());
graphics_box_state.set_content_y(bounding_box.y());
graphics_box_state.set_content_width(bounding_box.width());
graphics_box_state.set_content_height(bounding_box.height());
auto& box_state = m_state.get_mutable(descendant);
box_state.set_content_x(bounding_box.x());
box_state.set_content_y(bounding_box.y());
box_state.set_content_width(bounding_box.width());
box_state.set_content_height(bounding_box.height());
}
return IterationDecision::Continue;
});