LibWeb/SVG: SVGSymbolElement includes SVGFitToViewBox

This commit is contained in:
Jamie Mansfield 2024-07-20 18:32:53 +01:00 committed by Andreas Kling
parent 821416027d
commit 6c7089fc9e
Notes: github-actions[bot] 2024-07-21 11:26:44 +00:00
3 changed files with 21 additions and 2 deletions

View file

@ -13,6 +13,7 @@
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Layout/SVGGraphicsBox.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/SVGAnimatedRect.h>
#include <LibWeb/SVG/SVGSymbolElement.h>
#include <LibWeb/SVG/SVGUseElement.h>
@ -29,6 +30,13 @@ void SVGSymbolElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGSymbolElement);
m_view_box_for_bindings = heap().allocate<SVGAnimatedRect>(realm, realm);
}
void SVGSymbolElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_view_box_for_bindings);
}
// https://svgwg.org/svg2-draft/struct.html#SymbolNotes
@ -45,8 +53,14 @@ void SVGSymbolElement::apply_presentational_hints(CSS::StyleProperties& style) c
void SVGSymbolElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, old_value, value);
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox))
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox)) {
m_view_box = try_parse_view_box(value.value_or(String {}));
m_view_box_for_bindings->set_nulled(!m_view_box.has_value());
if (m_view_box.has_value()) {
m_view_box_for_bindings->set_base_val(Gfx::DoubleRect { m_view_box->min_x, m_view_box->min_y, m_view_box->width, m_view_box->height });
m_view_box_for_bindings->set_anim_val(Gfx::DoubleRect { m_view_box->min_x, m_view_box->min_y, m_view_box->width, m_view_box->height });
}
}
}
bool SVGSymbolElement::is_direct_child_of_use_shadow_tree() const

View file

@ -28,10 +28,13 @@ public:
return {};
}
JS::NonnullGCPtr<SVGAnimatedRect> view_box_for_bindings() { return *m_view_box_for_bindings; }
private:
SVGSymbolElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
@ -40,6 +43,8 @@ private:
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
Optional<ViewBox> m_view_box;
JS::GCPtr<SVGAnimatedRect> m_view_box_for_bindings;
};
}

View file

@ -6,4 +6,4 @@ interface SVGSymbolElement : SVGGraphicsElement {
};
// FIXME: SVGSymbolElement includes SVGFitToViewBox;
SVGSymbolElement includes SVGFitToViewBox;