瀏覽代碼

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.
Andreas Kling 3 年之前
父節點
當前提交
07096b7765
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. 9 5
      Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

+ 9 - 5
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<Box>([&](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<Box>([&](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<float>();
-        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();
     }