mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +00:00
LibWeb: Remove Layout::TableBox
Solves conflict in layout tree "type system" when elements <label> (or <button>) can't have `display: table` because Box can't be Layout::Label (or Layout::ButtonBox) and Layout::TableBox at the same time.
This commit is contained in:
parent
269310268d
commit
258f3ea952
34 changed files with 55 additions and 118 deletions
|
@ -18,7 +18,6 @@
|
|||
#include <LibWeb/Layout/ListItemMarkerBox.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableWrapper.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
|
||||
|
@ -385,7 +384,16 @@ CSSPixels BlockFormattingContext::compute_table_box_width_inside_table_wrapper(B
|
|||
auto context = create_independent_formatting_context_if_needed(throwaway_state, box);
|
||||
VERIFY(context);
|
||||
context->run(box, LayoutMode::IntrinsicSizing, m_state.get(box).available_inner_space_or_constraints_from(available_space));
|
||||
auto const* table_box = box.first_child_of_type<TableBox>();
|
||||
|
||||
Optional<Box const&> table_box;
|
||||
box.for_each_in_subtree_of_type<Box>([&](Box const& child_box) {
|
||||
if (child_box.display().is_table_inside()) {
|
||||
table_box = child_box;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
VERIFY(table_box.has_value());
|
||||
|
||||
auto table_used_width = throwaway_state.get(*table_box).content_width();
|
||||
return table_used_width > available_width ? available_width : table_used_width;
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/SVGFormattingContext.h>
|
||||
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableCellBox.h>
|
||||
#include <LibWeb/Layout/TableFormattingContext.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
|
@ -192,7 +191,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
|
|||
case Type::Grid:
|
||||
return make<GridFormattingContext>(state, child_box, this);
|
||||
case Type::Table:
|
||||
return make<TableFormattingContext>(state, verify_cast<TableBox>(child_box), this);
|
||||
return make<TableFormattingContext>(state, child_box, this);
|
||||
case Type::InternalReplaced:
|
||||
return make<ReplacedFormattingContext>(state, child_box);
|
||||
case Type::InternalDummy:
|
||||
|
@ -1230,7 +1229,7 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box)
|
|||
CSSPixels FormattingContext::calculate_min_content_height(Layout::Box const& box, AvailableSize const& available_width) const
|
||||
{
|
||||
// For block containers, tables, and inline boxes, this is equivalent to the max-content block size.
|
||||
if (box.is_block_container() || box.is_table())
|
||||
if (box.is_block_container() || box.display().is_table_inside())
|
||||
return calculate_max_content_height(box, available_width);
|
||||
|
||||
if (box.has_intrinsic_height())
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <LibWeb/Layout/BlockContainer.h>
|
||||
#include <LibWeb/Layout/FormattingContext.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
#include <LibWeb/Platform/FontPlugin.h>
|
||||
|
@ -759,7 +758,7 @@ JS::NonnullGCPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
|
|||
|
||||
void NodeWithStyle::reset_table_box_computed_values_used_by_wrapper_to_init_values()
|
||||
{
|
||||
VERIFY(is<TableBox>(*this));
|
||||
VERIFY(this->display().is_table_inside());
|
||||
|
||||
CSS::MutableComputedValues& mutable_computed_values = static_cast<CSS::MutableComputedValues&>(m_computed_values);
|
||||
mutable_computed_values.set_position(CSS::Position::Static);
|
||||
|
|
|
@ -95,7 +95,6 @@ public:
|
|||
virtual bool is_list_item_box() const { return false; }
|
||||
virtual bool is_list_item_marker_box() const { return false; }
|
||||
virtual bool is_table_wrapper() const { return false; }
|
||||
virtual bool is_table() const { return false; }
|
||||
virtual bool is_node_with_style_and_box_model_metrics() const { return false; }
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -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/TableBox.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
TableBox::TableBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
|
||||
: Layout::Box(document, element, move(style))
|
||||
{
|
||||
}
|
||||
|
||||
TableBox::TableBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
|
||||
: Layout::Box(document, element, move(computed_values))
|
||||
{
|
||||
}
|
||||
|
||||
TableBox::~TableBox() = default;
|
||||
|
||||
}
|
|
@ -1,35 +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 TableBox final : public Layout::Box {
|
||||
JS_CELL(TableBox, Box);
|
||||
|
||||
public:
|
||||
TableBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
TableBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
|
||||
virtual ~TableBox() override;
|
||||
|
||||
static CSS::Display static_display(bool inline_outside)
|
||||
{
|
||||
if (inline_outside)
|
||||
return CSS::Display::from_short(CSS::Display::Short::InlineTable);
|
||||
return CSS::Display::from_short(CSS::Display::Short::Table);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool is_table() const override { return true; }
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Node::fast_is<TableBox>() const { return is_table(); }
|
||||
|
||||
}
|
|
@ -20,8 +20,6 @@ public:
|
|||
|
||||
size_t colspan() const;
|
||||
size_t rowspan() const;
|
||||
|
||||
static CSS::Display static_display(bool) { return CSS::Display { CSS::Display::Internal::TableCell }; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/Layout/Box.h>
|
||||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableCellBox.h>
|
||||
#include <LibWeb/Layout/TableFormattingContext.h>
|
||||
#include <LibWeb/Layout/TableRowBox.h>
|
||||
|
@ -36,7 +35,7 @@ struct Traits<GridPosition> : public GenericTraits<GridPosition> {
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
TableFormattingContext::TableFormattingContext(LayoutState& state, TableBox const& root, FormattingContext* parent)
|
||||
TableFormattingContext::TableFormattingContext(LayoutState& state, Box const& root, FormattingContext* parent)
|
||||
: FormattingContext(Type::Table, state, root, parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -8,21 +8,20 @@
|
|||
|
||||
#include <AK/Forward.h>
|
||||
#include <LibWeb/Layout/FormattingContext.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableWrapper.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
class TableFormattingContext final : public FormattingContext {
|
||||
public:
|
||||
explicit TableFormattingContext(LayoutState&, TableBox const&, FormattingContext* parent);
|
||||
explicit TableFormattingContext(LayoutState&, Box const&, FormattingContext* parent);
|
||||
~TableFormattingContext();
|
||||
|
||||
virtual void run(Box const&, LayoutMode, AvailableSpace const&) override;
|
||||
virtual CSSPixels automatic_content_width() const override;
|
||||
virtual CSSPixels automatic_content_height() const override;
|
||||
|
||||
TableBox const& table_box() const { return static_cast<TableBox const&>(context_box()); }
|
||||
Box const& table_box() const { return context_box(); }
|
||||
TableWrapper const& table_wrapper() const
|
||||
{
|
||||
return verify_cast<TableWrapper>(*table_box().containing_block());
|
||||
|
|
|
@ -17,8 +17,6 @@ public:
|
|||
TableRowBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
TableRowBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
|
||||
virtual ~TableRowBox() override;
|
||||
|
||||
static CSS::Display static_display(bool) { return CSS::Display { CSS::Display::Internal::TableRow }; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <LibWeb/Layout/ListItemMarkerBox.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Layout/Progress.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableCellBox.h>
|
||||
#include <LibWeb/Layout/TableRowBox.h>
|
||||
#include <LibWeb/Layout/TableWrapper.h>
|
||||
|
@ -503,12 +502,12 @@ static void for_each_sequence_of_consecutive_children_matching(NodeWithStyle& pa
|
|||
}
|
||||
|
||||
template<typename WrapperBoxType>
|
||||
static void wrap_in_anonymous(Vector<JS::Handle<Node>>& sequence, Node* nearest_sibling)
|
||||
static void wrap_in_anonymous(Vector<JS::Handle<Node>>& sequence, Node* nearest_sibling, CSS::Display display)
|
||||
{
|
||||
VERIFY(!sequence.is_empty());
|
||||
auto& parent = *sequence.first()->parent();
|
||||
auto computed_values = parent.computed_values().clone_inherited_values();
|
||||
static_cast<CSS::MutableComputedValues&>(computed_values).set_display(WrapperBoxType::static_display(parent.display().is_inline_outside()));
|
||||
static_cast<CSS::MutableComputedValues&>(computed_values).set_display(display);
|
||||
auto wrapper = parent.heap().template allocate_without_realm<WrapperBoxType>(parent.document(), nullptr, move(computed_values));
|
||||
for (auto& child : sequence) {
|
||||
parent.remove_child(*child);
|
||||
|
@ -526,65 +525,65 @@ 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);
|
||||
wrap_in_anonymous<TableRowBox>(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);
|
||||
wrap_in_anonymous<TableRowBox>(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);
|
||||
wrap_in_anonymous<TableRowBox>(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);
|
||||
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
|
||||
});
|
||||
});
|
||||
|
||||
// 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);
|
||||
wrap_in_anonymous<TableCellBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableCell });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void TreeBuilder::generate_missing_parents(NodeWithStyle& root)
|
||||
{
|
||||
Vector<JS::Handle<TableBox>> table_roots_to_wrap;
|
||||
Vector<JS::Handle<Box>> 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)) {
|
||||
for_each_sequence_of_consecutive_children_matching(parent, is_table_cell, [&](auto& sequence, auto nearest_sibling) {
|
||||
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling);
|
||||
wrap_in_anonymous<TableRowBox>(sequence, nearest_sibling, CSS::Display { CSS::Display::Internal::TableRow });
|
||||
});
|
||||
}
|
||||
|
||||
// A table-row is misparented if its parent is neither a table-row-group nor a table-root box.
|
||||
if (!parent.display().is_table_inside() && !is_proper_table_child(parent)) {
|
||||
for_each_sequence_of_consecutive_children_matching(parent, is_table_row, [&](auto& sequence, auto nearest_sibling) {
|
||||
wrap_in_anonymous<TableBox>(sequence, nearest_sibling);
|
||||
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display::from_short(parent.display().is_inline_outside() ? CSS::Display::Short::InlineTable : CSS::Display::Short::Table));
|
||||
});
|
||||
}
|
||||
|
||||
// A table-row-group, table-column-group, or table-caption box is misparented if its parent is not a table-root box.
|
||||
if (!parent.display().is_table_inside() && !is_proper_table_child(parent)) {
|
||||
for_each_sequence_of_consecutive_children_matching(parent, is_proper_table_child, [&](auto& sequence, auto nearest_sibling) {
|
||||
wrap_in_anonymous<TableBox>(sequence, nearest_sibling);
|
||||
wrap_in_anonymous<Box>(sequence, nearest_sibling, CSS::Display::from_short(parent.display().is_inline_outside() ? CSS::Display::Short::InlineTable : CSS::Display::Short::Table));
|
||||
});
|
||||
}
|
||||
|
||||
// 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));
|
||||
table_roots_to_wrap.append(parent);
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue