summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-06 20:51:56 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-07 06:28:47 +0200
commitfc3c3aef2295e6684ea72f442025a4435450f937 (patch)
tree3c39f8607fb4c97746afec830b594770531bd60e
parent36ff6187f6f5e67ba3f2085b5257ec1de10cf79b (diff)
downloadserenity-fc3c3aef2295e6684ea72f442025a4435450f937.zip
LibWeb: Enforce min/max height constraints on abspos replaced boxes
Fixes #18658
-rw-r--r--Tests/LibWeb/Layout/expected/abspos-image-with-min-height-constraint.txt4
-rw-r--r--Tests/LibWeb/Layout/input/abspos-image-with-min-height-constraint.html9
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.cpp15
3 files changed, 24 insertions, 4 deletions
diff --git a/Tests/LibWeb/Layout/expected/abspos-image-with-min-height-constraint.txt b/Tests/LibWeb/Layout/expected/abspos-image-with-min-height-constraint.txt
new file mode 100644
index 0000000000..57a613234f
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/abspos-image-with-min-height-constraint.txt
@@ -0,0 +1,4 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer <html> at (0,0) content-size 800x16 [BFC] children: not-inline
+ BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
+ ImageBox <img#zero-dimensions-but-min-percentages> at (8,8) content-size 800x600 positioned children: not-inline
diff --git a/Tests/LibWeb/Layout/input/abspos-image-with-min-height-constraint.html b/Tests/LibWeb/Layout/input/abspos-image-with-min-height-constraint.html
new file mode 100644
index 0000000000..87309674db
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/abspos-image-with-min-height-constraint.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html><html><head><style>
+#zero-dimensions-but-min-percentages {
+ width: 0;
+ height: 0;
+ min-width: 100%;
+ min-height: 100%;
+ position: absolute;
+}
+</style><body><img id="zero-dimensions-but-min-percentages"> \ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index 48221e14fe..c997a1c222 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -497,8 +497,7 @@ CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState con
// 10.6.2 Inline replaced elements, block-level replaced elements in normal flow,
// 'inline-block' replaced elements in normal flow and floating replaced elements
- auto width_of_containing_block_as_length = CSS::Length::make_px(available_space.width.to_px());
- auto height_of_containing_block_as_length = CSS::Length::make_px(available_space.height.to_px());
+ auto height_of_containing_block = state.get(*box.containing_block()).content_height();
auto computed_width = should_treat_width_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().width();
auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height();
@@ -510,6 +509,14 @@ CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState con
used_height = solve_replaced_size_constraint(state, w, h, box).height();
}
+ auto const& computed_min_height = box.computed_values().min_height();
+ auto const& computed_max_height = box.computed_values().max_height();
+
+ if (!computed_max_height.is_none())
+ used_height = min(used_height, computed_max_height.to_px(box, height_of_containing_block));
+ if (!computed_min_height.is_auto())
+ used_height = max(used_height, computed_min_height.to_px(box, height_of_containing_block));
+
return used_height;
}
@@ -1310,9 +1317,9 @@ CSS::Length FormattingContext::calculate_inner_width(Layout::Box const& box, Ava
return width.resolved(box, width_of_containing_block_as_length_for_resolve);
}
-CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const& available_height, CSS::Size const& height) const
+CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const&, CSS::Size const& height) const
{
- auto height_of_containing_block = available_height.to_px();
+ auto height_of_containing_block = m_state.get(*box.containing_block()).content_height();
auto height_of_containing_block_as_length_for_resolve = CSS::Length::make_px(height_of_containing_block);
if (height.is_auto()) {
return height.resolved(box, height_of_containing_block_as_length_for_resolve);