ソースを参照

LibWeb: Remove Layout::TableRowGroupBox

Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
Aliaksandr Kalenik 2 年 前
コミット
578a937f94

+ 1 - 1
Tests/LibWeb/Layout/expected/blockify-layout-internal-box-without-crashing.txt

@@ -3,7 +3,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
     BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
     BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
       TableWrapper <(anonymous)> at (8,8) content-size 0x0 [BFC] children: not-inline
       TableWrapper <(anonymous)> at (8,8) content-size 0x0 [BFC] children: not-inline
         Box <table> at (8,8) content-size 0x0 [TFC] children: not-inline
         Box <table> at (8,8) content-size 0x0 [TFC] children: not-inline
-          TableRowGroupBox <tbody> at (8,8) content-size 0x0 children: not-inline
+          Box <tbody> at (8,8) content-size 0x0 children: not-inline
             TableRowBox <tr> at (8,8) content-size 0x0 children: not-inline
             TableRowBox <tr> at (8,8) content-size 0x0 children: not-inline
               TableCellBox <(anonymous)> at (8,8) content-size 0x0 [BFC] children: not-inline
               TableCellBox <(anonymous)> at (8,8) content-size 0x0 [BFC] children: not-inline
                 BlockContainer <td> at (9,9) content-size 0x0 positioned [BFC] children: not-inline
                 BlockContainer <td> at (9,9) content-size 0x0 positioned [BFC] children: not-inline

+ 1 - 1
Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt

@@ -3,7 +3,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
     BlockContainer <body> at (10,10) content-size 780x102 children: not-inline
     BlockContainer <body> at (10,10) content-size 780x102 children: not-inline
       TableWrapper <(anonymous)> at (10,10) content-size 102x102 [BFC] children: not-inline
       TableWrapper <(anonymous)> at (10,10) content-size 102x102 [BFC] children: not-inline
         Box <table> at (11,11) content-size 100x100 [TFC] children: not-inline
         Box <table> at (11,11) content-size 100x100 [TFC] children: not-inline
-          TableRowGroupBox <tbody> at (11,11) content-size 100x100 children: not-inline
+          Box <tbody> at (11,11) content-size 100x100 children: not-inline
             TableRowBox <tr> at (11,11) content-size 100x100 children: not-inline
             TableRowBox <tr> at (11,11) content-size 100x100 children: not-inline
               TableCellBox <td> at (13,49.082031) content-size 96x23.835937 [BFC] children: not-inline
               TableCellBox <td> at (13,49.082031) content-size 96x23.835937 [BFC] children: not-inline
                 BlockContainer <(anonymous)> at (14,50.082031) content-size 94x21.835937 children: inline
                 BlockContainer <(anonymous)> at (14,50.082031) content-size 94x21.835937 children: inline

+ 3 - 3
Tests/LibWeb/Layout/expected/table/basic.txt

@@ -14,7 +14,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
             TextNode <#text>
             TextNode <#text>
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <thead> at (8,8) content-size 95.171875x19.46875 children: not-inline
+          Box <thead> at (8,8) content-size 95.171875x19.46875 children: not-inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
               TextNode <#text>
               TextNode <#text>
             TableRowBox <tr> at (8,8) content-size 95.171875x19.46875 children: not-inline
             TableRowBox <tr> at (8,8) content-size 95.171875x19.46875 children: not-inline
@@ -31,7 +31,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
               TextNode <#text>
               TextNode <#text>
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tbody> at (8,27.46875) content-size 95.171875x19.46875 children: not-inline
+          Box <tbody> at (8,27.46875) content-size 95.171875x19.46875 children: not-inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
               TextNode <#text>
               TextNode <#text>
             TableRowBox <tr> at (8,27.46875) content-size 95.171875x19.46875 children: not-inline
             TableRowBox <tr> at (8,27.46875) content-size 95.171875x19.46875 children: not-inline
@@ -48,7 +48,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
               TextNode <#text>
               TextNode <#text>
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tfoot> at (8,46.9375) content-size 95.171875x19.46875 children: not-inline
+          Box <tfoot> at (8,46.9375) content-size 95.171875x19.46875 children: not-inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
               TextNode <#text>
               TextNode <#text>
             TableRowBox <tr> at (8,46.9375) content-size 95.171875x19.46875 children: not-inline
             TableRowBox <tr> at (8,46.9375) content-size 95.171875x19.46875 children: not-inline

