From 74e9a892e362ab3af3ee8c6a5e55775ea764acca Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 26 Mar 2021 17:01:44 -0400 Subject: [PATCH] LibWeb: Compute height of absolutely positioned blocks when possible Section 10.6.4 rule 5 of the CSS height property spec outlines a method to compute the height of an absolutely positioned block when the 'top' and 'bottom' CSS properties are specified. --- Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index b96fa7d039..5b387bcd74 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -460,6 +460,8 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el auto& computed_values = box.computed_values(); auto& containing_block = *box.containing_block(); + CSS::Length specified_top = computed_values.offset().top.resolved_or_auto(box, containing_block.height()); + CSS::Length specified_bottom = computed_values.offset().bottom.resolved_or_auto(box, containing_block.height()); CSS::Length specified_height; if (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute()) { @@ -477,6 +479,14 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box); box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box); + if (specified_height.is_auto() && !specified_top.is_auto() && !specified_bottom.is_auto()) { + const auto& margin = box.box_model().margin; + const auto& padding = box.box_model().padding; + const auto& border = box.box_model().border; + + specified_height = CSS::Length(containing_block.height() - specified_top.to_px(box) - margin.top - padding.top - border.top - specified_bottom.to_px(box) - margin.bottom - padding.bottom - border.bottom, CSS::Length::Type::Px); + } + if (!specified_height.is_auto()) { float used_height = specified_height.to_px(box); if (!specified_max_height.is_auto())