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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 873 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
874 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 874 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
875 | 875 |
876 LayoutRect oldChildRect = child->frameRect(); | 876 LayoutRect oldChildRect = child->frameRect(); |
877 | 877 |
878 // FIXME: Grid items should stretch to fill their cells. Once we | 878 // FIXME: Grid items should stretch to fill their cells. Once we |
879 // implement grid-{column,row}-align, we can also shrink to fit. For | 879 // implement grid-{column,row}-align, we can also shrink to fit. For |
880 // now, just size as if we were a regular child. | 880 // now, just size as if we were a regular child. |
881 child->layoutIfNeeded(); | 881 child->layoutIfNeeded(); |
882 | 882 |
883 child->setLogicalLocation(findChildLogicalPosition(child, sizingData)); | 883 #ifndef NDEBUG |
884 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
885 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks .size()); | |
886 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size( )); | |
887 #endif | |
888 child->setLogicalLocation(findChildLogicalPosition(child)); | |
884 | 889 |
885 // For correctness, we disable some painting optimizations if we have a child overflowing its grid area. | 890 // For correctness, we disable some painting optimizations if we have a child overflowing its grid area. |
886 m_gridItemOverflowGridArea = child->logicalHeight() > overrideContaining BlockContentLogicalHeight | 891 m_gridItemOverflowGridArea = child->logicalHeight() > overrideContaining BlockContentLogicalHeight |
887 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h; | 892 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h; |
888 | 893 |
889 // If the child moved, we have to repaint it as well as any floating/pos itioned | 894 // If the child moved, we have to repaint it as well as any floating/pos itioned |
890 // descendants. An exception is if we need a layout. In this case, we kn ow we're going to | 895 // descendants. An exception is if we need a layout. In this case, we kn ow we're going to |
891 // repaint ourselves (and the child) anyway. | 896 // repaint ourselves (and the child) anyway. |
892 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) | 897 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) |
893 child->repaintDuringLayoutIfMoved(oldChildRect); | 898 child->repaintDuringLayoutIfMoved(oldChildRect); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 m_columnPositions[0] = borderAndPaddingStart(); | 1081 m_columnPositions[0] = borderAndPaddingStart(); |
1077 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) | 1082 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
1078 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack s[i].m_usedBreadth; | 1083 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack s[i].m_usedBreadth; |
1079 | 1084 |
1080 m_rowPositions.resize(sizingData.rowTracks.size() + 1); | 1085 m_rowPositions.resize(sizingData.rowTracks.size() + 1); |
1081 m_rowPositions[0] = borderAndPaddingBefore(); | 1086 m_rowPositions[0] = borderAndPaddingBefore(); |
1082 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1087 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) |
1083 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth; | 1088 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth; |
1084 } | 1089 } |
1085 | 1090 |
1086 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const GridSiz ingData& sizingData) | 1091 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB ox* child) const |
1087 { | 1092 { |
1088 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1093 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1089 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.siz e()); | 1094 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit ionIndex]; |
1090 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); | 1095 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1096 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | |
1097 | |
1098 if (style()->isLeftToRightDirection()) | |
1099 return columnPosition; | |
1100 | |
1101 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI ndex + 1]; | |
1102 // FIXME: This should account for the grid item's <overflow-position>. | |
1103 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()); | |
1104 } | |
1105 | |
1106 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox * child) const | |
ojan
2014/01/28 21:38:05
Am I just misreading the code or is the exactly th
ojan
2014/01/28 23:13:07
Oh, I missed the !. You could avoid the code dupli
Julien - ping for review
2014/01/29 00:11:56
That's a good catch. I think it makes more sense t
| |
1107 { | |
1108 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
1109 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit ionIndex]; | |
1110 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | |
1111 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | |
1112 | |
1113 if (!style()->isLeftToRightDirection()) | |
1114 return columnPosition; | |
1115 | |
1116 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI ndex + 1]; | |
1117 // FIXME: This should account for the grid item's <overflow-position>. | |
1118 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()); | |
1119 } | |
1120 | |
1121 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co nst | |
1122 { | |
1123 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
1124 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit ionIndex]; | |
1125 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI ndex + 1]; | |
1126 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | |
1127 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; | |
1128 } | |
1129 | |
1130 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const | |
1131 { | |
1132 ItemPosition childJustifySelf = child->style()->justifySelf(); | |
1133 switch (childJustifySelf) { | |
1134 case ItemPositionSelfStart: | |
1135 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. | |
1136 if (child->style()->direction() != style()->direction()) | |
1137 return columnPositionAlignedWithGridContainerEnd(child); | |
1138 | |
1139 return columnPositionAlignedWithGridContainerStart(child); | |
1140 case ItemPositionSelfEnd: | |
1141 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction. | |
1142 if (child->style()->direction() != style()->direction()) | |
1143 return columnPositionAlignedWithGridContainerStart(child); | |
1144 | |
1145 return columnPositionAlignedWithGridContainerEnd(child); | |
1146 | |
1147 case ItemPositionFlexStart: | |
1148 case ItemPositionFlexEnd: | |
1149 // Only used in flex layout, for other layout, it's equivalent to 'start '. | |
1150 return columnPositionAlignedWithGridContainerStart(child); | |
1151 | |
1152 case ItemPositionLeft: | |
1153 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. | |
1154 if (!isHorizontalWritingMode()) | |
1155 return columnPositionAlignedWithGridContainerStart(child); | |
1156 | |
1157 if (style()->isLeftToRightDirection()) | |
1158 return columnPositionAlignedWithGridContainerStart(child); | |
1159 | |
1160 return columnPositionAlignedWithGridContainerEnd(child); | |
1161 case ItemPositionRight: | |
1162 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. | |
1163 if (!isHorizontalWritingMode()) | |
1164 return columnPositionAlignedWithGridContainerStart(child); | |
1165 | |
1166 if (style()->isLeftToRightDirection()) | |
1167 return columnPositionAlignedWithGridContainerEnd(child); | |
1168 | |
1169 return columnPositionAlignedWithGridContainerStart(child); | |
1170 | |
1171 case ItemPositionCenter: | |
1172 return centeredColumnPositionForChild(child); | |
1173 case ItemPositionStart: | |
1174 return columnPositionAlignedWithGridContainerStart(child); | |
1175 case ItemPositionEnd: | |
1176 return columnPositionAlignedWithGridContainerEnd(child); | |
1177 | |
1178 case ItemPositionAuto: | |
1179 case ItemPositionStretch: | |
1180 case ItemPositionBaseline: | |
1181 // FIXME: Implement the previous values. For now, we just return 'start' . | |
1182 return columnPositionAlignedWithGridContainerStart(child); | |
1183 } | |
1184 | |
1185 ASSERT_NOT_REACHED(); | |
1186 return 0; | |
1187 } | |
1188 | |
1189 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const | |
1190 { | |
1191 const GridCoordinate& coordinate = cachedGridCoordinate(child); | |
1091 | 1192 |
1092 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1193 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
1093 return LayoutPoint(m_columnPositions[coordinate.columns.initialPositionIndex ] + marginStartForChild(child), m_rowPositions[coordinate.rows.initialPositionIn dex] + marginBeforeForChild(child)); | 1194 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex] ; |
1195 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | |
1196 | |
1197 // FIXME: This function should account for 'align-self'. | |
1198 | |
1199 return rowPosition; | |
1200 } | |
1201 | |
1202 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const | |
1203 { | |
1204 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child) ); | |
1094 } | 1205 } |
1095 | 1206 |
1096 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) | 1207 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) |
1097 { | 1208 { |
1098 // This function does a binary search over the coordinates. | 1209 // This function does a binary search over the coordinates. |
1099 // FIXME: This doesn't work with grid items overflowing their grid areas and should be tested & fixed. | 1210 // FIXME: This doesn't work with grid items overflowing their grid areas and should be tested & fixed. |
1100 | 1211 |
1101 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin(); | 1212 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin(); |
1102 if (startGridAreaIndex > 0) | 1213 if (startGridAreaIndex > 0) |
1103 --startGridAreaIndex; | 1214 --startGridAreaIndex; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 if (isOutOfFlowPositioned()) | 1264 if (isOutOfFlowPositioned()) |
1154 return "RenderGrid (positioned)"; | 1265 return "RenderGrid (positioned)"; |
1155 if (isAnonymous()) | 1266 if (isAnonymous()) |
1156 return "RenderGrid (generated)"; | 1267 return "RenderGrid (generated)"; |
1157 if (isRelPositioned()) | 1268 if (isRelPositioned()) |
1158 return "RenderGrid (relative positioned)"; | 1269 return "RenderGrid (relative positioned)"; |
1159 return "RenderGrid"; | 1270 return "RenderGrid"; |
1160 } | 1271 } |
1161 | 1272 |
1162 } // namespace WebCore | 1273 } // namespace WebCore |
OLD | NEW |