+ 2 - 2
Tests/LibWeb/Layout/expected/table/borders.txt

@@ -5,7 +5,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
         Box <table.table-border-black> at (9,9) content-size 164.296875x64.40625 [TFC] children: not-inline
         Box <table.table-border-black> at (9,9) content-size 164.296875x64.40625 [TFC] children: not-inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tbody> at (9,9) content-size 166.296875x64.40625 children: not-inline
+          Box <tbody> at (9,9) content-size 166.296875x64.40625 children: not-inline
             TableRowBox <tr> at (9,9) content-size 166.296875x21.46875 children: not-inline
             TableRowBox <tr> at (9,9) content-size 166.296875x21.46875 children: not-inline
               BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
               BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
                 TextNode <#text>
                 TextNode <#text>
@@ -70,7 +70,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
         Box <table.table-border-black> at (8,74.40625) content-size 164.296875x62.40625 [TFC] children: not-inline
         Box <table.table-border-black> at (8,74.40625) content-size 164.296875x62.40625 [TFC] children: not-inline
           BlockContainer <(anonymous)> at (8,74.40625) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,74.40625) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tbody> at (8,74.40625) content-size 164.296875x62.40625 children: not-inline
+          Box <tbody> at (8,74.40625) content-size 164.296875x62.40625 children: not-inline
             TableRowBox <tr> at (8,74.40625) content-size 164.296875x20.46875 children: not-inline
             TableRowBox <tr> at (8,74.40625) content-size 164.296875x20.46875 children: not-inline
               BlockContainer <(anonymous)> at (8,74.40625) content-size 0x0 children: inline
               BlockContainer <(anonymous)> at (8,74.40625) content-size 0x0 children: inline
                 TextNode <#text>
                 TextNode <#text>

+ 1 - 1
Tests/LibWeb/Layout/expected/table/columns-width-distribution-1.txt

@@ -5,7 +5,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
         Box <table.ambox> at (9,9) content-size 780x90.21875 [TFC] children: not-inline
         Box <table.ambox> at (9,9) content-size 780x90.21875 [TFC] children: not-inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tbody> at (9,9) content-size 780x90.21875 children: not-inline
+          Box <tbody> at (9,9) content-size 780x90.21875 children: not-inline
             TableRowBox <tr> at (9,9) content-size 780x90.21875 children: not-inline
             TableRowBox <tr> at (9,9) content-size 780x90.21875 children: not-inline
               TableCellBox <td.mbox-image> at (10,29.109375) content-size 50x50 [BFC] children: not-inline
               TableCellBox <td.mbox-image> at (10,29.109375) content-size 50x50 [BFC] children: not-inline
                 BlockContainer <div.mbox-image-div> at (10,29.109375) content-size 50x50 children: not-inline
                 BlockContainer <div.mbox-image-div> at (10,29.109375) content-size 50x50 children: not-inline

+ 1 - 1
Tests/LibWeb/Layout/expected/table/inline-table-width.txt

@@ -6,7 +6,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
       BlockContainer <table> at (9,9) content-size 129.984375x38.9375 inline-block [BFC] children: not-inline
       BlockContainer <table> at (9,9) content-size 129.984375x38.9375 inline-block [BFC] children: not-inline
         TableWrapper <(anonymous)> at (9,9) content-size 129.984375x38.9375 inline-block [BFC] children: not-inline
         TableWrapper <(anonymous)> at (9,9) content-size 129.984375x38.9375 inline-block [BFC] children: not-inline
           Box <(anonymous)> at (9,9) content-size 129.984375x38.9375 inline-table [TFC] children: not-inline
           Box <(anonymous)> at (9,9) content-size 129.984375x38.9375 inline-table [TFC] children: not-inline
-            TableRowGroupBox <tbody> at (9,9) content-size 129.984375x38.9375 children: not-inline
+            Box <tbody> at (9,9) content-size 129.984375x38.9375 children: not-inline
               TableRowBox <tr> at (9,9) content-size 129.984375x19.46875 children: not-inline
               TableRowBox <tr> at (9,9) content-size 129.984375x19.46875 children: not-inline
                 TableCellBox <td> at (10,10) content-size 87.90625x17.46875 [BFC] children: inline
                 TableCellBox <td> at (10,10) content-size 87.90625x17.46875 [BFC] children: inline
                   line 0 width: 15.734375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
                   line 0 width: 15.734375, height: 17.46875, bottom: 17.46875, baseline: 13.53125

