mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 00:58:12 +00:00
LibWeb: Layout table-cell contents once again once final width is known
This makes centered and right-aligned table-cell contents position itself correctly.
This commit is contained in:
parent
4924b86b2a
commit
dcc25f7d7a
2 changed files with 19 additions and 9 deletions
|
@ -65,6 +65,8 @@ public:
|
||||||
|
|
||||||
virtual void split_into_lines(LayoutBlock& container, LayoutMode) override;
|
virtual void split_into_lines(LayoutBlock& container, LayoutMode) override;
|
||||||
|
|
||||||
|
void layout_inside(LayoutMode);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void compute_width();
|
void compute_width();
|
||||||
void compute_height();
|
void compute_height();
|
||||||
|
@ -89,7 +91,6 @@ private:
|
||||||
|
|
||||||
NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
|
NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
|
||||||
|
|
||||||
void layout_inside(LayoutMode);
|
|
||||||
void layout_inline_children(LayoutMode);
|
void layout_inline_children(LayoutMode);
|
||||||
void layout_contained_boxes(LayoutMode);
|
void layout_contained_boxes(LayoutMode);
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,13 @@ void LayoutTableRow::layout(LayoutMode)
|
||||||
void LayoutTableRow::calculate_column_widths(Vector<float>& column_widths)
|
void LayoutTableRow::calculate_column_widths(Vector<float>& column_widths)
|
||||||
{
|
{
|
||||||
size_t column_index = 0;
|
size_t column_index = 0;
|
||||||
|
auto* table = first_ancestor_of_type<LayoutTable>();
|
||||||
|
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
|
||||||
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
||||||
auto* table = first_ancestor_of_type<LayoutTable>();
|
if (use_auto_layout) {
|
||||||
if (table && !table->style().width().is_undefined_or_auto()) {
|
|
||||||
cell.layout(LayoutMode::Default);
|
|
||||||
} else {
|
|
||||||
cell.layout(LayoutMode::OnlyRequiredLineBreaks);
|
cell.layout(LayoutMode::OnlyRequiredLineBreaks);
|
||||||
|
} else {
|
||||||
|
cell.layout(LayoutMode::Default);
|
||||||
}
|
}
|
||||||
column_widths[column_index] = max(column_widths[column_index], cell.width());
|
column_widths[column_index] = max(column_widths[column_index], cell.width());
|
||||||
column_index += cell.colspan();
|
column_index += cell.colspan();
|
||||||
|
@ -64,21 +65,29 @@ void LayoutTableRow::layout_row(const Vector<float>& column_widths)
|
||||||
size_t column_index = 0;
|
size_t column_index = 0;
|
||||||
float tallest_cell_height = 0;
|
float tallest_cell_height = 0;
|
||||||
float content_width = 0;
|
float content_width = 0;
|
||||||
|
auto* table = first_ancestor_of_type<LayoutTable>();
|
||||||
|
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
|
||||||
|
|
||||||
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
||||||
cell.set_offset(effective_offset().translated(content_width, 0));
|
cell.set_offset(effective_offset().translated(content_width, 0));
|
||||||
|
|
||||||
|
// Layout the cell contents a second time, now that we know its final width.
|
||||||
|
if (use_auto_layout) {
|
||||||
|
cell.layout_inside(LayoutMode::OnlyRequiredLineBreaks);
|
||||||
|
} else {
|
||||||
|
cell.layout_inside(LayoutMode::Default);
|
||||||
|
}
|
||||||
|
|
||||||
size_t cell_colspan = cell.colspan();
|
size_t cell_colspan = cell.colspan();
|
||||||
for (size_t i = 0; i < cell_colspan; ++i)
|
for (size_t i = 0; i < cell_colspan; ++i)
|
||||||
content_width += column_widths[column_index++];
|
content_width += column_widths[column_index++];
|
||||||
tallest_cell_height = max(tallest_cell_height, cell.height());
|
tallest_cell_height = max(tallest_cell_height, cell.height());
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* table = first_ancestor_of_type<LayoutTable>();
|
if (use_auto_layout) {
|
||||||
if (table && !table->style().width().is_undefined_or_auto()) {
|
|
||||||
set_width(table->width());
|
|
||||||
} else {
|
|
||||||
set_width(content_width);
|
set_width(content_width);
|
||||||
|
} else {
|
||||||
|
set_width(table->width());
|
||||||
}
|
}
|
||||||
|
|
||||||
set_height(tallest_cell_height);
|
set_height(tallest_cell_height);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue