1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:57:44 +00:00

LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr

This commit is contained in:
Matthew Olsson 2023-02-26 16:09:02 -07:00 committed by Andreas Kling
parent 1df3652e27
commit 7c0c1c8f49
214 changed files with 825 additions and 827 deletions

View file

@ -85,7 +85,7 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()
// We can also layout absolutely positioned boxes within this BFC.
for (auto& box : m_absolutely_positioned_boxes) {
auto& cb_state = m_state.get(*box.containing_block());
auto& cb_state = m_state.get(*box->containing_block());
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
layout_absolutely_positioned_element(box, AvailableSpace(available_width, available_height));

View file

@ -76,7 +76,7 @@ private:
};
struct FloatingBox {
Box const& box;
JS::NonnullGCPtr<Box const> box;
// Offset from left/right edge to the left content edge of `box`.
CSSPixels offset_from_edge { 0 };
@ -155,7 +155,7 @@ private:
FloatSideData m_left_floats;
FloatSideData m_right_floats;
Vector<Box const&> m_absolutely_positioned_boxes;
Vector<JS::NonnullGCPtr<Box const>> m_absolutely_positioned_boxes;
bool m_was_notified_after_parent_dimensioned_my_root_box { false };
};

View file

@ -131,9 +131,9 @@ void FlexFormattingContext::run(Box const& run_box, LayoutMode, AvailableSpace c
// 3. Determine the flex base size and hypothetical main size of each item
for (auto& item : m_flex_items) {
if (item.box.is_replaced_box()) {
if (item.box->is_replaced_box()) {
// FIXME: Get rid of prepare_for_replaced_layout() and make replaced elements figure out their intrinsic size lazily.
static_cast<ReplacedBox&>(item.box).prepare_for_replaced_layout();
static_cast<ReplacedBox&>(*item.box).prepare_for_replaced_layout();
}
determine_flex_base_size_and_hypothetical_main_size(item);
}
@ -239,49 +239,49 @@ void FlexFormattingContext::parent_context_did_dimension_child_root_box()
void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::FlexDirection flex_direction) const
{
auto width_of_containing_block = m_state.get(*item.box.containing_block()).content_width();
auto width_of_containing_block = m_state.get(*item.box->containing_block()).content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
// FIXME: This should also take reverse-ness into account
if (flex_direction == CSS::FlexDirection::Row || flex_direction == CSS::FlexDirection::RowReverse) {
item.borders.main_before = item.box.computed_values().border_left().width;
item.borders.main_after = item.box.computed_values().border_right().width;
item.borders.cross_before = item.box.computed_values().border_top().width;
item.borders.cross_after = item.box.computed_values().border_bottom().width;
item.borders.main_before = item.box->computed_values().border_left().width;
item.borders.main_after = item.box->computed_values().border_right().width;
item.borders.cross_before = item.box->computed_values().border_top().width;
item.borders.cross_after = item.box->computed_values().border_bottom().width;
item.padding.main_before = item.box.computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_after = item.box.computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_before = item.box.computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_after = item.box.computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_before = item.box->computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_after = item.box->computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_before = item.box->computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_after = item.box->computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before = item.box.computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_after = item.box.computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_before = item.box.computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_after = item.box.computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before = item.box->computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_after = item.box->computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_before = item.box->computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_after = item.box->computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before_is_auto = item.box.computed_values().margin().left().is_auto();
item.margins.main_after_is_auto = item.box.computed_values().margin().right().is_auto();
item.margins.cross_before_is_auto = item.box.computed_values().margin().top().is_auto();
item.margins.cross_after_is_auto = item.box.computed_values().margin().bottom().is_auto();
item.margins.main_before_is_auto = item.box->computed_values().margin().left().is_auto();
item.margins.main_after_is_auto = item.box->computed_values().margin().right().is_auto();
item.margins.cross_before_is_auto = item.box->computed_values().margin().top().is_auto();
item.margins.cross_after_is_auto = item.box->computed_values().margin().bottom().is_auto();
} else {
item.borders.main_before = item.box.computed_values().border_top().width;
item.borders.main_after = item.box.computed_values().border_bottom().width;
item.borders.cross_before = item.box.computed_values().border_left().width;
item.borders.cross_after = item.box.computed_values().border_right().width;
item.borders.main_before = item.box->computed_values().border_top().width;
item.borders.main_after = item.box->computed_values().border_bottom().width;
item.borders.cross_before = item.box->computed_values().border_left().width;
item.borders.cross_after = item.box->computed_values().border_right().width;
item.padding.main_before = item.box.computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_after = item.box.computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_before = item.box.computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_after = item.box.computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_before = item.box->computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.main_after = item.box->computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_before = item.box->computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.padding.cross_after = item.box->computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before = item.box.computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_after = item.box.computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_before = item.box.computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_after = item.box.computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before = item.box->computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_after = item.box->computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_before = item.box->computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.cross_after = item.box->computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
item.margins.main_before_is_auto = item.box.computed_values().margin().top().is_auto();
item.margins.main_after_is_auto = item.box.computed_values().margin().bottom().is_auto();
item.margins.cross_before_is_auto = item.box.computed_values().margin().left().is_auto();
item.margins.cross_after_is_auto = item.box.computed_values().margin().right().is_auto();
item.margins.main_before_is_auto = item.box->computed_values().margin().top().is_auto();
item.margins.main_after_is_auto = item.box->computed_values().margin().bottom().is_auto();
item.margins.cross_before_is_auto = item.box->computed_values().margin().left().is_auto();
item.margins.cross_after_is_auto = item.box->computed_values().margin().right().is_auto();
}
};
@ -585,13 +585,13 @@ CSSPixels FlexFormattingContext::calculate_indefinite_main_size(FlexItem const&
// https://drafts.csswg.org/css-flexbox-1/#propdef-flex-basis
CSS::FlexBasisData FlexFormattingContext::used_flex_basis_for_item(FlexItem const& item) const
{
auto flex_basis = item.box.computed_values().flex_basis();
auto flex_basis = item.box->computed_values().flex_basis();
if (flex_basis.type == CSS::FlexBasis::Auto) {
// https://drafts.csswg.org/css-flexbox-1/#valdef-flex-basis-auto
// When specified on a flex item, the auto keyword retrieves the value of the main size property as the used flex-basis.
// If that value is itself auto, then the used value is content.
auto const& main_size = is_row_layout() ? item.box.computed_values().width() : item.box.computed_values().height();
auto const& main_size = is_row_layout() ? item.box->computed_values().width() : item.box->computed_values().height();
if (main_size.is_auto()) {
flex_basis.type = CSS::FlexBasis::Content;
@ -647,11 +647,11 @@ void FlexFormattingContext::determine_flex_base_size_and_hypothetical_main_size(
// - an intrinsic aspect ratio,
// - a used flex basis of content, and
// - a definite cross size,
if (item.box.has_intrinsic_aspect_ratio()
if (item.box->has_intrinsic_aspect_ratio()
&& item.used_flex_basis.type == CSS::FlexBasis::Content
&& has_definite_cross_size(item.box)) {
// flex_base_size is calculated from definite cross size and intrinsic aspect ratio
return resolved_definite_cross_size(item) * item.box.intrinsic_aspect_ratio().value();
return resolved_definite_cross_size(item) * item.box->intrinsic_aspect_ratio().value();
}
// C. If the used flex basis is content or depends on its available space,
@ -735,8 +735,8 @@ Optional<CSSPixels> FlexFormattingContext::transferred_size_suggestion(FlexItem
// If the item has a preferred aspect ratio and its preferred cross size is definite,
// then the transferred size suggestion is that size
// (clamped by its minimum and maximum cross sizes if they are definite), converted through the aspect ratio.
if (item.box.has_intrinsic_aspect_ratio() && has_definite_cross_size(item.box)) {
auto aspect_ratio = item.box.intrinsic_aspect_ratio().value();
if (item.box->has_intrinsic_aspect_ratio() && has_definite_cross_size(item.box)) {
auto aspect_ratio = item.box->intrinsic_aspect_ratio().value();
// FIXME: Clamp cross size to min/max cross size before this conversion.
return resolved_definite_cross_size(item) * aspect_ratio;
}
@ -757,7 +757,7 @@ CSSPixels FlexFormattingContext::content_based_minimum_size(FlexItem const& item
// otherwise, the smaller of its transferred size suggestion and its content size suggestion
// if the element is replaced and its transferred size suggestion exists;
if (item.box.is_replaced_box()) {
if (item.box->is_replaced_box()) {
if (auto transferred_size_suggestion = this->transferred_size_suggestion(item); transferred_size_suggestion.has_value()) {
return min(transferred_size_suggestion.value(), content_size_suggestion(item));
}
@ -899,9 +899,9 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
for (FlexItem& item : line.items) {
if (used_flex_factor == FlexFactor::FlexGrowFactor) {
item.flex_factor = item.box.computed_values().flex_grow();
item.flex_factor = item.box->computed_values().flex_grow();
} else if (used_flex_factor == FlexFactor::FlexShrinkFactor) {
item.flex_factor = item.box.computed_values().flex_shrink();
item.flex_factor = item.box->computed_values().flex_shrink();
}
// Freeze, setting its target main size to its hypothetical main size…
// - any item that has a flex factor of zero
@ -1092,7 +1092,7 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem&
}
auto cross_size = [&]() {
if (item.box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) {
if (item.box->computed_values().box_sizing() == CSS::BoxSizing::BorderBox) {
return max(CSSPixels(0.0f), resolved_definite_cross_size(item) - item.padding.cross_before - item.padding.cross_after - item.borders.cross_before - item.borders.cross_after);
}
@ -1358,7 +1358,7 @@ void FlexFormattingContext::dump_items() const
dbgln("{} flex-line #{}:", flex_container().debug_description(), i);
for (size_t j = 0; j < m_flex_lines[i].items.size(); ++j) {
auto& item = m_flex_lines[i].items[j];
dbgln("{} flex-item #{}: {} (main:{}, cross:{})", flex_container().debug_description(), j, item.box.debug_description(), item.main_size.value_or(-1), item.cross_size.value_or(-1));
dbgln("{} flex-item #{}: {} (main:{}, cross:{})", flex_container().debug_description(), j, item.box->debug_description(), item.main_size.value_or(-1), item.cross_size.value_or(-1));
}
}
}
@ -1533,20 +1533,20 @@ void FlexFormattingContext::copy_dimensions_from_flex_items_to_boxes()
auto const& box = item.box;
auto& box_state = m_state.get_mutable(box);
box_state.padding_left = box.computed_values().padding().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_right = box.computed_values().padding().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_top = box.computed_values().padding().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_bottom = box.computed_values().padding().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_left = box->computed_values().padding().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_right = box->computed_values().padding().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_top = box->computed_values().padding().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.padding_bottom = box->computed_values().padding().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_left = box.computed_values().margin().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_right = box.computed_values().margin().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_top = box.computed_values().margin().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_bottom = box.computed_values().margin().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_left = box->computed_values().margin().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_right = box->computed_values().margin().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_top = box->computed_values().margin().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.margin_bottom = box->computed_values().margin().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
box_state.border_left = box.computed_values().border_left().width;
box_state.border_right = box.computed_values().border_right().width;
box_state.border_top = box.computed_values().border_top().width;
box_state.border_bottom = box.computed_values().border_bottom().width;
box_state.border_left = box->computed_values().border_left().width;
box_state.border_right = box->computed_values().border_right().width;
box_state.border_top = box->computed_values().border_top().width;
box_state.border_bottom = box->computed_values().border_bottom().width;
set_main_size(box, item.main_size.value());
set_cross_size(box, item.cross_size.value());
@ -1604,10 +1604,10 @@ CSSPixels FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container
CSSPixels result = contribution - outer_flex_base_size;
if (result > 0) {
if (item.box.computed_values().flex_grow() >= 1) {
result /= item.box.computed_values().flex_grow();
if (item.box->computed_values().flex_grow() >= 1) {
result /= item.box->computed_values().flex_grow();
} else {
result *= item.box.computed_values().flex_grow();
result *= item.box->computed_values().flex_grow();
}
} else if (result < 0) {
if (item.scaled_flex_shrink_factor == 0)
@ -1636,8 +1636,8 @@ CSSPixels FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container
float sum_of_flex_shrink_factors = 0;
for (auto& item : flex_line.items) {
greatest_desired_flex_fraction = max(greatest_desired_flex_fraction, item.desired_flex_fraction);
sum_of_flex_grow_factors += item.box.computed_values().flex_grow();
sum_of_flex_shrink_factors += item.box.computed_values().flex_shrink();
sum_of_flex_grow_factors += item.box->computed_values().flex_grow();
sum_of_flex_shrink_factors += item.box->computed_values().flex_shrink();
}
float chosen_flex_fraction = greatest_desired_flex_fraction;
@ -1663,7 +1663,7 @@ CSSPixels FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container
for (auto& item : flex_line.items) {
float product = 0;
if (item.desired_flex_fraction > 0)
product = flex_line.chosen_flex_fraction * item.box.computed_values().flex_grow();
product = flex_line.chosen_flex_fraction * item.box->computed_values().flex_grow();
else if (item.desired_flex_fraction < 0)
product = flex_line.chosen_flex_fraction * item.scaled_flex_shrink_factor;
auto result = item.flex_base_size + product;
@ -1923,7 +1923,7 @@ bool FlexFormattingContext::flex_item_is_stretched(FlexItem const& item) const
if (alignment != CSS::AlignItems::Stretch)
return false;
// If the cross size property of the flex item computes to auto, and neither of the cross-axis margins are auto, the flex item is stretched.
auto const& computed_cross_size = is_row_layout() ? item.box.computed_values().height() : item.box.computed_values().width();
auto const& computed_cross_size = is_row_layout() ? item.box->computed_values().height() : item.box->computed_values().width();
return computed_cross_size.is_auto() && !item.margins.cross_before_is_auto && !item.margins.cross_after_is_auto;
}

View file

@ -48,7 +48,7 @@ private:
};
struct FlexItem {
Box& box;
JS::NonnullGCPtr<Box> box;
CSS::FlexBasisData used_flex_basis {};
bool used_flex_basis_is_definite { false };
CSSPixels flex_base_size { 0 };

View file

@ -321,7 +321,7 @@ CSSPixels FormattingContext::compute_auto_height_for_block_formatting_context_ro
// In addition, if the element has any floating descendants
// whose bottom margin edge is below the element's bottom content edge,
// then the height is increased to include those edges.
for (auto* floating_box : m_state.get(root).floating_descendants()) {
for (auto floating_box : m_state.get(root).floating_descendants()) {
// NOTE: Floating box coordinates are relative to their own containing block,
// which may or may not be the BFC root.
auto margin_box = margin_box_rect_in_ancestor_coordinate_space(*floating_box, root, m_state);

View file

@ -123,7 +123,7 @@ protected:
Type m_type {};
FormattingContext* m_parent { nullptr };
Box const& m_context_box;
JS::NonnullGCPtr<Box const> m_context_box;
LayoutState& m_state;
};

View file

@ -1680,8 +1680,8 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// 1. Position anything that's not auto-positioned.
for (size_t i = 0; i < m_boxes_to_place.size(); i++) {
auto const& child_box = m_boxes_to_place[i];
if (is_auto_positioned_row(child_box.computed_values().grid_row_start(), child_box.computed_values().grid_row_end())
|| is_auto_positioned_column(child_box.computed_values().grid_column_start(), child_box.computed_values().grid_column_end()))
if (is_auto_positioned_row(child_box->computed_values().grid_row_start(), child_box->computed_values().grid_row_end())
|| is_auto_positioned_column(child_box->computed_values().grid_column_start(), child_box->computed_values().grid_column_end()))
continue;
place_item_with_row_and_column_position(box, child_box);
m_boxes_to_place.remove(i);
@ -1692,7 +1692,7 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// FIXME: Do "dense" packing
for (size_t i = 0; i < m_boxes_to_place.size(); i++) {
auto const& child_box = m_boxes_to_place[i];
if (is_auto_positioned_row(child_box.computed_values().grid_row_start(), child_box.computed_values().grid_row_end()))
if (is_auto_positioned_row(child_box->computed_values().grid_row_start(), child_box->computed_values().grid_row_end()))
continue;
place_item_with_row_position(box, child_box);
m_boxes_to_place.remove(i);
@ -1723,7 +1723,7 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// FIXME: no distinction made. See #4.2
// 4.1.1. If the item has a definite column position:
if (!is_auto_positioned_column(child_box.computed_values().grid_column_start(), child_box.computed_values().grid_column_end()))
if (!is_auto_positioned_column(child_box->computed_values().grid_column_start(), child_box->computed_values().grid_column_end()))
place_item_with_column_position(box, child_box, auto_placement_cursor_x, auto_placement_cursor_y);
// 4.1.2. If the item has an automatic grid position in both axes:

View file

@ -49,7 +49,7 @@ public:
int gap_adjusted_column(Box const& parent_box);
private:
Box const& m_box;
JS::NonnullGCPtr<Box const> m_box;
int m_row { 0 };
int m_row_span { 1 };
int m_column { 0 };
@ -120,7 +120,7 @@ private:
OccupationGrid m_occupation_grid;
Vector<PositionedBox> m_positioned_boxes;
Vector<Box const&> m_boxes_to_place;
Vector<JS::NonnullGCPtr<Box const>> m_boxes_to_place;
CSSPixels get_free_space_x(AvailableSpace const& available_space);
CSSPixels get_free_space_y(Box const&);

View file

@ -52,7 +52,7 @@ void InlineLevelIterator::exit_node_with_box_model_metrics()
auto& node = m_box_model_node_stack.last();
auto& used_values = m_layout_state.get_mutable(node);
auto const& computed_values = node.computed_values();
auto const& computed_values = node->computed_values();
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;
@ -83,7 +83,7 @@ Layout::Node const* InlineLevelIterator::next_inline_node_in_pre_order(Layout::N
// If node is the last node on the "box model node stack", pop it off.
if (!m_box_model_node_stack.is_empty()
&& &m_box_model_node_stack.last() == node) {
&& m_box_model_node_stack.last() == node) {
exit_node_with_box_model_metrics();
}
if (!node || node == stay_within)
@ -92,7 +92,7 @@ Layout::Node const* InlineLevelIterator::next_inline_node_in_pre_order(Layout::N
// If node is the last node on the "box model node stack", pop it off.
if (!m_box_model_node_stack.is_empty()
&& &m_box_model_node_stack.last() == node) {
&& m_box_model_node_stack.last() == node) {
exit_node_with_box_model_metrics();
}
@ -104,7 +104,7 @@ void InlineLevelIterator::compute_next()
if (m_next_node == nullptr)
return;
do {
m_next_node = next_inline_node_in_pre_order(*m_next_node, &m_container);
m_next_node = next_inline_node_in_pre_order(*m_next_node, m_container);
} while (m_next_node && (!m_next_node->is_inline() && !m_next_node->is_out_of_flow(m_inline_formatting_context)));
}

View file

@ -31,7 +31,7 @@ public:
FloatingElement,
};
Type type {};
Layout::Node const* node { nullptr };
JS::GCPtr<Layout::Node const> node {};
size_t offset_in_node { 0 };
size_t length_in_node { 0 };
CSSPixels width { 0.0f };
@ -68,10 +68,10 @@ private:
Layout::InlineFormattingContext& m_inline_formatting_context;
Layout::LayoutState& m_layout_state;
Layout::BlockContainer const& m_container;
JS::NonnullGCPtr<Layout::BlockContainer const> m_container;
Layout::LayoutState::UsedValues const& m_container_state;
Layout::Node const* m_current_node { nullptr };
Layout::Node const* m_next_node { nullptr };
JS::GCPtr<Layout::Node const> m_current_node;
JS::GCPtr<Layout::Node const> m_next_node;
LayoutMode const m_layout_mode;
struct TextNodeContext {
@ -95,7 +95,7 @@ private:
Optional<ExtraBoxMetrics> m_extra_leading_metrics;
Optional<ExtraBoxMetrics> m_extra_trailing_metrics;
Vector<NodeWithStyleAndBoxModelMetrics const&> m_box_model_node_stack;
Vector<JS::NonnullGCPtr<NodeWithStyleAndBoxModelMetrics const>> m_box_model_node_stack;
};
}

View file

@ -131,7 +131,7 @@ struct LayoutState {
AvailableSize available_width_inside() const;
AvailableSize available_height_inside() const;
Layout::NodeWithStyleAndBoxModelMetrics* m_node { nullptr };
JS::GCPtr<Layout::NodeWithStyleAndBoxModelMetrics> m_node { nullptr };
CSSPixels m_content_width { 0 };
CSSPixels m_content_height { 0 };
@ -139,7 +139,7 @@ struct LayoutState {
bool m_has_definite_width { false };
bool m_has_definite_height { false };
HashTable<Box const*> m_floating_descendants;
HashTable<JS::GCPtr<Box const>> m_floating_descendants;
};
CSSPixels resolved_definite_width(Box const&) const;
@ -171,7 +171,7 @@ struct LayoutState {
Optional<CSSPixels> max_content_height_with_max_content_available_width;
};
HashMap<NodeWithStyleAndBoxModelMetrics const*, NonnullOwnPtr<IntrinsicSizes>> mutable intrinsic_sizes;
HashMap<JS::GCPtr<NodeWithStyleAndBoxModelMetrics const>, NonnullOwnPtr<IntrinsicSizes>> mutable intrinsic_sizes;
LayoutState const* m_parent { nullptr };
LayoutState const& m_root;

View file

@ -37,7 +37,7 @@ StringView LineBoxFragment::text() const
CSSPixelRect const LineBoxFragment::absolute_rect() const
{
CSSPixelRect rect { {}, size() };
rect.set_location(m_layout_node.containing_block()->paint_box()->absolute_position());
rect.set_location(m_layout_node->containing_block()->paint_box()->absolute_position());
rect.translate_by(offset());
return rect;
}

View file

@ -7,6 +7,7 @@
#pragma once
#include <LibGfx/Rect.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/PixelUnits.h>
@ -79,7 +80,7 @@ public:
bool is_atomic_inline() const;
private:
Node const& m_layout_node;
JS::NonnullGCPtr<Node const> m_layout_node;
int m_start { 0 };
int m_length { 0 };
CSSPixelPoint m_offset;

View file

@ -108,13 +108,13 @@ void TableFormattingContext::compute_table_measures()
for (auto& cell : m_cells) {
auto width_of_containing_block = m_state.get(*table_wrapper().containing_block()).content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto& computed_values = cell.box.computed_values();
auto& computed_values = cell.box->computed_values();
CSSPixels padding_left = computed_values.padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
CSSPixels padding_right = computed_values.padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
auto is_left_most_cell = cell.column_index == 0;
auto is_right_most_cell = cell.column_index == m_columns.size() - 1;
auto should_hide_borders = cell.box.computed_values().border_collapse() == CSS::BorderCollapse::Collapse;
auto should_hide_borders = cell.box->computed_values().border_collapse() == CSS::BorderCollapse::Collapse;
CSSPixels border_left = should_hide_borders && !is_left_most_cell ? 0 : computed_values.border_left().width;
CSSPixels border_right = should_hide_borders && !is_right_most_cell ? 0 : computed_values.border_right().width;
@ -392,24 +392,24 @@ void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode)
for (size_t i = 0; i < cell.column_span; ++i)
span_width += m_columns[cell.column_index + i].used_width;
auto width_of_containing_block = m_state.get(*cell.box.containing_block()).content_width();
auto width_of_containing_block = m_state.get(*cell.box->containing_block()).content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
cell_state.padding_top = cell.box.computed_values().padding().top().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_bottom = cell.box.computed_values().padding().bottom().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_left = cell.box.computed_values().padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_right = cell.box.computed_values().padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_top = cell.box->computed_values().padding().top().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_bottom = cell.box->computed_values().padding().bottom().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_left = cell.box->computed_values().padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_right = cell.box->computed_values().padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
auto is_top_most_cell = cell.row_index == 0;
auto is_left_most_cell = cell.column_index == 0;
auto is_right_most_cell = cell.column_index == m_columns.size() - 1;
auto is_bottom_most_cell = cell.row_index == m_rows.size() - 1;
auto should_hide_borders = cell.box.computed_values().border_collapse() == CSS::BorderCollapse::Collapse;
auto should_hide_borders = cell.box->computed_values().border_collapse() == CSS::BorderCollapse::Collapse;
cell_state.border_top = (should_hide_borders && is_top_most_cell) ? 0 : cell.box.computed_values().border_top().width;
cell_state.border_bottom = (should_hide_borders && is_bottom_most_cell) ? 0 : cell.box.computed_values().border_bottom().width;
cell_state.border_left = (should_hide_borders && is_left_most_cell) ? 0 : cell.box.computed_values().border_left().width;
cell_state.border_right = (should_hide_borders && is_right_most_cell) ? 0 : cell.box.computed_values().border_right().width;
cell_state.border_top = (should_hide_borders && is_top_most_cell) ? 0 : cell.box->computed_values().border_top().width;
cell_state.border_bottom = (should_hide_borders && is_bottom_most_cell) ? 0 : cell.box->computed_values().border_bottom().width;
cell_state.border_left = (should_hide_borders && is_left_most_cell) ? 0 : cell.box->computed_values().border_left().width;
cell_state.border_right = (should_hide_borders && is_right_most_cell) ? 0 : cell.box->computed_values().border_right().width;
cell_state.set_content_width((span_width - cell_state.border_box_left() - cell_state.border_box_right()));
if (auto independent_formatting_context = layout_inside(cell.box, layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
@ -484,7 +484,7 @@ void TableFormattingContext::position_cell_boxes()
auto& row_state = m_state.get(m_rows[cell.row_index].box);
CSSPixels const cell_border_box_height = cell_state.content_height() + cell_state.border_box_top() + cell_state.border_box_bottom();
CSSPixels const row_content_height = row_state.content_height();
auto const& vertical_align = cell.box.computed_values().vertical_align();
auto const& vertical_align = cell.box->computed_values().vertical_align();
if (vertical_align.has<CSS::VerticalAlign>()) {
switch (vertical_align.get<CSS::VerticalAlign>()) {
case CSS::VerticalAlign::Middle: {

View file

@ -57,13 +57,13 @@ private:
};
struct Row {
Box& box;
JS::NonnullGCPtr<Box> box;
CSSPixels used_height { 0 };
CSSPixels baseline { 0 };
};
struct Cell {
Box& box;
JS::NonnullGCPtr<Box> box;
size_t column_index;
size_t row_index;
size_t column_span;

View file

@ -128,11 +128,11 @@ void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node,
// Non-inlines can't be inserted into an inline parent, so find the nearest non-inline ancestor.
auto& nearest_non_inline_ancestor = [&]() -> Layout::NodeWithStyle& {
for (auto& ancestor : m_ancestor_stack.in_reverse()) {
if (!ancestor.display().is_inline_outside())
if (!ancestor->display().is_inline_outside())
return ancestor;
if (!ancestor.display().is_flow_inside())
if (!ancestor->display().is_flow_inside())
return ancestor;
if (ancestor.dom_node() && is<SVG::SVGForeignObjectElement>(*ancestor.dom_node()))
if (ancestor->dom_node() && is<SVG::SVGForeignObjectElement>(*ancestor->dom_node()))
return ancestor;
}
VERIFY_NOT_REACHED();
@ -237,7 +237,7 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
if (!dom_node.parent_or_shadow_host()) {
m_layout_root = layout_node;
} else if (layout_node->is_svg_box()) {
m_ancestor_stack.last().append_child(*layout_node);
m_ancestor_stack.last()->append_child(*layout_node);
} else {
insert_node_into_inline_or_block_ancestor(*layout_node, display, AppendOrPrepend::Append);
}

View file

@ -49,7 +49,7 @@ private:
ErrorOr<void> create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
JS::GCPtr<Layout::Node> m_layout_root;
Vector<Layout::NodeWithStyle&> m_ancestor_stack;
Vector<JS::NonnullGCPtr<Layout::NodeWithStyle>> m_ancestor_stack;
};
}