+ 1 - 1
Tests/LibWeb/Layout/expected/table/rowspan.txt

@@ -9,7 +9,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
         Box <table> at (8,8) content-size 221.359375x77.875 [TFC] children: not-inline
         Box <table> at (8,8) content-size 221.359375x77.875 [TFC] children: not-inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
           BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
             TextNode <#text>
             TextNode <#text>
-          TableRowGroupBox <tbody> at (8,8) content-size 221.359375x77.875 children: not-inline
+          Box <tbody> at (8,8) content-size 221.359375x77.875 children: not-inline
             TableRowBox <tr> at (8,8) content-size 221.359375x19.46875 children: not-inline
             TableRowBox <tr> at (8,8) content-size 221.359375x19.46875 children: not-inline
               BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
               BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
                 TextNode <#text>
                 TextNode <#text>

+ 1 - 1
Tests/LibWeb/Layout/expected/table/table-width.txt

@@ -3,6 +3,6 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
     BlockContainer <body> at (8,8) content-size 784x210 children: not-inline
     BlockContainer <body> at (8,8) content-size 784x210 children: not-inline
       TableWrapper <(anonymous)> at (8,8) content-size 584x210 [BFC] children: not-inline
       TableWrapper <(anonymous)> at (8,8) content-size 584x210 [BFC] children: not-inline
         Box <table.table> at (108,108) content-size 584x10 [TFC] children: not-inline
         Box <table.table> at (108,108) content-size 584x10 [TFC] children: not-inline
-          TableRowGroupBox <tbody> at (108,108) content-size 584x10 children: not-inline
+          Box <tbody> at (108,108) content-size 584x10 children: not-inline
             TableRowBox <tr> at (108,108) content-size 584x10 children: not-inline
             TableRowBox <tr> at (108,108) content-size 584x10 children: not-inline
               TableCellBox <td.cell> at (109,113) content-size 582x0 [BFC] children: not-inline
               TableCellBox <td.cell> at (109,113) content-size 582x0 [BFC] children: not-inline

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

@@ -421,7 +421,6 @@ set(SOURCES
     Layout/TableCellBox.cpp
     Layout/TableCellBox.cpp
     Layout/TableFormattingContext.cpp
     Layout/TableFormattingContext.cpp
     Layout/TableRowBox.cpp
     Layout/TableRowBox.cpp
-    Layout/TableRowGroupBox.cpp
     Layout/TableWrapper.cpp
     Layout/TableWrapper.cpp
     Layout/TextNode.cpp
     Layout/TextNode.cpp
     Layout/TreeBuilder.cpp
     Layout/TreeBuilder.cpp

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

@@ -51,7 +51,6 @@
 #include <LibWeb/Layout/ListItemBox.h>
 #include <LibWeb/Layout/ListItemBox.h>
 #include <LibWeb/Layout/TableCellBox.h>
 #include <LibWeb/Layout/TableCellBox.h>
 #include <LibWeb/Layout/TableRowBox.h>
 #include <LibWeb/Layout/TableRowBox.h>
-#include <LibWeb/Layout/TableRowGroupBox.h>
 #include <LibWeb/Layout/TreeBuilder.h>
 #include <LibWeb/Layout/TreeBuilder.h>
 #include <LibWeb/Layout/Viewport.h>
 #include <LibWeb/Layout/Viewport.h>
 #include <LibWeb/Namespace.h>
 #include <LibWeb/Namespace.h>
@@ -324,7 +323,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StyleProp
 
 
 JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr<CSS::StyleProperties> style, Element* element)
 JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr<CSS::StyleProperties> style, Element* element)
 {
 {
-    if (display.is_table_inside())
+    if (display.is_table_inside() || display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group())
         return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
         return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
 
 
     if (display.is_list_item())
     if (display.is_list_item())
@@ -336,9 +335,6 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
     if (display.is_table_cell())
     if (display.is_table_cell())
         return document.heap().allocate_without_realm<Layout::TableCellBox>(document, element, move(style));
         return document.heap().allocate_without_realm<Layout::TableCellBox>(document, element, move(style));
 
 
-    if (display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group())
-        return document.heap().allocate_without_realm<Layout::TableRowGroupBox>(document, element, move(style));
-
     if (display.is_table_column() || display.is_table_column_group() || display.is_table_caption()) {
     if (display.is_table_column() || display.is_table_column_group() || display.is_table_caption()) {
         // FIXME: This is just an incorrect placeholder until we improve table layout support.
         // FIXME: This is just an incorrect placeholder until we improve table layout support.
         return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));
         return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));

