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

Side by Side Diff: Source/core/rendering/RenderGrid.cpp

Issue 438043002: [CSS Grid Layout] Support for justify-items property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst 1111 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst
1112 { 1112 {
1113 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1113 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1114 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; 1114 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1115 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; 1115 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()];
1116 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); 1116 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child);
1117 // FIXME: This should account for the grid item's <overflow-position>. 1117 // FIXME: This should account for the grid item's <overflow-position>.
1118 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; 1118 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2;
1119 } 1119 }
1120 1120
1121 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R enderStyle* childStyle)
1122 {
1123 ItemPosition justify = childStyle->justifySelf();
1124 if (justify == ItemPositionAuto)
1125 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi onStretch : parentStyle->justifyItems();
1126
1127 return justify;
1128 }
1129
1121 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const 1130 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const
1122 { 1131 {
1123 ItemPosition childJustifySelf = child->style()->justifySelf(); 1132 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHorizo ntalWritingMode();
1124 switch (childJustifySelf) { 1133 ItemPosition justifySelf = resolveJustification(style(), child->style());
1134
1135 switch (justifySelf) {
Julien - ping for review 2014/08/22 21:22:14 Unneeded variable: switch(resolveJustification(st
jfernandez 2014/08/26 11:23:13 Done.
1125 case ItemPositionSelfStart: 1136 case ItemPositionSelfStart:
1137 // If orthogonal writing-modes, this computes to 'Start'.
Julien - ping for review 2014/08/22 21:22:14 'start' (lowercase s) to match the specification.
jfernandez 2014/08/26 11:23:13 Done.
1138 // FIXME: grid track sizing and positioning does not support orthogonal modes yet.
Julien - ping for review 2014/08/22 21:22:14 grid track sizing and position *do* not support (i
jfernandez 2014/08/26 11:23:13 Done.
1139 if (hasOrthogonalWritingMode)
1140 return columnPositionAlignedWithGridContainerStart(child);
1141
1126 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. 1142 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction.
1127 if (child->style()->direction() != style()->direction()) 1143 if (child->style()->direction() != style()->direction())
1128 return columnPositionAlignedWithGridContainerEnd(child); 1144 return columnPositionAlignedWithGridContainerEnd(child);
1129 1145
1130 return columnPositionAlignedWithGridContainerStart(child); 1146 return columnPositionAlignedWithGridContainerStart(child);
1131 case ItemPositionSelfEnd: 1147 case ItemPositionSelfEnd:
1148 // If orthogonal writing-modes, this computes to 'Start'.
1149 // FIXME: grid track sizing and positioning does not support orthogonal modes yet.
Julien - ping for review 2014/08/22 21:22:14 Same comments.
jfernandez 2014/08/26 11:23:13 Done.
1150 if (hasOrthogonalWritingMode)
1151 return columnPositionAlignedWithGridContainerEnd(child);
1152
1132 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction. 1153 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction.
1133 if (child->style()->direction() != style()->direction()) 1154 if (child->style()->direction() != style()->direction())
1134 return columnPositionAlignedWithGridContainerStart(child); 1155 return columnPositionAlignedWithGridContainerStart(child);
1135 1156
1136 return columnPositionAlignedWithGridContainerEnd(child); 1157 return columnPositionAlignedWithGridContainerEnd(child);
1137 1158
1138 case ItemPositionFlexStart:
1139 case ItemPositionFlexEnd:
1140 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1141 return columnPositionAlignedWithGridContainerStart(child);
Julien - ping for review 2014/08/22 21:22:14 Unneeded change. We can agree / disagree over whic
jfernandez 2014/08/26 11:23:13 Acknowledged.
1142
1143 case ItemPositionLeft: 1159 case ItemPositionLeft:
1144 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. 1160 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1145 if (!isHorizontalWritingMode()) 1161 if (!isHorizontalWritingMode())
1146 return columnPositionAlignedWithGridContainerStart(child); 1162 return columnPositionAlignedWithGridContainerStart(child);
1147 1163
1148 if (style()->isLeftToRightDirection()) 1164 if (style()->isLeftToRightDirection())
1149 return columnPositionAlignedWithGridContainerStart(child); 1165 return columnPositionAlignedWithGridContainerStart(child);
1150 1166
1151 return columnPositionAlignedWithGridContainerEnd(child); 1167 return columnPositionAlignedWithGridContainerEnd(child);
1152 case ItemPositionRight: 1168 case ItemPositionRight:
1153 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. 1169 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1154 if (!isHorizontalWritingMode()) 1170 if (!isHorizontalWritingMode())
1155 return columnPositionAlignedWithGridContainerStart(child); 1171 return columnPositionAlignedWithGridContainerStart(child);
1156 1172
1157 if (style()->isLeftToRightDirection()) 1173 if (style()->isLeftToRightDirection())
1158 return columnPositionAlignedWithGridContainerEnd(child); 1174 return columnPositionAlignedWithGridContainerEnd(child);
1159 1175
1160 return columnPositionAlignedWithGridContainerStart(child); 1176 return columnPositionAlignedWithGridContainerStart(child);
1161 1177
1162 case ItemPositionCenter: 1178 case ItemPositionCenter:
1163 return centeredColumnPositionForChild(child); 1179 return centeredColumnPositionForChild(child);
1180 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1181 case ItemPositionFlexStart:
1164 case ItemPositionStart: 1182 case ItemPositionStart:
1165 return columnPositionAlignedWithGridContainerStart(child); 1183 return columnPositionAlignedWithGridContainerStart(child);
1184 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1185 case ItemPositionFlexEnd:
1166 case ItemPositionEnd: 1186 case ItemPositionEnd:
1167 return columnPositionAlignedWithGridContainerEnd(child); 1187 return columnPositionAlignedWithGridContainerEnd(child);
1168 1188
1169 case ItemPositionAuto: 1189 case ItemPositionAuto:
1190 break;
Julien - ping for review 2014/08/22 21:22:14 ASSERT_NOT_REACHED();
jfernandez 2014/08/26 11:23:13 There is such ASSERT at the end of the function, w
1170 case ItemPositionStretch: 1191 case ItemPositionStretch:
1171 case ItemPositionBaseline: 1192 case ItemPositionBaseline:
1172 case ItemPositionLastBaseline: 1193 case ItemPositionLastBaseline:
1173 // FIXME: Implement the previous values. For now, we always start align the child. 1194 // FIXME: Implement the previous values. For now, we always start align the child.
1174 return startOfColumnForChild(child); 1195 return startOfColumnForChild(child);
1175 } 1196 }
1176 1197
1177 ASSERT_NOT_REACHED(); 1198 ASSERT_NOT_REACHED();
1178 return 0; 1199 return 0;
1179 } 1200 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 if (isOutOfFlowPositioned()) 1399 if (isOutOfFlowPositioned())
1379 return "RenderGrid (positioned)"; 1400 return "RenderGrid (positioned)";
1380 if (isAnonymous()) 1401 if (isAnonymous())
1381 return "RenderGrid (generated)"; 1402 return "RenderGrid (generated)";
1382 if (isRelPositioned()) 1403 if (isRelPositioned())
1383 return "RenderGrid (relative positioned)"; 1404 return "RenderGrid (relative positioned)";
1384 return "RenderGrid"; 1405 return "RenderGrid";
1385 } 1406 }
1386 1407
1387 } // namespace blink 1408 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698