Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 | 1099 |
| 1100 return endOfColumnForChild(child); | 1100 return endOfColumnForChild(child); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst | 1103 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst |
| 1104 { | 1104 { |
| 1105 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1105 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1106 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; | 1106 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; |
| 1107 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; | 1107 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; |
| 1108 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | 1108 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1109 // FIXME: This should account for the grid item's <overflow-position>. | |
| 1109 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; | 1110 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; |
| 1110 } | 1111 } |
| 1111 | 1112 |
| 1112 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const | 1113 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const |
| 1113 { | 1114 { |
| 1114 ItemPosition childJustifySelf = child->style()->justifySelf(); | 1115 ItemPosition childJustifySelf = child->style()->justifySelf(); |
| 1115 switch (childJustifySelf) { | 1116 switch (childJustifySelf) { |
| 1116 case ItemPositionSelfStart: | 1117 case ItemPositionSelfStart: |
| 1117 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. | 1118 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. |
| 1118 if (child->style()->direction() != style()->direction()) | 1119 if (child->style()->direction() != style()->direction()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 case ItemPositionStretch: | 1162 case ItemPositionStretch: |
| 1162 case ItemPositionBaseline: | 1163 case ItemPositionBaseline: |
| 1163 // FIXME: Implement the previous values. For now, we always start align the child. | 1164 // FIXME: Implement the previous values. For now, we always start align the child. |
| 1164 return startOfColumnForChild(child); | 1165 return startOfColumnForChild(child); |
| 1165 } | 1166 } |
| 1166 | 1167 |
| 1167 ASSERT_NOT_REACHED(); | 1168 ASSERT_NOT_REACHED(); |
| 1168 return 0; | 1169 return 0; |
| 1169 } | 1170 } |
| 1170 | 1171 |
| 1172 LayoutUnit RenderGrid::endOfRowForChild(const RenderBox* child) const | |
| 1173 { | |
| 1174 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
| 1175 | |
| 1176 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; | |
| 1177 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | |
| 1178 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | |
| 1179 | |
| 1180 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; | |
| 1181 // FIXME: This should account for the grid item's <overflow-position>. | |
| 1182 return rowPosition + std::max<LayoutUnit>(0, endOfRow - startOfRow - child-> logicalHeight()); | |
| 1183 } | |
| 1184 | |
| 1185 LayoutUnit RenderGrid::startOfRowForChild(const RenderBox* child) const | |
| 1186 { | |
| 1187 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
| 1188 | |
| 1189 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; | |
| 1190 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | |
| 1191 // FIXME: This should account for the grid item's <overflow-position>. | |
| 1192 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | |
| 1193 | |
| 1194 return rowPosition; | |
| 1195 } | |
| 1196 | |
| 1197 LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox* child) const | |
| 1198 { | |
| 1199 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
| 1200 | |
| 1201 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | |
| 1202 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()] + marginBeforeForChild(child); | |
| 1203 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; | |
| 1204 | |
| 1205 // FIXME: This should account for the grid item's <overflow-position>. | |
| 1206 return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child->l ogicalHeight()) / 2; | |
| 1207 } | |
| 1208 | |
| 1209 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende rStyle* childStyle) | |
| 1210 { | |
| 1211 ItemPosition align = childStyle->alignSelf(); | |
| 1212 // The auto keyword computes to the computed value of align-items on the par ent. | |
| 1213 if (align == ItemPositionAuto) | |
| 1214 align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionSt retch : parentStyle->alignItems(); | |
| 1215 return align; | |
| 1216 } | |
|
Julien - ping for review
2014/07/10 22:59:59
I assume this code is temporary as we talked about
jfernandez
2014/07/12 22:29:48
Yes, still have to reach an agreement on issue 363
| |
| 1217 | |
| 1171 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const | 1218 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| 1172 { | 1219 { |
| 1173 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1220 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHorizo ntalWritingMode(); |
| 1221 ItemPosition alignSelf = resolveAlignment(style(), child->style()); | |
| 1174 | 1222 |
| 1175 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1223 switch (alignSelf) { |
| 1176 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; | 1224 case ItemPositionSelfStart: |
| 1177 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | 1225 // If orthogonal writing-modes, this computes to 'Start'. |
| 1226 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | |
| 1227 if (hasOrthogonalWritingMode) | |
| 1228 return startOfRowForChild(child); | |
| 1178 | 1229 |
| 1179 // FIXME: This function should account for 'align-self'. | 1230 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. |
|
Julien - ping for review
2014/07/10 22:59:59
s/direction/block axis direction/
direction has a
jfernandez
2014/07/12 22:29:48
Done.
| |
| 1231 if (child->style()->writingMode() != style()->writingMode()) | |
| 1232 return endOfRowForChild(child); | |
| 1180 | 1233 |
| 1181 return rowPosition; | 1234 return startOfRowForChild(child); |
| 1235 case ItemPositionSelfEnd: | |
| 1236 // If orthogonal writing-modes, this computes to 'End'. | |
| 1237 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | |
| 1238 if (hasOrthogonalWritingMode) | |
| 1239 return endOfRowForChild(child); | |
| 1240 | |
| 1241 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction. | |
|
Julien - ping for review
2014/07/10 22:59:59
Same comment.
jfernandez
2014/07/12 22:29:48
Done.
| |
| 1242 if (child->style()->writingMode() != style()->writingMode()) | |
| 1243 return startOfRowForChild(child); | |
| 1244 | |
| 1245 return endOfRowForChild(child); | |
| 1246 | |
| 1247 case ItemPositionLeft: | |
| 1248 // orthogonal modes make property and inline axes to be parallel, but in any case | |
| 1249 // this is always equivalent to 'Start'. | |
| 1250 // | |
| 1251 // self-align's axis is never parallel to the inline axis, except in ort hogonal | |
| 1252 // writing-mode, so this is equivalent to 'Start’. | |
| 1253 return startOfRowForChild(child); | |
| 1254 | |
| 1255 case ItemPositionRight: | |
| 1256 // orthogonal modes make property and inline axes to be parallel. | |
| 1257 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | |
| 1258 if (hasOrthogonalWritingMode) | |
| 1259 return endOfRowForChild(child); | |
| 1260 | |
| 1261 // self-align's axis is never parallel to the inline axis, except in ort hogonal | |
| 1262 // writing-mode, so this is equivalent to 'Start'. | |
| 1263 return startOfRowForChild(child); | |
| 1264 | |
| 1265 case ItemPositionCenter: | |
| 1266 return centeredRowPositionForChild(child); | |
| 1267 // Only used in flex layout, for other layout, it's equivalent to 'Start '. | |
| 1268 case ItemPositionFlexStart: | |
| 1269 case ItemPositionStart: | |
| 1270 return startOfRowForChild(child); | |
| 1271 // Only used in flex layout, for other layout, it's equivalent to 'End'. | |
| 1272 case ItemPositionFlexEnd: | |
| 1273 case ItemPositionEnd: | |
| 1274 return endOfRowForChild(child); | |
| 1275 case ItemPositionStretch: | |
| 1276 // FIXME: Implement the Stretch value. For now, we always start align th e child. | |
| 1277 return startOfRowForChild(child); | |
| 1278 case ItemPositionBaseline: | |
| 1279 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. | |
| 1280 return startOfRowForChild(child); | |
| 1281 case ItemPositionAuto: | |
| 1282 break; | |
| 1283 } | |
| 1284 | |
| 1285 ASSERT_NOT_REACHED(); | |
| 1286 return 0; | |
| 1182 } | 1287 } |
| 1183 | 1288 |
| 1184 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const | 1289 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const |
| 1185 { | 1290 { |
| 1186 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child) ); | 1291 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child) ); |
| 1187 } | 1292 } |
| 1188 | 1293 |
| 1189 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) | 1294 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) |
| 1190 { | 1295 { |
| 1191 // This function does a binary search over the coordinates. | 1296 // This function does a binary search over the coordinates. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 if (isOutOfFlowPositioned()) | 1367 if (isOutOfFlowPositioned()) |
| 1263 return "RenderGrid (positioned)"; | 1368 return "RenderGrid (positioned)"; |
| 1264 if (isAnonymous()) | 1369 if (isAnonymous()) |
| 1265 return "RenderGrid (generated)"; | 1370 return "RenderGrid (generated)"; |
| 1266 if (isRelPositioned()) | 1371 if (isRelPositioned()) |
| 1267 return "RenderGrid (relative positioned)"; | 1372 return "RenderGrid (relative positioned)"; |
| 1268 return "RenderGrid"; | 1373 return "RenderGrid"; |
| 1269 } | 1374 } |
| 1270 | 1375 |
| 1271 } // namespace WebCore | 1376 } // namespace WebCore |
| OLD | NEW |