mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibWeb: Rename LayoutState::NodeState => LayoutState::UsedValues
This object contains all the CSS "used values" as seen during the layout process, so calling it "used values" seems appropriate. :^)
This commit is contained in:
parent
52862c72d0
commit
9b46091f38
10 changed files with 76 additions and 76 deletions
|
@ -614,12 +614,12 @@ void Document::update_layout()
|
|||
m_layout_root = static_ptr_cast<Layout::InitialContainingBlock>(tree_builder.build(*this));
|
||||
}
|
||||
|
||||
Layout::LayoutState formatting_state;
|
||||
formatting_state.nodes.resize(layout_node_count());
|
||||
Layout::BlockFormattingContext root_formatting_context(formatting_state, *m_layout_root, nullptr);
|
||||
Layout::LayoutState layout_state;
|
||||
layout_state.used_values_per_layout_node.resize(layout_node_count());
|
||||
Layout::BlockFormattingContext root_formatting_context(layout_state, *m_layout_root, nullptr);
|
||||
|
||||
auto& icb = static_cast<Layout::InitialContainingBlock&>(*m_layout_root);
|
||||
auto& icb_state = formatting_state.get_mutable(icb);
|
||||
auto& icb_state = layout_state.get_mutable(icb);
|
||||
icb_state.content_width = viewport_rect.width();
|
||||
icb_state.content_height = viewport_rect.height();
|
||||
|
||||
|
@ -627,7 +627,7 @@ void Document::update_layout()
|
|||
icb.set_has_definite_height(true);
|
||||
|
||||
root_formatting_context.run(*m_layout_root, Layout::LayoutMode::Normal);
|
||||
formatting_state.commit();
|
||||
layout_state.commit();
|
||||
|
||||
browsing_context()->set_needs_display();
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ private:
|
|||
|
||||
CSS::FlexBasisData used_flex_basis_for_item(FlexItem const&) const;
|
||||
|
||||
LayoutState::NodeState& m_flex_container_state;
|
||||
LayoutState::UsedValues& m_flex_container_state;
|
||||
|
||||
Vector<FlexLine> m_flex_lines;
|
||||
Vector<FlexItem> m_flex_items;
|
||||
|
|
|
@ -36,7 +36,7 @@ private:
|
|||
void generate_line_boxes(LayoutMode);
|
||||
void apply_justification_to_fragments(CSS::TextJustify, LineBox&, bool is_last_line);
|
||||
|
||||
LayoutState::NodeState const& m_containing_block_state;
|
||||
LayoutState::UsedValues const& m_containing_block_state;
|
||||
float m_effective_containing_block_width { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
InlineLevelIterator::InlineLevelIterator(Layout::InlineFormattingContext& inline_formatting_context, Layout::LayoutState& formatting_state, Layout::BlockContainer const& container, LayoutMode layout_mode)
|
||||
InlineLevelIterator::InlineLevelIterator(Layout::InlineFormattingContext& inline_formatting_context, Layout::LayoutState& layout_state, Layout::BlockContainer const& container, LayoutMode layout_mode)
|
||||
: m_inline_formatting_context(inline_formatting_context)
|
||||
, m_formatting_state(formatting_state)
|
||||
, m_layout_state(layout_state)
|
||||
, m_container(container)
|
||||
, m_container_state(formatting_state.get(container))
|
||||
, m_container_state(layout_state.get(container))
|
||||
, m_next_node(container.first_child())
|
||||
, m_layout_mode(layout_mode)
|
||||
{
|
||||
|
@ -31,16 +31,16 @@ void InlineLevelIterator::enter_node_with_box_model_metrics(Layout::NodeWithStyl
|
|||
|
||||
// FIXME: It's really weird that *this* is where we assign box model metrics for these layout nodes..
|
||||
|
||||
auto& node_state = m_formatting_state.get_mutable(node);
|
||||
auto& used_values = m_layout_state.get_mutable(node);
|
||||
auto const& computed_values = node.computed_values();
|
||||
|
||||
node_state.margin_left = computed_values.margin().left.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
node_state.border_left = computed_values.border_left().width;
|
||||
node_state.padding_left = computed_values.padding().left.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
used_values.margin_left = computed_values.margin().left.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
used_values.border_left = computed_values.border_left().width;
|
||||
used_values.padding_left = computed_values.padding().left.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
|
||||
m_extra_leading_metrics->margin += node_state.margin_left;
|
||||
m_extra_leading_metrics->border += node_state.border_left;
|
||||
m_extra_leading_metrics->padding += node_state.padding_left;
|
||||
m_extra_leading_metrics->margin += used_values.margin_left;
|
||||
m_extra_leading_metrics->border += used_values.border_left;
|
||||
m_extra_leading_metrics->padding += used_values.padding_left;
|
||||
|
||||
m_box_model_node_stack.append(node);
|
||||
}
|
||||
|
@ -51,16 +51,16 @@ void InlineLevelIterator::exit_node_with_box_model_metrics()
|
|||
m_extra_trailing_metrics = ExtraBoxMetrics {};
|
||||
|
||||
auto& node = m_box_model_node_stack.last();
|
||||
auto& node_state = m_formatting_state.get_mutable(node);
|
||||
auto& used_values = m_layout_state.get_mutable(node);
|
||||
auto const& computed_values = node.computed_values();
|
||||
|
||||
node_state.margin_right = computed_values.margin().right.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
node_state.border_right = computed_values.border_right().width;
|
||||
node_state.padding_right = computed_values.padding().right.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
used_values.margin_right = computed_values.margin().right.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
used_values.border_right = computed_values.border_right().width;
|
||||
used_values.padding_right = computed_values.padding().right.resolved(node, CSS::Length::make_px(m_container_state.content_width)).to_px(node);
|
||||
|
||||
m_extra_trailing_metrics->margin += node_state.margin_right;
|
||||
m_extra_trailing_metrics->border += node_state.border_right;
|
||||
m_extra_trailing_metrics->padding += node_state.padding_right;
|
||||
m_extra_trailing_metrics->margin += used_values.margin_right;
|
||||
m_extra_trailing_metrics->border += used_values.border_right;
|
||||
m_extra_trailing_metrics->padding += used_values.padding_right;
|
||||
|
||||
m_box_model_node_stack.take_last();
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next(float available_wi
|
|||
}
|
||||
|
||||
auto& box = verify_cast<Layout::Box>(*m_current_node);
|
||||
auto& box_state = m_formatting_state.get(box);
|
||||
auto& box_state = m_layout_state.get(box);
|
||||
m_inline_formatting_context.dimension_box_on_line(box, m_layout_mode);
|
||||
|
||||
skip_to_next();
|
||||
|
|
|
@ -66,9 +66,9 @@ private:
|
|||
Layout::Node const* next_inline_node_in_pre_order(Layout::Node const& current, Layout::Node const* stay_within);
|
||||
|
||||
Layout::InlineFormattingContext& m_inline_formatting_context;
|
||||
Layout::LayoutState& m_formatting_state;
|
||||
Layout::LayoutState& m_layout_state;
|
||||
Layout::BlockContainer const& m_container;
|
||||
Layout::LayoutState::NodeState const& m_container_state;
|
||||
Layout::LayoutState::UsedValues const& m_container_state;
|
||||
Layout::Node const* m_current_node { nullptr };
|
||||
Layout::Node const* m_next_node { nullptr };
|
||||
LayoutMode const m_layout_mode;
|
||||
|
|
|
@ -10,39 +10,39 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
LayoutState::NodeState& LayoutState::get_mutable(NodeWithStyleAndBoxModelMetrics const& box)
|
||||
LayoutState::UsedValues& LayoutState::get_mutable(NodeWithStyleAndBoxModelMetrics const& box)
|
||||
{
|
||||
auto serial_id = box.serial_id();
|
||||
if (nodes[serial_id])
|
||||
return *nodes[serial_id];
|
||||
if (used_values_per_layout_node[serial_id])
|
||||
return *used_values_per_layout_node[serial_id];
|
||||
|
||||
for (auto const* ancestor = m_parent; ancestor; ancestor = ancestor->m_parent) {
|
||||
if (ancestor->nodes[serial_id]) {
|
||||
auto cow_node_state = adopt_own(*new NodeState(*ancestor->nodes[serial_id]));
|
||||
auto* cow_node_state_ptr = cow_node_state.ptr();
|
||||
nodes[serial_id] = move(cow_node_state);
|
||||
return *cow_node_state_ptr;
|
||||
if (ancestor->used_values_per_layout_node[serial_id]) {
|
||||
auto cow_used_values = adopt_own(*new UsedValues(*ancestor->used_values_per_layout_node[serial_id]));
|
||||
auto* cow_used_values_ptr = cow_used_values.ptr();
|
||||
used_values_per_layout_node[serial_id] = move(cow_used_values);
|
||||
return *cow_used_values_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
nodes[serial_id] = adopt_own(*new NodeState);
|
||||
nodes[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box);
|
||||
return *nodes[serial_id];
|
||||
used_values_per_layout_node[serial_id] = adopt_own(*new UsedValues);
|
||||
used_values_per_layout_node[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box);
|
||||
return *used_values_per_layout_node[serial_id];
|
||||
}
|
||||
|
||||
LayoutState::NodeState const& LayoutState::get(NodeWithStyleAndBoxModelMetrics const& box) const
|
||||
LayoutState::UsedValues const& LayoutState::get(NodeWithStyleAndBoxModelMetrics const& box) const
|
||||
{
|
||||
auto serial_id = box.serial_id();
|
||||
if (nodes[serial_id])
|
||||
return *nodes[serial_id];
|
||||
if (used_values_per_layout_node[serial_id])
|
||||
return *used_values_per_layout_node[serial_id];
|
||||
|
||||
for (auto* ancestor = m_parent; ancestor; ancestor = ancestor->m_parent) {
|
||||
if (ancestor->nodes[serial_id])
|
||||
return *ancestor->nodes[serial_id];
|
||||
if (ancestor->used_values_per_layout_node[serial_id])
|
||||
return *ancestor->used_values_per_layout_node[serial_id];
|
||||
}
|
||||
const_cast<LayoutState*>(this)->nodes[serial_id] = adopt_own(*new NodeState);
|
||||
const_cast<LayoutState*>(this)->nodes[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box);
|
||||
return *nodes[serial_id];
|
||||
const_cast<LayoutState*>(this)->used_values_per_layout_node[serial_id] = adopt_own(*new UsedValues);
|
||||
const_cast<LayoutState*>(this)->used_values_per_layout_node[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box);
|
||||
return *used_values_per_layout_node[serial_id];
|
||||
}
|
||||
|
||||
void LayoutState::commit()
|
||||
|
@ -52,17 +52,17 @@ void LayoutState::commit()
|
|||
|
||||
HashTable<Layout::TextNode*> text_nodes;
|
||||
|
||||
for (auto& node_state_ptr : nodes) {
|
||||
if (!node_state_ptr)
|
||||
for (auto& used_values_ptr : used_values_per_layout_node) {
|
||||
if (!used_values_ptr)
|
||||
continue;
|
||||
auto& node_state = *node_state_ptr;
|
||||
auto& node = *node_state.node;
|
||||
auto& used_values = *used_values_ptr;
|
||||
auto& node = *used_values.node;
|
||||
|
||||
// Transfer box model metrics.
|
||||
node.box_model().inset = { node_state.inset_top, node_state.inset_right, node_state.inset_bottom, node_state.inset_left };
|
||||
node.box_model().padding = { node_state.padding_top, node_state.padding_right, node_state.padding_bottom, node_state.padding_left };
|
||||
node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left };
|
||||
node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left };
|
||||
node.box_model().inset = { used_values.inset_top, used_values.inset_right, used_values.inset_bottom, used_values.inset_left };
|
||||
node.box_model().padding = { used_values.padding_top, used_values.padding_right, used_values.padding_bottom, used_values.padding_left };
|
||||
node.box_model().border = { used_values.border_top, used_values.border_right, used_values.border_bottom, used_values.border_left };
|
||||
node.box_model().margin = { used_values.margin_top, used_values.margin_right, used_values.margin_bottom, used_values.margin_left };
|
||||
|
||||
node.set_paintable(node.create_paintable());
|
||||
|
||||
|
@ -70,19 +70,19 @@ void LayoutState::commit()
|
|||
if (is<Layout::Box>(node)) {
|
||||
auto& box = static_cast<Layout::Box&>(node);
|
||||
auto& paint_box = const_cast<Painting::PaintableBox&>(*box.paint_box());
|
||||
paint_box.set_offset(node_state.offset);
|
||||
paint_box.set_content_size(node_state.content_width, node_state.content_height);
|
||||
paint_box.set_overflow_data(move(node_state.overflow_data));
|
||||
paint_box.set_containing_line_box_fragment(node_state.containing_line_box_fragment);
|
||||
paint_box.set_offset(used_values.offset);
|
||||
paint_box.set_content_size(used_values.content_width, used_values.content_height);
|
||||
paint_box.set_overflow_data(move(used_values.overflow_data));
|
||||
paint_box.set_containing_line_box_fragment(used_values.containing_line_box_fragment);
|
||||
|
||||
if (is<Layout::BlockContainer>(box)) {
|
||||
for (auto& line_box : node_state.line_boxes) {
|
||||
for (auto& line_box : used_values.line_boxes) {
|
||||
for (auto& fragment : line_box.fragments()) {
|
||||
if (fragment.layout_node().is_text_node())
|
||||
text_nodes.set(static_cast<Layout::TextNode*>(const_cast<Layout::Node*>(&fragment.layout_node())));
|
||||
}
|
||||
}
|
||||
static_cast<Painting::PaintableWithLines&>(paint_box).set_line_boxes(move(node_state.line_boxes));
|
||||
static_cast<Painting::PaintableWithLines&>(paint_box).set_line_boxes(move(used_values.line_boxes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ struct LayoutState {
|
|||
: m_parent(parent)
|
||||
, m_root(find_root())
|
||||
{
|
||||
nodes.resize(m_root.nodes.size());
|
||||
used_values_per_layout_node.resize(m_root.used_values_per_layout_node.size());
|
||||
}
|
||||
|
||||
LayoutState const& find_root() const
|
||||
|
@ -41,7 +41,7 @@ struct LayoutState {
|
|||
return *root;
|
||||
}
|
||||
|
||||
struct NodeState {
|
||||
struct UsedValues {
|
||||
Layout::NodeWithStyleAndBoxModelMetrics* node { nullptr };
|
||||
|
||||
float content_width { 0 };
|
||||
|
@ -103,13 +103,13 @@ struct LayoutState {
|
|||
|
||||
void commit();
|
||||
|
||||
// NOTE: get_mutable() will CoW the NodeState if it's inherited from an ancestor state;
|
||||
NodeState& get_mutable(NodeWithStyleAndBoxModelMetrics const&);
|
||||
// NOTE: get_mutable() will CoW the UsedValues if it's inherited from an ancestor state;
|
||||
UsedValues& get_mutable(NodeWithStyleAndBoxModelMetrics const&);
|
||||
|
||||
// NOTE: get() will not CoW the NodeState.
|
||||
NodeState const& get(NodeWithStyleAndBoxModelMetrics const&) const;
|
||||
// NOTE: get() will not CoW the UsedValues.
|
||||
UsedValues const& get(NodeWithStyleAndBoxModelMetrics const&) const;
|
||||
|
||||
Vector<OwnPtr<NodeState>> nodes;
|
||||
Vector<OwnPtr<UsedValues>> used_values_per_layout_node;
|
||||
|
||||
// We cache intrinsic sizes once determined, as they will not change over the course of a full layout.
|
||||
// This avoids computing them several times while performing flex layout.
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& formatting_state, LayoutMode layout_mode)
|
||||
LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& layout_state, LayoutMode layout_mode)
|
||||
: m_context(context)
|
||||
, m_formatting_state(formatting_state)
|
||||
, m_containing_block_state(formatting_state.get_mutable(context.containing_block()))
|
||||
, m_layout_state(layout_state)
|
||||
, m_containing_block_state(layout_state.get_mutable(context.containing_block()))
|
||||
, m_layout_mode(layout_mode)
|
||||
{
|
||||
begin_new_line(false);
|
||||
|
@ -50,7 +50,7 @@ LineBox& LineBuilder::ensure_last_line_box()
|
|||
|
||||
void LineBuilder::append_box(Box const& box, float leading_size, float trailing_size, float leading_margin, float trailing_margin)
|
||||
{
|
||||
auto& box_state = m_formatting_state.get_mutable(box);
|
||||
auto& box_state = m_layout_state.get_mutable(box);
|
||||
auto& line_box = ensure_last_line_box();
|
||||
line_box.add_fragment(box, 0, 0, leading_size, trailing_size, leading_margin, trailing_margin, box_state.content_width, box_state.content_height, box_state.border_box_top(), box_state.border_box_bottom());
|
||||
m_max_height_on_current_line = max(m_max_height_on_current_line, box_state.border_box_height());
|
||||
|
@ -147,7 +147,7 @@ void LineBuilder::update_last_line()
|
|||
fragment_baseline = font_metrics.ascent;
|
||||
} else {
|
||||
auto const& box = verify_cast<Layout::Box>(fragment.layout_node());
|
||||
fragment_baseline = box_baseline(m_formatting_state, box);
|
||||
fragment_baseline = box_baseline(m_layout_state, box);
|
||||
}
|
||||
|
||||
fragment_baseline += half_leading;
|
||||
|
@ -213,7 +213,7 @@ void LineBuilder::update_last_line()
|
|||
{
|
||||
// FIXME: Support inline-table elements.
|
||||
if (fragment.layout_node().is_replaced_box() || fragment.layout_node().is_inline_block()) {
|
||||
auto const& fragment_box_state = m_formatting_state.get(static_cast<Box const&>(fragment.layout_node()));
|
||||
auto const& fragment_box_state = m_layout_state.get(static_cast<Box const&>(fragment.layout_node()));
|
||||
top_of_inline_box = fragment.offset().y() - fragment_box_state.margin_box_top();
|
||||
bottom_of_inline_box = fragment.offset().y() + fragment_box_state.content_height + fragment_box_state.margin_box_bottom();
|
||||
} else {
|
||||
|
|
|
@ -50,8 +50,8 @@ private:
|
|||
LineBox& ensure_last_line_box();
|
||||
|
||||
InlineFormattingContext& m_context;
|
||||
LayoutState& m_formatting_state;
|
||||
LayoutState::NodeState& m_containing_block_state;
|
||||
LayoutState& m_layout_state;
|
||||
LayoutState::UsedValues& m_containing_block_state;
|
||||
LayoutMode m_layout_mode {};
|
||||
float m_available_width_for_current_line { 0 };
|
||||
float m_current_y { 0 };
|
||||
|
|
|
@ -25,7 +25,7 @@ enum class LayoutMode {
|
|||
Normal,
|
||||
|
||||
// Intrinsic size determination.
|
||||
// Boxes honor min-content and max-content constraints (set via LayoutState::NodeState::{width,height}_constraint)
|
||||
// Boxes honor min-content and max-content constraints (set via LayoutState::UsedValues::{width,height}_constraint)
|
||||
// by considering their containing block to be 0-sized or infinitely large in the relevant axis.
|
||||
IntrinsicSizeDetermination,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue