mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 09:50:27 +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.
46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/DOM/Element.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
|
#include <LibWeb/SVG/SVGAnimatedRect.h>
|
|
#include <LibWeb/SVG/SVGFitToViewBox.h>
|
|
|
|
namespace Web::SVG {
|
|
|
|
void SVGFitToViewBox::initialize(JS::Realm& realm)
|
|
{
|
|
m_view_box_for_bindings = realm.create<SVGAnimatedRect>(realm);
|
|
}
|
|
|
|
void SVGFitToViewBox::visit_edges(JS::Cell::Visitor& visitor)
|
|
{
|
|
visitor.visit(m_view_box_for_bindings);
|
|
}
|
|
|
|
void SVGFitToViewBox::attribute_changed(DOM::Element& element, FlyString const& name, Optional<String> const& value)
|
|
{
|
|
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 = AttributeParser::parse_viewbox(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 });
|
|
}
|
|
}
|
|
element.set_needs_layout_update(DOM::SetNeedsLayoutReason::SVGViewBoxChange);
|
|
} else if (name.equals_ignoring_ascii_case(SVG::AttributeNames::preserveAspectRatio)) {
|
|
m_preserve_aspect_ratio = AttributeParser::parse_preserve_aspect_ratio(value.value_or(String {}));
|
|
element.set_needs_layout_update(DOM::SetNeedsLayoutReason::SVGViewBoxChange);
|
|
}
|
|
}
|
|
|
|
}
|