瀏覽代碼

LibWeb: Add GridFormattingContext

martinfalisse 2 年之前
父節點
當前提交
e4c5799026

+ 1 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -266,6 +266,7 @@ set(SOURCES
     Layout/FlexFormattingContext.cpp
     Layout/FormattingContext.cpp
     Layout/FrameBox.cpp
+    Layout/GridFormattingContext.cpp
     Layout/ImageBox.cpp
     Layout/InitialContainingBlock.cpp
     Layout/InlineFormattingContext.cpp

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

@@ -287,7 +287,7 @@ RefPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Document&
         return adopt_ref(*new Layout::InlineNode(document, element, move(style)));
     }
 
-    if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside())
+    if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside() || display.is_grid_inside())
         return adopt_ref(*new Layout::BlockContainer(document, element, move(style)));
 
     TODO();

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

@@ -9,6 +9,7 @@
 #include <LibWeb/Layout/Box.h>
 #include <LibWeb/Layout/FlexFormattingContext.h>
 #include <LibWeb/Layout/FormattingContext.h>
+#include <LibWeb/Layout/GridFormattingContext.h>
 #include <LibWeb/Layout/ReplacedBox.h>
 #include <LibWeb/Layout/SVGFormattingContext.h>
 #include <LibWeb/Layout/SVGSVGBox.h>
@@ -74,12 +75,16 @@ bool FormattingContext::creates_block_formatting_context(Box const& box)
             if (!display.is_flex_inside())
                 return true;
         }
+        if (parent_display.is_grid_inside()) {
+            if (!display.is_grid_inside()) {
+                return true;
+            }
+        }
     }
 
     // FIXME: table-caption
     // FIXME: anonymous table cells
     // FIXME: Elements with contain: layout, content, or paint.
-    // FIXME: grid
     // FIXME: multicol
     // FIXME: column-span: all
     return false;
@@ -120,6 +125,10 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
     if (child_display.is_table_inside())
         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);
+    }
+
     VERIFY(is_block_formatting_context());
     VERIFY(!child_box.children_are_inline());
 

+ 26 - 0
Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Layout/Box.h>
+#include <LibWeb/Layout/GridFormattingContext.h>
+
+namespace Web::Layout {
+
+GridFormattingContext::GridFormattingContext(LayoutState& state, BlockContainer const& block_container, FormattingContext* parent)
+    : BlockFormattingContext(state, block_container, parent)
+{
+}
+
+GridFormattingContext::~GridFormattingContext() = default;
+
+void GridFormattingContext::run(Box const& box, LayoutMode)
+{
+    box.for_each_child_of_type<Box>([&](Box& child_box) {
+        (void)layout_inside(child_box, LayoutMode::Normal);
+    });
+}
+
+}

+ 23 - 0
Userland/Libraries/LibWeb/Layout/GridFormattingContext.h

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/Layout/BlockFormattingContext.h>
+#include <LibWeb/Layout/Box.h>
+#include <LibWeb/Layout/FormattingContext.h>
+
+namespace Web::Layout {
+
+class GridFormattingContext final : public BlockFormattingContext {
+public:
+    explicit GridFormattingContext(LayoutState&, BlockContainer const&, FormattingContext* parent);
+    ~GridFormattingContext();
+
+    virtual void run(Box const&, LayoutMode) override;
+};
+
+}