浏览代码

LibWeb: Support `align` attribute on `table` elements

implicitfield 1 年之前
父节点
当前提交
a54e62bea0

+ 24 - 0
Tests/LibWeb/Layout/expected/table/table-align-center-with-margin.txt

@@ -0,0 +1,24 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+  BlockContainer <html> at (0,0) content-size 800x312 [BFC] children: not-inline
+    BlockContainer <body> at (8,100) content-size 784x204 children: not-inline
+      TableWrapper <(anonymous)> at (108,100) content-size 89.34375x204 [BFC] children: not-inline
+        Box <table> at (109,101) content-size 87.34375x202 table-box [TFC] children: not-inline
+          Box <tbody> at (109,101) content-size 83.34375x198 table-row-group children: not-inline
+            Box <tr> at (111,103) content-size 83.34375x198 table-row children: not-inline
+              BlockContainer <td> at (112,193.265625) content-size 81.34375x17.46875 table-cell [BFC] children: inline
+                line 0 width: 81.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                  frag 0 from TextNode start: 0, length: 10, rect: [112,193.265625 81.34375x17.46875]
+                    "off-center"
+                TextNode <#text>
+              BlockContainer <(anonymous)> (not painted) children: inline
+                TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x312]
+    PaintableWithLines (BlockContainer<BODY>) [8,100 784x204]
+      PaintableWithLines (TableWrapper(anonymous)) [108,100 89.34375x204]
+        PaintableBox (Box<TABLE>) [108,100 89.34375x204]
+          PaintableBox (Box<TBODY>) [109,101 83.34375x198] overflow: [109,101 85.34375x200]
+            PaintableBox (Box<TR>) [111,103 83.34375x198]
+              PaintableWithLines (BlockContainer<TD>) [111,103 83.34375x198]
+                TextPaintable (TextNode<#text>)

+ 24 - 0
Tests/LibWeb/Layout/expected/table/table-align-center.txt

@@ -0,0 +1,24 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+  BlockContainer <html> at (0,0) content-size 800x220 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x204 children: not-inline
+      TableWrapper <(anonymous)> at (370.1875,8) content-size 59.625x204 [BFC] children: not-inline
+        Box <table> at (371.1875,9) content-size 57.625x202 table-box [TFC] children: not-inline
+          Box <tbody> at (371.1875,9) content-size 53.625x198 table-row-group children: not-inline
+            Box <tr> at (373.1875,11) content-size 53.625x198 table-row children: not-inline
+              BlockContainer <td> at (374.1875,101.265625) content-size 51.625x17.46875 table-cell [BFC] children: inline
+                line 0 width: 51.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+                  frag 0 from TextNode start: 0, length: 6, rect: [374.1875,101.265625 51.625x17.46875]
+                    "center"
+                TextNode <#text>
+              BlockContainer <(anonymous)> (not painted) children: inline
+                TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x220]
+    PaintableWithLines (BlockContainer<BODY>) [8,8 784x204]
+      PaintableWithLines (TableWrapper(anonymous)) [370.1875,8 59.625x204]
+        PaintableBox (Box<TABLE>) [370.1875,8 59.625x204]
+          PaintableBox (Box<TBODY>) [371.1875,9 53.625x198] overflow: [371.1875,9 55.625x200]
+            PaintableBox (Box<TR>) [373.1875,11 53.625x198]
+              PaintableWithLines (BlockContainer<TD>) [373.1875,11 53.625x198]
+                TextPaintable (TextNode<#text>)

+ 7 - 0
Tests/LibWeb/Layout/input/table/table-align-center-with-margin.html

@@ -0,0 +1,7 @@
+<!doctype html><style>
+table {
+    height: 200px;
+    border: 1px solid black;
+    margin: 100px;
+}
+</style><table align="center"><td>off-center</td>

+ 6 - 0
Tests/LibWeb/Layout/input/table/table-align-center.html

@@ -0,0 +1,6 @@
+<!doctype html><style>
+table {
+    height: 200px;
+    border: 1px solid black;
+}
+</style><table align="center"><td>center</td>

+ 9 - 0
Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp

@@ -61,6 +61,15 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
                 style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
                 style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
             return;
             return;
         }
         }
+        if (name == HTML::AttributeNames::align) {
+            if (value.equals_ignoring_ascii_case("center"sv)) {
+                style.set_property(CSS::PropertyID::MarginLeft, CSS::IdentifierStyleValue::create(CSS::ValueID::Auto));
+                style.set_property(CSS::PropertyID::MarginRight, CSS::IdentifierStyleValue::create(CSS::ValueID::Auto));
+            } else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value.view(), CSS::PropertyID::Float)) {
+                style.set_property(CSS::PropertyID::Float, parsed_value.release_nonnull());
+            }
+            return;
+        }
         if (name == HTML::AttributeNames::bgcolor) {
         if (name == HTML::AttributeNames::bgcolor) {
             // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
             // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
             auto color = parse_legacy_color_value(value);
             auto color = parse_legacy_color_value(value);