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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); | 917 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); |
918 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); | 918 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); |
919 | 919 |
920 LayoutRect oldChildRect = child->frameRect(); | 920 LayoutRect oldChildRect = child->frameRect(); |
921 | 921 |
922 // FIXME: Grid items should stretch to fill their cells. Once we | 922 // FIXME: Grid items should stretch to fill their cells. Once we |
923 // implement grid-{column,row}-align, we can also shrink to fit. For | 923 // implement grid-{column,row}-align, we can also shrink to fit. For |
924 // now, just size as if we were a regular child. | 924 // now, just size as if we were a regular child. |
925 child->layoutIfNeeded(); | 925 child->layoutIfNeeded(); |
926 | 926 |
927 child->setLogicalLocation(findChildLogicalPosition(child, sizingData)); | 927 #ifndef NDEBUG |
| 928 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 929 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks
.size()); |
| 930 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size(
)); |
| 931 #endif |
| 932 child->setLogicalLocation(findChildLogicalPosition(child)); |
928 | 933 |
929 // For correctness, we disable some painting optimizations if we have a
child overflowing its grid area. | 934 // For correctness, we disable some painting optimizations if we have a
child overflowing its grid area. |
930 m_gridItemOverflowGridArea = child->logicalHeight() > overrideContaining
BlockContentLogicalHeight | 935 m_gridItemOverflowGridArea = child->logicalHeight() > overrideContaining
BlockContentLogicalHeight |
931 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h; | 936 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h; |
932 | 937 |
933 // If the child moved, we have to repaint it as well as any floating/pos
itioned | 938 // If the child moved, we have to repaint it as well as any floating/pos
itioned |
934 // descendants. An exception is if we need a layout. In this case, we kn
ow we're going to | 939 // descendants. An exception is if we need a layout. In this case, we kn
ow we're going to |
935 // repaint ourselves (and the child) anyway. | 940 // repaint ourselves (and the child) anyway. |
936 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) | 941 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) |
937 child->repaintDuringLayoutIfMoved(oldChildRect); | 942 child->repaintDuringLayoutIfMoved(oldChildRect); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 m_columnPositions[0] = borderAndPaddingStart(); | 1125 m_columnPositions[0] = borderAndPaddingStart(); |
1121 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) | 1126 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
1122 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; | 1127 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; |
1123 | 1128 |
1124 m_rowPositions.resize(sizingData.rowTracks.size() + 1); | 1129 m_rowPositions.resize(sizingData.rowTracks.size() + 1); |
1125 m_rowPositions[0] = borderAndPaddingBefore(); | 1130 m_rowPositions[0] = borderAndPaddingBefore(); |
1126 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1131 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) |
1127 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; | 1132 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; |
1128 } | 1133 } |
1129 | 1134 |
1130 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const GridSiz
ingData& sizingData) | 1135 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox* child) const |
1131 { | 1136 { |
1132 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1137 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1133 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.siz
e()); | 1138 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; |
1134 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); | 1139 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1140 // FIXME: This should account for the grid item's <overflow-position>. |
| 1141 return startOfColumn + marginStartForChild(child); |
| 1142 } |
| 1143 |
| 1144 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox* child) const |
| 1145 { |
| 1146 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1147 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; |
| 1148 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1149 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1150 |
| 1151 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex + 1]; |
| 1152 // FIXME: This should account for the grid item's <overflow-position>. |
| 1153 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositi
ons[coordinate.columns.initialPositionIndex] - child->logicalWidth()); |
| 1154 } |
| 1155 |
| 1156 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB
ox* child) const |
| 1157 { |
| 1158 if (style()->isLeftToRightDirection()) |
| 1159 return startOfColumnForChild(child); |
| 1160 |
| 1161 return endOfColumnForChild(child); |
| 1162 } |
| 1163 |
| 1164 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox
* child) const |
| 1165 { |
| 1166 if (!style()->isLeftToRightDirection()) |
| 1167 return startOfColumnForChild(child); |
| 1168 |
| 1169 return endOfColumnForChild(child); |
| 1170 } |
| 1171 |
| 1172 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co
nst |
| 1173 { |
| 1174 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1175 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; |
| 1176 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex + 1]; |
| 1177 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1178 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn
- child->logicalWidth()) / 2; |
| 1179 } |
| 1180 |
| 1181 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const |
| 1182 { |
| 1183 ItemPosition childJustifySelf = child->style()->justifySelf(); |
| 1184 switch (childJustifySelf) { |
| 1185 case ItemPositionSelfStart: |
| 1186 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. |
| 1187 if (child->style()->direction() != style()->direction()) |
| 1188 return columnPositionAlignedWithGridContainerEnd(child); |
| 1189 |
| 1190 return columnPositionAlignedWithGridContainerStart(child); |
| 1191 case ItemPositionSelfEnd: |
| 1192 // self-end is based on the child's direction. That's why we need to che
ck against the grid container's direction. |
| 1193 if (child->style()->direction() != style()->direction()) |
| 1194 return columnPositionAlignedWithGridContainerStart(child); |
| 1195 |
| 1196 return columnPositionAlignedWithGridContainerEnd(child); |
| 1197 |
| 1198 case ItemPositionFlexStart: |
| 1199 case ItemPositionFlexEnd: |
| 1200 // Only used in flex layout, for other layout, it's equivalent to 'start
'. |
| 1201 return columnPositionAlignedWithGridContainerStart(child); |
| 1202 |
| 1203 case ItemPositionLeft: |
| 1204 // If the property's axis is not parallel with the inline axis, this is
equivalent to ‘start’. |
| 1205 if (!isHorizontalWritingMode()) |
| 1206 return columnPositionAlignedWithGridContainerStart(child); |
| 1207 |
| 1208 if (style()->isLeftToRightDirection()) |
| 1209 return columnPositionAlignedWithGridContainerStart(child); |
| 1210 |
| 1211 return columnPositionAlignedWithGridContainerEnd(child); |
| 1212 case ItemPositionRight: |
| 1213 // If the property's axis is not parallel with the inline axis, this is
equivalent to ‘start’. |
| 1214 if (!isHorizontalWritingMode()) |
| 1215 return columnPositionAlignedWithGridContainerStart(child); |
| 1216 |
| 1217 if (style()->isLeftToRightDirection()) |
| 1218 return columnPositionAlignedWithGridContainerEnd(child); |
| 1219 |
| 1220 return columnPositionAlignedWithGridContainerStart(child); |
| 1221 |
| 1222 case ItemPositionCenter: |
| 1223 return centeredColumnPositionForChild(child); |
| 1224 case ItemPositionStart: |
| 1225 return columnPositionAlignedWithGridContainerStart(child); |
| 1226 case ItemPositionEnd: |
| 1227 return columnPositionAlignedWithGridContainerEnd(child); |
| 1228 |
| 1229 case ItemPositionAuto: |
| 1230 case ItemPositionStretch: |
| 1231 case ItemPositionBaseline: |
| 1232 // FIXME: Implement the previous values. For now, we always start align
the child. |
| 1233 return startOfColumnForChild(child); |
| 1234 } |
| 1235 |
| 1236 ASSERT_NOT_REACHED(); |
| 1237 return 0; |
| 1238 } |
| 1239 |
| 1240 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| 1241 { |
| 1242 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1135 | 1243 |
1136 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1244 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
1137 return LayoutPoint(m_columnPositions[coordinate.columns.initialPositionIndex
] + marginStartForChild(child), m_rowPositions[coordinate.rows.initialPositionIn
dex] + marginBeforeForChild(child)); | 1245 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex]
; |
| 1246 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| 1247 |
| 1248 // FIXME: This function should account for 'align-self'. |
| 1249 |
| 1250 return rowPosition; |
| 1251 } |
| 1252 |
| 1253 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const |
| 1254 { |
| 1255 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); |
1138 } | 1256 } |
1139 | 1257 |
1140 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn
it start, LayoutUnit end) | 1258 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn
it start, LayoutUnit end) |
1141 { | 1259 { |
1142 // This function does a binary search over the coordinates. | 1260 // This function does a binary search over the coordinates. |
1143 // FIXME: This doesn't work with grid items overflowing their grid areas and
should be tested & fixed. | 1261 // FIXME: This doesn't work with grid items overflowing their grid areas and
should be tested & fixed. |
1144 | 1262 |
1145 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate
s.end() - 1, start) - coordinates.begin(); | 1263 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate
s.end() - 1, start) - coordinates.begin(); |
1146 if (startGridAreaIndex > 0) | 1264 if (startGridAreaIndex > 0) |
1147 --startGridAreaIndex; | 1265 --startGridAreaIndex; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 if (isOutOfFlowPositioned()) | 1315 if (isOutOfFlowPositioned()) |
1198 return "RenderGrid (positioned)"; | 1316 return "RenderGrid (positioned)"; |
1199 if (isAnonymous()) | 1317 if (isAnonymous()) |
1200 return "RenderGrid (generated)"; | 1318 return "RenderGrid (generated)"; |
1201 if (isRelPositioned()) | 1319 if (isRelPositioned()) |
1202 return "RenderGrid (relative positioned)"; | 1320 return "RenderGrid (relative positioned)"; |
1203 return "RenderGrid"; | 1321 return "RenderGrid"; |
1204 } | 1322 } |
1205 | 1323 |
1206 } // namespace WebCore | 1324 } // namespace WebCore |
OLD | NEW |