mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb: Don't crash when calling getBBox() on the outermost SVG element
This commit is contained in:
parent
7a26de7464
commit
b140206a91
Notes:
github-actions[bot]
2024-09-07 12:35:52 +00:00
Author: https://github.com/tcl3
Commit: b140206a91
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1307
3 changed files with 17 additions and 1 deletions
|
@ -262,6 +262,7 @@ Optional<float> SVGGraphicsElement::stroke_width() const
|
|||
return width.to_px(*layout_node(), scaled_viewport_size).to_double();
|
||||
}
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#__svg__SVGGraphicsElement__getBBox
|
||||
JS::NonnullGCPtr<Geometry::DOMRect> SVGGraphicsElement::get_b_box(Optional<SVGBoundingBoxOptions>)
|
||||
{
|
||||
// FIXME: It should be possible to compute this without layout updates. The bounding box is within the
|
||||
|
@ -272,7 +273,10 @@ JS::NonnullGCPtr<Geometry::DOMRect> SVGGraphicsElement::get_b_box(Optional<SVGBo
|
|||
if (!layout_node())
|
||||
return Geometry::DOMRect::create(realm());
|
||||
// Invert the SVG -> screen space transform.
|
||||
auto svg_element_rect = shadow_including_first_ancestor_of_type<SVG::SVGSVGElement>()->paintable_box()->absolute_rect();
|
||||
auto owner_svg_element = this->owner_svg_element();
|
||||
if (!owner_svg_element)
|
||||
return Geometry::DOMRect::create(realm());
|
||||
auto svg_element_rect = owner_svg_element->paintable_box()->absolute_rect();
|
||||
auto inverse_transform = static_cast<Painting::SVGGraphicsPaintable&>(*paintable_box()).computed_transforms().svg_to_css_pixels_transform().inverse();
|
||||
auto translated_rect = paintable_box()->absolute_rect().to_type<float>().translated(-svg_element_rect.location().to_type<float>());
|
||||
if (inverse_transform.has_value())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue