1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:17:45 +00:00

LibWeb: Remove Layout::TableRowBox

Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
This commit is contained in:
Aliaksandr Kalenik 2023-05-29 16:07:28 +03:00 committed by Andreas Kling
parent 578a937f94
commit 3a3a085404
29 changed files with 64 additions and 113 deletions

View file

@ -6,7 +6,6 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableRowBox.h>
namespace Web::Layout {

View file

@ -10,7 +10,6 @@
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableFormattingContext.h>
#include <LibWeb/Layout/TableRowBox.h>
struct GridPosition {
size_t x;
@ -47,6 +46,11 @@ static inline bool is_table_row_group(Box const& box)
return display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group();
}
static inline bool is_table_row(Box const& box)
{
return box.display().is_table_row();
}
template<typename Matcher, typename Callback>
static void for_each_child_box_matching(Box const& parent, Matcher matcher, Callback callback)
{
@ -74,12 +78,12 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box)
for (auto* child = row.first_child(); child; child = child->next_sibling()) {
if (is<TableCellBox>(*child)) {
Box* box = static_cast<Box*>(child);
Box const* box = static_cast<Box const*>(child);
if (x_current == x_width)
x_width++;
const size_t colspan = static_cast<TableCellBox*>(child)->colspan();
const size_t rowspan = static_cast<TableCellBox*>(child)->rowspan();
const size_t colspan = static_cast<TableCellBox const*>(child)->colspan();
const size_t rowspan = static_cast<TableCellBox const*>(child)->rowspan();
if (x_width < x_current + colspan)
x_width = x_current + colspan;
@ -100,14 +104,14 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box)
};
for_each_child_box_matching(box, is_table_row_group, [&](auto& row_group_box) {
row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
process_row(row);
for_each_child_box_matching(row_group_box, is_table_row, [&](auto& row_box) {
process_row(row_box);
return IterationDecision::Continue;
});
});
box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
process_row(row);
for_each_child_box_matching(box, is_table_row, [&](auto& row_box) {
process_row(row_box);
return IterationDecision::Continue;
});
@ -635,7 +639,7 @@ void TableFormattingContext::position_row_boxes(CSSPixels& total_content_height)
row_group_box_state.set_content_x(row_group_left_offset);
row_group_box_state.set_content_y(row_group_top_offset);
row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
for_each_child_box_matching(row_group_box, is_table_row, [&](auto& row) {
auto const& row_state = m_state.get(row);
row_group_height += row_state.border_box_height();
row_group_width = max(row_group_width, row_state.border_box_width());

View file

@ -59,7 +59,7 @@ private:
};
struct Row {
JS::NonnullGCPtr<Box> box;
JS::NonnullGCPtr<Box const> box;
CSSPixels base_height { 0 };
CSSPixels reference_height { 0 };
CSSPixels final_height { 0 };
@ -67,7 +67,7 @@ private:
};
struct Cell {
JS::NonnullGCPtr<Box> box;
JS::NonnullGCPtr<Box const> box;
size_t column_index;
size_t row_index;
size_t column_span;

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/TableRowBox.h>
namespace Web::Layout {
TableRowBox::TableRowBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
: Box(document, element, move(style))
{
}
TableRowBox::TableRowBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
: Box(document, element, move(computed_values))
{
}
TableRowBox::~TableRowBox() = default;
}

View file

@ -1,22 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Layout/Box.h>
namespace Web::Layout {
class TableRowBox final : public Box {
JS_CELL(TableRowBox, Box);
public:
TableRowBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
TableRowBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
virtual ~TableRowBox() override;
};
}

View file

@ -25,7 +25,6 @@
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/Progress.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableRowBox.h>
#include <LibWeb/Layout/TableWrapper.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/TreeBuilder.h>
@ -525,26 +524,26 @@ void TreeBuilder::generate_missing_child_wrappers(NodeWithStyle& root)
// An anonymous table-row box must be generated around each sequence of consecutive children of a table-root box which are not proper table child boxes.
for_each_in_tree_with_inside_display<CSS::Display::Inside::Table>(root, [&](auto& parent) {
for_each_sequence_of_consecutive_children_matching(parent, is_not_proper_table_child, [&](auto sequence, auto nearest_sibling) {
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
});
});
// An anonymous table-row box must be generated around each sequence of consecutive children of a table-row-group box which are not table-row boxes.
for_each_in_tree_with_internal_display<CSS::Display::Internal::TableRowGroup>(root, [&](auto& parent) {
for_each_sequence_of_consecutive_children_matching(parent, is_not_table_row, [&](auto& sequence, auto nearest_sibling) {
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
});
});
// Unless explicitly mentioned otherwise, mentions of table-row-groups in this spec also encompass the specialized
// table-header-groups and table-footer-groups.
for_each_in_tree_with_internal_display<CSS::Display::Internal::TableHeaderGroup>(root, [&](auto& parent) {
for_each_sequence_of_consecutive_children_matching(parent, is_not_table_row, [&](auto& sequence, auto nearest_sibling) {
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
});
});
for_each_in_tree_with_internal_display<CSS::Display::Internal::TableFooterGroup>(root, [&](auto& parent) {
for_each_sequence_of_consecutive_children_matching(parent, is_not_table_row, [&](auto& sequence, auto nearest_sibling) {
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
});
});
@ -563,7 +562,7 @@ void TreeBuilder::generate_missing_parents(NodeWithStyle& root)
// 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)) {
for_each_sequence_of_consecutive_children_matching(parent, is_table_cell, [&](auto& sequence, auto nearest_sibling) {
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
});
}