Bläddra i källkod

LibWeb: Store overflow data in the FormattingState

Andreas Kling 3 år sedan
förälder
incheckning
2615728d6b

+ 2 - 4
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -528,6 +528,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
     auto viewport_rect = root().browsing_context().viewport_rect();
 
     auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
+    auto& icb_state = m_state.ensure(icb);
 
     VERIFY(!icb.children_are_inline());
     layout_block_level_children(root(), layout_mode);
@@ -546,13 +547,10 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
 
     if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) {
         // FIXME: Move overflow data to FormattingState!
-        auto& overflow_data = const_cast<InitialContainingBlock&>(icb).ensure_overflow_data();
+        auto& overflow_data = icb_state.ensure_overflow_data();
         overflow_data.scrollable_overflow_rect = viewport_rect.to_type<float>();
         // NOTE: The edges are *within* the rectangle, so we add 1 to get the width and height.
         overflow_data.scrollable_overflow_rect.set_size(right_edge + 1, bottom_edge + 1);
-    } else {
-        // FIXME: Move overflow data to FormattingState!
-        const_cast<InitialContainingBlock&>(icb).clear_overflow_data();
     }
 }
 

+ 1 - 8
Userland/Libraries/LibWeb/Layout/Box.h

@@ -113,14 +113,7 @@ public:
         return m_overflow_data->scrollable_overflow_rect;
     }
 
-    OverflowData& ensure_overflow_data()
-    {
-        if (!m_overflow_data)
-            m_overflow_data = make<OverflowData>();
-        return *m_overflow_data;
-    }
-
-    void clear_overflow_data() { m_overflow_data = nullptr; }
+    void set_overflow_data(OwnPtr<OverflowData> data) { m_overflow_data = move(data); }
 
     virtual void before_children_paint(PaintContext&, PaintPhase) override;
     virtual void after_children_paint(PaintContext&, PaintPhase) override;

+ 2 - 1
Userland/Libraries/LibWeb/Layout/FormattingState.cpp

@@ -21,11 +21,12 @@ void FormattingState::commit()
         node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left };
         node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left };
 
-        // For boxes, transfer relative offset and size.
+        // For boxes, transfer relative offset, size, and overflow data.
         if (is<Layout::Box>(node)) {
             auto& box = static_cast<Layout::Box&>(node);
             box.set_offset(node_state.offset);
             box.set_content_size(node_state.content_width, node_state.content_height);
+            box.set_overflow_data(move(node_state.overflow_data));
         }
 
         // For block containers, transfer line boxes.

+ 10 - 1
Userland/Libraries/LibWeb/Layout/FormattingState.h

@@ -8,8 +8,8 @@
 
 #include <AK/HashMap.h>
 #include <LibGfx/Point.h>
+#include <LibWeb/Layout/Box.h>
 #include <LibWeb/Layout/LineBox.h>
-#include <LibWeb/Layout/Node.h>
 
 namespace Web::Layout {
 
@@ -53,6 +53,15 @@ struct FormattingState {
 
         float border_box_width() const { return border_box_left() + content_width + border_box_right(); }
         float border_box_height() const { return border_box_top() + content_height + border_box_bottom(); }
+
+        OwnPtr<Layout::Box::OverflowData> overflow_data;
+
+        Layout::Box::OverflowData& ensure_overflow_data()
+        {
+            if (!overflow_data)
+                overflow_data = make<Layout::Box::OverflowData>();
+            return *overflow_data;
+        }
     };
 
     void commit();