Преглед на файлове

LibWeb: Check column or row size attributes for constrainedness

Better aligns our implementation with the specification, which requires
that columns and groups of columns are checked too.
Andi Gallo преди 2 години
родител
ревизия
28509e3edd

+ 32 - 0
Tests/LibWeb/Layout/expected/table/width-distribution-and-constrained-columns-size-on-col.txt

@@ -0,0 +1,32 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+  BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x27.46875 children: not-inline
+      TableWrapper <(anonymous)> at (8,8) content-size 420x27.46875 [BFC] children: not-inline
+        Box <table> at (9,9) content-size 418x25.46875 table-box [TFC] children: not-inline
+          BlockContainer <(anonymous)> (not painted) children: inline
+            TextNode <#text>
+          BlockContainer <colgroup> (not painted) table-column-group children: not-inline
+            BlockContainer <col> (not painted) children: not-inline
+            BlockContainer <col> (not painted) children: not-inline
+          BlockContainer <(anonymous)> (not painted) children: inline
+            TextNode <#text>
+          Box <tbody> at (9,9) content-size 412x21.46875 table-row-group children: not-inline
+            Box <tr> at (11,11) content-size 412x21.46875 table-row children: not-inline
+              BlockContainer <(anonymous)> (not painted) children: inline
+                TextNode <#text>
+              BlockContainer <td> at (13,13) content-size 14.265625x17.46875 table-cell [BFC] children: inline
+                line 0 width: 14.265625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                  frag 0 from TextNode start: 0, length: 1, rect: [13,13 14.265625x17.46875]
+                    "A"
+                TextNode <#text>
+              BlockContainer <(anonymous)> (not painted) children: inline
+                TextNode <#text>
+              BlockContainer <td> at (33.265625,13) content-size 389.734375x17.46875 table-cell [BFC] children: inline
+                line 0 width: 9.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                  frag 0 from TextNode start: 0, length: 1, rect: [33.265625,13 9.34375x17.46875]
+                    "B"
+                TextNode <#text>
+              BlockContainer <(anonymous)> (not painted) children: inline
+                TextNode <#text>
+            BlockContainer <(anonymous)> (not painted) children: inline
+              TextNode <#text>

+ 10 - 0
Tests/LibWeb/Layout/input/table/width-distribution-and-constrained-columns-size-on-col.html

@@ -0,0 +1,10 @@
+<table style="width:420px;border:1px solid">
+    <colgroup>
+        <col style="width:1px">
+        <col>
+    </colgroup>
+    <tr>
+        <td style="border:1px solid">A</td>
+        <td style="border:1px solid">B</td>
+    </tr>
+</table>

+ 44 - 6
Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp

@@ -54,6 +54,16 @@ static inline bool is_table_row(Box const& box)
     return box.display().is_table_row();
 }
 
+static inline bool is_table_column_group(Box const& box)
+{
+    return box.display().is_table_column_group();
+}
+
+static inline bool is_table_column(Box const& box)
+{
+    return box.display().is_table_column();
+}
+
 template<typename Matcher, typename Callback>
 static void for_each_child_box_matching(Box const& parent, Matcher matcher, Callback callback)
 {
@@ -173,16 +183,31 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box)
     }
 }
 
-void TableFormattingContext::compute_cell_measures(AvailableSpace const& available_space)
+void TableFormattingContext::compute_constrainedness()
 {
-    // Implements https://www.w3.org/TR/css-tables-3/#computing-cell-measures.
-    auto const& containing_block = m_state.get(*table_wrapper().containing_block());
-    auto table_width_is_auto = table_box().computed_values().width().is_auto();
+    // Definition of constrainedness: https://www.w3.org/TR/css-tables-3/#constrainedness
+    size_t column_index = 0;
+    for_each_child_box_matching(table_box(), is_table_column_group, [&](auto& column_group_box) {
+        for_each_child_box_matching(column_group_box, is_table_column, [&](auto& column_box) {
+            auto const& computed_values = column_box.computed_values();
+            if (!computed_values.width().is_auto() && !computed_values.width().is_percentage()) {
+                m_columns[column_index].is_constrained = true;
+            }
+            auto const& col_node = static_cast<HTML::HTMLTableColElement const&>(*column_box.dom_node());
+            unsigned span = col_node.attribute(HTML::AttributeNames::span).to_uint().value_or(1);
+            column_index += span;
+        });
+    });
+
+    for (auto& row : m_rows) {
+        auto const& computed_values = row.box->computed_values();
+        if (!computed_values.height().is_auto() && !computed_values.height().is_percentage()) {
+            row.is_constrained = true;
+        }
+    }
 
     for (auto& cell : m_cells) {
         auto const& computed_values = cell.box->computed_values();
-        // Definition of constrainedness: https://www.w3.org/TR/css-tables-3/#constrainedness
-        // FIXME: Consider table-column-group and table-column too.
         if (!computed_values.width().is_auto() && !computed_values.width().is_percentage()) {
             m_columns[cell.column_index].is_constrained = true;
         }
@@ -190,6 +215,19 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab
         if (!computed_values.height().is_auto() && !computed_values.height().is_percentage()) {
             m_rows[cell.row_index].is_constrained = true;
         }
+    }
+}
+
+void TableFormattingContext::compute_cell_measures(AvailableSpace const& available_space)
+{
+    // Implements https://www.w3.org/TR/css-tables-3/#computing-cell-measures.
+    auto const& containing_block = m_state.get(*table_wrapper().containing_block());
+    auto table_width_is_auto = table_box().computed_values().width().is_auto();
+
+    compute_constrainedness();
+
+    for (auto& cell : m_cells) {
+        auto const& computed_values = cell.box->computed_values();
 
         if (computed_values.width().is_percentage()) {
             m_columns[cell.column_index].has_percentage_width = true;

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

@@ -38,6 +38,7 @@ private:
     CSSPixels run_caption_layout(LayoutMode, CSS::CaptionSide);
     CSSPixels compute_capmin();
     void calculate_row_column_grid(Box const&);
+    void compute_constrainedness();
     void compute_cell_measures(AvailableSpace const& available_space);
     template<class RowOrColumn>
     void initialize_table_measures();