diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 38618cc347..2d0e0580d5 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -376,7 +376,7 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n margin_right = zero_value; auto& box_state = m_state.get_mutable(box); - box_state.set_content_width(compute_width_for_replaced_element(m_state, box, available_space)); + box_state.set_content_width(compute_width_for_replaced_element(box, available_space)); box_state.margin_left = margin_left.to_px(box); box_state.margin_right = margin_right.to_px(box); box_state.border_left = computed_values.border_left().width; @@ -437,7 +437,7 @@ void BlockFormattingContext::compute_height(Box const& box, AvailableSpace const // Then work out what the height is, based on box type and CSS properties. CSSPixels height = 0; if (is(box)) { - height = compute_height_for_replaced_element(m_state, verify_cast(box), available_space); + height = compute_height_for_replaced_element(verify_cast(box), available_space); } else { if (should_treat_height_as_auto(box, available_space)) { height = compute_auto_height_for_block_level_element(box, m_state.get(box).available_inner_space_or_constraints_from(available_space)); @@ -578,7 +578,7 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain if (is(box)) return; - resolve_vertical_box_model_metrics(box, m_state); + resolve_vertical_box_model_metrics(box); if (box.is_floating()) { auto const y = m_y_offset_of_current_block_container.value(); @@ -695,11 +695,11 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer const& b } } -void BlockFormattingContext::resolve_vertical_box_model_metrics(Box const& box, LayoutState& state) +void BlockFormattingContext::resolve_vertical_box_model_metrics(Box const& box) { - auto& box_state = state.get_mutable(box); + auto& box_state = m_state.get_mutable(box); auto const& computed_values = box.computed_values(); - auto width_of_containing_block = containing_block_width_for(box, state); + auto width_of_containing_block = containing_block_width_for(box); box_state.margin_top = computed_values.margin().top().to_px(box, width_of_containing_block); box_state.margin_bottom = computed_values.margin().bottom().to_px(box, width_of_containing_block); @@ -880,7 +880,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer auto& box_state = m_state.get_mutable(box); CSSPixels width_of_containing_block = available_space.width.to_px(); - resolve_vertical_box_model_metrics(box, m_state); + resolve_vertical_box_model_metrics(box); compute_width(box, available_space, layout_mode); auto independent_formatting_context = layout_inside(box, layout_mode, box_state.available_inner_space_or_constraints_from(available_space)); diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h index 63ce6d6e0e..d9d87b6e6e 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -66,7 +66,7 @@ private: void layout_block_level_children(BlockContainer const&, LayoutMode, AvailableSpace const&); void layout_inline_children(BlockContainer const&, LayoutMode, AvailableSpace const&); - static void resolve_vertical_box_model_metrics(Box const& box, LayoutState&); + void resolve_vertical_box_model_metrics(Box const&); void place_block_level_element_in_normal_flow_horizontally(Box const& child_box, AvailableSpace const&); void place_block_level_element_in_normal_flow_vertically(Box const&, CSSPixels y); diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 2216259ba9..5c2c95dca5 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -365,13 +365,13 @@ CSSPixels FormattingContext::compute_auto_height_for_block_formatting_context_ro } // 10.3.2 Inline, replaced elements, https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width -CSSPixels FormattingContext::tentative_width_for_replaced_element(LayoutState const& state, ReplacedBox const& box, CSS::Size const& computed_width, AvailableSpace const& available_space) +CSSPixels FormattingContext::tentative_width_for_replaced_element(ReplacedBox const& box, CSS::Size const& computed_width, AvailableSpace const& available_space) const { // Treat percentages of indefinite containing block widths as 0 (the initial width). - if (computed_width.is_percentage() && !state.get(*box.containing_block()).has_definite_width()) + if (computed_width.is_percentage() && !m_state.get(*box.containing_block()).has_definite_width()) return 0; - auto height_of_containing_block = CSS::Length::make_px(containing_block_height_for(box, state)); + auto height_of_containing_block = CSS::Length::make_px(containing_block_height_for(box)); auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height(); CSSPixels used_width = computed_width.to_px(box, available_space.width.to_px()); @@ -389,7 +389,7 @@ CSSPixels FormattingContext::tentative_width_for_replaced_element(LayoutState co // (used height) * (intrinsic ratio) if ((computed_height.is_auto() && computed_width.is_auto() && !box.has_intrinsic_width() && box.has_intrinsic_height() && box.has_intrinsic_aspect_ratio()) || (computed_width.is_auto() && !computed_height.is_auto() && box.has_intrinsic_aspect_ratio())) { - return compute_height_for_replaced_element(state, box, available_space) * static_cast(box.intrinsic_aspect_ratio().value()); + return compute_height_for_replaced_element(box, available_space) * static_cast(box.intrinsic_aspect_ratio().value()); } // If 'height' and 'width' both have computed values of 'auto' and the element has an intrinsic ratio but no intrinsic height or width, @@ -397,7 +397,7 @@ CSSPixels FormattingContext::tentative_width_for_replaced_element(LayoutState co // depend on the replaced element's width, then the used value of 'width' is calculated from the constraint equation used for block-level, // non-replaced elements in normal flow. if (computed_height.is_auto() && computed_width.is_auto() && !box.has_intrinsic_width() && !box.has_intrinsic_height() && box.has_intrinsic_aspect_ratio()) { - return calculate_stretch_fit_width(box, available_space.width, state); + return calculate_stretch_fit_width(box, available_space.width); } // Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'. @@ -428,7 +428,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_element(Box con compute_height_for_absolutely_positioned_non_replaced_element(box, available_space, before_or_after_inside_layout); } -CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState const& state, ReplacedBox const& box, AvailableSpace const& available_space) +CSSPixels FormattingContext::compute_width_for_replaced_element(ReplacedBox const& box, AvailableSpace const& available_space) const { // 10.3.4 Block-level, replaced elements in normal flow... // 10.3.2 Inline, replaced elements @@ -441,12 +441,12 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height(); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') - auto used_width = tentative_width_for_replaced_element(state, box, computed_width, available_space); + auto used_width = tentative_width_for_replaced_element(box, computed_width, available_space); if (computed_width.is_auto() && computed_height.is_auto() && box.has_intrinsic_aspect_ratio()) { CSSPixels w = used_width; - CSSPixels h = tentative_height_for_replaced_element(state, box, computed_height, available_space); - used_width = solve_replaced_size_constraint(state, w, h, box).width(); + CSSPixels h = tentative_height_for_replaced_element(box, computed_height, available_space); + used_width = solve_replaced_size_constraint(m_state, w, h, box).width(); return used_width; } @@ -455,7 +455,7 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons auto computed_max_width = box.computed_values().max_width(); if (!computed_max_width.is_none()) { if (used_width > computed_max_width.to_px(box, width_of_containing_block)) { - used_width = tentative_width_for_replaced_element(state, box, computed_max_width, available_space); + used_width = tentative_width_for_replaced_element(box, computed_max_width, available_space); } } @@ -464,7 +464,7 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons auto computed_min_width = box.computed_values().min_width(); if (!computed_min_width.is_auto()) { if (used_width < computed_min_width.to_px(box, width_of_containing_block)) { - used_width = tentative_width_for_replaced_element(state, box, computed_min_width, available_space); + used_width = tentative_width_for_replaced_element(box, computed_min_width, available_space); } } @@ -473,7 +473,7 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements // https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-height -CSSPixels FormattingContext::tentative_height_for_replaced_element(LayoutState const& state, ReplacedBox const& box, CSS::Size const& computed_height, AvailableSpace const& available_space) +CSSPixels FormattingContext::tentative_height_for_replaced_element(ReplacedBox const& box, CSS::Size const& computed_height, AvailableSpace const& available_space) const { // If 'height' and 'width' both have computed values of 'auto' and the element also has // an intrinsic height, then that intrinsic height is the used value of 'height'. @@ -484,7 +484,7 @@ CSSPixels FormattingContext::tentative_height_for_replaced_element(LayoutState c // // (used width) / (intrinsic ratio) if (computed_height.is_auto() && box.has_intrinsic_aspect_ratio()) - return state.get(box).content_width() / static_cast(box.intrinsic_aspect_ratio().value()); + return m_state.get(box).content_width() / static_cast(box.intrinsic_aspect_ratio().value()); // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic height, then that intrinsic height is the used value of 'height'. if (computed_height.is_auto() && box.has_intrinsic_height()) @@ -500,28 +500,28 @@ CSSPixels FormattingContext::tentative_height_for_replaced_element(LayoutState c return computed_height.to_px(box, available_space.height.to_px_or_zero()); } -CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState const& state, ReplacedBox const& box, AvailableSpace const& available_space) +CSSPixels FormattingContext::compute_height_for_replaced_element(ReplacedBox const& box, AvailableSpace const& available_space) const { // 10.6.2 Inline replaced elements // 10.6.4 Block-level replaced elements in normal flow // 10.6.6 Floating replaced elements // 10.6.10 'inline-block' replaced elements in normal flow - auto height_of_containing_block = state.get(*box.non_anyonymous_containing_block()).content_height(); + auto height_of_containing_block = m_state.get(*box.non_anyonymous_containing_block()).content_height(); auto computed_width = should_treat_width_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().width(); auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height(); // 1. The tentative used height is calculated (without 'min-height' and 'max-height') - CSSPixels used_height = tentative_height_for_replaced_element(state, box, computed_height, available_space); + CSSPixels used_height = tentative_height_for_replaced_element(box, computed_height, available_space); // However, for replaced elements with both 'width' and 'height' computed as 'auto', // use the algorithm under 'Minimum and maximum widths' // https://www.w3.org/TR/CSS22/visudet.html#min-max-widths // to find the used width and height. if (computed_width.is_auto() && computed_height.is_auto() && box.has_intrinsic_aspect_ratio()) { - CSSPixels w = tentative_width_for_replaced_element(state, box, computed_width, available_space); + CSSPixels w = tentative_width_for_replaced_element(box, computed_width, available_space); CSSPixels h = used_height; - used_height = solve_replaced_size_constraint(state, w, h, box).height(); + used_height = solve_replaced_size_constraint(m_state, w, h, box).height(); return used_height; } @@ -530,7 +530,7 @@ CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState con auto computed_max_height = box.computed_values().max_height(); if (!computed_max_height.is_none()) { if (used_height > computed_max_height.to_px(box, height_of_containing_block)) { - used_height = tentative_height_for_replaced_element(state, box, computed_max_height, available_space); + used_height = tentative_height_for_replaced_element(box, computed_max_height, available_space); } } @@ -539,7 +539,7 @@ CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState con auto computed_min_height = box.computed_values().min_height(); if (!computed_min_height.is_auto()) { if (used_height < computed_min_height.to_px(box, height_of_containing_block)) { - used_height = tentative_height_for_replaced_element(state, box, computed_min_height, available_space); + used_height = tentative_height_for_replaced_element(box, computed_min_height, available_space); } } @@ -695,7 +695,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_replaced_element // The used value of 'width' is determined as for inline replaced elements. // FIXME: This const_cast is gross. const_cast(box).prepare_for_replaced_layout(); - m_state.get_mutable(box).set_content_width(compute_width_for_replaced_element(m_state, box, available_space)); + m_state.get_mutable(box).set_content_width(compute_width_for_replaced_element(box, available_space)); } // https://drafts.csswg.org/css-position-3/#abs-non-replaced-height @@ -1065,7 +1065,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_replaced_elemen { // 10.6.5 Absolutely positioned, replaced elements // The used value of 'height' is determined as for inline replaced elements. - m_state.get_mutable(box).set_content_height(compute_height_for_replaced_element(m_state, box, available_space)); + m_state.get_mutable(box).set_content_height(compute_height_for_replaced_element(box, available_space)); } // https://www.w3.org/TR/css-position-3/#relpos-insets @@ -1397,10 +1397,10 @@ CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, Av return height.resolved(box, height_of_containing_block_as_length_for_resolve); } -CSSPixels FormattingContext::containing_block_width_for(Box const& box, LayoutState const& state) +CSSPixels FormattingContext::containing_block_width_for(Box const& box) const { - auto& containing_block_state = state.get(*box.containing_block()); - auto& box_state = state.get(box); + auto const& containing_block_state = m_state.get(*box.containing_block()); + auto const& box_state = m_state.get(box); switch (box_state.width_constraint) { case SizeConstraint::MinContent: @@ -1413,10 +1413,10 @@ CSSPixels FormattingContext::containing_block_width_for(Box const& box, LayoutSt VERIFY_NOT_REACHED(); } -CSSPixels FormattingContext::containing_block_height_for(Box const& box, LayoutState const& state) +CSSPixels FormattingContext::containing_block_height_for(Box const& box) const { - auto& containing_block_state = state.get(*box.containing_block()); - auto& box_state = state.get(box); + auto const& containing_block_state = m_state.get(*box.containing_block()); + auto const& box_state = m_state.get(box); switch (box_state.height_constraint) { case SizeConstraint::MinContent: @@ -1430,12 +1430,12 @@ CSSPixels FormattingContext::containing_block_height_for(Box const& box, LayoutS } // https://drafts.csswg.org/css-sizing-3/#stretch-fit-size -CSSPixels FormattingContext::calculate_stretch_fit_width(Box const& box, AvailableSize const& available_width, LayoutState const& state) +CSSPixels FormattingContext::calculate_stretch_fit_width(Box const& box, AvailableSize const& available_width) const { // The size a box would take if its outer size filled the available space in the given axis; // in other words, the stretch fit into the available space, if that is definite. // Undefined if the available space is indefinite. - auto const& box_state = state.get(box); + auto const& box_state = m_state.get(box); return available_width.to_px() - box_state.margin_left - box_state.margin_right @@ -1445,18 +1445,13 @@ CSSPixels FormattingContext::calculate_stretch_fit_width(Box const& box, Availab - box_state.border_right; } -CSSPixels FormattingContext::calculate_stretch_fit_width(Box const& box, AvailableSize const& available_width) const -{ - return calculate_stretch_fit_width(box, available_width, m_state); -} - // https://drafts.csswg.org/css-sizing-3/#stretch-fit-size -CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, AvailableSize const& available_height, LayoutState const& state) +CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, AvailableSize const& available_height) const { // The size a box would take if its outer size filled the available space in the given axis; // in other words, the stretch fit into the available space, if that is definite. // Undefined if the available space is indefinite. - auto const& box_state = state.get(box); + auto const& box_state = m_state.get(box); return available_height.to_px() - box_state.margin_top - box_state.margin_bottom @@ -1466,11 +1461,6 @@ CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, Availa - box_state.border_bottom; } -CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, AvailableSize const& available_height) const -{ - return calculate_stretch_fit_height(box, available_height, m_state); -} - bool FormattingContext::should_treat_width_as_auto(Box const& box, AvailableSpace const& available_space) { return box.computed_values().width().is_auto() diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index 9762b1263a..81347e57b6 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -50,8 +50,8 @@ public: static bool creates_block_formatting_context(Box const&); - static CSSPixels compute_width_for_replaced_element(LayoutState const&, ReplacedBox const&, AvailableSpace const&); - static CSSPixels compute_height_for_replaced_element(LayoutState const&, ReplacedBox const&, AvailableSpace const&); + CSSPixels compute_width_for_replaced_element(ReplacedBox const&, AvailableSpace const&) const; + CSSPixels compute_height_for_replaced_element(ReplacedBox const&, AvailableSpace const&) const; OwnPtr create_independent_formatting_context_if_needed(LayoutState&, Box const& child_box); @@ -70,18 +70,12 @@ public: virtual CSSPixels greatest_child_width(Box const&) const; - CSSPixels containing_block_width_for(Box const& box) const { return containing_block_width_for(box, m_state); } - CSSPixels containing_block_height_for(Box const& box) const { return containing_block_height_for(box, m_state); } - - static CSSPixels containing_block_width_for(Box const&, LayoutState const&); - static CSSPixels containing_block_height_for(Box const&, LayoutState const&); + [[nodiscard]] CSSPixels containing_block_width_for(Box const&) const; + [[nodiscard]] CSSPixels containing_block_height_for(Box const&) const; [[nodiscard]] CSSPixels calculate_stretch_fit_width(Box const&, AvailableSize const&) const; [[nodiscard]] CSSPixels calculate_stretch_fit_height(Box const&, AvailableSize const&) const; - [[nodiscard]] static CSSPixels calculate_stretch_fit_width(Box const&, AvailableSize const&, LayoutState const&); - [[nodiscard]] static CSSPixels calculate_stretch_fit_height(Box const&, AvailableSize const&, LayoutState const&); - virtual bool can_determine_size_of_child() const { return false; } virtual void determine_width_of_child(Box const&, AvailableSpace const&) { } virtual void determine_height_of_child(Box const&, AvailableSpace const&) { } @@ -108,8 +102,8 @@ protected: CSSPixels preferred_minimum_width { 0 }; }; - static CSSPixels tentative_width_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::Size const& computed_width, AvailableSpace const&); - static CSSPixels tentative_height_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::Size const& computed_height, AvailableSpace const&); + CSSPixels tentative_width_for_replaced_element(ReplacedBox const&, CSS::Size const& computed_width, AvailableSpace const&) const; + CSSPixels tentative_height_for_replaced_element(ReplacedBox const&, CSS::Size const& computed_height, AvailableSpace const&) const; CSSPixels compute_auto_height_for_block_formatting_context_root(Box const&) const; ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index ed016399c5..7889495c6e 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -113,8 +113,8 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l if (is(box)) { auto& replaced = verify_cast(box); - box_state.set_content_width(compute_width_for_replaced_element(m_state, replaced, *m_available_space)); - box_state.set_content_height(compute_height_for_replaced_element(m_state, replaced, *m_available_space)); + box_state.set_content_width(compute_width_for_replaced_element(replaced, *m_available_space)); + box_state.set_content_height(compute_height_for_replaced_element(replaced, *m_available_space)); if (is(box)) (void)layout_inside(replaced, layout_mode, box_state.available_inner_space_or_constraints_from(*m_available_space));