浏览代码

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.
Andreas Kling 1 年之前
父节点
当前提交
88949b10d8

+ 17 - 17
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:

+ 4 - 4
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;