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

LibWeb: Rename LayoutNode classes and move them into Layout namespace

Bring the names of various boxes closer to spec language. This should
hopefully make things easier to understand and hack on. :^)

Some notable changes:

- LayoutNode -> Layout::Node
- LayoutBox -> Layout::Box
- LayoutBlock -> Layout::BlockBox
- LayoutReplaced -> Layout::ReplacedBox
- LayoutDocument -> Layout::InitialContainingBlockBox
- LayoutText -> Layout::TextNode
- LayoutInline -> Layout::InlineNode

Note that this is not strictly a "box tree" as we also hang inline/text
nodes in the same tree, and they don't generate boxes. (Instead, they
contribute line box fragments to their containing block!)
This commit is contained in:
Andreas Kling 2020-11-22 15:53:01 +01:00
parent f358f2255f
commit 5aeab9878e
114 changed files with 863 additions and 880 deletions

View file

@ -26,19 +26,19 @@
#include <LibWeb/CSS/Length.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/Layout/BlockBox.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/LayoutBlock.h>
#include <LibWeb/Layout/LayoutBox.h>
#include <LibWeb/Layout/LayoutTable.h>
#include <LibWeb/Layout/LayoutTableCell.h>
#include <LibWeb/Layout/LayoutTableRow.h>
#include <LibWeb/Layout/LayoutTableRowGroup.h>
#include <LibWeb/Layout/TableBox.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableFormattingContext.h>
#include <LibWeb/Layout/TableRowBox.h>
#include <LibWeb/Layout/TableRowGroupBox.h>
#include <LibWeb/Page/Frame.h>
namespace Web::Layout {
TableFormattingContext::TableFormattingContext(LayoutBox& context_box)
TableFormattingContext::TableFormattingContext(Box& context_box)
: BlockFormattingContext(context_box)
{
}
@ -51,19 +51,19 @@ void TableFormattingContext::run(LayoutMode)
{
compute_width(context_box());
context_box().for_each_child_of_type<LayoutTableRowGroup>([&](auto& box) {
context_box().for_each_child_of_type<TableRowGroupBox>([&](auto& box) {
compute_width(box);
auto column_count = box.column_count();
Vector<float> column_widths;
column_widths.resize(column_count);
box.template for_each_child_of_type<LayoutTableRow>([&](auto& row) {
box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
calculate_column_widths(row, column_widths);
});
float content_height = 0;
box.template for_each_child_of_type<LayoutTableRow>([&](auto& row) {
box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
row.set_offset(0, content_height);
layout_row(row, column_widths);
content_height += row.height();
@ -75,12 +75,12 @@ void TableFormattingContext::run(LayoutMode)
compute_height(context_box());
}
void TableFormattingContext::calculate_column_widths(LayoutBox& row, Vector<float>& column_widths)
void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& column_widths)
{
size_t column_index = 0;
auto* table = row.first_ancestor_of_type<LayoutTable>();
auto* table = row.first_ancestor_of_type<TableBox>();
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
row.for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
compute_width(cell);
if (use_auto_layout) {
layout_inside(cell, LayoutMode::OnlyRequiredLineBreaks);
@ -92,15 +92,15 @@ void TableFormattingContext::calculate_column_widths(LayoutBox& row, Vector<floa
});
}
void TableFormattingContext::layout_row(LayoutBox& row, Vector<float>& column_widths)
void TableFormattingContext::layout_row(Box& row, Vector<float>& column_widths)
{
size_t column_index = 0;
float tallest_cell_height = 0;
float content_width = 0;
auto* table = row.first_ancestor_of_type<LayoutTable>();
auto* table = row.first_ancestor_of_type<TableBox>();
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
row.for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
cell.set_offset(row.effective_offset().translated(content_width, 0));
// Layout the cell contents a second time, now that we know its final width.