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

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

Issue 1880393005: [css-grid] Fix alignment with content distribution (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 if (hasAutoMarginsInColumnAxis(child)) 1960 if (hasAutoMarginsInColumnAxis(child))
1961 return startPosition; 1961 return startPosition;
1962 GridAxisPosition axisPosition = columnAxisPositionForChild(child); 1962 GridAxisPosition axisPosition = columnAxisPositionForChild(child);
1963 switch (axisPosition) { 1963 switch (axisPosition) {
1964 case GridAxisStart: 1964 case GridAxisStart:
1965 return startPosition; 1965 return startPosition;
1966 case GridAxisEnd: 1966 case GridAxisEnd:
1967 case GridAxisCenter: { 1967 case GridAxisCenter: {
1968 size_t childEndLine = rowsSpan.endLine(); 1968 size_t childEndLine = rowsSpan.endLine();
1969 LayoutUnit endOfRow = m_rowPositions[childEndLine]; 1969 LayoutUnit endOfRow = m_rowPositions[childEndLine];
1970 // m_rowPositions include gutters so we need to subtract them to get the actual end position for a given 1970 // m_rowPositions include distribution offset (becuase of content alignm ent) and gutters
cbiesinger 2016/04/15 21:56:04 becuase -> because
1971 // row (this does not have to be done for the last track as there are no more m_rowPositions after it) 1971 // so we need to subtract them to get the actual end position for a give n row
1972 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
1972 LayoutUnit trackGap = guttersSize(ForRows, 2); 1973 LayoutUnit trackGap = guttersSize(ForRows, 2);
1973 if (childEndLine < m_rowPositions.size() - 1) 1974 if (childEndLine < m_rowPositions.size() - 1) {
1974 endOfRow -= trackGap; 1975 endOfRow -= trackGap;
1976 endOfRow -= m_offsetBetweenRows;
1977 }
1975 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); 1978 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght();
1976 // The track's start and end lines may be not adjacent because of conten t alignment, so we assume the stored
1977 // lines are all start plus a content-alignment distribution offset.
1978 // We must subtract last line's offset because is not part of the track the items belongs to.
1979 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s ize() - 1)
1980 endOfRow -= m_offsetBetweenRows;
1981 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); 1979 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow();
1982 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth); 1980 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth);
1983 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 1981 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
1984 } 1982 }
1985 } 1983 }
1986 1984
1987 ASSERT_NOT_REACHED(); 1985 ASSERT_NOT_REACHED();
1988 return LayoutUnit(); 1986 return LayoutUnit();
1989 } 1987 }
1990 1988
1991 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD ata& sizingData) const 1989 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD ata& sizingData) const
1992 { 1990 {
1993 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); 1991 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns);
1994 size_t childStartLine = columnsSpan.startLine(); 1992 size_t childStartLine = columnsSpan.startLine();
1995 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; 1993 LayoutUnit startOfColumn = m_columnPositions[childStartLine];
1996 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); 1994 LayoutUnit startPosition = startOfColumn + marginStartForChild(child);
1997 if (hasAutoMarginsInRowAxis(child)) 1995 if (hasAutoMarginsInRowAxis(child))
1998 return startPosition; 1996 return startPosition;
1999 GridAxisPosition axisPosition = rowAxisPositionForChild(child); 1997 GridAxisPosition axisPosition = rowAxisPositionForChild(child);
2000 switch (axisPosition) { 1998 switch (axisPosition) {
2001 case GridAxisStart: 1999 case GridAxisStart:
2002 return startPosition; 2000 return startPosition;
2003 case GridAxisEnd: 2001 case GridAxisEnd:
2004 case GridAxisCenter: { 2002 case GridAxisCenter: {
2005 size_t childEndLine = columnsSpan.endLine(); 2003 size_t childEndLine = columnsSpan.endLine();
2006 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; 2004 LayoutUnit endOfColumn = m_columnPositions[childEndLine];
2007 // m_columnPositions include gutters so we need to subtract them to get the actual end position for a given 2005 // m_columnPositions include distribution offset (becuase of content ali gnment) and gutters
cbiesinger 2016/04/15 21:56:03 same here
2008 // column (this does not have to be done for the last track as there are no more m_columnPositions after it) 2006 // so we need to subtract them to get the actual end position for a give n column
2007 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
2009 LayoutUnit trackGap = guttersSize(ForColumns, 2); 2008 LayoutUnit trackGap = guttersSize(ForColumns, 2);
2010 if (childEndLine < m_columnPositions.size() - 1) 2009 if (childEndLine < m_columnPositions.size() - 1) {
2011 endOfColumn -= trackGap; 2010 endOfColumn -= trackGap;
2011 endOfColumn -= m_offsetBetweenColumns;
2012 }
2012 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); 2013 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h();
2013 // The track's start and end lines may be not adjacent because of conten t alignment, so we assume the stored
2014 // lines are all start plus a content-alignment distribution offset.
2015 // We must subtract last line's offset because is not part of the track the items belongs to.
2016 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition s.size() - 1)
2017 endOfColumn -= m_offsetBetweenColumns;
2018 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); 2014 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth);
2019 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 2015 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
2020 } 2016 }
2021 } 2017 }
2022 2018
2023 ASSERT_NOT_REACHED(); 2019 ASSERT_NOT_REACHED();
2024 return LayoutUnit(); 2020 return LayoutUnit();
2025 } 2021 }
2026 2022
2027 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution) 2023 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution)
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 2134
2139 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); 2135 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData ));
2140 } 2136 }
2141 2137
2142 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2138 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2143 { 2139 {
2144 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2140 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2145 } 2141 }
2146 2142
2147 } // namespace blink 2143 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css-grid-layout/grid-content-alignment-and-self-alignment-spanning-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698