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 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 m_columnPositions[0] = borderAndPaddingStart(); | 1159 m_columnPositions[0] = borderAndPaddingStart(); |
1160 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) | 1160 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
1161 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; | 1161 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; |
1162 | 1162 |
1163 m_rowPositions.resize(sizingData.rowTracks.size() + 1); | 1163 m_rowPositions.resize(sizingData.rowTracks.size() + 1); |
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 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) |
| 1170 { |
| 1171 LayoutUnit trackBreadth = endOfTrack - startOfTrack; |
| 1172 LayoutUnit offset = trackBreadth - childBreadth; |
| 1173 |
| 1174 // If overflow is 'safe', we have to make sure we don't overflow the 'start' |
| 1175 // edge (potentially cause some data loss as the overflow is unreachable). |
| 1176 if (overflow == OverflowAlignmentSafe) |
| 1177 offset = std::max<LayoutUnit>(0, offset); |
| 1178 |
| 1179 // If we overflow our alignment container and overflow is 'true' (default),
we |
| 1180 // ignore the overflow and just return the value regardless (which may cause
data |
| 1181 // loss as we overflow the 'start' edge). |
| 1182 return offset; |
| 1183 } |
| 1184 |
1169 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox& child) const | 1185 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox& child) const |
1170 { | 1186 { |
1171 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1187 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1172 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1188 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. | 1189 // 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); | 1190 return startOfColumn + marginStartForChild(&child); |
1176 } | 1191 } |
1177 | 1192 |
1178 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox& child) const | 1193 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox& child) const |
1179 { | 1194 { |
1180 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1195 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1181 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1196 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. | 1197 // 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); | 1198 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); |
1184 | 1199 |
1185 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; | 1200 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; |
1186 // FIXME: This should account for the grid item's <overflow-position>. | 1201 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth()); |
1187 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositi
ons[coordinate.columns.resolvedInitialPosition.toInt()] - child.logicalWidth()); | 1202 |
| 1203 return columnPosition + offsetFromColumnPosition; |
1188 } | 1204 } |
1189 | 1205 |
1190 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB
ox& child) const | 1206 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB
ox& child) const |
1191 { | 1207 { |
1192 if (style()->isLeftToRightDirection()) | 1208 if (style()->isLeftToRightDirection()) |
1193 return startOfColumnForChild(child); | 1209 return startOfColumnForChild(child); |
1194 | 1210 |
1195 return endOfColumnForChild(child); | 1211 return endOfColumnForChild(child); |
1196 } | 1212 } |
1197 | 1213 |
1198 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox
& child) const | 1214 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox
& child) const |
1199 { | 1215 { |
1200 if (!style()->isLeftToRightDirection()) | 1216 if (!style()->isLeftToRightDirection()) |
1201 return startOfColumnForChild(child); | 1217 return startOfColumnForChild(child); |
1202 | 1218 |
1203 return endOfColumnForChild(child); | 1219 return endOfColumnForChild(child); |
1204 } | 1220 } |
1205 | 1221 |
1206 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox& child) co
nst | 1222 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox& child) co
nst |
1207 { | 1223 { |
1208 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1224 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1209 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1225 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; |
1210 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; | 1226 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; |
1211 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); | 1227 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); |
1212 // FIXME: This should account for the grid item's <overflow-position>. | 1228 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth()); |
1213 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn
- child.logicalWidth()) / 2; | 1229 |
| 1230 return columnPosition + offsetFromColumnPosition / 2; |
1214 } | 1231 } |
1215 | 1232 |
1216 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R
enderStyle* childStyle) | 1233 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R
enderStyle* childStyle) |
1217 { | 1234 { |
1218 ItemPosition justify = childStyle->justifySelf(); | 1235 ItemPosition justify = childStyle->justifySelf(); |
1219 if (justify == ItemPositionAuto) | 1236 if (justify == ItemPositionAuto) |
1220 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi
onStretch : parentStyle->justifyItems(); | 1237 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi
onStretch : parentStyle->justifyItems(); |
1221 | |
1222 return justify; | 1238 return justify; |
1223 } | 1239 } |
1224 | 1240 |
1225 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const | 1241 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const |
1226 { | 1242 { |
1227 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1243 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1228 | 1244 |
1229 switch (resolveJustification(style(), child.style())) { | 1245 switch (resolveJustification(style(), child.style())) { |
1230 case ItemPositionSelfStart: | 1246 case ItemPositionSelfStart: |
1231 // For orthogonal writing-modes, this computes to 'start' | 1247 // For orthogonal writing-modes, this computes to 'start' |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 | 1314 |
1299 LayoutUnit RenderGrid::endOfRowForChild(const RenderBox& child) const | 1315 LayoutUnit RenderGrid::endOfRowForChild(const RenderBox& child) const |
1300 { | 1316 { |
1301 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1317 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1302 | 1318 |
1303 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; | 1319 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. | 1320 // 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); | 1321 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1306 | 1322 |
1307 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; | 1323 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; |
1308 // FIXME: This should account for the grid item's <overflow-position>. | 1324 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight()); |
1309 return rowPosition + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.l
ogicalHeight()); | 1325 |
| 1326 return rowPosition + offsetFromRowPosition; |
1310 } | 1327 } |
1311 | 1328 |
1312 LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const | 1329 LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const |
1313 { | 1330 { |
1314 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1331 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1315 | 1332 |
1316 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; | 1333 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. | 1334 // 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); | 1335 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1320 | 1336 |
1321 return rowPosition; | 1337 return rowPosition; |
1322 } | 1338 } |
1323 | 1339 |
1324 LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox& child) const | 1340 LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox& child) const |
1325 { | 1341 { |
1326 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1342 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1327 | 1343 |
1328 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1344 // 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); | 1345 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()] + marginBeforeForChild(&child); |
1330 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; | 1346 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; |
| 1347 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
| 1348 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight()); |
1331 | 1349 |
1332 // FIXME: This should account for the grid item's <overflow-position>. | 1350 return rowPosition + offsetFromRowPosition / 2; |
1333 return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.lo
gicalHeight()) / 2; | |
1334 } | 1351 } |
1335 | 1352 |
1336 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const | 1353 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
1337 { | 1354 { |
1338 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1355 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1339 ItemPosition alignSelf = RenderStyle::resolveAlignment(style(), child.style(
)); | |
1340 | 1356 |
1341 switch (alignSelf) { | 1357 switch (RenderStyle::resolveAlignment(style(), child.style())) { |
1342 case ItemPositionSelfStart: | 1358 case ItemPositionSelfStart: |
1343 // If orthogonal writing-modes, this computes to 'Start'. | 1359 // If orthogonal writing-modes, this computes to 'Start'. |
1344 // FIXME: grid track sizing and positioning does not support orthogonal
modes yet. | 1360 // FIXME: grid track sizing and positioning does not support orthogonal
modes yet. |
1345 if (hasOrthogonalWritingMode) | 1361 if (hasOrthogonalWritingMode) |
1346 return startOfRowForChild(child); | 1362 return startOfRowForChild(child); |
1347 | 1363 |
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. | 1364 // 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()) | 1365 if (child.style()->writingMode() != style()->writingMode()) |
1350 return endOfRowForChild(child); | 1366 return endOfRowForChild(child); |
1351 | 1367 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 if (isOutOfFlowPositioned()) | 1438 if (isOutOfFlowPositioned()) |
1423 return "RenderGrid (positioned)"; | 1439 return "RenderGrid (positioned)"; |
1424 if (isAnonymous()) | 1440 if (isAnonymous()) |
1425 return "RenderGrid (generated)"; | 1441 return "RenderGrid (generated)"; |
1426 if (isRelPositioned()) | 1442 if (isRelPositioned()) |
1427 return "RenderGrid (relative positioned)"; | 1443 return "RenderGrid (relative positioned)"; |
1428 return "RenderGrid"; | 1444 return "RenderGrid"; |
1429 } | 1445 } |
1430 | 1446 |
1431 } // namespace blink | 1447 } // namespace blink |
OLD | NEW |