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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1082 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; | 1083 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth; |
1084 } | 1084 } |
1085 | 1085 |
1086 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const GridSiz ingData& sizingData) | 1086 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const GridSiz ingData& sizingData) |
1087 { | 1087 { |
1088 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1088 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1089 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.siz e()); | 1089 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.siz e()); |
1090 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); | 1090 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); |
1091 | 1091 |
1092 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit ionIndex]; | |
1093 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex] ; | |
1092 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1094 // 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)); | 1095 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
1096 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | |
1097 | |
1098 ItemPosition childJustifySelf = child->style()->justifySelf(); | |
ojan
2014/01/22 23:43:14
Maybe move this and the switch statement below int
| |
1099 // This first switch pre-processes the justify-self value following the rule s in css-align. It also resolves | |
1100 // all the position into the grid container's logical coordinate for easier computation (and code sharing). | |
1101 switch (childJustifySelf) { | |
1102 case ItemPositionStretch: | |
1103 case ItemPositionBaseline: | |
1104 case ItemPositionCenter: | |
1105 case ItemPositionStart: | |
1106 case ItemPositionEnd: | |
1107 // Nothing to do. | |
1108 break; | |
1109 | |
1110 case ItemPositionAuto: | |
1111 // FIXME: We should use 'justify-items' value and convert any auto value here. For now, we ignore it. | |
1112 break; | |
1113 case ItemPositionSelfStart: | |
1114 if (child->style()->direction() != style()->direction()) | |
1115 childJustifySelf = ItemPositionEnd; | |
1116 else | |
1117 childJustifySelf = ItemPositionStart; | |
1118 break; | |
1119 case ItemPositionSelfEnd: | |
1120 if (child->style()->direction() != style()->direction()) | |
1121 childJustifySelf = ItemPositionStart; | |
1122 else | |
1123 childJustifySelf = ItemPositionEnd; | |
1124 break; | |
1125 case ItemPositionFlexStart: | |
1126 case ItemPositionFlexEnd: | |
ojan
2014/01/22 23:43:14
It's weird the flex-end is equivalent to start. I'
| |
1127 // Only used in flex layout, for other layout, it's equivalent to 'start '. | |
1128 childJustifySelf = ItemPositionStart; | |
1129 break; | |
1130 | |
ojan
2014/01/22 23:43:14
Are these line-breaks intentional?
| |
1131 case ItemPositionLeft: | |
1132 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. | |
1133 if (!isHorizontalWritingMode()) | |
1134 childJustifySelf = ItemPositionStart; | |
1135 else | |
1136 childJustifySelf = style()->isLeftToRightDirection() ? ItemPositionS tart : ItemPositionEnd; | |
1137 break; | |
1138 case ItemPositionRight: | |
1139 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. | |
1140 if (!isHorizontalWritingMode()) | |
1141 childJustifySelf = ItemPositionStart; | |
1142 else | |
1143 childJustifySelf = style()->isLeftToRightDirection() ? ItemPositionE nd : ItemPositionStart; | |
1144 break; | |
1145 } | |
Julien - ping for review
2014/01/22 19:13:42
I am not happy with this 2-pass code. I will come
ojan
2014/01/22 23:43:14
Seems fine to me if you move the first pass into a
| |
1146 | |
1147 switch (childJustifySelf) { | |
1148 case ItemPositionCenter: { | |
1149 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPosit ionIndex + 1]; | |
1150 columnPosition += std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; | |
1151 break; | |
1152 } | |
1153 case ItemPositionLeft: | |
1154 case ItemPositionRight: | |
1155 case ItemPositionFlexStart: | |
1156 case ItemPositionFlexEnd: | |
1157 case ItemPositionSelfStart: | |
1158 case ItemPositionSelfEnd: | |
1159 ASSERT_NOT_REACHED(); | |
1160 break; | |
1161 case ItemPositionStart: | |
1162 // Move the item to account for the column's direction. | |
ojan
2014/01/22 23:43:14
Meh. this comment and the one below don't really t
| |
1163 if (!style()->isLeftToRightDirection()) { | |
1164 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalP ositionIndex + 1]; | |
1165 columnPosition += std::max<LayoutUnit>(0, endOfColumn - startOfColum n - child->logicalWidth()); | |
1166 } | |
1167 break; | |
1168 case ItemPositionEnd: | |
1169 // Move the item to account for the column's direction. | |
1170 if (style()->isLeftToRightDirection()) { | |
1171 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalP ositionIndex + 1]; | |
1172 columnPosition += std::max<LayoutUnit>(0, endOfColumn - startOfColum n - child->logicalWidth()); | |
1173 } | |
1174 break; | |
1175 case ItemPositionStretch: | |
1176 // FIXME: Handle this value. | |
1177 case ItemPositionBaseline: | |
1178 // FIXME: This is blocked on implementing the grid container's baseline. | |
1179 case ItemPositionAuto: | |
1180 // FIXME: We should never see this value (per the comment above). | |
ojan
2014/01/22 23:43:14
Per which comment?
| |
1181 break; | |
1182 } | |
1183 | |
1184 return LayoutPoint(columnPosition, rowPosition); | |
1094 } | 1185 } |
1095 | 1186 |
1096 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) | 1187 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end) |
1097 { | 1188 { |
1098 // This function does a binary search over the coordinates. | 1189 // 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. | 1190 // FIXME: This doesn't work with grid items overflowing their grid areas and should be tested & fixed. |
1100 | 1191 |
1101 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin(); | 1192 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin(); |
1102 if (startGridAreaIndex > 0) | 1193 if (startGridAreaIndex > 0) |
1103 --startGridAreaIndex; | 1194 --startGridAreaIndex; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 if (isOutOfFlowPositioned()) | 1244 if (isOutOfFlowPositioned()) |
1154 return "RenderGrid (positioned)"; | 1245 return "RenderGrid (positioned)"; |
1155 if (isAnonymous()) | 1246 if (isAnonymous()) |
1156 return "RenderGrid (generated)"; | 1247 return "RenderGrid (generated)"; |
1157 if (isRelPositioned()) | 1248 if (isRelPositioned()) |
1158 return "RenderGrid (relative positioned)"; | 1249 return "RenderGrid (relative positioned)"; |
1159 return "RenderGrid"; | 1250 return "RenderGrid"; |
1160 } | 1251 } |
1161 | 1252 |
1162 } // namespace WebCore | 1253 } // namespace WebCore |
OLD | NEW |