diff --git a/Libraries/LibWeb/Painting/DisplayList.cpp b/Libraries/LibWeb/Painting/DisplayList.cpp index f0664151df0..254a3ee3563 100644 --- a/Libraries/LibWeb/Painting/DisplayList.cpp +++ b/Libraries/LibWeb/Painting/DisplayList.cpp @@ -18,9 +18,28 @@ void DisplayList::append(DisplayListCommand&& command, Optional scroll_fram String DisplayList::dump() const { StringBuilder builder; - for (auto const& command : m_commands) { - command.command.visit([&builder](auto const& cmd) { cmd.dump(builder); }); - builder.appendff("\n"); + int indentation = 0; + for (auto const& command_list_item : m_commands) { + auto const& command = command_list_item.command; + + command.visit([&indentation](auto const& command) { + if constexpr (requires { command.nesting_level_change; }) { + if (command.nesting_level_change < 0 && indentation >= -command.nesting_level_change) + indentation += command.nesting_level_change; + } + }); + + if (indentation > 0) + builder.append(MUST(String::repeated(" "_string, indentation))); + command.visit([&builder](auto const& cmd) { cmd.dump(builder); }); + builder.append('\n'); + + command.visit([&indentation](auto const& command) { + if constexpr (requires { command.nesting_level_change; }) { + if (command.nesting_level_change > 0) + indentation += command.nesting_level_change; + } + }); } return builder.to_string_without_validation(); } diff --git a/Libraries/LibWeb/Painting/DisplayListCommand.h b/Libraries/LibWeb/Painting/DisplayListCommand.h index ad0f925feea..29e85b96eee 100644 --- a/Libraries/LibWeb/Painting/DisplayListCommand.h +++ b/Libraries/LibWeb/Painting/DisplayListCommand.h @@ -99,14 +99,20 @@ struct DrawRepeatedImmutableBitmap { }; struct Save { + static constexpr int nesting_level_change = 1; + void dump(StringBuilder&) const; }; struct SaveLayer { + static constexpr int nesting_level_change = 1; + void dump(StringBuilder&) const; }; struct Restore { + static constexpr int nesting_level_change = -1; + void dump(StringBuilder&) const; }; @@ -127,6 +133,8 @@ struct AddClipRect { }; struct PushStackingContext { + static constexpr int nesting_level_change = 1; + float opacity; Gfx::CompositingAndBlendingOperator compositing_and_blending_operator; bool isolate; @@ -145,6 +153,8 @@ struct PushStackingContext { }; struct PopStackingContext { + static constexpr int nesting_level_change = -1; + void dump(StringBuilder&) const; }; @@ -445,16 +455,22 @@ struct PaintScrollBar { }; struct ApplyOpacity { + static constexpr int nesting_level_change = 1; + float opacity; void dump(StringBuilder&) const; }; struct ApplyCompositeAndBlendingOperator { + static constexpr int nesting_level_change = 1; + Gfx::CompositingAndBlendingOperator compositing_and_blending_operator; void dump(StringBuilder&) const; }; struct ApplyFilter { + static constexpr int nesting_level_change = 1; + Gfx::Filter filter; void dump(StringBuilder&) const; }; diff --git a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp index 2e376dcb13d..859e9724f68 100644 --- a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp +++ b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp @@ -462,7 +462,7 @@ void DisplayListRecorder::apply_opacity(float opacity) void DisplayListRecorder::apply_compositing_and_blending_operator(Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) { // Implementation of this item does saveLayer(), so we need to increment the nesting level. - m_save_nesting_level++; + ++m_save_nesting_level; APPEND(ApplyCompositeAndBlendingOperator { .compositing_and_blending_operator = compositing_and_blending_operator }); } diff --git a/Tests/LibWeb/Text/expected/display_list/simple-overflow-hidden.txt b/Tests/LibWeb/Text/expected/display_list/simple-overflow-hidden.txt index e1ac6f5d6ee..a0182d2faff 100644 --- a/Tests/LibWeb/Text/expected/display_list/simple-overflow-hidden.txt +++ b/Tests/LibWeb/Text/expected/display_list/simple-overflow-hidden.txt @@ -1,10 +1,10 @@ SaveLayer -PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0] -PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0] -FillPathUsingColor -FillRect rect=[10,10 300x150] color=rgb(240, 128, 128) -DrawGlyphRun rect=[10,10 38x18] translation=[10,23.796875] color=rgb(0, 0, 0) scale=1 -PopStackingContext -PopStackingContext + PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0] + PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0] + FillPathUsingColor + FillRect rect=[10,10 300x150] color=rgb(240, 128, 128) + DrawGlyphRun rect=[10,10 38x18] translation=[10,23.796875] color=rgb(0, 0, 0) scale=1 + PopStackingContext + PopStackingContext Restore