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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 1583433002: [css-align] New CSS Value 'normal' for Content Alignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed layout tests failing. Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 // the grid and its children are correctly laid out according to the new sty le rules. 1356 // the grid and its children are correctly laid out according to the new sty le rules.
1357 setNeedsLayout(LayoutInvalidationReason::GridChanged); 1357 setNeedsLayout(LayoutInvalidationReason::GridChanged);
1358 1358
1359 m_grid.resize(0); 1359 m_grid.resize(0);
1360 m_gridItemArea.clear(); 1360 m_gridItemArea.clear();
1361 m_gridItemsOverflowingGridArea.resize(0); 1361 m_gridItemsOverflowingGridArea.resize(0);
1362 m_gridItemsIndexesMap.clear(); 1362 m_gridItemsIndexesMap.clear();
1363 m_gridIsDirty = true; 1363 m_gridIsDirty = true;
1364 } 1364 }
1365 1365
1366 static const StyleContentAlignmentData& normalValueBehavior()
1367 {
1368 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch};
1369 return normalBehavior;
1370 }
1371
1366 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) 1372 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData)
1367 { 1373 {
1368 LayoutUnit& availableSpace = sizingData.freeSpaceForDirection(direction); 1374 LayoutUnit& availableSpace = sizingData.freeSpaceForDirection(direction);
1369 if (availableSpace <= 0 1375 if (availableSpace <= 0
1370 || (direction == ForColumns && styleRef().justifyContentDistribution() ! = ContentDistributionStretch) 1376 || (direction == ForColumns && styleRef().resolvedJustifyContentDistribu tion(normalValueBehavior()) != ContentDistributionStretch)
1371 || (direction == ForRows && styleRef().alignContentDistribution() != Con tentDistributionStretch)) 1377 || (direction == ForRows && styleRef().resolvedAlignContentDistribution( normalValueBehavior()) != ContentDistributionStretch))
1372 return; 1378 return;
1373 1379
1374 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion. 1380 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion.
1375 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 1381 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
1376 Vector<unsigned> autoSizedTracksIndex; 1382 Vector<unsigned> autoSizedTracksIndex;
1377 for (unsigned i = 0; i < tracks.size(); ++i) { 1383 for (unsigned i = 0; i < tracks.size(); ++i) {
1378 const GridTrackSize& trackSize = gridTrackSize(direction, i); 1384 const GridTrackSize& trackSize = gridTrackSize(direction, i);
1379 if (trackSize.hasAutoMaxTrackBreadth()) 1385 if (trackSize.hasAutoMaxTrackBreadth())
1380 autoSizedTracksIndex.append(i); 1386 autoSizedTracksIndex.append(i);
1381 } 1387 }
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 case GridAxisEnd: 1905 case GridAxisEnd:
1900 case GridAxisCenter: { 1906 case GridAxisCenter: {
1901 size_t childEndLine = rowsSpan.resolvedFinalPosition(); 1907 size_t childEndLine = rowsSpan.resolvedFinalPosition();
1902 LayoutUnit endOfRow = m_rowPositions[childEndLine]; 1908 LayoutUnit endOfRow = m_rowPositions[childEndLine];
1903 // m_rowPositions include gutters so we need to subtract them to get the actual end position for a given 1909 // m_rowPositions include gutters so we need to subtract them to get the actual end position for a given
1904 // row (this does not have to be done for the last track as there are no more m_rowPositions after it) 1910 // row (this does not have to be done for the last track as there are no more m_rowPositions after it)
1905 if (childEndLine < m_rowPositions.size() - 1) 1911 if (childEndLine < m_rowPositions.size() - 1)
1906 endOfRow -= guttersSize(ForRows, 2); 1912 endOfRow -= guttersSize(ForRows, 2);
1907 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); 1913 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght();
1908 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s ize() - 1) 1914 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s ize() - 1)
1909 endOfRow -= offsetBetweenTracks(styleRef().alignContentDistribution( ), m_rowPositions, childBreadth); 1915 endOfRow -= offsetBetweenTracks(styleRef().resolvedAlignContentDistr ibution(normalValueBehavior()), m_rowPositions, childBreadth);
1910 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); 1916 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow();
1911 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth); 1917 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth);
1912 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 1918 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
1913 } 1919 }
1914 } 1920 }
1915 1921
1916 ASSERT_NOT_REACHED(); 1922 ASSERT_NOT_REACHED();
1917 return LayoutUnit(); 1923 return LayoutUnit();
1918 } 1924 }
1919 1925
(...skipping 12 matching lines...) Expand all
1932 case GridAxisEnd: 1938 case GridAxisEnd:
1933 case GridAxisCenter: { 1939 case GridAxisCenter: {
1934 size_t childEndLine = columnsSpan.resolvedFinalPosition(); 1940 size_t childEndLine = columnsSpan.resolvedFinalPosition();
1935 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; 1941 LayoutUnit endOfColumn = m_columnPositions[childEndLine];
1936 // m_columnPositions include gutters so we need to subtract them to get the actual end position for a given 1942 // m_columnPositions include gutters so we need to subtract them to get the actual end position for a given
1937 // column (this does not have to be done for the last track as there are no more m_columnPositions after it) 1943 // column (this does not have to be done for the last track as there are no more m_columnPositions after it)
1938 if (childEndLine < m_columnPositions.size() - 1) 1944 if (childEndLine < m_columnPositions.size() - 1)
1939 endOfColumn -= guttersSize(ForRows, 2); 1945 endOfColumn -= guttersSize(ForRows, 2);
1940 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); 1946 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h();
1941 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition s.size() - 1) 1947 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition s.size() - 1)
1942 endOfColumn -= offsetBetweenTracks(styleRef().justifyContentDistribu tion(), m_columnPositions, childBreadth); 1948 endOfColumn -= offsetBetweenTracks(styleRef().resolvedJustifyContent Distribution(normalValueBehavior()), m_columnPositions, childBreadth);
1943 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); 1949 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth);
1944 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 1950 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
1945 } 1951 }
1946 } 1952 }
1947 1953
1948 ASSERT_NOT_REACHED(); 1954 ASSERT_NOT_REACHED();
1949 return LayoutUnit(); 1955 return LayoutUnit();
1950 } 1956 }
1951 1957
1952 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution) 1958 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution)
1953 { 1959 {
1954 switch (distribution) { 1960 switch (distribution) {
1955 case ContentDistributionSpaceBetween: 1961 case ContentDistributionSpaceBetween:
1956 return ContentPositionStart; 1962 return ContentPositionStart;
1957 case ContentDistributionSpaceAround: 1963 case ContentDistributionSpaceAround:
1958 return ContentPositionCenter; 1964 return ContentPositionCenter;
1959 case ContentDistributionSpaceEvenly: 1965 case ContentDistributionSpaceEvenly:
1960 return ContentPositionCenter; 1966 return ContentPositionCenter;
1961 case ContentDistributionStretch: 1967 case ContentDistributionStretch:
1962 return ContentPositionStart; 1968 return ContentPositionStart;
1963 case ContentDistributionDefault: 1969 case ContentDistributionDefault:
1964 return ContentPositionAuto; 1970 return ContentPositionNormal;
1965 } 1971 }
1966 1972
1967 ASSERT_NOT_REACHED(); 1973 ASSERT_NOT_REACHED();
1968 return ContentPositionAuto; 1974 return ContentPositionNormal;
1969 } 1975 }
1970 1976
1971 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa bleSpace)
1972 {
1973 return isLeftToRight ? LayoutUnit() : availableSpace;
1974 }
1975
1976 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl eSpace)
1977 {
1978 return !isLeftToRight ? LayoutUnit() : availableSpace;
1979 }
1980
1981
1982 static ContentAlignmentData contentDistributionOffset(const LayoutUnit& availabl eFreeSpace, ContentPosition& fallbackPosition, ContentDistributionType distribut ion, unsigned numberOfGridTracks) 1977 static ContentAlignmentData contentDistributionOffset(const LayoutUnit& availabl eFreeSpace, ContentPosition& fallbackPosition, ContentDistributionType distribut ion, unsigned numberOfGridTracks)
1983 { 1978 {
1984 if (distribution != ContentDistributionDefault && fallbackPosition == Conten tPositionAuto) 1979 if (distribution != ContentDistributionDefault && fallbackPosition == Conten tPositionNormal)
1985 fallbackPosition = resolveContentDistributionFallback(distribution); 1980 fallbackPosition = resolveContentDistributionFallback(distribution);
1986 1981
1987 if (availableFreeSpace <= 0) 1982 if (availableFreeSpace <= 0)
1988 return {}; 1983 return {};
1989 1984
1990 LayoutUnit distributionOffset; 1985 LayoutUnit distributionOffset;
1991 switch (distribution) { 1986 switch (distribution) {
1992 case ContentDistributionSpaceBetween: 1987 case ContentDistributionSpaceBetween:
1993 if (numberOfGridTracks < 2) 1988 if (numberOfGridTracks < 2)
1994 return {}; 1989 return {};
1995 return {LayoutUnit(), availableFreeSpace / (numberOfGridTracks - 1)}; 1990 return {LayoutUnit(), availableFreeSpace / (numberOfGridTracks - 1)};
1996 case ContentDistributionSpaceAround: 1991 case ContentDistributionSpaceAround:
1997 if (numberOfGridTracks < 1) 1992 if (numberOfGridTracks < 1)
1998 return {}; 1993 return {};
1999 distributionOffset = availableFreeSpace / numberOfGridTracks; 1994 distributionOffset = availableFreeSpace / numberOfGridTracks;
2000 return {distributionOffset / 2, distributionOffset}; 1995 return {distributionOffset / 2, distributionOffset};
2001 case ContentDistributionSpaceEvenly: 1996 case ContentDistributionSpaceEvenly:
2002 distributionOffset = availableFreeSpace / (numberOfGridTracks + 1); 1997 distributionOffset = availableFreeSpace / (numberOfGridTracks + 1);
2003 return {distributionOffset, distributionOffset}; 1998 return {distributionOffset, distributionOffset};
2004 case ContentDistributionStretch: 1999 case ContentDistributionStretch:
2005 return {LayoutUnit(), LayoutUnit()};
2006 case ContentDistributionDefault: 2000 case ContentDistributionDefault:
2007 return {}; 2001 return {};
2008 } 2002 }
2009 2003
2010 ASSERT_NOT_REACHED(); 2004 ASSERT_NOT_REACHED();
2011 return {}; 2005 return {};
2012 } 2006 }
2013 2007
2014 ContentAlignmentData LayoutGrid::computeContentPositionAndDistributionOffset(Gri dTrackSizingDirection direction, const LayoutUnit& availableFreeSpace, unsigned numberOfGridTracks) const 2008 ContentAlignmentData LayoutGrid::computeContentPositionAndDistributionOffset(Gri dTrackSizingDirection direction, const LayoutUnit& availableFreeSpace, unsigned numberOfGridTracks) const
2015 { 2009 {
2016 bool isRowAxis = direction == ForColumns; 2010 bool isRowAxis = direction == ForColumns;
2017 ContentPosition position = isRowAxis ? styleRef().justifyContentPosition() : styleRef().alignContentPosition(); 2011 ContentPosition position = isRowAxis ? styleRef().resolvedJustifyContentPosi tion(normalValueBehavior()) : styleRef().resolvedAlignContentPosition(normalValu eBehavior());
2018 ContentDistributionType distribution = isRowAxis ? styleRef().justifyContent Distribution() : styleRef().alignContentDistribution(); 2012 ContentDistributionType distribution = isRowAxis ? styleRef().resolvedJustif yContentDistribution(normalValueBehavior()) : styleRef().resolvedAlignContentDis tribution(normalValueBehavior());
2019 // If <content-distribution> value can't be applied, 'position' will become the associated 2013 // If <content-distribution> value can't be applied, 'position' will become the associated
2020 // <content-position> fallback value. 2014 // <content-position> fallback value.
2021 ContentAlignmentData contentAlignment = contentDistributionOffset(availableF reeSpace, position, distribution, numberOfGridTracks); 2015 ContentAlignmentData contentAlignment = contentDistributionOffset(availableF reeSpace, position, distribution, numberOfGridTracks);
2022 if (contentAlignment.isValid()) 2016 if (contentAlignment.isValid())
2023 return contentAlignment; 2017 return contentAlignment;
2024 2018
2025 OverflowAlignment overflow = isRowAxis ? styleRef().justifyContentOverflowAl ignment() : styleRef().alignContentOverflowAlignment(); 2019 OverflowAlignment overflow = isRowAxis ? styleRef().justifyContentOverflowAl ignment() : styleRef().alignContentOverflowAlignment();
2026 if (availableFreeSpace <= 0 && overflow == OverflowAlignmentSafe) 2020 if (availableFreeSpace <= 0 && overflow == OverflowAlignmentSafe)
2027 return {LayoutUnit(), LayoutUnit()}; 2021 return {LayoutUnit(), LayoutUnit()};
2028 2022
2029 switch (position) { 2023 switch (position) {
2030 case ContentPositionLeft: 2024 case ContentPositionLeft:
2031 // The align-content's axis is always orthogonal to the inline-axis. 2025 // The align-content's axis is always orthogonal to the inline-axis.
2032 return {LayoutUnit(), LayoutUnit()}; 2026 return {LayoutUnit(), LayoutUnit()};
2033 case ContentPositionRight: 2027 case ContentPositionRight:
2034 if (isRowAxis) 2028 if (isRowAxis)
2035 return {availableFreeSpace, LayoutUnit()}; 2029 return {availableFreeSpace, LayoutUnit()};
2036 // The align-content's axis is always orthogonal to the inline-axis. 2030 // The align-content's axis is always orthogonal to the inline-axis.
2037 return {LayoutUnit(), LayoutUnit()}; 2031 return {LayoutUnit(), LayoutUnit()};
2038 case ContentPositionCenter: 2032 case ContentPositionCenter:
2039 return {availableFreeSpace / 2, LayoutUnit()}; 2033 return {availableFreeSpace / 2, LayoutUnit()};
2040 case ContentPositionFlexEnd: // Only used in flex layout, for other layout, it's equivalent to 'End'. 2034 case ContentPositionFlexEnd: // Only used in flex layout, for other layout, it's equivalent to 'End'.
2041 case ContentPositionEnd: 2035 case ContentPositionEnd:
2042 if (isRowAxis) 2036 if (isRowAxis)
2043 return {offsetToEndEdge(styleRef().isLeftToRightDirection(), availab leFreeSpace), LayoutUnit()}; 2037 return {styleRef().isLeftToRightDirection() ? availableFreeSpace : L ayoutUnit(), LayoutUnit()};
2044 return {availableFreeSpace, LayoutUnit()}; 2038 return {availableFreeSpace, LayoutUnit()};
2045 case ContentPositionFlexStart: // Only used in flex layout, for other layout , it's equivalent to 'Start'. 2039 case ContentPositionFlexStart: // Only used in flex layout, for other layout , it's equivalent to 'Start'.
2046 case ContentPositionStart: 2040 case ContentPositionStart:
2047 if (isRowAxis) 2041 if (isRowAxis)
2048 return {offsetToStartEdge(styleRef().isLeftToRightDirection(), avail ableFreeSpace), LayoutUnit()}; 2042 return {styleRef().isLeftToRightDirection() ? LayoutUnit() : availab leFreeSpace, LayoutUnit()};
2049 return {LayoutUnit(), LayoutUnit()}; 2043 return {LayoutUnit(), LayoutUnit()};
2050 case ContentPositionBaseline: 2044 case ContentPositionBaseline:
2051 case ContentPositionLastBaseline: 2045 case ContentPositionLastBaseline:
2052 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. 2046 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child.
2053 // crbug.com/234191 2047 // crbug.com/234191
2054 if (isRowAxis) 2048 if (isRowAxis)
2055 return {offsetToStartEdge(styleRef().isLeftToRightDirection(), avail ableFreeSpace), LayoutUnit()}; 2049 return {styleRef().isLeftToRightDirection() ? LayoutUnit() : availab leFreeSpace, LayoutUnit()};
2056 return {LayoutUnit(), LayoutUnit()}; 2050 return {LayoutUnit(), LayoutUnit()};
2057 case ContentPositionAuto: 2051 case ContentPositionNormal:
2058 break; 2052 break;
2059 } 2053 }
2060 2054
2061 ASSERT_NOT_REACHED(); 2055 ASSERT_NOT_REACHED();
2062 return {LayoutUnit(), LayoutUnit()}; 2056 return {LayoutUnit(), LayoutUnit()};
2063 } 2057 }
2064 2058
2065 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const 2059 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const
2066 { 2060 {
2067 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child); 2061 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child);
2068 // We stored m_columnPosition s's data ignoring the direction, hence we migh t need now 2062 // We stored m_columnPosition s's data ignoring the direction, hence we migh t need now
2069 // to translate positions from RTL to LTR, as it's more convenient for paint ing. 2063 // to translate positions from RTL to LTR, as it's more convenient for paint ing.
2070 if (!style()->isLeftToRightDirection()) { 2064 if (!style()->isLeftToRightDirection()) {
2071 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); 2065 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt();
2072 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); 2066 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft();
2073 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); 2067 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth());
2074 } 2068 }
2075 2069
2076 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); 2070 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child));
2077 } 2071 }
2078 2072
2079 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2073 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2080 { 2074 {
2081 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2075 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2082 } 2076 }
2083 2077
2084 } // namespace blink 2078 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.cpp ('k') | third_party/WebKit/Source/core/style/ComputedStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698