Skip to content

Commit 6894034

Browse files
committed
LibWeb: Mark flex item main size definite if resolved from aspect-ratio
This matches the behavior of other engines and makes the cards on the Apple App Store appear in the narrower layouts.
1 parent cde3941 commit 6894034

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Libraries/LibWeb/Layout/FlexFormattingContext.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ void FlexFormattingContext::determine_flex_base_size(FlexItem& item)
667667
&& item.used_flex_basis->has<CSS::FlexBasisContent>()
668668
&& has_definite_cross_size(item)) {
669669
// flex_base_size is calculated from definite cross size and intrinsic aspect ratio
670+
671+
// AD-HOC: Mark that we resolved the main size from the aspect ratio,
672+
// so that we can mark the item as having definite main size after resolving flexible lengths.
673+
item.main_size_was_resolved_from_aspect_ratio = true;
674+
670675
return adjust_main_size_through_aspect_ratio_for_cross_size_min_max_constraints(
671676
item.box,
672677
calculate_main_size_from_cross_size_and_aspect_ratio(inner_cross_size(item), item.box->preferred_aspect_ratio().value()),
@@ -1119,7 +1124,8 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
11191124
// https://drafts.csswg.org/css-flexbox-1/#definite-sizes
11201125
// 1. If the flex container has a definite main size, then the post-flexing main sizes of its flex items are treated as definite.
11211126
// 2. If a flex item’s flex basis is definite, then its post-flexing main size is also definite.
1122-
if (has_definite_main_size(m_flex_container_state) || item.used_flex_basis_is_definite)
1127+
// AD-HOC: 3. If a flex item’s main size was resolved from its intrinsic aspect ratio, then its post-flexing main size is also definite.
1128+
if (has_definite_main_size(m_flex_container_state) || item.used_flex_basis_is_definite || item.main_size_was_resolved_from_aspect_ratio)
11231129
set_has_definite_main_size(item);
11241130
}
11251131
}

Libraries/LibWeb/Layout/FlexFormattingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class FlexFormattingContext final : public FormattingContext {
5858
LayoutState::UsedValues& used_values;
5959
Optional<CSS::FlexBasis> used_flex_basis {};
6060
bool used_flex_basis_is_definite { false };
61+
bool main_size_was_resolved_from_aspect_ratio { false };
6162
CSSPixels flex_base_size { 0 };
6263
CSSPixels hypothetical_main_size { 0 };
6364
CSSPixels hypothetical_cross_size { 0 };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 400 0+0+400] [0+0+0 400 0+0+0] [BFC] children: not-inline
3+
Box <body> at [8,8] flex-container(column) [8+0+0 400 0+0+-8] [8+0+0 200 0+0+8] [FFC] children: not-inline
4+
BlockContainer <main> at [8,8] flex-item [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] [BFC] children: not-inline
5+
BlockContainer <article> at [8,8] [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] children: not-inline
6+
7+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
8+
PaintableWithLines (BlockContainer<HTML>) [0,0 400x400] overflow: [0,0 408x400]
9+
PaintableBox (Box<BODY>) [8,8 400x200]
10+
PaintableWithLines (BlockContainer<MAIN>) [8,8 300x200]
11+
PaintableWithLines (BlockContainer<ARTICLE>) [8,8 300x200]
12+
13+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
14+
SC for BlockContainer<HTML> [0,0 400x400] [children: 0] (z-index: auto)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html><style>
2+
* { outline: 1px solid black; }
3+
html {
4+
background: white;
5+
width: 400px;
6+
height: 400px;
7+
}
8+
body {
9+
display: flex;
10+
flex-direction: column;
11+
width: 400px;
12+
}
13+
main {
14+
background-color: magenta;
15+
aspect-ratio: 3 / 2;
16+
width: 300px;
17+
}
18+
article {
19+
background-color: pink;
20+
height: 100%;
21+
}
22+
div {
23+
background-color: orange;
24+
position: absolute;
25+
}
26+
</style><body><main><article>

0 commit comments

Comments
 (0)