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

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

Issue 2057113002: [css-grid] Allow percentage values for column and row gutters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch rebased. New positioned test cases and related bug fixes. Created 4 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Vector<GridTrack> columnTracks; 242 Vector<GridTrack> columnTracks;
243 Vector<GridTrack> rowTracks; 243 Vector<GridTrack> rowTracks;
244 Vector<size_t> contentSizedTracksIndex; 244 Vector<size_t> contentSizedTracksIndex;
245 245
246 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. 246 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free.
247 Vector<GridTrack*> filteredTracks; 247 Vector<GridTrack*> filteredTracks;
248 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; 248 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan;
249 Vector<GridTrack*> growBeyondGrowthLimitsTracks; 249 Vector<GridTrack*> growBeyondGrowthLimitsTracks;
250 250
251 LayoutUnit& freeSpaceForDirection(GridTrackSizingDirection direction) { retu rn direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } 251 LayoutUnit& freeSpaceForDirection(GridTrackSizingDirection direction) { retu rn direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; }
252 void setTrackGapsForDirection(GridTrackSizingDirection direction, LayoutUnit gap) { direction == ForColumns ? gapsForColumns = gap : gapsForRows = gap; }
cbiesinger 2016/06/22 18:46:13 Please don't use the ternary operator instead of a
jfernandez 2016/06/27 23:56:47 Acknowledged.
253 LayoutUnit trackGapsForDirection(GridTrackSizingDirection direction) const { return direction == ForColumns ? gapsForColumns : gapsForRows; }
254 LayoutUnit guttersSize(GridTrackSizingDirection direction, size_t span) cons t { return span <= 1 ? LayoutUnit() : trackGapsForDirection(direction) * (span - 1); }
252 255
253 SizingOperation sizingOperation { TrackSizing }; 256 SizingOperation sizingOperation { TrackSizing };
254 257
255 private: 258 private:
256 LayoutUnit freeSpaceForColumns { }; 259 LayoutUnit freeSpaceForColumns { };
257 LayoutUnit freeSpaceForRows { }; 260 LayoutUnit freeSpaceForRows { };
261 LayoutUnit gapsForColumns { };
262 LayoutUnit gapsForRows { };
258 }; 263 };
259 264
260 struct GridItemsSpanGroupRange { 265 struct GridItemsSpanGroupRange {
261 Vector<GridItemWithSpan>::iterator rangeStart; 266 Vector<GridItemWithSpan>::iterator rangeStart;
262 Vector<GridItemWithSpan>::iterator rangeEnd; 267 Vector<GridItemWithSpan>::iterator rangeEnd;
263 }; 268 };
264 269
265 LayoutGrid::LayoutGrid(Element* element) 270 LayoutGrid::LayoutGrid(Element* element)
266 : LayoutBlock(element) 271 : LayoutBlock(element)
267 , m_gridIsDirty(true) 272 , m_gridIsDirty(true)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return m_grid.size(); 346 return m_grid.size();
342 } 347 }
343 348
344 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const 349 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const
345 { 350 {
346 LayoutUnit logicalHeight; 351 LayoutUnit logicalHeight;
347 352
348 for (const auto& row : sizingData.rowTracks) 353 for (const auto& row : sizingData.rowTracks)
349 logicalHeight += row.baseSize(); 354 logicalHeight += row.baseSize();
350 355
351 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); 356 logicalHeight += sizingData.guttersSize(ForRows, sizingData.rowTracks.size() );
352 357
353 return logicalHeight; 358 return logicalHeight;
354 } 359 }
355 360
356 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) 361 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace)
357 { 362 {
358 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); 363 sizingData.freeSpaceForDirection(direction) = freeSpace - sizingData.gutters Size(direction, direction == ForRows ? gridRowCount() : gridColumnCount());
359 sizingData.sizingOperation = TrackSizing; 364 sizingData.sizingOperation = TrackSizing;
360 365
361 LayoutUnit baseSizes, growthLimits; 366 LayoutUnit baseSizes, growthLimits;
362 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s); 367 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s);
363 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); 368 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
364 } 369 }
365 370
366 void LayoutGrid::layoutBlock(bool relayoutChildren) 371 void LayoutGrid::layoutBlock(bool relayoutChildren)
367 { 372 {
368 ASSERT(needsLayout()); 373 ASSERT(needsLayout());
(...skipping 17 matching lines...) Expand all
386 391
387 placeItemsOnGrid(); 392 placeItemsOnGrid();
388 393
389 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 394 GridSizingData sizingData(gridColumnCount(), gridRowCount());
390 395
391 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 396 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns.
392 // At this point the logical width is always definite as the above call to updateLogicalWidth() 397 // At this point the logical width is always definite as the above call to updateLogicalWidth()
393 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code 398 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
394 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve 399 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
395 // heights properly (like for positioned items for example). 400 // heights properly (like for positioned items for example).
396 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); 401 LayoutUnit availableWidth = availableLogicalWidth();
402 sizingData.setTrackGapsForDirection(ForColumns, guttersSize(ForColumns, 2, availableWidth));
403 computeTrackSizesForDirection(ForColumns, sizingData, availableWidth);
397 404
398 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the 405 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the
399 // grid column sizes calculated in the previous step. 406 // grid column sizes calculated in the previous step.
400 if (logicalHeightWasIndefinite) 407 if (logicalHeightWasIndefinite) {
408 sizingData.setTrackGapsForDirection(ForRows, guttersSize(ForRows, 2, LayoutUnit()));
401 computeIntrinsicLogicalHeight(sizingData); 409 computeIntrinsicLogicalHeight(sizingData);
402 else 410 } else {
403 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); 411 LayoutUnit availableHeight = availableLogicalHeight(ExcludeMarginBor derPadding);
cbiesinger 2016/06/22 18:46:13 Does this code do something reasonable with an uns
jfernandez 2016/06/27 23:56:48 This branch of code supposes height is "definite",
412 sizingData.setTrackGapsForDirection(ForRows, guttersSize(ForRows, 2, availableHeight));
413 computeTrackSizesForDirection(ForRows, sizingData, availableHeight);
414 }
404 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); 415 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight());
405 416
406 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 417 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
407 updateLogicalHeight(); 418 updateLogicalHeight();
408 419
409 // The above call might have changed the grid's logical height depending on min|max height restrictions. 420 // The above call might have changed the grid's logical height depending on min|max height restrictions.
410 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). 421 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes).
411 if (logicalHeightWasIndefinite) 422 if (logicalHeightWasIndefinite)
412 computeTrackSizesForDirection(ForRows, sizingData, contentLogicalHei ght()); 423 computeTrackSizesForDirection(ForRows, sizingData, contentLogicalHei ght());
413 424
(...skipping 13 matching lines...) Expand all
427 438
428 computeOverflow(oldClientAfterEdge); 439 computeOverflow(oldClientAfterEdge);
429 } 440 }
430 441
431 updateLayerTransformAfterLayout(); 442 updateLayerTransformAfterLayout();
432 updateAfterLayout(); 443 updateAfterLayout();
433 444
434 clearNeedsLayout(); 445 clearNeedsLayout();
435 } 446 }
436 447
437 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t sp an) const 448 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t sp an, LayoutUnit availableSize) const
438 { 449 {
439 if (span <= 1) 450 if (span <= 1)
440 return LayoutUnit(); 451 return LayoutUnit();
441 452
442 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap(); 453 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap();
443 return valueForLength(trackGap, LayoutUnit()) * (span - 1); 454 return valueForLength(trackGap, availableSize) * (span - 1);
444 } 455 }
445 456
446 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 457 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
447 { 458 {
448 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(); 459 const_cast<LayoutGrid*>(this)->placeItemsOnGrid();
449 460
450 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 461 GridSizingData sizingData(gridColumnCount(), gridRowCount());
451 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); 462 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit();
452 sizingData.sizingOperation = IntrinsicSizeComputation; 463 sizingData.sizingOperation = IntrinsicSizeComputation;
464 sizingData.setTrackGapsForDirection(ForColumns, guttersSize(ForColumns, 2, L ayoutUnit()));
453 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth); 465 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth);
454 466
455 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size()); 467 LayoutUnit totalGuttersSize = sizingData.guttersSize(ForColumns, sizingData. columnTracks.size());
456 minLogicalWidth += totalGuttersSize; 468 minLogicalWidth += totalGuttersSize;
457 maxLogicalWidth += totalGuttersSize; 469 maxLogicalWidth += totalGuttersSize;
458 470
459 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 471 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
460 minLogicalWidth += scrollbarWidth; 472 minLogicalWidth += scrollbarWidth;
461 maxLogicalWidth += scrollbarWidth; 473 maxLogicalWidth += scrollbarWidth;
462 } 474 }
463 475
464 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) 476 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData)
465 { 477 {
466 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); 478 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData));
467 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); 479 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit();
468 sizingData.sizingOperation = IntrinsicSizeComputation; 480 sizingData.sizingOperation = IntrinsicSizeComputation;
481 sizingData.setTrackGapsForDirection(ForRows, guttersSize(ForRows, 2, LayoutU nit()));
469 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); 482 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight);
470 483
471 LayoutUnit totalGuttersSize = guttersSize(ForRows, gridRowCount()); 484 LayoutUnit totalGuttersSize = sizingData.guttersSize(ForRows, gridRowCount() );
472 m_minContentHeight += totalGuttersSize; 485 m_minContentHeight += totalGuttersSize;
473 m_maxContentHeight += totalGuttersSize; 486 m_maxContentHeight += totalGuttersSize;
474 487
475 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); 488 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData));
476 } 489 }
477 490
478 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const 491 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const
479 { 492 {
480 if (logicalHeightLength.isMinContent()) 493 if (logicalHeightLength.isMinContent())
481 return m_minContentHeight; 494 return m_minContentHeight;
(...skipping 16 matching lines...) Expand all
498 511
499 static inline double normalizedFlexFraction(const GridTrack& track, double flexF actor) 512 static inline double normalizedFlexFraction(const GridTrack& track, double flexF actor)
500 { 513 {
501 return track.baseSize() / std::max<double>(1, flexFactor); 514 return track.baseSize() / std::max<double>(1, flexFactor);
502 } 515 }
503 516
504 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization) 517 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization)
505 { 518 {
506 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); 519 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction);
507 const LayoutUnit initialFreeSpace = freeSpace; 520 const LayoutUnit initialFreeSpace = freeSpace;
508 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 521 bool isRowAxis = direction == ForColumns;
522 Vector<GridTrack>& tracks = isRowAxis ? sizingData.columnTracks : sizingData .rowTracks;
509 Vector<size_t> flexibleSizedTracksIndex; 523 Vector<size_t> flexibleSizedTracksIndex;
510 sizingData.contentSizedTracksIndex.shrink(0); 524 sizingData.contentSizedTracksIndex.shrink(0);
511 525
512 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); 526 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace);
513 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. 527 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes.
514 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; 528 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing;
515 if (hasDefiniteFreeSpace) 529 if (hasDefiniteFreeSpace)
516 maxSize += guttersSize(direction, direction == ForRows ? gridRowCount() : gridColumnCount()); 530 maxSize += sizingData.guttersSize(direction, isRowAxis ? gridColumnCount () : gridRowCount());
517 531
518 // 1. Initialize per Grid track variables. 532 // 1. Initialize per Grid track variables.
519 for (size_t i = 0; i < tracks.size(); ++i) { 533 for (size_t i = 0; i < tracks.size(); ++i) {
520 GridTrack& track = tracks[i]; 534 GridTrack& track = tracks[i];
521 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); 535 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration);
522 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); 536 const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
523 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); 537 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth();
524 538
525 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize )); 539 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize ));
526 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize)); 540 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize));
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 return LayoutUnit(); 1103 return LayoutUnit();
1090 } 1104 }
1091 1105
1092 ASSERT_NOT_REACHED(); 1106 ASSERT_NOT_REACHED();
1093 return LayoutUnit(); 1107 return LayoutUnit();
1094 } 1108 }
1095 1109
1096 template <TrackSizeComputationPhase phase> 1110 template <TrackSizeComputationPhase phase>
1097 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, const GridItemsSpanGroupRange& gridItemsWithSpan) 1111 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, const GridItemsSpanGroupRange& gridItemsWithSpan)
1098 { 1112 {
1099 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 1113 bool isRowAxis = direction == ForColumns;
1114 Vector<GridTrack>& tracks = isRowAxis ? sizingData.columnTracks : sizingData .rowTracks;
1100 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 1115 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
1101 GridTrack& track = tracks[trackIndex]; 1116 GridTrack& track = tracks[trackIndex];
1102 track.setPlannedSize(trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity)); 1117 track.setPlannedSize(trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity));
1103 } 1118 }
1104 1119
1105 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { 1120 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) {
1106 GridItemWithSpan& gridItemWithSpan = *it; 1121 GridItemWithSpan& gridItemWithSpan = *it;
1107 ASSERT(gridItemWithSpan.getGridSpan().integerSpan() > 1); 1122 ASSERT(gridItemWithSpan.getGridSpan().integerSpan() > 1);
1108 const GridSpan& itemSpan = gridItemWithSpan.getGridSpan(); 1123 const GridSpan& itemSpan = gridItemWithSpan.getGridSpan();
1109 1124
1110 sizingData.growBeyondGrowthLimitsTracks.shrink(0); 1125 sizingData.growBeyondGrowthLimitsTracks.shrink(0);
1111 sizingData.filteredTracks.shrink(0); 1126 sizingData.filteredTracks.shrink(0);
1112 LayoutUnit spanningTracksSize; 1127 LayoutUnit spanningTracksSize;
1113 for (const auto& trackPosition : itemSpan) { 1128 for (const auto& trackPosition : itemSpan) {
1114 GridTrackSize trackSize = gridTrackSize(direction, trackPosition); 1129 GridTrackSize trackSize = gridTrackSize(direction, trackPosition);
1115 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition] : sizingData.rowTracks[trackPosition]; 1130 GridTrack& track = isRowAxis ? sizingData.columnTracks[trackPosition ] : sizingData.rowTracks[trackPosition];
1116 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); 1131 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity);
1117 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) 1132 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize ))
1118 continue; 1133 continue;
1119 1134
1120 sizingData.filteredTracks.append(&track); 1135 sizingData.filteredTracks.append(&track);
1121 1136
1122 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) 1137 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize))
1123 sizingData.growBeyondGrowthLimitsTracks.append(&track); 1138 sizingData.growBeyondGrowthLimitsTracks.append(&track);
1124 } 1139 }
1125 1140
1126 if (sizingData.filteredTracks.isEmpty()) 1141 if (sizingData.filteredTracks.isEmpty())
1127 continue; 1142 continue;
1128 1143
1129 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); 1144 spanningTracksSize += sizingData.guttersSize(direction, itemSpan.integer Span());
1130 1145
1131 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; 1146 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize;
1132 extraSpace = extraSpace.clampNegativeToZero(); 1147 extraSpace = extraSpace.clampNegativeToZero();
1133 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; 1148 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks;
1134 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); 1149 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace);
1135 } 1150 }
1136 1151
1137 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 1152 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
1138 GridTrack& track = tracks[trackIndex]; 1153 GridTrack& track = tracks[trackIndex];
1139 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); 1154 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows(); 1297 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows();
1283 1298
1284 for (const auto& track : trackSizes) { 1299 for (const auto& track : trackSizes) {
1285 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized(); 1300 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized();
1286 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized())); 1301 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized()));
1287 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize); 1302 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize);
1288 } 1303 }
1289 1304
1290 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when 1305 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when
1291 // computing the repetitions. 1306 // computing the repetitions.
1292 LayoutUnit gapSize = guttersSize(direction, 2); 1307 LayoutUnit gapSize = guttersSize(direction, 2, availableSize);
1293 tracksSize += gapSize * trackSizes.size(); 1308 tracksSize += gapSize * trackSizes.size();
1294 1309
1295 LayoutUnit freeSpace = availableSize - tracksSize; 1310 LayoutUnit freeSpace = availableSize - tracksSize;
1296 if (freeSpace <= 0) 1311 if (freeSpace <= 0)
1297 return 1; 1312 return 1;
1298 1313
1299 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt (); 1314 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt ();
1300 1315
1301 // Provided the grid container does not have a definite size or max-size in the relevant axis, 1316 // Provided the grid container does not have a definite size or max-size in the relevant axis,
1302 // if the min size is definite then the number of repetitions is the largest possible positive 1317 // if the min size is definite then the number of repetitions is the largest possible positive
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 if (isForColumns) { 1737 if (isForColumns) {
1723 if (styleRef().isLeftToRightDirection()) 1738 if (styleRef().isLeftToRightDirection())
1724 start = m_columnPositions[startLine] - borderLogicalLeft(); 1739 start = m_columnPositions[startLine] - borderLogicalLeft();
1725 else 1740 else
1726 start = logicalWidth() - translateRTLCoordinate(m_columnPosition s[startLine]) - borderLogicalRight(); 1741 start = logicalWidth() - translateRTLCoordinate(m_columnPosition s[startLine]) - borderLogicalRight();
1727 } else { 1742 } else {
1728 start = m_rowPositions[startLine] - borderBefore(); 1743 start = m_rowPositions[startLine] - borderBefore();
1729 } 1744 }
1730 } 1745 }
1731 1746
1747 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPreferre dSize, style()->logicalHeight(), LayoutUnit(-1)) == LayoutUnit(-1);
1732 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight() ; 1748 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight() ;
1733 if (!endIsAuto) { 1749 if (!endIsAuto) {
1734 if (isForColumns) { 1750 if (isForColumns) {
1735 if (styleRef().isLeftToRightDirection()) 1751 if (styleRef().isLeftToRightDirection())
1736 end = m_columnPositions[endLine] - borderLogicalLeft(); 1752 end = m_columnPositions[endLine] - borderLogicalLeft();
1737 else 1753 else
1738 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight(); 1754 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight();
1739 } else { 1755 } else {
1740 end = m_rowPositions[endLine] - borderBefore(); 1756 end = m_rowPositions[endLine] - borderBefore();
1741 } 1757 }
1742 1758
1743 // These vectors store line positions including gaps, but we shouldn't c onsider them for the edges of the grid. 1759 // These vectors store line positions including gaps, but we shouldn't c onsider them for the edges of the grid.
1744 if (endLine > 0 && endLine < lastLine) { 1760 if (endLine > 0 && endLine < lastLine) {
1745 end -= guttersSize(direction, 2); 1761 end -= guttersSize(direction, 2, isForColumns ? logicalWidth() : log icalHeightWasIndefinite ? LayoutUnit() : logicalHeight());
cbiesinger 2016/06/22 18:46:13 Again, I think this needs to be contentLogicalHeig
jfernandez 2016/06/27 23:56:47 Done.
1746 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; 1762 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows;
1747 } 1763 }
1748 } 1764 }
1749 1765
1750 breadth = end - start; 1766 breadth = end - start;
1751 offset = start; 1767 offset = start;
1752 1768
1753 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef( ).hasStaticInlinePosition(child.isHorizontalWritingMode())) { 1769 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef( ).hasStaticInlinePosition(child.isHorizontalWritingMode())) {
1754 // If the child doesn't have a static inline position (i.e. "left" and/o r "right" aren't "auto", 1770 // If the child doesn't have a static inline position (i.e. "left" and/o r "right" aren't "auto",
1755 // we need to calculate the offset from the left (even if we're in RTL). 1771 // we need to calculate the offset from the left (even if we're in RTL).
1756 if (endIsAuto) { 1772 if (endIsAuto) {
1757 offset = LayoutUnit(); 1773 offset = LayoutUnit();
1758 } else { 1774 } else {
1759 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border LogicalLeft(); 1775 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border LogicalLeft();
1760 1776
1761 if (endLine > 0 && endLine < lastLine) { 1777 if (endLine > 0 && endLine < lastLine) {
1762 offset += guttersSize(direction, 2); 1778 offset += guttersSize(direction, 2, isForColumns ? logicalWidth( ) : logicalHeightWasIndefinite ? LayoutUnit() : logicalHeight());
1763 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee nRows; 1779 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee nRows;
1764 } 1780 }
1765 } 1781 }
1766 } 1782 }
1767 1783
1768 } 1784 }
1769 1785
1770 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const 1786 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const
1771 { 1787 {
1772 ASSERT(m_gridItemArea.contains(&gridItem)); 1788 ASSERT(m_gridItemArea.contains(&gridItem));
1773 return m_gridItemArea.get(&gridItem); 1789 return m_gridItemArea.get(&gridItem);
1774 } 1790 }
1775 1791
1776 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const 1792 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const
1777 { 1793 {
1778 GridArea area = cachedGridArea(gridItem); 1794 GridArea area = cachedGridArea(gridItem);
1779 return direction == ForColumns ? area.columns : area.rows; 1795 return direction == ForColumns ? area.columns : area.rows;
1780 } 1796 }
1781 1797
1782 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const 1798 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const
1783 { 1799 {
1784 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; 1800 bool isRowAxis = direction == ForColumns;
1801 const Vector<GridTrack>& tracks = isRowAxis ? sizingData.columnTracks : sizi ngData.rowTracks;
1785 const GridSpan& span = cachedGridSpan(child, direction); 1802 const GridSpan& span = cachedGridSpan(child, direction);
1786 LayoutUnit gridAreaBreadth; 1803 LayoutUnit gridAreaBreadth;
1787 for (const auto& trackPosition : span) 1804 for (const auto& trackPosition : span)
1788 gridAreaBreadth += tracks[trackPosition].baseSize(); 1805 gridAreaBreadth += tracks[trackPosition].baseSize();
1789 1806
1790 gridAreaBreadth += guttersSize(direction, span.integerSpan()); 1807 gridAreaBreadth += sizingData.guttersSize(direction, span.integerSpan());
1791 1808
1792 return gridAreaBreadth; 1809 return gridAreaBreadth;
1793 } 1810 }
1794 1811
1795 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const 1812 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const
1796 { 1813 {
1797 // We need the cached value when available because Content Distribution alig nment properties 1814 // We need the cached value when available because Content Distribution alig nment properties
1798 // may have some influence in the final grid area breadth. 1815 // may have some influence in the final grid area breadth.
1799 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; 1816 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1800 const GridSpan& span = cachedGridSpan(child, direction); 1817 const GridSpan& span = cachedGridSpan(child, direction);
(...skipping 12 matching lines...) Expand all
1813 1830
1814 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the 1831 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the
1815 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification 1832 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification
1816 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction. 1833 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction.
1817 bool isRowAxis = direction == ForColumns; 1834 bool isRowAxis = direction == ForColumns;
1818 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; 1835 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks;
1819 size_t numberOfTracks = tracks.size(); 1836 size_t numberOfTracks = tracks.size();
1820 size_t numberOfLines = numberOfTracks + 1; 1837 size_t numberOfLines = numberOfTracks + 1;
1821 size_t lastLine = numberOfLines - 1; 1838 size_t lastLine = numberOfLines - 1;
1822 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpaceForDirection(direction), numberOfTracks); 1839 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpaceForDirection(direction), numberOfTracks);
1823 LayoutUnit trackGap = guttersSize(direction, 2); 1840 LayoutUnit trackGap = sizingData.trackGapsForDirection(direction);
1824 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; 1841 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions;
1825 positions.resize(numberOfLines); 1842 positions.resize(numberOfLines);
1826 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore(); 1843 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore();
1827 positions[0] = borderAndPadding + offset.positionOffset; 1844 positions[0] = borderAndPadding + offset.positionOffset;
1828 if (numberOfLines > 1) { 1845 if (numberOfLines > 1) {
1829 size_t nextToLastLine = numberOfLines - 2; 1846 size_t nextToLastLine = numberOfLines - 2;
1830 for (size_t i = 0; i < nextToLastLine; ++i) 1847 for (size_t i = 0; i < nextToLastLine; ++i)
1831 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + trackGap; 1848 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + trackGap;
1832 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize(); 1849 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize();
1833 } 1850 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 switch (axisPosition) { 2090 switch (axisPosition) {
2074 case GridAxisStart: 2091 case GridAxisStart:
2075 return startPosition; 2092 return startPosition;
2076 case GridAxisEnd: 2093 case GridAxisEnd:
2077 case GridAxisCenter: { 2094 case GridAxisCenter: {
2078 size_t childEndLine = rowsSpan.endLine(); 2095 size_t childEndLine = rowsSpan.endLine();
2079 LayoutUnit endOfRow = m_rowPositions[childEndLine]; 2096 LayoutUnit endOfRow = m_rowPositions[childEndLine];
2080 // m_rowPositions include distribution offset (because of content alignm ent) and gutters 2097 // m_rowPositions include distribution offset (because of content alignm ent) and gutters
2081 // so we need to subtract them to get the actual end position for a give n row 2098 // so we need to subtract them to get the actual end position for a give n row
2082 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). 2099 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
2083 LayoutUnit trackGap = guttersSize(ForRows, 2); 2100 LayoutUnit trackGap = sizingData.trackGapsForDirection(ForRows);
2084 if (childEndLine < m_rowPositions.size() - 1) { 2101 if (childEndLine < m_rowPositions.size() - 1) {
2085 endOfRow -= trackGap; 2102 endOfRow -= trackGap;
2086 endOfRow -= m_offsetBetweenRows; 2103 endOfRow -= m_offsetBetweenRows;
2087 } 2104 }
2088 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); 2105 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght();
2089 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); 2106 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow();
2090 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth); 2107 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth);
2091 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 2108 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
2092 } 2109 }
2093 } 2110 }
(...skipping 14 matching lines...) Expand all
2108 switch (axisPosition) { 2125 switch (axisPosition) {
2109 case GridAxisStart: 2126 case GridAxisStart:
2110 return startPosition; 2127 return startPosition;
2111 case GridAxisEnd: 2128 case GridAxisEnd:
2112 case GridAxisCenter: { 2129 case GridAxisCenter: {
2113 size_t childEndLine = columnsSpan.endLine(); 2130 size_t childEndLine = columnsSpan.endLine();
2114 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; 2131 LayoutUnit endOfColumn = m_columnPositions[childEndLine];
2115 // m_columnPositions include distribution offset (because of content ali gnment) and gutters 2132 // m_columnPositions include distribution offset (because of content ali gnment) and gutters
2116 // so we need to subtract them to get the actual end position for a give n column 2133 // so we need to subtract them to get the actual end position for a give n column
2117 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). 2134 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
2118 LayoutUnit trackGap = guttersSize(ForColumns, 2); 2135 LayoutUnit trackGap = sizingData.trackGapsForDirection(ForColumns);
2119 if (childEndLine < m_columnPositions.size() - 1) { 2136 if (childEndLine < m_columnPositions.size() - 1) {
2120 endOfColumn -= trackGap; 2137 endOfColumn -= trackGap;
2121 endOfColumn -= m_offsetBetweenColumns; 2138 endOfColumn -= m_offsetBetweenColumns;
2122 } 2139 }
2123 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); 2140 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h();
2124 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); 2141 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth);
2125 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 2142 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
2126 } 2143 }
2127 } 2144 }
2128 2145
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); 2268 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData ));
2252 } 2269 }
2253 2270
2254 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2271 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2255 { 2272 {
2256 if (!m_gridItemArea.isEmpty()) 2273 if (!m_gridItemArea.isEmpty())
2257 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2274 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2258 } 2275 }
2259 2276
2260 } // namespace blink 2277 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698