diff --git a/Libraries/LibWeb/Painting/StackingContext.cpp b/Libraries/LibWeb/Painting/StackingContext.cpp index f51f422b4cb..75fcac9c395 100644 --- a/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Libraries/LibWeb/Painting/StackingContext.cpp @@ -460,9 +460,8 @@ TraversalDecision StackingContext::hit_test(CSSPixelPoint position, HitTestType return TraversalDecision::Continue; } -void StackingContext::dump(int indent) const +void StackingContext::dump(StringBuilder& builder, int indent) const { - StringBuilder builder; for (int i = 0; i < indent; ++i) builder.append(' '); CSSPixelRect rect = paintable_box().absolute_rect(); @@ -478,9 +477,9 @@ void StackingContext::dump(int indent) const if (!affine_transform.is_identity()) { builder.appendff(", transform: {}", affine_transform); } - dbgln("{}", builder.string_view()); + builder.append('\n'); for (auto& child : m_children) - child->dump(indent + 1); + child->dump(builder, indent + 1); } } diff --git a/Libraries/LibWeb/Painting/StackingContext.h b/Libraries/LibWeb/Painting/StackingContext.h index 03e995e2c69..1d668133d71 100644 --- a/Libraries/LibWeb/Painting/StackingContext.h +++ b/Libraries/LibWeb/Painting/StackingContext.h @@ -40,7 +40,7 @@ public: Gfx::AffineTransform affine_transform_matrix() const; - void dump(int indent = 0) const; + void dump(StringBuilder&, int indent = 0) const; void sort(); diff --git a/Libraries/LibWebView/PageInfo.h b/Libraries/LibWebView/PageInfo.h index 25f6ea6649d..af6a5a6cd4b 100644 --- a/Libraries/LibWebView/PageInfo.h +++ b/Libraries/LibWebView/PageInfo.h @@ -15,6 +15,7 @@ enum class PageInfoType { LayoutTree = 1 << 2, PaintTree = 1 << 3, GCGraph = 1 << 4, + StackingContextTree = 1 << 5, }; AK_ENUM_BITWISE_OPERATORS(PageInfoType); diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index c17ac8a3394..24468a15ab4 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -278,8 +278,13 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString request, ByteSt if (request == "dump-stacking-context-tree") { if (auto* doc = page->page().top_level_browsing_context().active_document()) { if (auto* viewport = doc->layout_node()) { - if (auto* stacking_context = viewport->paintable_box()->stacking_context()) - stacking_context->dump(); + auto& viewport_paintable = static_cast(*viewport->paintable_box()); + viewport_paintable.build_stacking_context_tree_if_needed(); + if (auto* stacking_context = viewport_paintable.stacking_context()) { + StringBuilder builder; + stacking_context->dump(builder); + dbgln("{}", builder.string_view()); + } } } return; @@ -976,6 +981,33 @@ static void append_paint_tree(Web::Page& page, StringBuilder& builder) Web::dump_tree(builder, *layout_root->first_paintable()); } +static void append_stacking_context_tree(Web::Page& page, StringBuilder& builder) +{ + auto* document = page.top_level_browsing_context().active_document(); + if (!document) { + builder.append("(no DOM tree)"sv); + return; + } + + document->update_layout(Web::DOM::UpdateLayoutReason::Debugging); + + auto* layout_root = document->layout_node(); + if (!layout_root) { + builder.append("(no layout tree)"sv); + return; + } + if (!layout_root->first_paintable()) { + builder.append("(no paint tree)"sv); + return; + } + + auto& viewport_paintable = static_cast(*layout_root->paintable_box()); + viewport_paintable.build_stacking_context_tree_if_needed(); + if (auto* stacking_context = viewport_paintable.stacking_context()) { + stacking_context->dump(builder); + } +} + static void append_gc_graph(StringBuilder& builder) { auto gc_graph = Web::Bindings::main_thread_vm().heap().dump_graph(); @@ -1008,6 +1040,12 @@ void ConnectionFromClient::request_internal_page_info(u64 page_id, WebView::Page append_paint_tree(page->page(), builder); } + if (has_flag(type, WebView::PageInfoType::StackingContextTree)) { + if (!builder.is_empty()) + builder.append("\n"sv); + append_stacking_context_tree(page->page(), builder); + } + if (has_flag(type, WebView::PageInfoType::GCGraph)) { if (!builder.is_empty()) builder.append("\n"sv); diff --git a/Tests/LibWeb/Layout/expected/Element-insertAdjacentHTML.txt b/Tests/LibWeb/Layout/expected/Element-insertAdjacentHTML.txt index 5108abc5ab6..3d40f0ffad5 100644 --- a/Tests/LibWeb/Layout/expected/Element-insertAdjacentHTML.txt +++ b/Tests/LibWeb/Layout/expected/Element-insertAdjacentHTML.txt @@ -41,3 +41,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer
) [8,206 784x18] TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,224 784x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x232] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/HTMLImageElement-update-the-image-data-temporary-document.txt b/Tests/LibWeb/Layout/expected/HTMLImageElement-update-the-image-data-temporary-document.txt index a8520c1ab91..29879a0b11e 100644 --- a/Tests/LibWeb/Layout/expected/HTMLImageElement-update-the-image-data-temporary-document.txt +++ b/Tests/LibWeb/Layout/expected/HTMLImageElement-update-the-image-data-temporary-document.txt @@ -17,3 +17,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer
#image-container) [8,8 784x150] ImagePaintable (ImageBox) [8,8 150x150] PaintableWithLines (BlockContainer(anonymous)) [8,158 784x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x166] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/HTMLSelectElement-selected-index.txt b/Tests/LibWeb/Layout/expected/HTMLSelectElement-selected-index.txt index 66e8be53d70..934812ed6a8 100644 --- a/Tests/LibWeb/Layout/expected/HTMLSelectElement-selected-index.txt +++ b/Tests/LibWeb/Layout/expected/HTMLSelectElement-selected-index.txt @@ -25,3 +25,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer
) [75.390625,11 16x16] SVGSVGPaintable (SVGSVGBox) [75.390625,11 16x16] SVGPathPaintable (SVGGeometryBox) [79.390625,16.71875 8x4.953125] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x38] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-box-bottom-with-max-height.txt b/Tests/LibWeb/Layout/expected/abspos-box-bottom-with-max-height.txt index 9a8a1f5838d..a16887e5c99 100644 --- a/Tests/LibWeb/Layout/expected/abspos-box-bottom-with-max-height.txt +++ b/Tests/LibWeb/Layout/expected/abspos-box-bottom-with-max-height.txt @@ -8,3 +8,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x16] PaintableWithLines (BlockContainer) [8,8 784x0] PaintableWithLines (BlockContainer
) [8,550 100x50] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x16] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-box-with-block-level-sibling.txt b/Tests/LibWeb/Layout/expected/abspos-box-with-block-level-sibling.txt index 1a9fcb8afc2..b5baf665253 100644 --- a/Tests/LibWeb/Layout/expected/abspos-box-with-block-level-sibling.txt +++ b/Tests/LibWeb/Layout/expected/abspos-box-with-block-level-sibling.txt @@ -12,3 +12,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer
.static) [18,18 210x210] PaintableWithLines (BlockContainer
.absolute) [18,228 110x210] PaintableWithLines (BlockContainer(anonymous)) [18,228 764x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [5,5 790x236] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt b/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt index 61bc33c1c88..af66f4d8ec5 100644 --- a/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt +++ b/Tests/LibWeb/Layout/expected/abspos-box-with-replaced-element.txt @@ -10,3 +10,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [9,9 502x102] overflow: [10,10 501x100] PaintableWithLines (BlockContainer
.image-container) [260,10 250x30.46875] overflow: [261,11 250x28.46875] ImagePaintable (ImageBox) [261,11 250x28.46875] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [1,1 798x0] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-flex-container-with-auto-height.txt b/Tests/LibWeb/Layout/expected/abspos-flex-container-with-auto-height.txt index 3361bf56b23..61bb9a09e74 100644 --- a/Tests/LibWeb/Layout/expected/abspos-flex-container-with-auto-height.txt +++ b/Tests/LibWeb/Layout/expected/abspos-flex-container-with-auto-height.txt @@ -11,3 +11,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableBox (Box) [8,8 514.859375x22] PaintableWithLines (BlockContainer
) [9,9 512.859375x20] TextPaintable (TextNode<#text>) + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [1,1 798x0] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-1.txt b/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-1.txt index 18cf45cfc96..41bf6b17ab7 100644 --- a/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-1.txt +++ b/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-1.txt @@ -14,3 +14,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [8,8 784x0] PaintableBox (Box
.container) [8,8 100x100] PaintableWithLines (BlockContainer
.bottom-left) [8,38 70x70] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x16] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-2.txt b/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-2.txt index 44cee02c6af..0ce53e73910 100644 --- a/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-2.txt +++ b/Tests/LibWeb/Layout/expected/abspos-flex-margin-limits-2.txt @@ -14,3 +14,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [8,8 784x0] PaintableBox (Box
.container) [8,8 100x100] PaintableWithLines (BlockContainer
.top-right) [38,8 70x70] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x16] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/abspos-flexbox-with-auto-height.txt b/Tests/LibWeb/Layout/expected/abspos-flexbox-with-auto-height.txt index 56e5d51b2f2..df91ba3a17f 100644 --- a/Tests/LibWeb/Layout/expected/abspos-flexbox-with-auto-height.txt +++ b/Tests/LibWeb/Layout/expected/abspos-flexbox-with-auto-height.txt @@ -13,3 +13,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableBox (Box