LibWeb: Remove Document.h include from SVGElement.h

This reduces the recompilation cascade when Document.h is modified,
cutting off the transitive path through ~30 SVG element headers.

Move the inline try_resolve_url_to() template body in
SVGGraphicsElement.h to a non-template helper in the .cpp file to
avoid needing Document.h and ShadowRoot.h in the header.

Add explicit includes to files that relied on the transitive dependency.
This commit is contained in:
Aliaksandr Kalenik 2026-02-08 17:13:36 +01:00 committed by Alexander Kalenik
parent e76cf3e225
commit edf42ec9f9
12 changed files with 37 additions and 18 deletions

View file

@ -9,6 +9,8 @@
#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/Bindings/HTMLOptionElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentFragment.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLDataListElement.h>

View file

@ -5,6 +5,7 @@
*/
#include <LibWeb/ContentSecurityPolicy/PolicyList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Focus.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/HTMLOrSVGElement.h>

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/InlineFormattingContext.h>

View file

@ -6,9 +6,9 @@
#pragma once
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Export.h>
#include <LibWeb/HTML/GlobalEventHandlers.h>
#include <LibWeb/HTML/HTMLOrSVGElement.h>
#include <LibWeb/SVG/SVGAnimatedString.h>

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibGfx/CompositingAndBlendingOperator.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGAnimatedLength.h>
#include <LibWeb/SVG/SVGElement.h>

View file

@ -8,6 +8,7 @@
#include <LibCore/Timer.h>
#include <LibGfx/ImmutableBitmap.h>
#include <LibWeb/Bindings/SVGFEImageElementPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/DecodedImageData.h>
#include <LibWeb/HTML/PotentialCORSRequest.h>
#include <LibWeb/HTML/SharedResourceRequest.h>

View file

@ -11,6 +11,7 @@
#include <LibWeb/Bindings/SVGGraphicsElementPrototype.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Painting/PaintStyle.h>
#include <LibWeb/Painting/PaintableBox.h>
@ -76,6 +77,27 @@ Optional<Painting::PaintStyle> SVGGraphicsElement::stroke_paint_style(SVGPaintCo
return svg_paint_computed_value_to_gfx_paint_style(paint_context, layout_node()->computed_values().stroke());
}
GC::Ptr<DOM::Element> SVGGraphicsElement::resolve_url_to_element(CSS::URL const& url) const
{
// FIXME: Complete and use the entire URL, not just the fragment.
Optional<FlyString> fragment;
if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
}
if (!fragment.has_value())
return {};
if (auto element = document().get_element_by_id(*fragment))
return element;
auto containing_shadow = containing_shadow_root();
if (containing_shadow) {
if (auto element = containing_shadow->get_element_by_id(*fragment))
return element;
}
return {};
}
GC::Ptr<SVG::SVGMaskElement const> SVGGraphicsElement::mask() const
{
auto const& mask_reference = layout_node()->computed_values().mask();

View file

@ -89,26 +89,12 @@ protected:
Gfx::AffineTransform m_transform = {};
GC::Ptr<DOM::Element> resolve_url_to_element(CSS::URL const& url) const;
template<typename T>
GC::Ptr<T> try_resolve_url_to(CSS::URL const& url) const
{
// FIXME: Complete and use the entire URL, not just the fragment.
Optional<FlyString> fragment;
if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
}
if (!fragment.has_value())
return {};
if (auto node = as_if<T>(document().get_element_by_id(*fragment).ptr()))
return *node;
auto containing_shadow = containing_shadow_root();
if (containing_shadow) {
if (auto node = as_if<T>(containing_shadow->get_element_by_id(*fragment).ptr()))
return *node;
}
return {};
return as_if<T>(resolve_url_to_element(url).ptr());
}
private:

View file

@ -7,6 +7,7 @@
#pragma once
#include <LibGC/Ptr.h>
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
#include <LibWeb/Layout/ImageProvider.h>
#include <LibWeb/SVG/SVGAnimatedLength.h>
#include <LibWeb/SVG/SVGGraphicsElement.h>

View file

@ -6,8 +6,10 @@
*/
#include <LibWeb/Bindings/SVGScriptElementPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/MimeSniff/MimeType.h>

View file

@ -7,6 +7,7 @@
#pragma once
#include <LibWeb/CSS/PercentageOr.h>
#include <LibWeb/SVG/SVGTextContentElement.h>
namespace Web::SVG {

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/FlyString.h>
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
#include <LibWeb/DOM/DocumentObserver.h>
#include <LibWeb/SVG/SVGAnimatedLength.h>
#include <LibWeb/SVG/SVGGraphicsElement.h>