+ 17 - 3
Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp

@@ -11,7 +11,6 @@
 #include <LibWeb/Layout/TableCellBox.h>
 #include <LibWeb/Layout/TableCellBox.h>
 #include <LibWeb/Layout/TableFormattingContext.h>
 #include <LibWeb/Layout/TableFormattingContext.h>
 #include <LibWeb/Layout/TableRowBox.h>
 #include <LibWeb/Layout/TableRowBox.h>
-#include <LibWeb/Layout/TableRowGroupBox.h>
 
 
 struct GridPosition {
 struct GridPosition {
     size_t x;
     size_t x;
@@ -42,6 +41,21 @@ TableFormattingContext::TableFormattingContext(LayoutState& state, Box const& ro
 
 
 TableFormattingContext::~TableFormattingContext() = default;
 TableFormattingContext::~TableFormattingContext() = default;
 
 
+static inline bool is_table_row_group(Box const& box)
+{
+    auto const& display = box.display();
+    return display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group();
+}
+
+template<typename Matcher, typename Callback>
+static void for_each_child_box_matching(Box const& parent, Matcher matcher, Callback callback)
+{
+    parent.for_each_child_of_type<Box>([&](Box const& child_box) {
+        if (matcher(child_box))
+            callback(child_box);
+    });
+}
+
 void TableFormattingContext::calculate_row_column_grid(Box const& box)
 void TableFormattingContext::calculate_row_column_grid(Box const& box)
 {
 {
     // Implements https://html.spec.whatwg.org/multipage/tables.html#forming-a-table
     // Implements https://html.spec.whatwg.org/multipage/tables.html#forming-a-table
@@ -85,7 +99,7 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box)
         y_current++;
         y_current++;
     };
     };
 
 
-    box.template for_each_child_of_type<TableRowGroupBox>([&](auto& row_group_box) {
+    for_each_child_box_matching(box, is_table_row_group, [&](auto& row_group_box) {
         row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
         row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
             process_row(row);
             process_row(row);
             return IterationDecision::Continue;
             return IterationDecision::Continue;
@@ -613,7 +627,7 @@ void TableFormattingContext::position_row_boxes(CSSPixels& total_content_height)
 
 
     CSSPixels row_group_top_offset = table_state.border_top + table_state.padding_top;
     CSSPixels row_group_top_offset = table_state.border_top + table_state.padding_top;
     CSSPixels row_group_left_offset = table_state.border_left + table_state.padding_left;
     CSSPixels row_group_left_offset = table_state.border_left + table_state.padding_left;
-    table_box().for_each_child_of_type<TableRowGroupBox>([&](auto& row_group_box) {
+    for_each_child_box_matching(table_box(), is_table_row_group, [&](auto& row_group_box) {
         CSSPixels row_group_height = 0.0f;
         CSSPixels row_group_height = 0.0f;
         CSSPixels row_group_width = 0.0f;
         CSSPixels row_group_width = 0.0f;
 
 

+ 0 - 21
Userland/Libraries/LibWeb/Layout/TableRowGroupBox.cpp

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibWeb/DOM/Element.h>
-#include <LibWeb/Layout/TableCellBox.h>
-#include <LibWeb/Layout/TableRowBox.h>
-#include <LibWeb/Layout/TableRowGroupBox.h>
-
-namespace Web::Layout {
-
-TableRowGroupBox::TableRowGroupBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::Box(document, element, move(style))
-{
-}
-
-TableRowGroupBox::~TableRowGroupBox() = default;
-
-}

+ 0 - 21
Userland/Libraries/LibWeb/Layout/TableRowGroupBox.h

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/Layout/Box.h>
-
-namespace Web::Layout {
-
-class TableRowGroupBox final : public Box {
-    JS_CELL(TableRowGroupBox, Box);
-
-public:
-    TableRowGroupBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
-    virtual ~TableRowGroupBox() override;
-};
-
-}