summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-10-12 11:14:45 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-14 19:52:07 +0200
commitd7d8e3c78b06451ba7a319c4ac4d67024df7a81a (patch)
tree45cec705aeb1e4673b72dfb78e6847b14e079eee
parent834d98520ab4de7b727150c2c4255988b1b7560e (diff)
downloadserenity-d7d8e3c78b06451ba7a319c4ac4d67024df7a81a.zip
LibWeb: Resolve *all* percentages in abspos height calculation
We were neglecting to resolve() percentages for many values.
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index 6176488297..4165d31878 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -697,6 +697,8 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
auto bottom = box.computed_values().inset().bottom();
auto height = box.computed_values().height();
+ auto width_of_containing_block = containing_block_width_for(box);
+ auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto height_of_containing_block = available_space.height.to_px();
auto height_of_containing_block_as_length = CSS::Length::make_px(height_of_containing_block);
@@ -704,13 +706,13 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
return CSS::Length::make_px(
height_of_containing_block
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
- - margin_top.length().to_px(box)
+ - margin_top.resolved(box, width_of_containing_block_as_length).to_px(box)
- box.computed_values().border_top().width
- - box.computed_values().padding().top().length().to_px(box)
+ - box.computed_values().padding().top().resolved(box, width_of_containing_block_as_length).to_px(box)
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
- - box.computed_values().padding().bottom().length().to_px(box)
+ - box.computed_values().padding().bottom().resolved(box, width_of_containing_block_as_length).to_px(box)
- box.computed_values().border_bottom().width
- - margin_bottom.length().to_px(box)
+ - margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box)
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box)
+ length.to_px(box));
};
@@ -728,15 +730,15 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
};
auto solve_for_margin_top = [&] {
- margin_top = solve_for(margin_top.length());
+ margin_top = solve_for(margin_top.resolved(box, width_of_containing_block_as_length));
};
auto solve_for_margin_bottom = [&] {
- margin_bottom = solve_for(margin_bottom.length());
+ margin_bottom = solve_for(margin_bottom.resolved(box, width_of_containing_block_as_length));
};
auto solve_for_margin_top_and_margin_bottom = [&] {
- auto remainder = solve_for(CSS::Length::make_px(margin_top.length().to_px(box) + margin_bottom.length().to_px(box))).to_px(box);
+ auto remainder = solve_for(CSS::Length::make_px(margin_top.resolved(box, width_of_containing_block_as_length).to_px(box) + margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box))).to_px(box);
margin_top = CSS::Length::make_px(remainder / 2);
margin_bottom = CSS::Length::make_px(remainder / 2);
};
@@ -850,9 +852,6 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
// NOTE: The following is not directly part of any spec, but this is where we resolve
// the final used values for vertical margin/border/padding.
- auto width_of_containing_block = containing_block_width_for(box);
- auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
-
auto& box_state = m_state.get_mutable(box);
box_state.margin_top = margin_top.resolved(box, width_of_containing_block_as_length).to_px(box);
box_state.margin_bottom = margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box);