mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-22 17:01:54 +00:00
More things need this than just the `<path>` element, so let's avoid having to include `SVGPathElement.h` in places that don't need it. Minor changes at the same time: - Wrap it in a Path class - Specify underlying type for PathInstructionType - Make a couple of free functions into methods - Give PathInstruction an operator== No functionality changes.
43 lines
1.1 KiB
C++
43 lines
1.1 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 {}));
|
|
}
|
|
|
|
Gfx::Path SVGPathElement::get_path(CSSPixelSize)
|
|
{
|
|
return m_path.to_gfx_path();
|
|
}
|
|
|
|
}
|