ladybird/Libraries/LibWeb/SVG/SVGPathElement.cpp
Aliaksandr Kalenik 317075e8b0 LibWeb: Invalidate layout when SVGPathElement attributes change
SVGPathElement::get_path() produces a path based on the d attribute.
During layout, this path is copied into paintables. If the d attribute
changes after layout, the path stored in the paintable becomes stale.
Fix by calling set_needs_layout_update() when it changes so the path
is recomputed.
2026-02-05 15:43:41 +01:00

46 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Optional.h>
#include <LibGfx/Path.h>
#include <LibWeb/Bindings/SVGPathElementPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/Layout/SVGGeometryBox.h>
#include <LibWeb/SVG/SVGPathElement.h>
namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGPathElement);
SVGPathElement::SVGPathElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGGeometryElement(document, move(qualified_name))
{
}
void SVGPathElement::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPathElement);
Base::initialize(realm);
}
void SVGPathElement::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 == "d") {
m_path = AttributeParser::parse_path_data(value.value_or(String {}));
if (layout_node())
layout_node()->set_needs_layout_update(DOM::SetNeedsLayoutReason::StyleChange);
}
}
Gfx::Path SVGPathElement::get_path(CSSPixelSize)
{
return m_path.to_gfx_path();
}
}