Truly independent web browser
LibWeb: Treat anchor-center as center for flex and grid items
sideshowbarker90f6b7124b03
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex db5fce7953b..f890ca2d0ae 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -2028,7 +2028,10 @@ impl<'pass> FlexFormattingContext<'pass> {align_self::SELF_END => align_items::SELF_END,align_self::FLEX_START => align_items::FLEX_START,align_self::FLEX_END => align_items::FLEX_END,- align_self::CENTER => align_items::CENTER,+ // https://drafts.csswg.org/css-anchor-position-1/#valdef-justify-self-anchor-center+ // If the box is not absolutely positioned, or does not have a default anchor box, this value behaves as+ // center and has no additional effect on how inset properties resolve.+ align_self::CENTER | align_self::ANCHOR_CENTER => align_items::CENTER,align_self::BASELINE => align_items::BASELINE,align_self::START => align_items::START,align_self::STRETCH => align_items::STRETCH,diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 39fb3d7f284..df708f8a789 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -48,7 +48,10 @@ pub(crate) fn inline_item_alignment(justify_self_value: u8, container_justify_it_ => unreachable!("invalid justify-items value"),},justify_self::BASELINE => Alignment::Baseline,- justify_self::CENTER => Alignment::Center,+ // https://drafts.csswg.org/css-anchor-position-1/#valdef-justify-self-anchor-center+ // If the box is not absolutely positioned, or does not have a default anchor box, this value behaves as+ // center and has no additional effect on how inset properties resolve.+ justify_self::CENTER | justify_self::ANCHOR_CENTER => Alignment::Center,justify_self::END | justify_self::FLEX_END => Alignment::End,justify_self::FLEX_START | justify_self::START => Alignment::Start,justify_self::LEFT => Alignment::Left,@@ -79,7 +82,10 @@ pub(crate) fn block_item_alignment(align_self_value: u8, container_align_items:_ => unreachable!("invalid align-items value"),},align_self::BASELINE => Alignment::Baseline,- align_self::CENTER => Alignment::Center,+ // https://drafts.csswg.org/css-anchor-position-1/#valdef-justify-self-anchor-center+ // If the box is not absolutely positioned, or does not have a default anchor box, this value behaves as+ // center and has no additional effect on how inset properties resolve.+ align_self::CENTER | align_self::ANCHOR_CENTER => Alignment::Center,align_self::END | align_self::FLEX_END => Alignment::End,align_self::FLEX_START | align_self::START => Alignment::Start,align_self::NORMAL => Alignment::Normal,diff --git a/Tests/LibWeb/Layout/expected/flex/align-self-anchor-center.txt b/Tests/LibWeb/Layout/expected/flex/align-self-anchor-center.txtnew file mode 100644index 00000000000..9c2ac9af9d9--- /dev/null+++ b/Tests/LibWeb/Layout/expected/flex/align-self-anchor-center.txt@@ -0,0 +1,11 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 118 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 102 0+0+8] children: not-inline+ Box <div.flex> at [9,9] flex-container(row) [0+1+0 200 0+1+582] [0+1+0 100 0+1+0] [FFC] children: not-inline+ BlockContainer <div.item> at [9,49] flex-item [0+0+0 50 0+0+0] [0+0+0 20 0+0+0] [BFC] children: not-inline+ BlockContainer <div.item> at [59,49] flex-item [0+0+0 50 0+0+0] [0+0+0 20 0+0+0] [BFC] children: not-inline+ BlockContainer <(anonymous)> at [8,110] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x118] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/grid/place-self-anchor-center.txt b/Tests/LibWeb/Layout/expected/grid/place-self-anchor-center.txtnew file mode 100644index 00000000000..9ddb8fe4a83--- /dev/null+++ b/Tests/LibWeb/Layout/expected/grid/place-self-anchor-center.txt@@ -0,0 +1,11 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 118 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 102 0+0+8] children: not-inline+ Box <div.grid> at [9,9] [0+1+0 782 0+1+0] [0+1+0 100 0+1+0] [GFC] children: not-inline+ BlockContainer <div.item> at [34,49] [25+0+0 50 0+0+25] [40+0+0 20 0+0+40] [BFC] children: not-inline+ BlockContainer <div.item> at [134,49] [25+0+0 50 0+0+25] [40+0+0 20 0+0+40] [BFC] children: not-inline+ BlockContainer <(anonymous)> at [8,110] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x118] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/flex/align-self-anchor-center.html b/Tests/LibWeb/Layout/input/flex/align-self-anchor-center.htmlnew file mode 100644index 00000000000..9e8dd4caec1--- /dev/null+++ b/Tests/LibWeb/Layout/input/flex/align-self-anchor-center.html@@ -0,0 +1,14 @@+<!DOCTYPE html><style>+ .flex {+ display: flex;+ width: 200px;+ height: 100px;+ border: 1px solid black;+ }+ .item {+ width: 50px;+ height: 20px;+ background: green;+ }+</style>+<div class="flex"><div class="item" style="align-self: anchor-center"></div><div class="item" style="align-self: center"></div></div>diff --git a/Tests/LibWeb/Layout/input/grid/place-self-anchor-center.html b/Tests/LibWeb/Layout/input/grid/place-self-anchor-center.htmlnew file mode 100644index 00000000000..436881653e1--- /dev/null+++ b/Tests/LibWeb/Layout/input/grid/place-self-anchor-center.html@@ -0,0 +1,14 @@+<!DOCTYPE html><style>+ .grid {+ display: grid;+ grid-template-columns: 100px 100px;+ grid-template-rows: 100px;+ border: 1px solid black;+ }+ .item {+ width: 50px;+ height: 20px;+ background: green;+ }+</style>+<div class="grid"><div class="item" style="place-self: anchor-center"></div><div class="item" style="place-self: center"></div></div>