Przeglądaj źródła

LibWeb: Make grid containers be Layout::Box

Grid containers were incorrectly represented as BlockContainer before.
Furthermore, GridFormattingContext had a bogus inheritance relationship
with BlockFormattingContext.

This patch brings our architecture closer to spec by making grid
containers be plain boxes and making GFC not inherit from BFC.
Andreas Kling 2 lat temu
rodzic
commit
8fe748bb89

+ 2 - 2
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -320,10 +320,10 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
         return document.heap().allocate_without_realm<Layout::InlineNode>(document, element, move(style));
     }
 
-    if (display.is_flex_inside())
+    if (display.is_flex_inside() || display.is_grid_inside())
         return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
 
-    if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_grid_inside())
+    if (display.is_flow_inside() || display.is_flow_root_inside())
         return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));
 
     TODO();

+ 1 - 1
Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

@@ -151,7 +151,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
         return make<TableFormattingContext>(state, verify_cast<TableBox>(child_box), this);
 
     if (child_display.is_grid_inside()) {
-        return make<GridFormattingContext>(state, verify_cast<BlockContainer>(child_box), this);
+        return make<GridFormattingContext>(state, child_box, this);
     }
 
     VERIFY(is_block_formatting_context());

+ 1 - 0
Userland/Libraries/LibWeb/Layout/FormattingContext.h

@@ -21,6 +21,7 @@ public:
         Block,
         Inline,
         Flex,
+        Grid,
         Table,
         SVG,
     };

+ 2 - 2
Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

@@ -10,8 +10,8 @@
 
 namespace Web::Layout {
 
-GridFormattingContext::GridFormattingContext(LayoutState& state, BlockContainer const& block_container, FormattingContext* parent)
-    : BlockFormattingContext(state, block_container, parent)
+GridFormattingContext::GridFormattingContext(LayoutState& state, Box const& grid_container, FormattingContext* parent)
+    : FormattingContext(Type::Grid, state, grid_container, parent)
 {
 }
 

+ 2 - 4
Userland/Libraries/LibWeb/Layout/GridFormattingContext.h

@@ -7,8 +7,6 @@
 #pragma once
 
 #include <LibWeb/CSS/Length.h>
-#include <LibWeb/Layout/BlockFormattingContext.h>
-#include <LibWeb/Layout/Box.h>
 #include <LibWeb/Layout/FormattingContext.h>
 
 namespace Web::Layout {
@@ -31,9 +29,9 @@ private:
     Vector<Vector<bool>> m_occupation_grid;
 };
 
-class GridFormattingContext final : public BlockFormattingContext {
+class GridFormattingContext final : public FormattingContext {
 public:
-    explicit GridFormattingContext(LayoutState&, BlockContainer const&, FormattingContext* parent);
+    explicit GridFormattingContext(LayoutState&, Box const& grid_container, FormattingContext* parent);
     ~GridFormattingContext();
 
     virtual void run(Box const&, LayoutMode, AvailableSpace const& available_space) override;

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

@@ -66,7 +66,8 @@ static Box const* nearest_ancestor_capable_of_forming_a_containing_block(Node co
 {
     for (auto const* ancestor = node.parent(); ancestor; ancestor = ancestor->parent()) {
         if (ancestor->is_block_container()
-            || ancestor->display().is_flex_inside()) {
+            || ancestor->display().is_flex_inside()
+            || ancestor->display().is_grid_inside()) {
             return verify_cast<Box>(ancestor);
         }
     }