From 88949b10d88e546e6febac3cd6c848efba695535 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 15 Aug 2023 09:30:13 +0200 Subject: [PATCH] LibWeb: Make containing_block_{width,height}_for(...) take non-box nodes There's no reason for this API to require a Layout::Box as input. Any node that can have layout state is welcome, so this patch makes it take NodeWithStyleAndBoxModelMetrics. --- .../LibWeb/Layout/FormattingContext.cpp | 34 +++++++++---------- .../LibWeb/Layout/FormattingContext.h | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 4be56ad171..3d5381223e 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1199,7 +1199,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_replaced_elemen } // https://www.w3.org/TR/css-position-3/#relpos-insets -void FormattingContext::compute_inset(Box const& box) +void FormattingContext::compute_inset(NodeWithStyleAndBoxModelMetrics const& box) { if (box.computed_values().position() != CSS::Position::Relative) return; @@ -1512,12 +1512,12 @@ 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) const +CSSPixels FormattingContext::containing_block_width_for(NodeWithStyleAndBoxModelMetrics const& node) const { - auto const& containing_block_state = m_state.get(*box.containing_block()); - auto const& box_state = m_state.get(box); + auto const& containing_block_state = m_state.get(*node.containing_block()); + auto const& node_state = m_state.get(node); - switch (box_state.width_constraint) { + switch (node_state.width_constraint) { case SizeConstraint::MinContent: return 0; case SizeConstraint::MaxContent: @@ -1528,12 +1528,12 @@ CSSPixels FormattingContext::containing_block_width_for(Box const& box) const VERIFY_NOT_REACHED(); } -CSSPixels FormattingContext::containing_block_height_for(Box const& box) const +CSSPixels FormattingContext::containing_block_height_for(NodeWithStyleAndBoxModelMetrics const& node) const { - auto const& containing_block_state = m_state.get(*box.containing_block()); - auto const& box_state = m_state.get(box); + auto const& containing_block_state = m_state.get(*node.containing_block()); + auto const& node_state = m_state.get(node); - switch (box_state.height_constraint) { + switch (node_state.height_constraint) { case SizeConstraint::MinContent: return 0; case SizeConstraint::MaxContent: @@ -1544,12 +1544,12 @@ CSSPixels FormattingContext::containing_block_height_for(Box const& box) const VERIFY_NOT_REACHED(); } -AvailableSize FormattingContext::containing_block_width_as_available_size(Box const& box) const +AvailableSize FormattingContext::containing_block_width_as_available_size(NodeWithStyleAndBoxModelMetrics const& node) const { - auto const& containing_block_state = m_state.get(*box.containing_block()); - auto const& box_state = m_state.get(box); + auto const& containing_block_state = m_state.get(*node.containing_block()); + auto const& node_state = m_state.get(node); - switch (box_state.width_constraint) { + switch (node_state.width_constraint) { case SizeConstraint::MinContent: return AvailableSize::make_min_content(); case SizeConstraint::MaxContent: @@ -1560,12 +1560,12 @@ AvailableSize FormattingContext::containing_block_width_as_available_size(Box co VERIFY_NOT_REACHED(); } -AvailableSize FormattingContext::containing_block_height_as_available_size(Box const& box) const +AvailableSize FormattingContext::containing_block_height_as_available_size(NodeWithStyleAndBoxModelMetrics const& node) const { - auto const& containing_block_state = m_state.get(*box.containing_block()); - auto const& box_state = m_state.get(box); + auto const& containing_block_state = m_state.get(*node.containing_block()); + auto const& node_state = m_state.get(node); - switch (box_state.height_constraint) { + switch (node_state.height_constraint) { case SizeConstraint::MinContent: return AvailableSize::make_min_content(); case SizeConstraint::MaxContent: diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index db7a8eae51..4f1de6d645 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -80,11 +80,11 @@ public: [[nodiscard]] CSSPixels box_baseline(Box const&) const; [[nodiscard]] CSSPixelRect content_box_rect_in_static_position_ancestor_coordinate_space(Box const&, Box const& ancestor_box) const; - [[nodiscard]] CSSPixels containing_block_width_for(Box const&) const; - [[nodiscard]] CSSPixels containing_block_height_for(Box const&) const; + [[nodiscard]] CSSPixels containing_block_width_for(NodeWithStyleAndBoxModelMetrics const&) const; + [[nodiscard]] CSSPixels containing_block_height_for(NodeWithStyleAndBoxModelMetrics const&) const; - [[nodiscard]] AvailableSize containing_block_width_as_available_size(Box const&) const; - [[nodiscard]] AvailableSize containing_block_height_as_available_size(Box const&) const; + [[nodiscard]] AvailableSize containing_block_width_as_available_size(NodeWithStyleAndBoxModelMetrics const&) const; + [[nodiscard]] AvailableSize containing_block_height_as_available_size(NodeWithStyleAndBoxModelMetrics const&) const; [[nodiscard]] CSSPixels calculate_stretch_fit_width(Box const&, AvailableSize const&) const; [[nodiscard]] CSSPixels calculate_stretch_fit_height(Box const&, AvailableSize const&) const;