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

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: Applied suggested changes. Created 6 years, 3 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 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst 1156 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst
1157 { 1157 {
1158 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1158 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1159 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; 1159 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1160 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; 1160 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()];
1161 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); 1161 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child);
1162 // FIXME: This should account for the grid item's <overflow-position>. 1162 // FIXME: This should account for the grid item's <overflow-position>.
1163 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; 1163 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2;
1164 } 1164 }
1165 1165
1166 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R enderStyle* childStyle)
1167 {
1168 ItemPosition justify = childStyle->justifySelf();
1169 if (justify == ItemPositionAuto)
1170 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi onStretch : parentStyle->justifyItems();
1171
1172 return justify;
1173 }
1174
1166 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const 1175 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const
1167 { 1176 {
1168 ItemPosition childJustifySelf = child->style()->justifySelf(); 1177 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHorizo ntalWritingMode();
1169 switch (childJustifySelf) { 1178
1179 switch (resolveJustification(style(), child->style())) {
1170 case ItemPositionSelfStart: 1180 case ItemPositionSelfStart:
1181 // For orthogonal writing-modes, this computes to 'start'
1182 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1183 if (hasOrthogonalWritingMode)
1184 return columnPositionAlignedWithGridContainerStart(child);
1185
1171 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. 1186 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction.
1172 if (child->style()->direction() != style()->direction()) 1187 if (child->style()->direction() != style()->direction())
1173 return columnPositionAlignedWithGridContainerEnd(child); 1188 return columnPositionAlignedWithGridContainerEnd(child);
1174 1189
1175 return columnPositionAlignedWithGridContainerStart(child); 1190 return columnPositionAlignedWithGridContainerStart(child);
1176 case ItemPositionSelfEnd: 1191 case ItemPositionSelfEnd:
1192 // For orthogonal writing-modes, this computes to 'start'
1193 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1194 if (hasOrthogonalWritingMode)
1195 return columnPositionAlignedWithGridContainerEnd(child);
1196
1177 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction. 1197 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction.
1178 if (child->style()->direction() != style()->direction()) 1198 if (child->style()->direction() != style()->direction())
1179 return columnPositionAlignedWithGridContainerStart(child); 1199 return columnPositionAlignedWithGridContainerStart(child);
1180 1200
1181 return columnPositionAlignedWithGridContainerEnd(child); 1201 return columnPositionAlignedWithGridContainerEnd(child);
1182 1202
1183 case ItemPositionFlexStart: 1203 case ItemPositionFlexStart:
1204 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1205 return columnPositionAlignedWithGridContainerStart(child);
1184 case ItemPositionFlexEnd: 1206 case ItemPositionFlexEnd:
1185 // Only used in flex layout, for other layout, it's equivalent to 'start '. 1207 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1186 return columnPositionAlignedWithGridContainerStart(child); 1208 return columnPositionAlignedWithGridContainerEnd(child);
1187 1209
1188 case ItemPositionLeft: 1210 case ItemPositionLeft:
1189 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. 1211 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1190 if (!isHorizontalWritingMode()) 1212 if (!isHorizontalWritingMode())
1191 return columnPositionAlignedWithGridContainerStart(child); 1213 return columnPositionAlignedWithGridContainerStart(child);
1192 1214
1193 if (style()->isLeftToRightDirection()) 1215 if (style()->isLeftToRightDirection())
1194 return columnPositionAlignedWithGridContainerStart(child); 1216 return columnPositionAlignedWithGridContainerStart(child);
1195 1217
1196 return columnPositionAlignedWithGridContainerEnd(child); 1218 return columnPositionAlignedWithGridContainerEnd(child);
1197 case ItemPositionRight: 1219 case ItemPositionRight:
1198 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. 1220 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1199 if (!isHorizontalWritingMode()) 1221 if (!isHorizontalWritingMode())
1200 return columnPositionAlignedWithGridContainerStart(child); 1222 return columnPositionAlignedWithGridContainerStart(child);
1201 1223
1202 if (style()->isLeftToRightDirection()) 1224 if (style()->isLeftToRightDirection())
1203 return columnPositionAlignedWithGridContainerEnd(child); 1225 return columnPositionAlignedWithGridContainerEnd(child);
1204 1226
1205 return columnPositionAlignedWithGridContainerStart(child); 1227 return columnPositionAlignedWithGridContainerStart(child);
1206 1228
1207 case ItemPositionCenter: 1229 case ItemPositionCenter:
1208 return centeredColumnPositionForChild(child); 1230 return centeredColumnPositionForChild(child);
1209 case ItemPositionStart: 1231 case ItemPositionStart:
1210 return columnPositionAlignedWithGridContainerStart(child); 1232 return columnPositionAlignedWithGridContainerStart(child);
1211 case ItemPositionEnd: 1233 case ItemPositionEnd:
1212 return columnPositionAlignedWithGridContainerEnd(child); 1234 return columnPositionAlignedWithGridContainerEnd(child);
1213 1235
1214 case ItemPositionAuto: 1236 case ItemPositionAuto:
1237 break;
1215 case ItemPositionStretch: 1238 case ItemPositionStretch:
1216 case ItemPositionBaseline: 1239 case ItemPositionBaseline:
1217 case ItemPositionLastBaseline: 1240 case ItemPositionLastBaseline:
1218 // FIXME: Implement the previous values. For now, we always start align the child. 1241 // FIXME: Implement the previous values. For now, we always start align the child.
1219 return startOfColumnForChild(child); 1242 return startOfColumnForChild(child);
1220 } 1243 }
1221 1244
1222 ASSERT_NOT_REACHED(); 1245 ASSERT_NOT_REACHED();
1223 return 0; 1246 return 0;
1224 } 1247 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 if (isOutOfFlowPositioned()) 1446 if (isOutOfFlowPositioned())
1424 return "RenderGrid (positioned)"; 1447 return "RenderGrid (positioned)";
1425 if (isAnonymous()) 1448 if (isAnonymous())
1426 return "RenderGrid (generated)"; 1449 return "RenderGrid (generated)";
1427 if (isRelPositioned()) 1450 if (isRelPositioned())
1428 return "RenderGrid (relative positioned)"; 1451 return "RenderGrid (relative positioned)";
1429 return "RenderGrid"; 1452 return "RenderGrid";
1430 } 1453 }
1431 1454
1432 } // namespace blink 1455 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698