diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-10-27 23:48:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-28 13:33:33 +0200 |
commit | 934360583f538c040d700f3fd209d7a0b57f6be4 (patch) | |
tree | b099e5ab0126f85f2a0ffcb1caece34e5b0f9d63 /Userland/Libraries | |
parent | 84b15cc7b196375dc7e1a9d7deaee7d8df87bb06 (diff) | |
download | serenity-934360583f538c040d700f3fd209d7a0b57f6be4.zip |
LibWeb: Remove duplicated auto height computation
Note that these two implementation differ, but the one in
FormattingContext.cpp seems to be more complete. It is also more recent.
Diffstat (limited to 'Userland/Libraries')
3 files changed, 20 insertions, 57 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index d07ab706bb..663394fbe5 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -289,50 +289,6 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n box.set_width(compute_width_for_replaced_element(box)); } -static float compute_auto_height_for_block_level_element(Box const& box) -{ - Optional<float> top; - Optional<float> bottom; - - if (box.children_are_inline()) { - // If it only has inline-level children, the height is the distance between - // the top of the topmost line box and the bottom of the bottommost line box. - auto& block_container = verify_cast<Layout::BlockContainer>(box); - if (!block_container.line_boxes().is_empty()) { - for (auto& fragment : block_container.line_boxes().first().fragments()) { - if (!top.has_value() || fragment.offset().y() < top.value()) - top = fragment.offset().y(); - } - for (auto& fragment : block_container.line_boxes().last().fragments()) { - if (!bottom.has_value() || (fragment.offset().y() + fragment.height()) > bottom.value()) - bottom = fragment.offset().y() + fragment.height(); - } - } - } else { - // If it has block-level children, the height is the distance between - // the top margin-edge of the topmost block-level child box - // and the bottom margin-edge of the bottommost block-level child box. - box.for_each_child_of_type<Box>([&](Layout::Box& child_box) { - if (child_box.is_absolutely_positioned()) - return IterationDecision::Continue; - if ((box.computed_values().overflow_y() == CSS::Overflow::Visible) && child_box.is_floating()) - return IterationDecision::Continue; - - float child_box_top = child_box.effective_offset().y() - child_box.box_model().margin_box().top; - float child_box_bottom = child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom; - - if (!top.has_value() || child_box_top < top.value()) - top = child_box_top; - - if (!bottom.has_value() || child_box_bottom > bottom.value()) - bottom = child_box_bottom; - - return IterationDecision::Continue; - }); - } - return bottom.value_or(0) - top.value_or(0); -} - float BlockFormattingContext::compute_theoretical_height(const Box& box) { auto& computed_values = box.computed_values(); @@ -345,7 +301,7 @@ float BlockFormattingContext::compute_theoretical_height(const Box& box) } else { if (box.computed_values().height().is_undefined_or_auto() || (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) { - height = compute_auto_height_for_block_level_element(box); + height = compute_auto_height_for_block_level_element(box, ConsiderFloats::No); } else { height = computed_values.height().resolved_or_auto(box, containing_block.height()).to_px(box); } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index d6899a790c..fc5f8ce096 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -187,7 +187,7 @@ static Gfx::FloatSize solve_replaced_size_constraint(float w, float h, const Rep return { w, h }; } -static float compute_auto_height_for_block_level_element(Box const& box) +float FormattingContext::compute_auto_height_for_block_level_element(Box const& box, ConsiderFloats consider_floats) { Optional<float> top; Optional<float> bottom; @@ -227,20 +227,22 @@ static float compute_auto_height_for_block_level_element(Box const& box) return IterationDecision::Continue; }); - // 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. - box.for_each_child_of_type<Box>([&](Layout::Box& child_box) { - if (!child_box.is_floating()) - return IterationDecision::Continue; + if (consider_floats == ConsiderFloats::Yes) { + // 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. + box.for_each_child_of_type<Box>([&](Layout::Box& child_box) { + if (!child_box.is_floating()) + return IterationDecision::Continue; - float child_box_bottom = child_box.effective_offset().y() + child_box.height(); + float child_box_bottom = child_box.effective_offset().y() + child_box.height(); - if (!bottom.has_value() || child_box_bottom > bottom.value()) - bottom = child_box_bottom; + if (!bottom.has_value() || child_box_bottom > bottom.value()) + bottom = child_box_bottom; - return IterationDecision::Continue; - }); + return IterationDecision::Continue; + }); + } } return bottom.value_or(0) - top.value_or(0); } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index 895bd9ddff..2ff1e452ed 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -55,6 +55,11 @@ protected: static float tentative_width_for_replaced_element(const ReplacedBox&, const CSS::Length& width); static float tentative_height_for_replaced_element(const ReplacedBox&, const CSS::Length& height); + enum ConsiderFloats { + Yes, + No, + }; + static float compute_auto_height_for_block_level_element(Box const&, ConsiderFloats consider_floats = ConsiderFloats::Yes); ShrinkToFitResult calculate_shrink_to_fit_widths(Box&); |