diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-18 20:22:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-18 20:23:35 +0100 |
commit | 72d817d4ea2476252160ac52936a2871a2c25ae1 (patch) | |
tree | 6b68c6d91eb22f3e0738cd4fb233dea3719cdaf8 /Userland/Libraries | |
parent | a13c21c80761127cd5913a766dc8d55f4c04ad0e (diff) | |
download | serenity-72d817d4ea2476252160ac52936a2871a2c25ae1.zip |
LibWeb+Browser+Ladybird: Add menu action to dump paint tree
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Dump.cpp | 48 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Dump.h | 2 |
2 files changed, 50 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 4219081607..ee6de8ae3b 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -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); + } +} + } diff --git a/Userland/Libraries/LibWeb/Dump.h b/Userland/Libraries/LibWeb/Dump.h index 28688bca25..7a2387a1b7 100644 --- a/Userland/Libraries/LibWeb/Dump.h +++ b/Userland/Libraries/LibWeb/Dump.h @@ -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); |