From 07096b77655dcc0bd176c3c3102b878fd36d18bc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 15 Oct 2021 00:10:41 +0200 Subject: [PATCH] LibWeb: Compute horizontal overflow for the initial containing block This finally allows LibWeb to scroll pages horizontally instead of just clipping things at the right edge. --- .../LibWeb/Layout/BlockFormattingContext.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index e492ef57b1..d872bc6f71 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -577,15 +577,19 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m layout_block_level_children(root(), layout_mode); // Compute scrollable overflow. - float lowest_bottom = 0; - icb.for_each_child_of_type([&](auto& child) { - lowest_bottom = max(lowest_bottom, child.absolute_rect().bottom()); + float bottom_edge = 0; + float right_edge = 0; + icb.for_each_in_subtree_of_type([&](auto& child) { + auto child_rect = child.absolute_rect(); + bottom_edge = max(bottom_edge, child_rect.bottom()); + right_edge = max(right_edge, child_rect.right()); + return IterationDecision::Continue; }); - if (lowest_bottom >= viewport_rect.height()) { + if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) { auto& overflow_data = icb.ensure_overflow_data(); overflow_data.scrollable_overflow_rect = viewport_rect.to_type(); - overflow_data.scrollable_overflow_rect.set_height(lowest_bottom); + overflow_data.scrollable_overflow_rect.set_size(right_edge, bottom_edge); } else { icb.clear_overflow_data(); }