mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
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:
parent
9b2b28b612
commit
2248d85894
2 changed files with 24 additions and 24 deletions
|
@ -10,8 +10,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
SVGSVGBox <svg> at (8,8) content-size 300x150 [SVG] children: inline
|
SVGSVGBox <svg> at (8,8) content-size 300x150 [SVG] children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
Box <use> at (8,8) content-size 0x0 children: inline
|
Box <use> at (8,8) content-size 215.625x130.90625 children: inline
|
||||||
Box <symbol#braces> at (8,8) content-size 0x0 [BFC] children: inline
|
Box <symbol#braces> at (92.375,26.75) content-size 131.25x112.15625 [BFC] children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
SVGGeometryBox <path> at (92.375,26.75) content-size 131.25x112.15625 children: inline
|
SVGGeometryBox <path> at (92.375,26.75) content-size 131.25x112.15625 children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
|
@ -25,6 +25,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||||
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
|
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
|
||||||
PaintableWithLines (BlockContainer<DIV>) [8,8 784x150]
|
PaintableWithLines (BlockContainer<DIV>) [8,8 784x150]
|
||||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
|
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
|
||||||
PaintableBox (Box<use>) [8,8 0x0]
|
PaintableBox (Box<use>) [8,8 215.625x130.90625]
|
||||||
PaintableBox (Box<symbol>#braces) [8,8 0x0]
|
PaintableBox (Box<symbol>#braces) [92.375,26.75 131.25x112.15625]
|
||||||
SVGPathPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]
|
SVGPathPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <LibWeb/Layout/SVGSVGBox.h>
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||||
#include <LibWeb/Layout/SVGTextBox.h>
|
#include <LibWeb/Layout/SVGTextBox.h>
|
||||||
#include <LibWeb/SVG/SVGForeignObjectElement.h>
|
#include <LibWeb/SVG/SVGForeignObjectElement.h>
|
||||||
|
#include <LibWeb/SVG/SVGGElement.h>
|
||||||
|
#include <LibWeb/SVG/SVGMaskElement.h>
|
||||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||||
#include <LibWeb/SVG/SVGSymbolElement.h>
|
#include <LibWeb/SVG/SVGSymbolElement.h>
|
||||||
#include <LibWeb/SVG/SVGUseElement.h>
|
#include <LibWeb/SVG/SVGUseElement.h>
|
||||||
|
@ -134,16 +136,20 @@ static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio
|
||||||
return viewbox_transform;
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,10 +266,6 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
||||||
} else if (is<SVGSVGBox>(descendant)) {
|
} else if (is<SVGSVGBox>(descendant)) {
|
||||||
SVGFormattingContext nested_context(m_state, static_cast<SVGSVGBox const&>(descendant), this);
|
SVGFormattingContext nested_context(m_state, static_cast<SVGSVGBox const&>(descendant), this);
|
||||||
nested_context.run(static_cast<SVGSVGBox const&>(descendant), layout_mode, available_space);
|
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;
|
return IterationDecision::Continue;
|
||||||
|
@ -273,10 +275,7 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
||||||
// 5.2. Grouping: the ‘g’ element
|
// 5.2. Grouping: the ‘g’ element
|
||||||
// The ‘g’ element is a container element for grouping together related graphics elements.
|
// The ‘g’ element is a container element for grouping together related graphics elements.
|
||||||
box.for_each_in_subtree_of_type<Box>([&](Box const& descendant) {
|
box.for_each_in_subtree_of_type<Box>([&](Box const& descendant) {
|
||||||
if (is<SVGGraphicsBox>(descendant) && !is<SVGGeometryBox>(descendant) && !is<SVGTextBox>(descendant)) {
|
if (is_container_element(descendant)) {
|
||||||
auto const& svg_graphics_box = static_cast<SVGGraphicsBox const&>(descendant);
|
|
||||||
auto& graphics_box_state = m_state.get_mutable(svg_graphics_box);
|
|
||||||
|
|
||||||
Gfx::BoundingBox<CSSPixels> bounding_box;
|
Gfx::BoundingBox<CSSPixels> bounding_box;
|
||||||
descendant.for_each_in_subtree_of_type<Box>([&](Box const& child_of_svg_container) {
|
descendant.for_each_in_subtree_of_type<Box>([&](Box const& child_of_svg_container) {
|
||||||
auto& box_state = m_state.get(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;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
graphics_box_state.set_content_x(bounding_box.x());
|
auto& box_state = m_state.get_mutable(descendant);
|
||||||
graphics_box_state.set_content_y(bounding_box.y());
|
box_state.set_content_x(bounding_box.x());
|
||||||
graphics_box_state.set_content_width(bounding_box.width());
|
box_state.set_content_y(bounding_box.y());
|
||||||
graphics_box_state.set_content_height(bounding_box.height());
|
box_state.set_content_width(bounding_box.width());
|
||||||
|
box_state.set_content_height(bounding_box.height());
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue