Skip to content

Truly independent web browser

LibWeb: Resolve positional justify-content values in flex containers

Andreas Klingbd7ab66347d5
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 50e3a69313c..670918c70ef 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -341,6 +341,54 @@ impl<'pass> FlexFormattingContext<'pass> {
reverse
}
+ // Whether the start side of the writing mode, in the main axis, is the frame's right or bottom side.
+ fn main_axis_writing_mode_start_is_reverse(&self) -> bool {
+ if self.is_row_layout() {
+ self.inline_axis_is_reverse(self.run.box_)
+ } else {
+ self.block_axis_is_reverse(self.run.box_)
+ }
+ }
+
+ // Whether the given start, end, left or right value of justify-content packs the flex items against the main
+ // axis side that is the frame's right or bottom side.
+ // https://drafts.csswg.org/css-align-3/#positional-values
+ fn justify_content_position_is_reverse(&self, justify: u8) -> bool {
+ let start_is_reverse = self.main_axis_writing_mode_start_is_reverse();
+ match justify {
+ justify_content::START => start_is_reverse,
+ justify_content::END => !start_is_reverse,
+ // left: Aligns the alignment subject to be flush with the alignment container's line-left or physical
+ // left edge, whichever is in the appropriate axis.
+ // If the property's axis is not parallel with either left↔right axis, this value behaves as start.
+ // NB: The frame's left side is the line-left side. The main axis of a column flex container runs along
+ // the physical left↔right axis in a vertical writing mode.
+ justify_content::LEFT => {
+ if self.is_row_layout() {
+ false
+ } else if self.run.callbacks.frame.is_transposed() {
+ self.run.callbacks.frame.frame_side(geometry::Side::Left) == geometry::Side::Bottom
+ } else {
+ start_is_reverse
+ }
+ }
+ // right: Aligns the alignment subject to be flush with the alignment container's line-right or physical
+ // right edge, whichever is in the appropriate axis.
+ // If the property's axis is not parallel with either left↔right axis, this value behaves as
+ // start.
+ justify_content::RIGHT => {
+ if self.is_row_layout() {
+ true
+ } else if self.run.callbacks.frame.is_transposed() {
+ self.run.callbacks.frame.frame_side(geometry::Side::Right) == geometry::Side::Bottom
+ } else {
+ start_is_reverse
+ }
+ }
+ _ => unreachable!("not a positional justify-content value"),
+ }
+ }
+
fn is_direction_reverse(&self) -> bool {
let mut reverse = if self.is_row_layout() {
self.inline_axis_is_reverse(self.run.box_)
@@ -2170,17 +2218,13 @@ impl<'pass> FlexFormattingContext<'pass> {
let justify = self.style(self.run.box_).justify_content();
if auto_margins == 0 && number_of_items > 0 {
match justify {
- justify_content::START | justify_content::LEFT => {}
- justify_content::STRETCH | justify_content::NORMAL | justify_content::FLEX_START => {
- if self.is_direction_reverse() {
+ justify_content::START | justify_content::END | justify_content::LEFT | justify_content::RIGHT => {
+ if self.justify_content_position_is_reverse(justify) {
initial_offset = self.inner_main_size_used(self.container_used());
}
}
- justify_content::END => {
- initial_offset = self.inner_main_size_used(self.container_used());
- }
- justify_content::RIGHT => {
- if self.is_row_layout() {
+ justify_content::STRETCH | justify_content::NORMAL | justify_content::FLEX_START => {
+ if self.is_direction_reverse() {
initial_offset = self.inner_main_size_used(self.container_used());
}
}
@@ -2234,7 +2278,9 @@ impl<'pass> FlexFormattingContext<'pass> {
// Otherwise the cursor offset is the 'start' of the region or initial offset
let cursor_right = if auto_margins == 0 {
match justify {
- justify_content::START | justify_content::LEFT => false,
+ justify_content::START | justify_content::END | justify_content::LEFT | justify_content::RIGHT => {
+ self.justify_content_position_is_reverse(justify)
+ }
justify_content::NORMAL
| justify_content::FLEX_START
| justify_content::CENTER
@@ -2242,8 +2288,6 @@ impl<'pass> FlexFormattingContext<'pass> {
| justify_content::SPACE_BETWEEN
| justify_content::SPACE_EVENLY
| justify_content::STRETCH => self.is_direction_reverse(),
- justify_content::END => true,
- justify_content::RIGHT => self.is_row_layout(),
justify_content::FLEX_END => !self.is_direction_reverse(),
_ => false,
}
@@ -2750,8 +2794,15 @@ impl<'pass> FlexFormattingContext<'pass> {
// assuming both the child and the flex container were fixed-size boxes of their used size.
// (For this purpose, auto margins are treated as zero.
- let main_alignment = match self.style(self.run.box_).justify_content() {
- justify_content::START | justify_content::LEFT => StaticPositionAlignment::Start,
+ let justify = self.style(self.run.box_).justify_content();
+ let main_alignment = match justify {
+ justify_content::START | justify_content::END | justify_content::LEFT | justify_content::RIGHT => {
+ if self.justify_content_position_is_reverse(justify) {
+ StaticPositionAlignment::End
+ } else {
+ StaticPositionAlignment::Start
+ }
+ }
justify_content::STRETCH
| justify_content::NORMAL
| justify_content::FLEX_START
@@ -2762,7 +2813,6 @@ impl<'pass> FlexFormattingContext<'pass> {
StaticPositionAlignment::Start
}
}
- justify_content::END | justify_content::RIGHT => StaticPositionAlignment::End,
justify_content::FLEX_END => {
if self.is_direction_reverse() {
StaticPositionAlignment::Start
diff --git a/Tests/LibWeb/Layout/expected/flex/abspos-flex-child-static-position-with-justify-content.txt b/Tests/LibWeb/Layout/expected/flex/abspos-flex-child-static-position-with-justify-content.txt
index 17390d670e6..469ec1775b3 100644
--- a/Tests/LibWeb/Layout/expected/flex/abspos-flex-child-static-position-with-justify-content.txt
+++ b/Tests/LibWeb/Layout/expected/flex/abspos-flex-child-static-position-with-justify-content.txt
@@ -207,8 +207,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [10,1808] [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
Box <div.column.outer.right> at [11,1809] flex-container(column) [0+1+0 300 0+1+478] [0+1+0 60 0+1+0] [FFC] children: not-inline
- BlockContainer <div> at [12,1818] positioned [0+1+0 150 0+1+0] [0+1+0 50 0+1+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 5, rect: [12,1818 37.109375x16] baseline: 12.796875
+ BlockContainer <div> at [12,1810] positioned [0+1+0 150 0+1+0] [0+1+0 50 0+1+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 5, rect: [12,1810 37.109375x16] baseline: 12.796875
"right"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> at [10,1870] [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: inline
@@ -277,8 +277,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [10,2428] [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
Box <div.column.reverse.outer.right> at [11,2429] flex-container(column-reverse) [0+1+0 300 0+1+478] [0+1+0 60 0+1+0] [FFC] children: not-inline
- BlockContainer <div> at [12,2438] positioned [0+1+0 150 0+1+0] [0+1+0 50 0+1+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 5, rect: [12,2438 37.109375x16] baseline: 12.796875
+ BlockContainer <div> at [12,2430] positioned [0+1+0 150 0+1+0] [0+1+0 50 0+1+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 5, rect: [12,2430 37.109375x16] baseline: 12.796875
"right"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> at [10,2490] [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: inline
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-005.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-005.txt
index d7140f843ee..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-005.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-005.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-22 Pass
-2 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -15,7 +14,7 @@ Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
-Fail .container > div 12
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -27,4 +26,4 @@ Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-006.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-006.txt
index d7140f843ee..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-006.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-006.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-22 Pass
-2 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -15,7 +14,7 @@ Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
-Fail .container > div 12
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -27,4 +26,4 @@ Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-007.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-007.txt
index d7140f843ee..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-007.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-007.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-22 Pass
-2 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -15,7 +14,7 @@ Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
-Fail .container > div 12
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -27,4 +26,4 @@ Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-008.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-008.txt
index d7140f843ee..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-008.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-008.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-22 Pass
-2 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -15,7 +14,7 @@ Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
-Fail .container > div 12
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -27,4 +26,4 @@ Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-001.txt
index 6d9560b04a9..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-001.txt
@@ -2,16 +2,15 @@ Harness status: OK
Found 24 tests
-20 Pass
-4 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
Pass .container > div 4
Pass .container > div 5
Pass .container > div 6
-Fail .container > div 7
-Fail .container > div 8
+Pass .container > div 7
+Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
@@ -22,8 +21,8 @@ Pass .container > div 15
Pass .container > div 16
Pass .container > div 17
Pass .container > div 18
-Fail .container > div 19
-Fail .container > div 20
+Pass .container > div 19
+Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-002.txt
index d7140f843ee..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-002.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-rtl-002.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-22 Pass
-2 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -15,7 +14,7 @@ Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11
-Fail .container > div 12
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -27,4 +26,4 @@ Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
Pass .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-vertWM-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-vertWM-002.txt
index 89682674c64..a1cd201dd16 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-vertWM-002.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/abspos/flex-abspos-staticpos-justify-content-vertWM-002.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 24 tests
-20 Pass
-4 Fail
+24 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
@@ -14,8 +13,8 @@ Pass .container > div 7
Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
-Fail .container > div 11
-Fail .container > div 12
+Pass .container > div 11
+Pass .container > div 12
Pass .container > div 13
Pass .container > div 14
Pass .container > div 15
@@ -26,5 +25,5 @@ Pass .container > div 19
Pass .container > div 20
Pass .container > div 21
Pass .container > div 22
-Fail .container > div 23
-Fail .container > div 24
\ No newline at end of file
+Pass .container > div 23
+Pass .container > div 24
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-justify-content-wmvert-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-justify-content-wmvert-002.txt
index 71e8e4e07e1..1cc66c9a64b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-justify-content-wmvert-002.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-justify-content-wmvert-002.txt
@@ -2,9 +2,8 @@ Harness status: OK
Found 4 tests
-2 Pass
-2 Fail
-Fail .flexitem 1
+4 Pass
+Pass .flexitem 1
Pass .flexitem 2
Pass .flexitem 3
-Fail .flexitem 4
\ No newline at end of file
+Pass .flexitem 4
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox_justifycontent-rtl-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox_justifycontent-rtl-001.txt
index 0f3de60b1b0..2fd6b4588fc 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox_justifycontent-rtl-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox_justifycontent-rtl-001.txt
@@ -2,16 +2,15 @@ Harness status: OK
Found 12 tests
-10 Pass
-2 Fail
+12 Pass
Pass .container > div 1
Pass .container > div 2
Pass .container > div 3
Pass .container > div 4
Pass .container > div 5
Pass .container > div 6
-Fail .container > div 7
-Fail .container > div 8
+Pass .container > div 7
+Pass .container > div 8
Pass .container > div 9
Pass .container > div 10
Pass .container > div 11