Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 1709963002: [css-align] New CSS Value 'normal' for Self Alignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New test for alignment and anonymous boxes. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
index 1ac1d2d35d3cc99dcec4971c84193397ebd0a8ea..23b9c453d6ceb233dd636ee3d944d87d287a4812 100644
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
@@ -1554,7 +1554,7 @@ void LayoutGrid::dirtyGrid()
m_gridIsDirty = true;
}
-static const StyleContentAlignmentData& normalValueBehavior()
+static const StyleContentAlignmentData& contentAlignmentNormalBehavior()
{
static const StyleContentAlignmentData normalBehavior = {ContentPositionNormal, ContentDistributionStretch};
return normalBehavior;
@@ -1564,8 +1564,8 @@ void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection
{
LayoutUnit& availableSpace = sizingData.freeSpaceForDirection(direction);
if (availableSpace <= 0
- || (direction == ForColumns && styleRef().resolvedJustifyContentDistribution(normalValueBehavior()) != ContentDistributionStretch)
- || (direction == ForRows && styleRef().resolvedAlignContentDistribution(normalValueBehavior()) != ContentDistributionStretch))
+ || (direction == ForColumns && styleRef().resolvedJustifyContentDistribution(contentAlignmentNormalBehavior()) != ContentDistributionStretch)
+ || (direction == ForRows && styleRef().resolvedAlignContentDistribution(contentAlignmentNormalBehavior()) != ContentDistributionStretch))
return;
// Spec defines auto-sized tracks as the ones with an 'auto' max-sizing function.
@@ -1886,6 +1886,24 @@ LayoutUnit LayoutGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni
return gridAreaBreadthForChild - (child.needsLayout() ? computeMarginLogicalSizeForChild(BlockDirection, child) : marginLogicalHeightForChild(child));
}
+StyleSelfAlignmentData LayoutGrid::alignSelfForChild(const LayoutBox& child) const
+{
+ if (!child.isAnonymous())
+ return child.styleRef().resolvedAlignSelf(selfAlignmentNormalBehavior());
+ // All the 'auto' values has been solved by the StyleAdjuster, but it's possible that
+ // some grid items generate Anonymous boxes, which need to be solved during layout.
+ return child.styleRef().resolvedAlignSelf(selfAlignmentNormalBehavior(), style());
+}
+
+StyleSelfAlignmentData LayoutGrid::justifySelfForChild(const LayoutBox& child) const
+{
+ if (!child.isAnonymous())
+ return child.styleRef().resolvedJustifySelf(ItemPositionStretch);
+ // All the 'auto' values has been solved by the StyleAdjuster, but it's possible that
+ // some grid items generate Anonymous boxes, which need to be solved during layout.
+ return child.styleRef().resolvedJustifySelf(ItemPositionStretch, style());
+}
+
// FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to LayoutBox.
void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child)
{
@@ -1897,7 +1915,7 @@ void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child)
bool isHorizontalMode = isHorizontalWritingMode();
bool hasAutoSizeInColumnAxis = isHorizontalMode ? childStyle.height().isAuto() : childStyle.width().isAuto();
bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !childStyle.marginBeforeUsing(style()).isAuto() && !childStyle.marginAfterUsing(style()).isAuto();
- if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment(styleRef(), childStyle, ItemPositionStretch) == ItemPositionStretch) {
+ if (allowedToStretchChildAlongColumnAxis && alignSelfForChild(child).position() == ItemPositionStretch) {
// TODO (lajava): If the child has orthogonal flow, then it already has an override height set, so use it.
// TODO (lajava): grid track sizing and positioning do not support orthogonal modes yet.
if (child.isHorizontalWritingMode() == isHorizontalMode) {
@@ -1975,7 +1993,7 @@ GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
{
bool hasSameWritingMode = child.styleRef().getWritingMode() == styleRef().getWritingMode();
- switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch)) {
+ switch (alignSelfForChild(child).position()) {
case ItemPositionSelfStart:
// If orthogonal writing-modes, this computes to 'start'.
// FIXME: grid track sizing and positioning do not support orthogonal modes yet.
@@ -2012,6 +2030,7 @@ GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
// crbug.com/234191
return GridAxisStart;
case ItemPositionAuto:
+ case ItemPositionNormal:
break;
}
@@ -2024,7 +2043,7 @@ GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con
bool hasSameDirection = child.styleRef().direction() == styleRef().direction();
bool isLTR = styleRef().isLeftToRightDirection();
- switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch)) {
+ switch (justifySelfForChild(child).position()) {
case ItemPositionSelfStart:
// For orthogonal writing-modes, this computes to 'start'
// FIXME: grid track sizing and positioning do not support orthogonal modes yet.
@@ -2054,6 +2073,7 @@ GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con
// crbug.com/234191
return GridAxisStart;
case ItemPositionAuto:
+ case ItemPositionNormal:
break;
}
@@ -2086,7 +2106,7 @@ LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child, GridSizi
endOfRow -= m_offsetBetweenRows;
}
LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHeight();
- OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef(), ItemPositionStretch).overflow();
+ OverflowAlignment overflow = alignSelfForChild(child).overflow();
LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(overflow, endOfRow - startOfRow, childBreadth);
return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2);
}
@@ -2121,7 +2141,8 @@ LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD
endOfColumn -= m_offsetBetweenColumns;
}
LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidth();
- LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childBreadth);
+ OverflowAlignment overflow = justifySelfForChild(child).overflow();
+ LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(overflow, endOfColumn - startOfColumn, childBreadth);
return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2);
}
}
@@ -2183,8 +2204,8 @@ static ContentAlignmentData contentDistributionOffset(const LayoutUnit& availabl
ContentAlignmentData LayoutGrid::computeContentPositionAndDistributionOffset(GridTrackSizingDirection direction, const LayoutUnit& availableFreeSpace, unsigned numberOfGridTracks) const
{
bool isRowAxis = direction == ForColumns;
- ContentPosition position = isRowAxis ? styleRef().resolvedJustifyContentPosition(normalValueBehavior()) : styleRef().resolvedAlignContentPosition(normalValueBehavior());
- ContentDistributionType distribution = isRowAxis ? styleRef().resolvedJustifyContentDistribution(normalValueBehavior()) : styleRef().resolvedAlignContentDistribution(normalValueBehavior());
+ ContentPosition position = isRowAxis ? styleRef().resolvedJustifyContentPosition(contentAlignmentNormalBehavior()) : styleRef().resolvedAlignContentPosition(contentAlignmentNormalBehavior());
+ ContentDistributionType distribution = isRowAxis ? styleRef().resolvedJustifyContentDistribution(contentAlignmentNormalBehavior()) : styleRef().resolvedAlignContentDistribution(contentAlignmentNormalBehavior());
// If <content-distribution> value can't be applied, 'position' will become the associated
// <content-position> fallback value.
ContentAlignmentData contentAlignment = contentDistributionOffset(availableFreeSpace, position, distribution, numberOfGridTracks);

Powered by Google App Engine
This is Rietveld 408576698