Truly independent web browser
LibWeb: Map valign on table row groups to vertical-align
sideshowbarker21b9b4c94a39
diff --git a/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Libraries/LibWeb/HTML/HTMLTableSectionElement.cppindex ca66b314c2e..ca03e093db4 100644--- a/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp@@ -5,6 +5,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibWeb/CSS/Parser/Parser.h>#include <LibWeb/CSS/PropertyID.h>#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>@@ -100,7 +101,8 @@ bool HTMLTableSectionElement::is_presentational_hint(Utf16FlyString const& name)HTML::AttributeNames::align,HTML::AttributeNames::background,HTML::AttributeNames::bgcolor,- HTML::AttributeNames::height);+ HTML::AttributeNames::height,+ HTML::AttributeNames::valign);}void HTMLTableSectionElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const@@ -124,6 +126,13 @@ void HTMLTableSectionElement::apply_presentational_hints(Vector<CSS::StyleProperif (auto parsed_value = parse_dimension_value(value))properties.append({ .property_id = CSS::PropertyID::Height, .value = parsed_value.release_nonnull() });}+ // https://html.spec.whatwg.org/multipage/rendering.html#tables-2+ // AD-HOC: The spec maps only "top", "middle", "bottom", and "baseline". Any value that parses as a+ // vertical-align value is mapped instead, the same as for rows and cells, for web compatibility.+ else if (name == HTML::AttributeNames::valign) {+ if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::VerticalAlign))+ properties.append({ .property_id = CSS::PropertyID::VerticalAlign, .value = parsed_value.release_nonnull() });+ }});}diff --git a/Tests/LibWeb/Text/expected/table/table-section-valign.txt b/Tests/LibWeb/Text/expected/table/table-section-valign.txtnew file mode 100644index 00000000000..0fca8e25899--- /dev/null+++ b/Tests/LibWeb/Text/expected/table/table-section-valign.txt@@ -0,0 +1,5 @@+thead-bottom: vertical-align bottom, offset 80+tbody-top: vertical-align top, offset 0+tr-overrides-tbody: vertical-align bottom, offset 80+td-overrides-tbody: vertical-align middle, offset 40+tfoot-middle: vertical-align middle, offset 40diff --git a/Tests/LibWeb/Text/input/table/table-section-valign.html b/Tests/LibWeb/Text/input/table/table-section-valign.htmlnew file mode 100644index 00000000000..d8a2515c04f--- /dev/null+++ b/Tests/LibWeb/Text/input/table/table-section-valign.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<style>+ td { padding: 0; }+ .tall { height: 100px; }+ .box { width: 20px; height: 20px; }+</style>+<table cellspacing="0">+ <thead valign="bottom"><tr><td class="tall"></td><td><div class="box" id="thead-bottom"></div></td></tr></thead>+ <tbody valign="TOP"><tr><td class="tall"></td><td><div class="box" id="tbody-top"></div></td></tr></tbody>+ <tbody valign="top"><tr valign="bottom"><td class="tall"></td><td><div class="box" id="tr-overrides-tbody"></div></td></tr></tbody>+ <tbody valign="top"><tr><td class="tall"></td><td valign="middle"><div class="box" id="td-overrides-tbody"></div></td></tr></tbody>+ <tfoot valign="middle"><tr><td class="tall"></td><td><div class="box" id="tfoot-middle"></div></td></tr></tfoot>+</table>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const id of ["thead-bottom", "tbody-top", "tr-overrides-tbody", "td-overrides-tbody", "tfoot-middle"]) {+ const box = document.getElementById(id);+ const cell = box.parentElement;+ const offset = box.getBoundingClientRect().top - cell.getBoundingClientRect().top;+ println(`${id}: vertical-align ${getComputedStyle(cell).verticalAlign}, offset ${Math.round(offset)}`);+ }+ });+</script>