Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1483)

Side by Side Diff: Source/core/layout/LayoutGrid.cpp

Issue 1220043002: [CSS Grid Layout] Removing Content Alignment logic from track sizing alg (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void ensureGrowthLimitIsBiggerThanBaseSize() 112 void ensureGrowthLimitIsBiggerThanBaseSize()
113 { 113 {
114 if (m_growthLimit != infinity && m_growthLimit < m_baseSize) 114 if (m_growthLimit != infinity && m_growthLimit < m_baseSize)
115 m_growthLimit = m_baseSize; 115 m_growthLimit = m_baseSize;
116 } 116 }
117 117
118 LayoutUnit m_baseSize; 118 LayoutUnit m_baseSize;
119 LayoutUnit m_growthLimit; 119 LayoutUnit m_growthLimit;
120 }; 120 };
121 121
122 struct ContentAlignmentData {
123 ContentAlignmentData(LayoutUnit position, LayoutUnit distribution)
124 : positionOffset(position)
125 , distributionOffset(distribution)
126 {
127 }
128
129 LayoutUnit positionOffset;
130 LayoutUnit distributionOffset;
svillar 2015/07/01 16:22:55 missing "m_"
jfernandez 2015/07/02 10:04:22 I've been told that when fields are accessible dir
svillar 2015/07/07 18:32:54 The idea in general is not to allow public accesso
jfernandez 2015/07/07 21:18:34 Yeah, but when using structs it's all assumed as p
131 };
132
122 struct GridTrackForNormalization { 133 struct GridTrackForNormalization {
123 GridTrackForNormalization(const GridTrack& track, double flex) 134 GridTrackForNormalization(const GridTrack& track, double flex)
124 : m_track(&track) 135 : m_track(&track)
125 , m_flex(flex) 136 , m_flex(flex)
126 , m_normalizedFlexValue(track.baseSize() / flex) 137 , m_normalizedFlexValue(track.baseSize() / flex)
127 { 138 {
128 } 139 }
129 140
130 // Required by std::sort. 141 // Required by std::sort.
131 GridTrackForNormalization& operator=(const GridTrackForNormalization& o) 142 GridTrackForNormalization& operator=(const GridTrackForNormalization& o)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 size_t m_childIndex; 236 size_t m_childIndex;
226 }; 237 };
227 238
228 struct LayoutGrid::GridSizingData { 239 struct LayoutGrid::GridSizingData {
229 WTF_MAKE_NONCOPYABLE(GridSizingData); 240 WTF_MAKE_NONCOPYABLE(GridSizingData);
230 STACK_ALLOCATED(); 241 STACK_ALLOCATED();
231 public: 242 public:
232 GridSizingData(size_t gridColumnCount, size_t gridRowCount) 243 GridSizingData(size_t gridColumnCount, size_t gridRowCount)
233 : columnTracks(gridColumnCount) 244 : columnTracks(gridColumnCount)
234 , rowTracks(gridRowCount) 245 , rowTracks(gridRowCount)
246 , columnTracksPositionsCacheIsValid(false)
247 , rowTracksPositionsCacheIsValid(false)
235 { 248 {
236 } 249 }
237 250
251 bool tracksPositionsCacheIsValid(GridTrackSizingDirection direction) const
252 {
253 return direction == ForColumns ? columnTracksPositionsCacheIsValid : row TracksPositionsCacheIsValid;
254 }
255
256 void setTracksPositionsCacheValidity(GridTrackSizingDirection direction, boo l isValid)
257 {
258 if (direction == ForColumns)
259 columnTracksPositionsCacheIsValid = isValid;
260 else
261 rowTracksPositionsCacheIsValid = isValid;
262 }
263
264 void setTracksPositionsCacheValidity(bool isValid)
265 {
266 columnTracksPositionsCacheIsValid = isValid;
267 rowTracksPositionsCacheIsValid = isValid;
svillar 2015/07/01 16:22:55 Can be a single line. Also it's called just once s
jfernandez 2015/07/02 10:04:21 Well, we might be overprotecting our code. The rea
svillar 2015/07/02 11:19:28 You didn't understand me, I was not talking about
jfernandez 2015/07/02 13:48:52 Done.
268 }
269
238 Vector<GridTrack> columnTracks; 270 Vector<GridTrack> columnTracks;
239 Vector<GridTrack> rowTracks; 271 Vector<GridTrack> rowTracks;
240 Vector<size_t> contentSizedTracksIndex; 272 Vector<size_t> contentSizedTracksIndex;
241 273
242 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. 274 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free.
243 Vector<GridTrack*> filteredTracks; 275 Vector<GridTrack*> filteredTracks;
244 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; 276 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan;
245 Vector<GridTrack*> growBeyondGrowthLimitsTracks; 277 Vector<GridTrack*> growBeyondGrowthLimitsTracks;
246 278
247 LayoutUnit rowsPositionOffset; 279 // Performance optimization: caching grid area size based on tracks position s.
248 LayoutUnit rowsDistributionOffset; 280 bool columnTracksPositionsCacheIsValid;
249 LayoutUnit columnsPositionOffset; 281 bool rowTracksPositionsCacheIsValid;
250 LayoutUnit columnsDistributionOffset;
251 }; 282 };
252 283
253 struct GridItemsSpanGroupRange { 284 struct GridItemsSpanGroupRange {
254 Vector<GridItemWithSpan>::iterator rangeStart; 285 Vector<GridItemWithSpan>::iterator rangeStart;
255 Vector<GridItemWithSpan>::iterator rangeEnd; 286 Vector<GridItemWithSpan>::iterator rangeEnd;
256 }; 287 };
257 288
258 LayoutGrid::LayoutGrid(Element* element) 289 LayoutGrid::LayoutGrid(Element* element)
259 : LayoutBlock(element) 290 : LayoutBlock(element)
260 , m_gridIsDirty(true) 291 , m_gridIsDirty(true)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 { 431 {
401 return isFloatingOrOutOfFlowPositioned(); 432 return isFloatingOrOutOfFlowPositioned();
402 } 433 }
403 434
404 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& freeSpace) 435 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& freeSpace)
405 { 436 {
406 const LayoutUnit initialFreeSpace = freeSpace; 437 const LayoutUnit initialFreeSpace = freeSpace;
407 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 438 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
408 Vector<size_t> flexibleSizedTracksIndex; 439 Vector<size_t> flexibleSizedTracksIndex;
409 sizingData.contentSizedTracksIndex.shrink(0); 440 sizingData.contentSizedTracksIndex.shrink(0);
441 sizingData.setTracksPositionsCacheValidity(direction, false);
410 442
411 // 1. Initialize per Grid track variables. 443 // 1. Initialize per Grid track variables.
412 for (size_t i = 0; i < tracks.size(); ++i) { 444 for (size_t i = 0; i < tracks.size(); ++i) {
413 GridTrack& track = tracks[i]; 445 GridTrack& track = tracks[i];
414 GridTrackSize trackSize = gridTrackSize(direction, i); 446 GridTrackSize trackSize = gridTrackSize(direction, i);
415 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); 447 const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
416 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); 448 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth();
417 449
418 track.setBaseSize(computeUsedBreadthOfMinLength(direction, minTrackBread th)); 450 track.setBaseSize(computeUsedBreadthOfMinLength(direction, minTrackBread th));
419 track.setGrowthLimit(computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.baseSize())); 451 track.setGrowthLimit(computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.baseSize()));
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 // the grid and its children are correctly laid out according to the new sty le rules. 1258 // the grid and its children are correctly laid out according to the new sty le rules.
1227 setNeedsLayout(LayoutInvalidationReason::GridChanged); 1259 setNeedsLayout(LayoutInvalidationReason::GridChanged);
1228 1260
1229 m_grid.resize(0); 1261 m_grid.resize(0);
1230 m_gridItemCoordinate.clear(); 1262 m_gridItemCoordinate.clear();
1231 m_gridItemsOverflowingGridArea.resize(0); 1263 m_gridItemsOverflowingGridArea.resize(0);
1232 m_gridItemsIndexesMap.clear(); 1264 m_gridItemsIndexesMap.clear();
1233 m_gridIsDirty = true; 1265 m_gridIsDirty = true;
1234 } 1266 }
1235 1267
1268 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit availableSpace)
1269 {
1270 if (availableSpace <= 0
1271 || (direction == ForColumns && styleRef().justifyContentDistribution() ! = ContentDistributionStretch)
1272 || (direction == ForRows && styleRef().alignContentDistribution() != Con tentDistributionStretch))
1273 return;
1274
1275 // We consider auto-sized tracks as content-sized (min-content, max-content, auto).
1276 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
1277 Vector<unsigned> autoSizedTracksIndex;
1278 for (unsigned i = 0; i < tracks.size(); ++i) {
1279 const GridTrackSize& trackSize = gridTrackSize(direction, i);
1280 // If there is some flexible-sized track, they should have exhausted ava ilable space during sizing algorithm.
1281 ASSERT(!trackSize.maxTrackBreadth().isFlex());
svillar 2015/07/07 18:32:54 I don't get this ASSERT. If the max function is fl
jfernandez 2015/07/07 21:18:34 We shouldn't reach this point if there are flex tr
1282 if (trackSize.isContentSized())
1283 autoSizedTracksIndex.append(i);
svillar 2015/07/01 16:22:55 Sizing data already has the indexes of the content
jfernandez 2015/07/02 10:04:22 The reason is that SizingData structure uses the c
1284 }
1285
1286 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size();
1287 if (numberOfAutoSizedTracks < 1)
1288 return;
1289
1290 // We are changing track sizes, so positions cache must be invalidated.
1291 sizingData.setTracksPositionsCacheValidity(direction, false);
1292
1293 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks;
1294 for (const auto& trackIndex : autoSizedTracksIndex) {
1295 GridTrack* track = tracks.data() + trackIndex;
1296 // FIXME: Respecting the constraints imposed by max-height/max-width.
svillar 2015/07/01 16:22:55 Not sure what you mean here. Which max-height/max-
jfernandez 2015/07/02 10:04:22 Well, Alignment spec states that stretching should
svillar 2015/07/02 11:19:28 The min and max in tracks are the min and max trac
jfernandez 2015/07/02 13:48:52 Stretching can be applied only for 'auto-sized" al
1297 LayoutUnit baseSize = track->baseSize() + sizeToIncrease;
1298 track->setBaseSize(baseSize);
1299 }
1300 }
1301
1236 void LayoutGrid::layoutGridItems() 1302 void LayoutGrid::layoutGridItems()
1237 { 1303 {
1238 placeItemsOnGrid(); 1304 placeItemsOnGrid();
1239 1305
1240 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 1306 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
1241 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde rPadding); 1307 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde rPadding);
1242 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 1308 GridSizingData sizingData(gridColumnCount(), gridRowCount());
1243 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu mns); 1309 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu mns);
1244 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks )); 1310 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks ));
1245 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); 1311 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows);
1246 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); 1312 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks));
1247 1313
1248 computeContentPositionAndDistributionColumnOffset(availableSpaceForColumns, sizingData); 1314 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData, availableSpace ForColumns);
1249 computeContentPositionAndDistributionRowOffset(availableSpaceForRows, sizing Data); 1315 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData, availableSpaceFor Rows);
1250 1316
1251 populateGridPositions(sizingData); 1317 populateGridPositions(sizingData, availableSpaceForColumns, availableSpaceFo rRows);
1252 m_gridItemsOverflowingGridArea.resize(0); 1318 m_gridItemsOverflowingGridArea.resize(0);
1253 1319
1254 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 1320 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
1255 if (child->isOutOfFlowPositioned()) { 1321 if (child->isOutOfFlowPositioned()) {
1256 child->containingBlock()->insertPositionedObject(child); 1322 child->containingBlock()->insertPositionedObject(child);
1257 continue; 1323 continue;
1258 } 1324 }
1259 1325
1260 // Because the grid area cannot be styled, we don't need to adjust 1326 // Because the grid area cannot be styled, we don't need to adjust
1261 // the grid breadth to account for 'box-sizing'. 1327 // the grid breadth to account for 'box-sizing'.
1262 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); 1328 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit();
1263 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); 1329 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit();
1264 1330
1265 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(*child, ForColumns, sizingData.columnTracks); 1331 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(*child, ForColumns, sizingData);
1266 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(*child, ForRows, sizingData.rowTracks); 1332 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(*child, ForRows, sizingData);
1267 1333
1268 SubtreeLayoutScope layoutScope(*child); 1334 SubtreeLayoutScope layoutScope(*child);
1269 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) 1335 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight()))
1270 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); 1336 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged);
1271 1337
1272 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); 1338 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth);
1273 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); 1339 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight);
1274 1340
1275 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded 1341 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded
1276 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly 1342 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 1453
1388 offset = start; 1454 offset = start;
1389 } 1455 }
1390 1456
1391 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const 1457 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const
1392 { 1458 {
1393 ASSERT(m_gridItemCoordinate.contains(&gridItem)); 1459 ASSERT(m_gridItemCoordinate.contains(&gridItem));
1394 return m_gridItemCoordinate.get(&gridItem); 1460 return m_gridItemCoordinate.get(&gridItem);
1395 } 1461 }
1396 1462
1397 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const 1463 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const
svillar 2015/07/01 16:22:55 Is this version still used after your patch?
jfernandez 2015/07/02 10:04:22 Yes it is. As I commented before, we need somethin
1398 { 1464 {
1399 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1465 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1400 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; 1466 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows;
1401 const Vector<LayoutUnit>& trackPositions = (direction == ForColumns) ? m_col umnPositions : m_rowPositions;
1402 if (span.resolvedFinalPosition.toInt() < trackPositions.size()) {
1403 LayoutUnit startOftrack = trackPositions[span.resolvedInitialPosition.to Int()];
1404 LayoutUnit endOfTrack = trackPositions[span.resolvedFinalPosition.toInt( )];
1405 return endOfTrack - startOftrack + tracks[span.resolvedFinalPosition.toI nt()].baseSize();
1406 }
1407 LayoutUnit gridAreaBreadth = 0; 1467 LayoutUnit gridAreaBreadth = 0;
1408 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) 1468 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition)
1409 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); 1469 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize();
1410
1411 return gridAreaBreadth; 1470 return gridAreaBreadth;
1412 } 1471 }
1413 1472
1414 void LayoutGrid::populateGridPositions(const GridSizingData& sizingData) 1473 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const
1474 {
1475 ASSERT(sizingData.tracksPositionsCacheIsValid(direction));
1476 // We need the cached value when available because Content Distribution alig nment properties
1477 // may have some influence in the final grid area breadth.
1478 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1479 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1480 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows;
1481 const Vector<LayoutUnit>& trackPositions = (direction == ForColumns) ? m_col umnPositions : m_rowPositions;
1482 LayoutUnit startOftrack = trackPositions[span.resolvedInitialPosition.toInt( )];
1483 LayoutUnit endOfTrack = trackPositions[span.resolvedFinalPosition.toInt()];
1484 return endOfTrack - startOftrack + tracks[span.resolvedFinalPosition.toInt() ].baseSize();
1485 }
1486
1487 void LayoutGrid::populateGridPositions(GridSizingData& sizingData, LayoutUnit av ailableSpaceForColumns, LayoutUnit availableSpaceForRows)
1415 { 1488 {
1416 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); 1489 unsigned numberOfColumnTracks = sizingData.columnTracks.size();
1417 unsigned numberOfRowTracks = sizingData.rowTracks.size(); 1490 unsigned numberOfRowTracks = sizingData.rowTracks.size();
1418 1491
1492 ContentAlignmentData columnOffset = computeContentPositionAndDistributionCol umnOffset(availableSpaceForColumns, numberOfColumnTracks);
1419 m_columnPositions.resize(numberOfColumnTracks + 1); 1493 m_columnPositions.resize(numberOfColumnTracks + 1);
1420 m_columnPositions[0] = borderAndPaddingStart() + sizingData.columnsPositionO ffset; 1494 m_columnPositions[0] = borderAndPaddingStart() + columnOffset.positionOffset ;
1421 for (unsigned i = 0; i < numberOfColumnTracks; ++i) 1495 for (unsigned i = 0; i < numberOfColumnTracks - 1; ++i)
1422 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnsDist ributionOffset + sizingData.columnTracks[i].baseSize(); 1496 m_columnPositions[i + 1] = m_columnPositions[i] + columnOffset.distribut ionOffset + sizingData.columnTracks[i].baseSize();
1497 m_columnPositions[numberOfColumnTracks] = m_columnPositions[numberOfColumnTr acks - 1] + sizingData.columnTracks[numberOfColumnTracks - 1].baseSize();
svillar 2015/07/01 16:22:55 Why this change in the loop?
jfernandez 2015/07/02 10:04:22 Well, since I had to change this function because
svillar 2015/07/02 11:19:28 I think this likely deserves a separate patch + te
jfernandez 2015/07/02 13:48:52 I can do a new patch for this, not sure about the
1423 1498
1499 ContentAlignmentData rowOffset = computeContentPositionAndDistributionRowOff set(availableSpaceForRows, numberOfRowTracks);
1424 m_rowPositions.resize(numberOfRowTracks + 1); 1500 m_rowPositions.resize(numberOfRowTracks + 1);
1425 m_rowPositions[0] = borderAndPaddingBefore() + sizingData.rowsPositionOffset ; 1501 m_rowPositions[0] = borderAndPaddingBefore() + rowOffset.positionOffset;
1426 for (unsigned i = 0; i < numberOfRowTracks; ++i) 1502 for (unsigned i = 0; i < numberOfRowTracks - 1; ++i)
1427 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowsDistributionO ffset + sizingData.rowTracks[i].baseSize(); 1503 m_rowPositions[i + 1] = m_rowPositions[i] + rowOffset.distributionOffset + sizingData.rowTracks[i].baseSize();
1504 m_rowPositions[numberOfRowTracks] = m_rowPositions[numberOfRowTracks - 1] + sizingData.rowTracks[numberOfRowTracks - 1].baseSize();
svillar 2015/07/01 16:22:55 Why this change in the loop?
jfernandez 2015/07/02 10:04:21 Same as above comment.
1505
1506 sizingData.setTracksPositionsCacheValidity(true);
1428 } 1507 }
1429 1508
1430 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth) 1509 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth)
1431 { 1510 {
1432 LayoutUnit offset = trackBreadth - childBreadth; 1511 LayoutUnit offset = trackBreadth - childBreadth;
1433 switch (overflow) { 1512 switch (overflow) {
1434 case OverflowAlignmentSafe: 1513 case OverflowAlignmentSafe:
1435 // If overflow is 'safe', we have to make sure we don't overflow the 'st art' 1514 // If overflow is 'safe', we have to make sure we don't overflow the 'st art'
1436 // edge (potentially cause some data loss as the overflow is unreachable ). 1515 // edge (potentially cause some data loss as the overflow is unreachable ).
1437 return std::max<LayoutUnit>(0, offset); 1516 return std::max<LayoutUnit>(0, offset);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 { 1784 {
1706 return isLeftToRight ? LayoutUnit() : availableSpace; 1785 return isLeftToRight ? LayoutUnit() : availableSpace;
1707 } 1786 }
1708 1787
1709 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl eSpace) 1788 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl eSpace)
1710 { 1789 {
1711 return !isLeftToRight ? LayoutUnit() : availableSpace; 1790 return !isLeftToRight ? LayoutUnit() : availableSpace;
1712 } 1791 }
1713 1792
1714 1793
1715 static bool contentDistributionOffset(LayoutUnit availableFreeSpace, ContentPosi tion& fallbackPosition, ContentDistributionType distribution, unsigned numberOfG ridTracks, LayoutUnit& positionOffset, LayoutUnit& distributionOffset) 1794 static PassOwnPtr<ContentAlignmentData> contentDistributionOffset(LayoutUnit ava ilableFreeSpace, ContentPosition& fallbackPosition, ContentDistributionType dist ribution, unsigned numberOfGridTracks)
1716 { 1795 {
1717 if (distribution != ContentDistributionDefault && fallbackPosition == Conten tPositionAuto) 1796 if (distribution != ContentDistributionDefault && fallbackPosition == Conten tPositionAuto)
1718 fallbackPosition = resolveContentDistributionFallback(distribution); 1797 fallbackPosition = resolveContentDistributionFallback(distribution);
1719 1798
1720 if (availableFreeSpace <= 0) 1799 if (availableFreeSpace <= 0)
1721 return false; 1800 return nullptr;
1722 1801
1802 LayoutUnit distributionOffset;
1723 switch (distribution) { 1803 switch (distribution) {
1724 case ContentDistributionSpaceBetween: 1804 case ContentDistributionSpaceBetween:
1725 if (numberOfGridTracks < 2) 1805 if (numberOfGridTracks < 2)
1726 return false; 1806 return nullptr;
1727 distributionOffset = availableFreeSpace / (numberOfGridTracks - 1); 1807 return adoptPtr(new ContentAlignmentData(0, availableFreeSpace / (number OfGridTracks - 1)));
1728 positionOffset = 0;
1729 return true;
1730 case ContentDistributionSpaceAround: 1808 case ContentDistributionSpaceAround:
1731 if (numberOfGridTracks < 1) 1809 if (numberOfGridTracks < 1)
1732 return false; 1810 return nullptr;
1733 distributionOffset = availableFreeSpace / numberOfGridTracks; 1811 distributionOffset = availableFreeSpace / numberOfGridTracks;
1734 positionOffset = distributionOffset / 2; 1812 return adoptPtr(new ContentAlignmentData(distributionOffset / 2, distrib utionOffset));
1735 return true;
1736 case ContentDistributionSpaceEvenly: 1813 case ContentDistributionSpaceEvenly:
1737 distributionOffset = availableFreeSpace / (numberOfGridTracks + 1); 1814 distributionOffset = availableFreeSpace / (numberOfGridTracks + 1);
1738 positionOffset = distributionOffset; 1815 return adoptPtr(new ContentAlignmentData(distributionOffset, distributio nOffset));
1739 return true;
1740 case ContentDistributionStretch: 1816 case ContentDistributionStretch:
1741 distributionOffset = 0; 1817 return adoptPtr(new ContentAlignmentData(0, 0));
1742 positionOffset = 0;
1743 return true;
1744 case ContentDistributionDefault: 1818 case ContentDistributionDefault:
1745 distributionOffset = 0; 1819 return nullptr;
1746 positionOffset = 0;
1747 return false;
1748 } 1820 }
1749 1821
1750 ASSERT_NOT_REACHED(); 1822 ASSERT_NOT_REACHED();
1751 return false; 1823 return nullptr;
1752 } 1824 }
svillar 2015/07/01 16:22:55 Why are you allocating all those objects in the st
jfernandez 2015/07/02 10:04:22 Yes, that was my first idea. The issue is that I n
svillar 2015/07/02 11:19:28 You mean is not enough with returning false but yo
jfernandez 2015/07/02 13:48:52 Well, the function returns now data structure, ins
1753 1825
1754 void LayoutGrid::computeContentPositionAndDistributionColumnOffset(LayoutUnit av ailableFreeSpace, GridSizingData& sizingData) const 1826 ContentAlignmentData LayoutGrid::computeContentPositionAndDistributionColumnOffs et(LayoutUnit availableFreeSpace, unsigned numberOfGridTracks) const
1755 { 1827 {
1756 ContentPosition position = styleRef().justifyContentPosition(); 1828 ContentPosition position = styleRef().justifyContentPosition();
1757 ContentDistributionType distribution = styleRef().justifyContentDistribution (); 1829 ContentDistributionType distribution = styleRef().justifyContentDistribution ();
1758 // If <content-distribution> value can't be applied, 'position' will become the associated 1830 // If <content-distribution> value can't be applied, 'position' will become the associated
1759 // <content-position> fallback value. 1831 // <content-position> fallback value.
1760 if (contentDistributionOffset(availableFreeSpace, position, distribution, si zingData.columnTracks.size(), sizingData.columnsPositionOffset, sizingData.colum nsDistributionOffset)) 1832 OwnPtr<ContentAlignmentData> contentAlignment = contentDistributionOffset(av ailableFreeSpace, position, distribution, numberOfGridTracks);
1761 return; 1833 if (contentAlignment)
1834 return *contentAlignment;
1762 1835
1763 OverflowAlignment overflow = styleRef().justifyContentOverflowAlignment(); 1836 if (availableFreeSpace <= 0 && styleRef().justifyContentOverflowAlignment() == OverflowAlignmentSafe)
1764 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) 1837 return {0, 0};
1765 return;
1766 1838
1767 switch (position) { 1839 switch (position) {
1768 case ContentPositionLeft: 1840 case ContentPositionLeft:
1769 sizingData.columnsPositionOffset = 0; 1841 return {0, 0};
1770 return;
1771 case ContentPositionRight: 1842 case ContentPositionRight:
1772 sizingData.columnsPositionOffset = availableFreeSpace; 1843 return {availableFreeSpace, 0};
1773 return;
1774 case ContentPositionCenter: 1844 case ContentPositionCenter:
1775 sizingData.columnsPositionOffset = availableFreeSpace / 2; 1845 return {availableFreeSpace / 2, 0};
1776 return;
1777 case ContentPositionFlexEnd: 1846 case ContentPositionFlexEnd:
1778 // Only used in flex layout, for other layout, it's equivalent to 'end'. 1847 // Only used in flex layout, for other layout, it's equivalent to 'end'.
1779 case ContentPositionEnd: 1848 case ContentPositionEnd:
1780 sizingData.columnsPositionOffset = offsetToEndEdge(style()->isLeftToRigh tDirection(), availableFreeSpace); 1849 return {offsetToEndEdge(styleRef().isLeftToRightDirection(), availableFr eeSpace), 0};
1781 return;
1782 case ContentPositionFlexStart: 1850 case ContentPositionFlexStart:
1783 // Only used in flex layout, for other layout, it's equivalent to 'start '. 1851 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1784 case ContentPositionStart: 1852 case ContentPositionStart:
1785 sizingData.columnsPositionOffset = offsetToStartEdge(style()->isLeftToRi ghtDirection(), availableFreeSpace); 1853 return {offsetToStartEdge(styleRef().isLeftToRightDirection(), available FreeSpace), 0};
1786 return;
1787 case ContentPositionBaseline: 1854 case ContentPositionBaseline:
1788 case ContentPositionLastBaseline: 1855 case ContentPositionLastBaseline:
1789 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. 1856 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child.
1790 // crbug.com/234191 1857 // crbug.com/234191
1791 sizingData.columnsPositionOffset = offsetToStartEdge(style()->isLeftToRi ghtDirection(), availableFreeSpace); 1858 return {offsetToStartEdge(styleRef().isLeftToRightDirection(), available FreeSpace), 0};
1792 return;
1793 case ContentPositionAuto: 1859 case ContentPositionAuto:
1794 break; 1860 break;
1795 } 1861 }
1796 1862
1797 ASSERT_NOT_REACHED(); 1863 ASSERT_NOT_REACHED();
1864 return {0, 0};
1798 } 1865 }
1799 1866
1800 void LayoutGrid::computeContentPositionAndDistributionRowOffset(LayoutUnit avail ableFreeSpace, GridSizingData& sizingData) const 1867 ContentAlignmentData LayoutGrid::computeContentPositionAndDistributionRowOffset( LayoutUnit availableFreeSpace, unsigned numberOfGridTracks) const
1801 { 1868 {
1802 ContentPosition position = styleRef().alignContentPosition(); 1869 ContentPosition position = styleRef().alignContentPosition();
1803 ContentDistributionType distribution = styleRef().alignContentDistribution() ; 1870 ContentDistributionType distribution = styleRef().alignContentDistribution() ;
1804 // If <content-distribution> value can't be applied, 'position' will become the associated 1871 // If <content-distribution> value can't be applied, 'position' will become the associated
1805 // <content-position> fallback value. 1872 // <content-position> fallback value.
1806 if (contentDistributionOffset(availableFreeSpace, position, distribution, si zingData.rowTracks.size(), sizingData.rowsPositionOffset, sizingData.rowsDistrib utionOffset)) 1873 OwnPtr<ContentAlignmentData> contentAlignment = contentDistributionOffset(av ailableFreeSpace, position, distribution, numberOfGridTracks);
1807 return; 1874 if (contentAlignment)
1875 return *contentAlignment;
1808 1876
1809 OverflowAlignment overflow = styleRef().alignContentOverflowAlignment(); 1877 if (availableFreeSpace <= 0 && styleRef().alignContentOverflowAlignment() == OverflowAlignmentSafe)
1810 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) 1878 return {0, 0};
1811 return;
1812 1879
1813 switch (position) { 1880 switch (position) {
1814 case ContentPositionLeft: 1881 case ContentPositionLeft:
1815 // The align-content's axis is always orthogonal to the inline-axis. 1882 // The align-content's axis is always orthogonal to the inline-axis.
1816 sizingData.rowsPositionOffset = 0; 1883 return {0, 0};
1817 return;
1818 case ContentPositionRight: 1884 case ContentPositionRight:
1819 // The align-content's axis is always orthogonal to the inline-axis. 1885 // The align-content's axis is always orthogonal to the inline-axis.
1820 sizingData.rowsPositionOffset = 0; 1886 return {0, 0};
1821 return;
1822 case ContentPositionCenter: 1887 case ContentPositionCenter:
1823 sizingData.rowsPositionOffset = availableFreeSpace / 2; 1888 return {availableFreeSpace / 2, 0};
1824 return;
1825 case ContentPositionFlexEnd: 1889 case ContentPositionFlexEnd:
1826 // Only used in flex layout, for other layout, it's equivalent to 'End'. 1890 // Only used in flex layout, for other layout, it's equivalent to 'End'.
1827 case ContentPositionEnd: 1891 case ContentPositionEnd:
1828 sizingData.rowsPositionOffset = availableFreeSpace; 1892 return {availableFreeSpace, 0};
1829 return;
1830 case ContentPositionFlexStart: 1893 case ContentPositionFlexStart:
1831 // Only used in flex layout, for other layout, it's equivalent to 'Start '. 1894 // Only used in flex layout, for other layout, it's equivalent to 'Start '.
1832 case ContentPositionStart: 1895 case ContentPositionStart:
1833 sizingData.rowsPositionOffset = 0; 1896 return {0, 0};
1834 return;
1835 case ContentPositionBaseline: 1897 case ContentPositionBaseline:
1836 case ContentPositionLastBaseline: 1898 case ContentPositionLastBaseline:
1837 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. 1899 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child.
1838 // crbug.com/234191 1900 // crbug.com/234191
1839 sizingData.rowsPositionOffset = 0; 1901 return {0, 0};
1840 return;
1841 case ContentPositionAuto: 1902 case ContentPositionAuto:
1842 break; 1903 break;
1843 } 1904 }
1844 1905
1845 ASSERT_NOT_REACHED(); 1906 ASSERT_NOT_REACHED();
1907 return {0, 0};
1846 } 1908 }
1847 1909
1848 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const 1910 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const
1849 { 1911 {
1850 LayoutUnit columnPosition = columnPositionForChild(child); 1912 LayoutUnit columnPosition = columnPositionForChild(child);
1851 // We stored m_columnPositions's data ignoring the direction, hence we might need now 1913 // We stored m_columnPositions's data ignoring the direction, hence we might need now
1852 // to translate positions from RTL to LTR, as it's more convenient for paint ing. 1914 // to translate positions from RTL to LTR, as it's more convenient for paint ing.
1853 if (!style()->isLeftToRightDirection()) 1915 if (!style()->isLeftToRightDirection()) {
1854 columnPosition = (m_columnPositions[m_columnPositions.size() - 1] + bord erAndPaddingLogicalLeft() + sizingData.columnsPositionOffset) - columnPosition - sizingData.columnsDistributionOffset - child.logicalWidth(); 1916 LayoutUnit rightEdgePosition = m_columnPositions[m_columnPositions.size( ) - 1] + borderAndPaddingLogicalLeft();
1917 LayoutUnit leftEdgePosition = m_columnPositions[0] - borderAndPaddingSt art();
1918 columnPosition = rightEdgePosition + leftEdgePosition - columnPosition - child.logicalWidth();
1919 }
svillar 2015/07/01 16:22:55 Not sure that I understand this, perhaps it's beca
jfernandez 2015/07/02 10:04:22 Are the names changes enough to make the code unde
1855 1920
1856 return LayoutPoint(columnPosition, rowPositionForChild(child)); 1921 return LayoutPoint(columnPosition, rowPositionForChild(child));
1857 } 1922 }
1858 1923
1859 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 1924 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
1860 { 1925 {
1861 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1926 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1862 } 1927 }
1863 1928
1864 } // namespace blink 1929 } // namespace blink
OLDNEW
« Source/core/layout/LayoutGrid.h ('K') | « Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698