1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00

LibWeb: Wrap table roots in anonymous block boxes

According to table fixup algorithm:
https://www.w3.org/TR/css-tables-3/#fixup-algorithm
around every table-root should be generated anonymous
box wrapper.

Also this patch implements important part of CSS 2.2
spec that is currently not present in CSS Tables 3
spec draft: https://www.w3.org/TR/CSS22/tables.html#model
that portion of computed properties should be moved
from table-root to table wrapper box. Without having
this part implemented height of absolutely positioned
table with `height: auto` won't be computed correctly.
This commit is contained in:
Aliaksandr Kalenik 2023-01-09 08:27:39 +03:00 committed by Andreas Kling
parent e107c83a57
commit 57940f4370
3 changed files with 43 additions and 0 deletions

View file

@ -550,6 +550,7 @@ void TreeBuilder::generate_missing_child_wrappers(NodeWithStyle& root)
void TreeBuilder::generate_missing_parents(NodeWithStyle& root)
{
Vector<JS::Handle<TableBox>> table_roots_to_wrap;
root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& parent) {
// An anonymous table-row box must be generated around each sequence of consecutive table-cell boxes whose parent is not a table-row.
if (is_not_table_row(parent)) {
@ -572,8 +573,36 @@ void TreeBuilder::generate_missing_parents(NodeWithStyle& root)
});
}
// An anonymous table-wrapper box must be generated around each table-root.
if (parent.display().is_table_inside()) {
table_roots_to_wrap.append(static_cast<TableBox&>(parent));
}
return IterationDecision::Continue;
});
for (auto& table_box : table_roots_to_wrap) {
auto* nearest_sibling = table_box->next_sibling();
auto& parent = *table_box->parent();
CSS::ComputedValues wrapper_computed_values;
// The computed values of properties 'position', 'float', 'margin-*', 'top', 'right', 'bottom', and 'left' on the table element are used on the table wrapper box and not the table box;
// all other values of non-inheritable properties are used on the table box and not the table wrapper box.
// (Where the table element's values are not used on the table and table wrapper boxes, the initial values are used instead.)
auto& mutable_wrapper_computed_values = static_cast<CSS::MutableComputedValues&>(wrapper_computed_values);
mutable_wrapper_computed_values.set_display(CSS::Display(CSS::Display::Outside::Block, CSS::Display::Inside::FlowRoot));
mutable_wrapper_computed_values.set_position(table_box->computed_values().position());
mutable_wrapper_computed_values.set_inset(table_box->computed_values().inset());
mutable_wrapper_computed_values.set_float(table_box->computed_values().float_());
mutable_wrapper_computed_values.set_margin(table_box->computed_values().margin());
table_box->reset_table_box_computed_values_used_by_wrapper_to_init_values();
auto wrapper = parent.heap().allocate_without_realm<BlockContainer>(parent.document(), nullptr, move(wrapper_computed_values));
parent.remove_child(*table_box);
wrapper->append_child(*table_box);
parent.insert_before(*wrapper, *nearest_sibling);
}
}
}