diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index f88ae009571..f67f0b30d9c 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -463,6 +464,19 @@ String Internals::dump_display_list() return window().associated_document().dump_display_list(); } +String Internals::dump_layout_tree(GC::Ref node) +{ + node->document().update_layout(DOM::UpdateLayoutReason::Debugging); + + auto* layout_node = node->layout_node(); + if (!layout_node) + return "(no layout node)"_string; + + StringBuilder builder; + Web::dump_tree(builder, *layout_node); + return builder.to_string_without_validation(); +} + String Internals::dump_stacking_context_tree() { return window().associated_document().dump_stacking_context_tree(); diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h index bf87495cc21..398f8b7b7df 100644 --- a/Libraries/LibWeb/Internals/Internals.h +++ b/Libraries/LibWeb/Internals/Internals.h @@ -89,6 +89,7 @@ public: bool headless(); String dump_display_list(); + String dump_layout_tree(GC::Ref); String dump_stacking_context_tree(); String dump_gc_graph(); diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl index 6cd4de52e9e..07d355b48b2 100644 --- a/Libraries/LibWeb/Internals/Internals.idl +++ b/Libraries/LibWeb/Internals/Internals.idl @@ -70,6 +70,7 @@ interface Internals { readonly attribute boolean headless; DOMString dumpDisplayList(); + DOMString dumpLayoutTree(Node node); DOMString dumpStackingContextTree(); DOMString dumpGCGraph(); diff --git a/Tests/LibWeb/Text/expected/Internals/dump-layout-tree.txt b/Tests/LibWeb/Text/expected/Internals/dump-layout-tree.txt new file mode 100644 index 00000000000..d8b390d34e4 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Internals/dump-layout-tree.txt @@ -0,0 +1,8 @@ +BlockContainer at [8,8] [0+0+0 100 0+0+684] [0+0+0 50 0+0+0] children: inline + TextNode <#text> (not painted) + InlineNode at [8,8] [0+0+0 39.78125 0+0+0] [0+0+0 18 0+0+0] + frag 0 from TextNode start: 0, length: 5, rect: [8,8 39.78125x18] baseline: 13.796875 + "Hello" + TextNode <#text> (not painted) + TextNode <#text> (not painted) + diff --git a/Tests/LibWeb/Text/input/Internals/dump-layout-tree.html b/Tests/LibWeb/Text/input/Internals/dump-layout-tree.html new file mode 100644 index 00000000000..e9102736cd7 --- /dev/null +++ b/Tests/LibWeb/Text/input/Internals/dump-layout-tree.html @@ -0,0 +1,11 @@ + + +
+ Hello +
+