LibWeb: Move common SVGViewport code into an SVGFitToViewBox class

Special handling for SVGClipPathElement and SVGMaskElement, which use a
a ViewBox and PreserveAspectRatio value internally, has been moved to
`SVGFormattingContext`.
This commit is contained in:
Tim Ledbetter 2025-08-27 22:17:33 +01:00 committed by Jelle Raaijmakers
commit ea41aba6c7
Notes: github-actions[bot] 2025-08-28 13:44:09 +00:00
16 changed files with 144 additions and 152 deletions

View file

@ -24,13 +24,13 @@ void SVGViewElement::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGViewElement);
Base::initialize(realm);
m_view_box_for_bindings = realm.create<SVGAnimatedRect>(realm);
SVGFitToViewBox::initialize(realm);
}
void SVGViewElement::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_view_box_for_bindings);
SVGFitToViewBox::visit_edges(visitor);
}
bool SVGViewElement::is_presentational_hint(FlyString const& name) const
@ -52,21 +52,7 @@ void SVGViewElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties>
void SVGViewElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{
Base::attribute_changed(name, old_value, value, namespace_);
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox)) {
if (!value.has_value()) {
m_view_box_for_bindings->set_nulled(true);
} else {
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 });
}
}
}
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::preserveAspectRatio))
m_preserve_aspect_ratio = AttributeParser::parse_preserve_aspect_ratio(value.value_or(String {}));
SVGFitToViewBox::attribute_changed(*this, name, value);
}
}