فهرست منبع

LibWeb: Set width in `compute_width_for_table_wrapper()`

Width of table wrapper need to be set to to calculate width of table
box inside. Otherwise TFC will set wrong width assuming width of
containing block is 0.
Aliaksandr Kalenik 2 سال پیش
والد
کامیت
3a605d8c19

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

@@ -0,0 +1,31 @@
+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 784x40.9375 children: inline
+      line 0 width: 131.984375, height: 40.9375, bottom: 40.9375, baseline: 35
+        frag 0 from BlockContainer start: 0, length: 0, rect: [9,9 129.984375x38.9375]
+      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
+          TableBox <(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
+              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
+                  line 0 width: 15.734375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                    frag 0 from TextNode start: 0, length: 2, rect: [10,10 15.734375x17.46875]
+                      "ID"
+                  TextNode <#text>
+                TableCellBox <td> at (99.90625,10) content-size 38.078125x17.46875 [BFC] children: inline
+                  line 0 width: 27.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                    frag 0 from TextNode start: 0, length: 4, rect: [99.90625,10 27.84375x17.46875]
+                      "null"
+                  TextNode <#text>
+              TableRowBox <tr> at (9,28.46875) content-size 129.984375x19.46875 children: not-inline
+                TableCellBox <td> at (10,29.46875) content-size 87.90625x17.46875 [BFC] children: inline
+                  line 0 width: 87.90625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                    frag 0 from TextNode start: 0, length: 11, rect: [10,29.46875 87.90625x17.46875]
+                      "Is Selected"
+                  TextNode <#text>
+                TableCellBox <td> at (99.90625,29.46875) content-size 38.078125x17.46875 [BFC] children: inline
+                  line 0 width: 38.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                    frag 0 from TextNode start: 0, length: 5, rect: [99.90625,29.46875 38.078125x17.46875]
+                      "false"
+                  TextNode <#text>

+ 10 - 0
Tests/LibWeb/Layout/input/table/inline-table-width.html

@@ -0,0 +1,10 @@
+<style type="text/css">
+* {
+    font-family: 'SerenitySans';
+}
+
+table {
+    border: 1px solid #333;
+    display: inline-block;
+}
+</style><table><tr><td>ID</td><td>null</td></tr><tr><td>Is Selected</td><td>false</td></tr></table>

+ 1 - 0
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -375,6 +375,7 @@ CSSPixels BlockFormattingContext::compute_width_for_table_wrapper(Box const& box
     auto available_width = width_of_containing_block - margin_left.to_px(box) - margin_right.to_px(box);
 
     LayoutState throwaway_state(&m_state);
+    throwaway_state.get_mutable(box).set_content_width(available_width);
     auto context = create_independent_formatting_context_if_needed(throwaway_state, box);
     VERIFY(context);
     context->run(box, LayoutMode::IntrinsicSizing, m_state.get(box).available_inner_space_or_constraints_from(available_space));