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 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1164 m_rowPositions[0] = borderAndPaddingBefore(); | 1164 m_rowPositions[0] = borderAndPaddingBefore(); |
1165 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1165 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) |
1166 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth; | 1166 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth; |
1167 } | 1167 } |
1168 | 1168 |
1169 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox& child) const | 1169 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox& child) const |
1170 { | 1170 { |
1171 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1171 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1172 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; | 1172 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; |
1173 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1173 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1174 // FIXME: This should account for the grid item's <overflow-position>. | |
1175 return startOfColumn + marginStartForChild(&child); | 1174 return startOfColumn + marginStartForChild(&child); |
1176 } | 1175 } |
1177 | 1176 |
1178 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox& child) const | 1177 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox& child) const |
1179 { | 1178 { |
1179 OverflowAlignment overflow = child.style()->justifySelfOverflowAlignment(); | |
1180 ASSERT(overflow == OverflowAlignmentDefault); | |
Julien - ping for review
2014/10/23 00:57:25
I don't think this is the ASSERT you were thinking
jfernandez
2014/10/23 18:09:02
Done.
| |
1181 | |
1180 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1182 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1181 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; | 1183 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; |
1182 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1184 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1183 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); | 1185 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); |
1184 | 1186 |
1185 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; | 1187 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; |
1186 // FIXME: This should account for the grid item's <overflow-position>. | 1188 LayoutUnit childLogicalWidth = child.logicalWidth(); |
1187 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositi ons[coordinate.columns.resolvedInitialPosition.toInt()] - child.logicalWidth()); | 1189 LayoutUnit columnWidth = endOfColumn - startOfColumn; |
1190 // It overflows through the alignment container's 'start' edge (may cause da ta loss). | |
Julien - ping for review
2014/10/23 00:57:25
I think we could improve this comment as I had a h
jfernandez
2014/10/23 18:09:03
Acknowledged.
| |
1191 if (childLogicalWidth > columnWidth && overflow == OverflowAlignmentTrue) | |
1192 return columnPosition + columnWidth - childLogicalWidth; | |
1193 return columnPosition + std::max<LayoutUnit>(0, columnWidth - childLogicalWi dth); | |
Julien - ping for review
2014/10/23 00:57:25
I think it would be a lot more readable with the f
jfernandez
2014/10/23 18:09:03
Done.
| |
1188 } | 1194 } |
1189 | 1195 |
1190 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB ox& child) const | 1196 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB ox& child) const |
1191 { | 1197 { |
1192 if (style()->isLeftToRightDirection()) | 1198 if (style()->isLeftToRightDirection()) |
1193 return startOfColumnForChild(child); | 1199 return startOfColumnForChild(child); |
1194 | 1200 |
1195 return endOfColumnForChild(child); | 1201 return endOfColumnForChild(child); |
1196 } | 1202 } |
1197 | 1203 |
1198 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox & child) const | 1204 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox & child) const |
1199 { | 1205 { |
1200 if (!style()->isLeftToRightDirection()) | 1206 if (!style()->isLeftToRightDirection()) |
1201 return startOfColumnForChild(child); | 1207 return startOfColumnForChild(child); |
1202 | 1208 |
1203 return endOfColumnForChild(child); | 1209 return endOfColumnForChild(child); |
1204 } | 1210 } |
1205 | 1211 |
1206 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox& child) co nst | 1212 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox& child) co nst |
1207 { | 1213 { |
1214 OverflowAlignment overflow = child.style()->justifySelfOverflowAlignment(); | |
1215 ASSERT(overflow == OverflowAlignmentDefault); | |
Julien - ping for review
2014/10/23 00:57:25
Same comment about the ASSERT.
jfernandez
2014/10/23 18:09:02
Done.
| |
1216 | |
1208 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1217 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1209 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; | 1218 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()]; |
1210 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; | 1219 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()]; |
1211 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); | 1220 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); |
1212 // FIXME: This should account for the grid item's <overflow-position>. | 1221 LayoutUnit childLogicalWidth = child.logicalWidth(); |
1213 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child.logicalWidth()) / 2; | 1222 LayoutUnit columnWidth = endOfColumn - startOfColumn; |
1223 // It overflows through both alignment container's 'start' and 'end' edges ( may cause data loss). | |
1224 if (childLogicalWidth > columnWidth && overflow == OverflowAlignmentTrue) | |
1225 return columnPosition + (columnWidth - childLogicalWidth) / 2; | |
1226 return columnPosition + std::max<LayoutUnit>(0, columnWidth - childLogicalWi dth) / 2; | |
Julien - ping for review
2014/10/23 00:57:25
Same general comments.
jfernandez
2014/10/23 18:09:03
Done.
| |
1214 } | 1227 } |
1215 | 1228 |
1216 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R enderStyle* childStyle) | 1229 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R enderStyle* childStyle) |
1217 { | 1230 { |
1218 ItemPosition justify = childStyle->justifySelf(); | 1231 ItemPosition justify = childStyle->justifySelf(); |
1219 if (justify == ItemPositionAuto) | 1232 if (justify == ItemPositionAuto) |
1220 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi onStretch : parentStyle->justifyItems(); | 1233 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi onStretch : parentStyle->justifyItems(); |
1221 | |
1222 return justify; | 1234 return justify; |
1223 } | 1235 } |
1224 | 1236 |
1225 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const | 1237 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const |
1226 { | 1238 { |
1227 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1239 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
1228 | 1240 |
1229 switch (resolveJustification(style(), child.style())) { | 1241 switch (resolveJustification(style(), child.style())) { |
1230 case ItemPositionSelfStart: | 1242 case ItemPositionSelfStart: |
1231 // For orthogonal writing-modes, this computes to 'start' | 1243 // For orthogonal writing-modes, this computes to 'start' |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 // FIXME: Implement the previous values. For now, we always start align the child. | 1303 // FIXME: Implement the previous values. For now, we always start align the child. |
1292 return startOfColumnForChild(child); | 1304 return startOfColumnForChild(child); |
1293 } | 1305 } |
1294 | 1306 |
1295 ASSERT_NOT_REACHED(); | 1307 ASSERT_NOT_REACHED(); |
1296 return 0; | 1308 return 0; |
1297 } | 1309 } |
1298 | 1310 |
1299 LayoutUnit RenderGrid::endOfRowForChild(const RenderBox& child) const | 1311 LayoutUnit RenderGrid::endOfRowForChild(const RenderBox& child) const |
1300 { | 1312 { |
1313 OverflowAlignment overflow = child.style()->alignSelfOverflowAlignment(); | |
1314 ASSERT(overflow == OverflowAlignmentDefault); | |
Julien - ping for review
2014/10/23 00:57:25
Ditto.
jfernandez
2014/10/23 18:09:02
Done.
| |
1301 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1315 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1302 | 1316 |
1303 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; | 1317 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; |
1304 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1318 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1305 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); | 1319 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1306 | 1320 |
1307 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; | 1321 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; |
1308 // FIXME: This should account for the grid item's <overflow-position>. | 1322 LayoutUnit childLogicalHeight = child.logicalHeight(); |
1309 return rowPosition + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.l ogicalHeight()); | 1323 LayoutUnit rowHeight = endOfRow - startOfRow; |
1324 // It overflows through the alignment container's 'end' edge (may cause data loss). | |
1325 if (childLogicalHeight > rowHeight && overflow == OverflowAlignmentTrue) | |
1326 return rowPosition + rowHeight - childLogicalHeight; | |
1327 return rowPosition + std::max<LayoutUnit>(0, rowHeight - childLogicalHeight) ; | |
Julien - ping for review
2014/10/23 00:57:25
Ditto.
jfernandez
2014/10/23 18:09:02
Done.
| |
1310 } | 1328 } |
1311 | 1329 |
1312 LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const | 1330 LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const |
1313 { | 1331 { |
1314 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1332 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1315 | 1333 |
1316 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; | 1334 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()]; |
1317 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1335 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1318 // FIXME: This should account for the grid item's <overflow-position>. | |
1319 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); | 1336 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1320 | 1337 |
1321 return rowPosition; | 1338 return rowPosition; |
1322 } | 1339 } |
1323 | 1340 |
1324 LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox& child) const | 1341 LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox& child) const |
1325 { | 1342 { |
1343 OverflowAlignment overflow = child.style()->alignSelfOverflowAlignment(); | |
1344 ASSERT(overflow == OverflowAlignmentDefault); | |
Julien - ping for review
2014/10/23 00:57:25
Ditto.
jfernandez
2014/10/23 18:09:02
Done.
| |
1326 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1345 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1327 | 1346 |
1328 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1347 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1329 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()] + marginBeforeForChild(&child); | 1348 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()] + marginBeforeForChild(&child); |
1330 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; | 1349 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; |
1331 | 1350 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1332 // FIXME: This should account for the grid item's <overflow-position>. | 1351 LayoutUnit childLogicalHeight = child.logicalHeight(); |
1333 return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.lo gicalHeight()) / 2; | 1352 LayoutUnit rowHeight = endOfRow - startOfRow; |
1353 // It overflows through both alignment container's 'start' and 'end' edges ( may cause data loss). | |
1354 if (childLogicalHeight > rowHeight && overflow == OverflowAlignmentTrue) | |
1355 return rowPosition + (rowHeight - childLogicalHeight) / 2; | |
1356 return rowPosition + std::max<LayoutUnit>(0, rowHeight - childLogicalHeight) / 2; | |
Julien - ping for review
2014/10/23 00:57:24
Ditto.
jfernandez
2014/10/23 18:09:03
Done.
| |
1334 } | 1357 } |
1335 | 1358 |
1336 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const | 1359 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
1337 { | 1360 { |
1338 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1361 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
1339 ItemPosition alignSelf = RenderStyle::resolveAlignment(style(), child.style( )); | |
1340 | 1362 |
1341 switch (alignSelf) { | 1363 switch (RenderStyle::resolveAlignment(style(), child.style())) { |
1342 case ItemPositionSelfStart: | 1364 case ItemPositionSelfStart: |
1343 // If orthogonal writing-modes, this computes to 'Start'. | 1365 // If orthogonal writing-modes, this computes to 'Start'. |
1344 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | 1366 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
1345 if (hasOrthogonalWritingMode) | 1367 if (hasOrthogonalWritingMode) |
1346 return startOfRowForChild(child); | 1368 return startOfRowForChild(child); |
1347 | 1369 |
1348 // self-start is based on the child's block axis direction. That's why w e need to check against the grid container's block flow. | 1370 // self-start is based on the child's block axis direction. That's why w e need to check against the grid container's block flow. |
1349 if (child.style()->writingMode() != style()->writingMode()) | 1371 if (child.style()->writingMode() != style()->writingMode()) |
1350 return endOfRowForChild(child); | 1372 return endOfRowForChild(child); |
1351 | 1373 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 if (isOutOfFlowPositioned()) | 1444 if (isOutOfFlowPositioned()) |
1423 return "RenderGrid (positioned)"; | 1445 return "RenderGrid (positioned)"; |
1424 if (isAnonymous()) | 1446 if (isAnonymous()) |
1425 return "RenderGrid (generated)"; | 1447 return "RenderGrid (generated)"; |
1426 if (isRelPositioned()) | 1448 if (isRelPositioned()) |
1427 return "RenderGrid (relative positioned)"; | 1449 return "RenderGrid (relative positioned)"; |
1428 return "RenderGrid"; | 1450 return "RenderGrid"; |
1429 } | 1451 } |
1430 | 1452 |
1431 } // namespace blink | 1453 } // namespace blink |
OLD | NEW |