summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-03-18 20:22:58 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-18 20:23:35 +0100
commit72d817d4ea2476252160ac52936a2871a2c25ae1 (patch)
tree6b68c6d91eb22f3e0738cd4fb233dea3719cdaf8
parenta13c21c80761127cd5913a766dc8d55f4c04ad0e (diff)
downloadserenity-72d817d4ea2476252160ac52936a2871a2c25ae1.zip
LibWeb+Browser+Ladybird: Add menu action to dump paint tree
-rw-r--r--Ladybird/BrowserWindow.cpp6
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp5
-rw-r--r--Userland/Libraries/LibWeb/Dump.cpp48
-rw-r--r--Userland/Libraries/LibWeb/Dump.h2
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp7
5 files changed, 68 insertions, 0 deletions
diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp
index 6b6a7d4f08..e1b874bd23 100644
--- a/Ladybird/BrowserWindow.cpp
+++ b/Ladybird/BrowserWindow.cpp
@@ -176,6 +176,12 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
debug_request("dump-layout-tree");
});
+ auto* dump_paint_tree_action = new QAction("Dump Paint Tree", this);
+ debug_menu->addAction(dump_paint_tree_action);
+ QObject::connect(dump_paint_tree_action, &QAction::triggered, this, [this] {
+ debug_request("dump-paint-tree");
+ });
+
auto* dump_stacking_context_tree_action = new QAction("Dump Stacking Context Tree", this);
dump_stacking_context_tree_action->setIcon(QIcon(QString("%1/res/icons/16x16/layers.png").arg(s_serenity_resource_root.characters())));
debug_menu->addAction(dump_stacking_context_tree_action);
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index e5fbf64b36..c8ca1c6b93 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -365,6 +365,11 @@ void BrowserWindow::build_menus()
},
this));
debug_menu.add_action(GUI::Action::create(
+ "Dump &Paint Tree", g_icon_bag.layout, [this](auto&) {
+ active_tab().view().debug_request("dump-paint-tree");
+ },
+ this));
+ debug_menu.add_action(GUI::Action::create(
"Dump S&tacking Context Tree", g_icon_bag.layers, [this](auto&) {
active_tab().view().debug_request("dump-stacking-context-tree");
},
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);
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index a39e99a3d9..63c65b8fdd 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -341,6 +341,13 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec
}
}
+ if (request == "dump-paint-tree") {
+ if (auto* doc = page().top_level_browsing_context().active_document()) {
+ if (auto* paintable = doc->paintable())
+ Web::dump_tree(*paintable);
+ }
+ }
+
if (request == "dump-stacking-context-tree") {
if (auto* doc = page().top_level_browsing_context().active_document()) {
if (auto* viewport = doc->layout_node()) {