ladybird/Userland/Libraries/LibWeb/SVG/SVGPolygonElement.cpp
Shannon Booth bad44f8fc9 LibWeb: Remove Bindings/Forward.h from LibWeb/Forward.h
This was resulting in a whole lot of rebuilding whenever a new IDL
interface was added.

Instead, just directly include the prototype in every C++ file which
needs it. While we only really need a forward declaration in each cpp
file; including the full prototype header (which itself only includes
LibJS/Object.h, which is already transitively brought in by
PlatformObject) - it seems like a small price to pay compared to what
feels like a full rebuild of LibWeb whenever a new IDL file is added.

Given all of these includes are only needed for the ::initialize
method, there is probably a smart way of avoiding this problem
altogether. I've considered both using some macro trickery or generating
these functions somehow instead.
2024-04-27 18:29:35 -04:00

57 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/SVGPolygonElementPrototype.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGPolygonElement.h>
namespace Web::SVG {
JS_DEFINE_ALLOCATOR(SVGPolygonElement);
SVGPolygonElement::SVGPolygonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGGeometryElement(document, qualified_name)
{
}
void SVGPolygonElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPolygonElement);
}
void SVGPolygonElement::attribute_changed(FlyString const& name, Optional<String> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::points)
m_points = AttributeParser::parse_points(value.value_or(String {}));
}
Gfx::Path SVGPolygonElement::get_path(CSSPixelSize)
{
Gfx::Path path;
if (m_points.is_empty())
return path;
// 1. perform an absolute moveto operation to the first coordinate pair in the list of points
path.move_to(m_points.first());
// 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair.
for (size_t point_index = 1; point_index < m_points.size(); ++point_index)
path.line_to(m_points[point_index]);
// 3. perform a closepath command
path.close();
return path;
}
}