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

LibWeb: Remove Layout::TableCellBox

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 17:15:00 +03:00 committed by Andreas Kling
parent 3a3a085404
commit 787f2d2a10
28 changed files with 75 additions and 138 deletions

View file

@ -418,7 +418,6 @@ set(SOURCES
Layout/SVGGeometryBox.cpp
Layout/SVGGraphicsBox.cpp
Layout/SVGSVGBox.cpp
Layout/TableCellBox.cpp
Layout/TableFormattingContext.cpp
Layout/TableWrapper.cpp
Layout/TextNode.cpp

View file

@ -49,7 +49,6 @@
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/InlineNode.h>
#include <LibWeb/Layout/ListItemBox.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TreeBuilder.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Namespace.h>
@ -329,7 +328,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
return document.heap().allocate_without_realm<Layout::ListItemBox>(document, element, move(style));
if (display.is_table_cell())
return document.heap().allocate_without_realm<Layout::TableCellBox>(document, element, move(style));
return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));
if (display.is_table_column() || display.is_table_column_group() || display.is_table_caption()) {
// FIXME: This is just an incorrect placeholder until we improve table layout support.

View file

@ -13,7 +13,6 @@
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Layout/SVGFormattingContext.h>
#include <LibWeb/Layout/SVGSVGBox.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableFormattingContext.h>
#include <LibWeb/Layout/Viewport.h>

View file

@ -1,38 +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/TableCellBox.h>
namespace Web::Layout {
TableCellBox::TableCellBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
: Layout::BlockContainer(document, element, move(style))
{
}
TableCellBox::TableCellBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
: Layout::BlockContainer(document, element, move(computed_values))
{
}
TableCellBox::~TableCellBox() = default;
size_t TableCellBox::colspan() const
{
if (!dom_node())
return 1;
return verify_cast<DOM::Element>(*dom_node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
}
size_t TableCellBox::rowspan() const
{
if (!dom_node())
return 1;
return verify_cast<DOM::Element>(*dom_node()).attribute(HTML::AttributeNames::rowspan).to_uint().value_or(1);
}
}

View file

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

View file

@ -6,9 +6,9 @@
#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLTableCellElement.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableFormattingContext.h>
struct GridPosition {
@ -77,13 +77,17 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box)
x_current++;
for (auto* child = row.first_child(); child; child = child->next_sibling()) {
if (is<TableCellBox>(*child)) {
if (child->display().is_table_cell()) {
Box const* box = static_cast<Box const*>(child);
if (x_current == x_width)
x_width++;
const size_t colspan = static_cast<TableCellBox const*>(child)->colspan();
const size_t rowspan = static_cast<TableCellBox const*>(child)->rowspan();
size_t colspan = 1, rowspan = 1;
if (box->dom_node() && is<HTML::HTMLTableCellElement>(*box->dom_node())) {
auto const& node = static_cast<HTML::HTMLTableCellElement const&>(*box->dom_node());
colspan = node.col_span();
rowspan = node.row_span();
}
if (x_width < x_current + colspan)
x_width = x_current + colspan;

View file

@ -24,7 +24,6 @@
#include <LibWeb/Layout/ListItemMarkerBox.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/Progress.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableWrapper.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/TreeBuilder.h>
@ -550,7 +549,7 @@ void TreeBuilder::generate_missing_child_wrappers(NodeWithStyle& root)
// An anonymous table-cell box must be generated around each sequence of consecutive children of a table-row box which are not table-cell boxes. !Testcase
for_each_in_tree_with_internal_display<CSS::Display::Internal::TableRow>(root, [&](auto& parent) {
for_each_sequence_of_consecutive_children_matching(parent, is_not_table_cell, [&](auto& sequence, auto nearest_sibling) {
wrap_in_anonymous<TableCellBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableCell });
wrap_in_anonymous<BlockContainer>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableCell });
});
});
}