LibWeb: Include SVG-as-image isolated contexts in layout/DOM tree dumps

This allows us to see the inside of SVG-as-image in layout tests. :^)
This commit is contained in:
Andreas Kling 2023-05-21 07:02:41 +02:00
parent 24ea78c613
commit 94a26e2715
Notes: sideshowbarker 2024-07-17 02:39:10 +09:00
3 changed files with 43 additions and 1 deletions

View file

@ -2,3 +2,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x1584 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x1568 children: not-inline
ImageBox <img> at (8,8) content-size 784x1568 children: not-inline
(SVG-as-image isolated context)
Viewport <#document> at (0,0) content-size 0x0 children: inline
SVGSVGBox <svg> at (0,0) content-size 0x0 [SVG] children: inline
TextNode <#text>
SVGGeometryBox <rect> at (0,0) content-size 0x0 children: not-inline
TextNode <#text>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
@ -22,15 +22,19 @@
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/HTMLTemplateElement.h>
#include <LibWeb/HTML/ImageRequest.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/FormattingContext.h>
#include <LibWeb/Layout/FrameBox.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/SVGBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/TextPaintable.h>
#include <LibWeb/SVG/SVGDecodedImageData.h>
#include <stdio.h>
namespace Web {
@ -70,6 +74,19 @@ void dump_tree(StringBuilder& builder, DOM::Node const& node)
dump_tree(builder, *shadow_root);
}
}
if (is<HTML::HTMLImageElement>(node)) {
if (auto image_data = static_cast<HTML::HTMLImageElement const&>(node).current_request().image_data()) {
if (is<SVG::SVGDecodedImageData>(*image_data)) {
++indent;
for (int i = 0; i < indent; ++i)
builder.append(" "sv);
builder.append("(SVG-as-image isolated context)\n"sv);
auto& svg_data = verify_cast<SVG::SVGDecodedImageData>(*image_data);
dump_tree(builder, svg_data.svg_document());
--indent;
}
}
}
if (is<DOM::ParentNode>(node)) {
if (!is<HTML::HTMLTemplateElement>(node)) {
static_cast<DOM::ParentNode const&>(node).for_each_child([&](auto& child) {
@ -264,6 +281,23 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
builder.append("\n"sv);
}
if (layout_node.dom_node() && is<HTML::HTMLImageElement>(*layout_node.dom_node())) {
if (auto image_data = static_cast<HTML::HTMLImageElement const&>(*layout_node.dom_node()).current_request().image_data()) {
if (is<SVG::SVGDecodedImageData>(*image_data)) {
auto& svg_data = verify_cast<SVG::SVGDecodedImageData>(*image_data);
if (svg_data.svg_document().layout_node()) {
++indent;
for (size_t i = 0; i < indent; ++i)
builder.append(" "sv);
builder.append("(SVG-as-image isolated context)\n"sv);
dump_tree(builder, *svg_data.svg_document().layout_node(), show_box_model, show_specified_style, interactive);
--indent;
}
}
}
}
if (is<Layout::BlockContainer>(layout_node) && static_cast<Layout::BlockContainer const&>(layout_node).children_are_inline()) {
auto& block = static_cast<Layout::BlockContainer const&>(layout_node);
for (size_t line_box_index = 0; block.paintable_with_lines() && line_box_index < block.paintable_with_lines()->line_boxes().size(); ++line_box_index) {

View file

@ -27,6 +27,8 @@ public:
virtual size_t loop_count() const override { return 0; }
virtual bool is_animated() const override { return false; }
DOM::Document const& svg_document() const { return *m_document; }
private:
class SVGPageClient;
SVGDecodedImageData(NonnullOwnPtr<Page>, NonnullOwnPtr<SVGPageClient>, JS::Handle<DOM::Document>, JS::Handle<SVG::SVGSVGElement>);