Move the layout tree from GC allocation to refcounted ownership so removed layout and paint subtrees are destroyed synchronously instead of waiting for the next GC sweep. This dramatically reduces GC memory usage peaks after layout tree churn and makes it easier for memory use to fall back after large document updates. Update layout factories, tree traversal, SVG layout node creation, paintable back-pointers, and pseudo-element layout links to use RefPtr ownership. Make display: contents follow the same shape as Blink and WebKit: the element itself does not create a layout node, and its children are flattened into the nearest layout parent. Wrap direct non-whitespace text in an anonymous inline node when the boxless element contributes inherited style to that text. Use an internal inline wrapper for display: contents pseudo-elements so generated content can still participate in layout, painting, hit testing, and pseudo-element queries. Keep CSSOM reporting the computed display value from the pseudo style, not the internal wrapper. Remove the retained out-of-tree layout node list and its testing hook, since the flattened model does not need a side owner for boxless elements. Add coverage for inherited text style, dynamic insertion order, pseudo-element hit testing, and computed style queries.
111 lines
3.2 KiB
C++
111 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) 2023, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibWeb/Layout/Box.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
class TableGrid {
|
|
public:
|
|
struct GridPosition {
|
|
size_t x;
|
|
size_t y;
|
|
inline bool operator==(GridPosition const&) const = default;
|
|
};
|
|
|
|
struct Row {
|
|
Box const& box;
|
|
CSSPixels base_height { 0 };
|
|
CSSPixels reference_height { 0 };
|
|
CSSPixels final_height { 0 };
|
|
CSSPixels baseline { 0 };
|
|
CSSPixels min_size { 0 };
|
|
CSSPixels max_size { 0 };
|
|
bool is_collapsed { false };
|
|
bool has_intrinsic_percentage { false };
|
|
double intrinsic_percentage { 0 };
|
|
// Store whether the row is constrained: https://www.w3.org/TR/css-tables-3/#constrainedness
|
|
bool is_constrained { false };
|
|
};
|
|
|
|
struct Cell {
|
|
Box const& box;
|
|
size_t column_index;
|
|
size_t row_index;
|
|
size_t column_span;
|
|
size_t row_span;
|
|
CSSPixels baseline { 0 };
|
|
CSSPixels outer_min_width { 0 };
|
|
CSSPixels outer_max_width { 0 };
|
|
CSSPixels outer_min_height { 0 };
|
|
CSSPixels outer_max_height { 0 };
|
|
};
|
|
|
|
// Calculate and return the grid and also rows and cells as output parameters.
|
|
static TableGrid calculate_row_column_grid(Box const&, Vector<Cell>&, Vector<Row>&);
|
|
// Overload for callers that don't care about rows and cells (currently the layout tree builder).
|
|
static TableGrid calculate_row_column_grid(Box const& box);
|
|
|
|
size_t column_count() const { return m_column_count; }
|
|
HashMap<GridPosition, bool> const& occupancy_grid() const { return m_occupancy_grid; }
|
|
|
|
static bool is_table_row_group(Node const& node)
|
|
{
|
|
auto const& display = node.display();
|
|
return display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group();
|
|
}
|
|
|
|
static bool is_table_row(Node const& node)
|
|
{
|
|
return node.display().is_table_row();
|
|
}
|
|
|
|
static bool is_table_column_group(Node const& node)
|
|
{
|
|
return node.display().is_table_column_group();
|
|
}
|
|
|
|
template<typename Matcher, typename Callback>
|
|
static void for_each_child_box_matching(Box const& parent, Matcher matcher, Callback callback)
|
|
{
|
|
parent.for_each_child_of_type<Box>([&](Box const& child_box) {
|
|
if (matcher(child_box))
|
|
callback(child_box);
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
|
|
template<typename Matcher, typename Callback>
|
|
static void for_each_child_box_matching(Box& parent, Matcher matcher, Callback callback)
|
|
{
|
|
parent.for_each_child_of_type<Box>([&](Box& child_box) {
|
|
if (matcher(child_box))
|
|
callback(child_box);
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
|
|
private:
|
|
size_t m_column_count { 0 };
|
|
HashMap<GridPosition, bool> m_occupancy_grid;
|
|
};
|
|
|
|
}
|
|
|
|
namespace AK {
|
|
|
|
template<>
|
|
struct Traits<Web::Layout::TableGrid::GridPosition> : public DefaultTraits<Web::Layout::TableGrid::GridPosition> {
|
|
static unsigned hash(Web::Layout::TableGrid::GridPosition const& key)
|
|
{
|
|
return pair_int_hash(key.x, key.y);
|
|
}
|
|
};
|
|
|
|
}
|