mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 18:00:31 +00:00
Add unsafe_layout_node(), unsafe_paintable(), and unsafe_paintable_box() accessors that skip layout-staleness verification. These are for use in contexts where accessing layout/paintable data is legitimate despite layout not being up to date: tree construction, style recalculation, painting, animation interpolation, DOM mutation, and invalidation propagation. Also add wrapper APIs on Node to centralize common patterns: - set_needs_display() wraps if (unsafe_paintable()) ...set_needs_display - set_needs_paint_only_properties_update() wraps similar - set_needs_layout_update() wraps if (unsafe_layout_node()) ... And add Document::layout_is_up_to_date() which checks whether layout tree update flags are all clear.
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibGfx/Path.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/Bindings/SVGPolygonElementPrototype.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
|
#include <LibWeb/SVG/SVGPolygonElement.h>
|
|
|
|
namespace Web::SVG {
|
|
|
|
GC_DEFINE_ALLOCATOR(SVGPolygonElement);
|
|
|
|
SVGPolygonElement::SVGPolygonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
: SVGGeometryElement(document, qualified_name)
|
|
{
|
|
}
|
|
|
|
void SVGPolygonElement::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPolygonElement);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void SVGPolygonElement::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 == SVG::AttributeNames::points) {
|
|
m_points = AttributeParser::parse_points(value.value_or(String {}));
|
|
set_needs_layout_update(DOM::SetNeedsLayoutReason::StyleChange);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|