Commit a123787c authored by Javier Fernandez's avatar Javier Fernandez Committed by Commit Bot

[css-grid] Allow alignment of in-flow items with non-static positions

This is a fix for a regression introduced in r515391, where we landed
the implementation of alignment for positioned objects in a Grid Layout
container.

We assumed that items with non-static positions shouldn't honor the
CSS Box Alignment properties. This is only true for out-of-flow items,
absolute or fixed positioned elements. However, sticky positioned
elements are treated as relative positioned items, but they indeed use
non-static position to define their behavior.

Bug: 806622
Change-Id: Ibaed2c36530d81223d1491def9022e82cf9c3525
Reviewed-on: https://chromium-review.googlesource.com/897949
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Reviewed-by: default avatarManuel Rego Casasnovas <rego@igalia.com>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534029}
parent d54b7828
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Self-Alignment along column axis of stcky positioned items</title>
<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#column-align">
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-align-self">
<link rel="stylesheet" href="../../support/alignment.css">
<meta name="assert" content="Sticky positioned grid items are aligned correcly.">
<style>
.container {
border: solid 1px;
overflow: auto;
height: 500px;
}
.grid {
position: relative;
float: left;
display: grid;
grid-template-columns: 75px 75px 75px 75px;
grid-template-rows: 100px 100px 100px 300px;
background: grey;
height: 400px;
margin-right: 20px;
}
.sticky {
position: -webkit-sticky;
position: sticky;
width: 20px;
height: 20px;
background-color: #cae8ca;
}
.item1 {
top: 0px;
grid-column: 1;
grid-row: 1;
}
.item2 {
top: 0px;
grid-column: 2;
grid-row: 2;
}
.item3 {
top: 0px;
grid-column: 3;
grid-row: 3;
}
.item4 {
grid-column: 4;
grid-row: 4;
background: lightgrey;
}
.scroll { overflow: auto; }
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<body onload="checkLayout('.grid')">
<div class="container">
<div style="height:30px"></div>
<div class="grid">
<div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="0"></div>
<div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
<div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="280"></div>
<div class="item4"></div>
</div>
<div class="grid scroll">
<div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="0"></div>
<div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
<div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="280"></div>
<div class="item4"></div>
</div>
<div style="height:2000px"></div>
</div>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Self-Alignment along column axis of stcky positioned items</title>
<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#column-align">
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-align-self">
<link rel="stylesheet" href="../../support/alignment.css">
<meta name="assert" content="Sticky positioned grid items are aligned correcly, but preserving non-static positions when required.">
<style>
.container {
border: solid 1px;
overflow: auto;
height: 500px;
}
.grid {
position: relative;
float: left;
display: grid;
grid-template-columns: 75px 75px 75px 75px;
grid-template-rows: 100px 100px 100px 300px;
background: grey;
height: 400px;
margin-right: 20px;
}
.sticky {
position: -webkit-sticky;
position: sticky;
width: 20px;
height: 20px;
background-color: #cae8ca;
}
.item1 {
top: 40px;
grid-column: 1;
grid-row: 1;
}
.item2 {
top: 100px;
grid-column: 2;
grid-row: 2;
}
.item3 {
top: 290px;
grid-column: 3;
grid-row: 3;
}
.item4 {
grid-column: 4;
grid-row: 4;
background: lightgrey;
}
.scroll { overflow: auto; }
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<body onload="checkLayout('.grid')">
<div class="container">
<div style="height:30px"></div>
<div class="grid">
<div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="10"></div>
<div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
<div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="280"></div>
<div class="item4"></div>
</div>
<div class="grid scroll">
<div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="40"></div>
<div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
<div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="290"></div>
<div class="item4"></div>
</div>
<div style="height:2000px"></div>
</div>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Self-Alignment along row axis of stcky positioned items</title>
<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#row-align">
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-justify-self">
<link rel="stylesheet" href="../../support/alignment.css">
<meta name="assert" content="Sticky positioned grid items are aligned correcly.">
<style>
.container {
border: solid 1px;
overflow: auto;
width: 500px;
}
.grid {
position: relative;
display: grid;
grid-template-columns: 100px 100px 100px 300px;
grid-template-rows: 75px 75px 75px 75px;
background: grey;
width: 400px;
margin-bottom: 20px;
}
.sticky {
position: -webkit-sticky;
position: sticky;
width: 20px;
height: 20px;
background-color: #cae8ca;
}
.item1 {
left: 0px;
grid-column: 1;
grid-row: 1;
}
.item2 {
left: 0px;
grid-column: 2;
grid-row: 2;
}
.item3 {
left: 0px;
grid-column: 3;
grid-row: 3;
}
.item4 {
grid-column: 4;
grid-row: 4;
background: lightgrey;
}
.scroll { overflow: auto; }
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<body onload="checkLayout('.grid')">
<div class="container">
<div style="width: 30px; float:left; height: 10px;"></div>
<div class="grid">
<div class="item1 sticky justifySelfStart" data-offset-x="0" data-offset-y="0"></div>
<div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
<div class="item3 sticky justifySelfEnd" data-offset-x="280" data-offset-y="150"></div>
<div class="item4"></div>
</div>
<div style="width: 30px; float:left; height: 10px;"></div>
<div class="grid scroll">
<div class="item1 sticky justifySelfStart" data-offset-x="0" data-offset-y="0"></div>
<div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
<div class="item3 sticky justifySelfEnd" data-offset-x="280" data-offset-y="150"></div>
<div class="item4"></div>
</div>
<div style="width: 2000px; height: 10px;"></div>
</div>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Self-Alignment along row axis of stcky positioned items</title>
<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#row-align">
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-justify-self">
<link rel="stylesheet" href="../../support/alignment.css">
<meta name="assert" content="Sticky positioned grid items are aligned correcly, but preserving non-static positions when required.">
<style>
.container {
border: solid 1px;
overflow: auto;
width: 500px;
}
.grid {
position: relative;
display: grid;
grid-template-columns: 100px 100px 100px 300px;
grid-template-rows: 75px 75px 75px 75px;
background: grey;
width: 400px;
margin-bottom: 20px;
}
.sticky {
position: -webkit-sticky;
position: sticky;
width: 20px;
height: 20px;
background-color: #cae8ca;
}
.item1 {
left: 40px;
grid-column: 1;
grid-row: 1;
}
.item2 {
left: 100px;
grid-column: 2;
grid-row: 2;
}
.item3 {
left: 290px;
grid-column: 3;
grid-row: 3;
}
.item4 {
grid-column: 4;
grid-row: 4;
background: lightgrey;
}
.scroll { overflow: auto; }
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<body onload="checkLayout('.grid')">
<div class="container">
<div style="width: 30px; float:left; height: 10px;"></div>
<div class="grid">
<div class="item1 sticky justifySelfStart" data-offset-x="10" data-offset-y="0"></div>
<div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
<div class="item3 sticky justifySelfEnd" data-offset-x="280" data-offset-y="150"></div>
<div class="item4"></div>
</div>
<div style="width: 30px; float:left; height: 10px;"></div>
<div class="grid scroll">
<div class="item1 sticky justifySelfStart" data-offset-x="40" data-offset-y="0"></div>
<div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
<div class="item3 sticky justifySelfEnd" data-offset-x="290" data-offset-y="150"></div>
<div class="item4"></div>
</div>
<div style="width: 2000px; height: 10px;"></div>
</div>
</body>
......@@ -1832,7 +1832,8 @@ GridAxisPosition LayoutGrid::ColumnAxisPositionForChild(
bool has_same_writing_mode =
child.StyleRef().GetWritingMode() == StyleRef().GetWritingMode();
bool child_is_ltr = child.StyleRef().IsLeftToRightDirection();
if (!HasStaticPositionForChild(child, kForRows))
if (child.IsOutOfFlowPositioned() &&
!HasStaticPositionForChild(child, kForRows))
return kGridAxisStart;
switch (AlignSelfForChild(child).GetPosition()) {
......@@ -1905,7 +1906,8 @@ GridAxisPosition LayoutGrid::RowAxisPositionForChild(
bool has_same_direction =
child.StyleRef().Direction() == StyleRef().Direction();
bool grid_is_ltr = StyleRef().IsLeftToRightDirection();
if (!HasStaticPositionForChild(child, kForColumns))
if (child.IsOutOfFlowPositioned() &&
!HasStaticPositionForChild(child, kForColumns))
return kGridAxisStart;
switch (JustifySelfForChild(child).GetPosition()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment