1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:17:34 +00:00

LibWeb+Browser+Ladybird: Add menu action to dump paint tree

This commit is contained in:
Andreas Kling 2023-03-18 20:22:58 +01:00
parent a13c21c807
commit 72d817d4ea
5 changed files with 68 additions and 0 deletions

View file

@ -29,6 +29,7 @@
#include <LibWeb/Layout/SVGBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/TextPaintable.h>
#include <stdio.h>
namespace Web {
@ -678,4 +679,51 @@ ErrorOr<void> dump_sheet(StringBuilder& builder, CSS::StyleSheet const& sheet)
return {};
}
void dump_tree(Painting::Paintable const& paintable)
{
StringBuilder builder;
dump_tree(builder, paintable, true);
dbgln("{}", builder.string_view());
}
void dump_tree(StringBuilder& builder, Painting::Paintable const& paintable, bool colorize, int indent)
{
for (int i = 0; i < indent; ++i)
builder.append(" "sv);
StringView paintable_with_lines_color_on = ""sv;
StringView paintable_box_color_on = ""sv;
StringView text_paintable_color_on = ""sv;
StringView paintable_color_on = ""sv;
StringView color_off = ""sv;
if (colorize) {
paintable_with_lines_color_on = "\033[34m"sv;
paintable_box_color_on = "\033[33m"sv;
text_paintable_color_on = "\033[35m"sv;
paintable_color_on = "\033[32m"sv;
color_off = "\033[0m"sv;
}
if (is<Painting::PaintableWithLines>(paintable))
builder.append(paintable_with_lines_color_on);
else if (is<Painting::PaintableBox>(paintable))
builder.append(paintable_box_color_on);
else if (is<Painting::TextPaintable>(paintable))
builder.append(text_paintable_color_on);
else
builder.append(paintable_color_on);
builder.appendff("{}{} ({})", paintable.class_name(), color_off, paintable.layout_node().debug_description());
if (paintable.layout_node().is_box()) {
auto const& paint_box = static_cast<Painting::PaintableBox const&>(paintable);
builder.appendff(" {}", paint_box.absolute_border_box_rect());
}
builder.append("\n"sv);
for (auto const* child = paintable.first_child(); child; child = child->next_sibling()) {
dump_tree(builder, *child, colorize, indent + 1);
}
}
}

View file

@ -16,6 +16,8 @@ void dump_tree(StringBuilder&, DOM::Node const&);
void dump_tree(DOM::Node const&);
void dump_tree(StringBuilder&, Layout::Node const&, bool show_box_model = false, bool show_specified_style = false, bool colorize = false);
void dump_tree(Layout::Node const&, bool show_box_model = true, bool show_specified_style = false);
void dump_tree(StringBuilder&, Painting::Paintable const&, bool colorize = false, int indent = 0);
void dump_tree(Painting::Paintable const&);
ErrorOr<void> dump_sheet(StringBuilder&, CSS::StyleSheet const&);
ErrorOr<void> dump_sheet(CSS::StyleSheet const&);
ErrorOr<void> dump_rule(StringBuilder&, CSS::CSSRule const&, int indent_levels = 0);