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

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

Issue 2080643002: [css-grid] Implement repeat(auto-fit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Collapse empty tracks (do not drop them) 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return m_grid.size(); 380 return m_grid.size();
381 } 381 }
382 382
383 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const 383 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const
384 { 384 {
385 LayoutUnit logicalHeight; 385 LayoutUnit logicalHeight;
386 386
387 for (const auto& row : sizingData.rowTracks) 387 for (const auto& row : sizingData.rowTracks)
388 logicalHeight += row.baseSize(); 388 logicalHeight += row.baseSize();
389 389
390 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); 390 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size());
391 391
392 return logicalHeight; 392 return logicalHeight;
393 } 393 }
394 394
395 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) 395 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace)
396 { 396 {
397 DCHECK(sizingData.isValidTransitionForDirection(direction)); 397 DCHECK(sizingData.isValidTransitionForDirection(direction));
398 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); 398 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, 0, direction == ForRows ? gridRowCount() : gridColumnCount());
399 sizingData.sizingOperation = TrackSizing; 399 sizingData.sizingOperation = TrackSizing;
400 400
401 LayoutUnit baseSizes, growthLimits; 401 LayoutUnit baseSizes, growthLimits;
402 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s); 402 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s);
403 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); 403 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
404 sizingData.nextState(); 404 sizingData.nextState();
405 } 405 }
406 406
407 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) 407 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows)
408 { 408 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 computeOverflow(oldClientAfterEdge); 494 computeOverflow(oldClientAfterEdge);
495 } 495 }
496 496
497 updateLayerTransformAfterLayout(); 497 updateLayerTransformAfterLayout();
498 updateAfterLayout(); 498 updateAfterLayout();
499 499
500 clearNeedsLayout(); 500 clearNeedsLayout();
501 } 501 }
502 502
503 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t sp an) const 503 bool LayoutGrid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, size _t lineNumber) const
Manuel Rego 2016/07/08 11:12:34 We usually use just "line" to refer to the other l
svillar 2016/07/11 12:46:19 Acknowledged.
504 {
505 return direction == ForColumns ? m_autoRepeatEmptyColumns->contains(lineNumb er) : m_autoRepeatEmptyRows->contains(lineNumber);
506 }
507
508 LayoutUnit LayoutGrid::gridGapForDirection(GridTrackSizingDirection direction) c onst
509 {
510 return valueForLength(direction == ForColumns ? styleRef().gridColumnGap() : styleRef().gridRowGap(), LayoutUnit());
511 }
512
513 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t st artLine, size_t span) const
Manuel Rego 2016/07/08 11:12:35 In most of the cases startLine is simply 0. I'd mo
svillar 2016/07/11 12:46:19 That's correct, but I did it like this for API coh
504 { 514 {
505 if (span <= 1) 515 if (span <= 1)
506 return LayoutUnit(); 516 return LayoutUnit();
507 517
508 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap(); 518 bool isRowAxis = direction == ForColumns;
509 return valueForLength(trackGap, LayoutUnit()) * (span - 1); 519 LayoutUnit gap = gridGapForDirection(direction);
520
521 // Fast path, no collapsing tracks.
522 if (isRowAxis ? !m_autoRepeatEmptyColumns : !m_autoRepeatEmptyRows)
523 return gap * (span - 1);
524
525 // If there are collapsing tracks we need to be sure that gutters are proper ly collapsed. Apart
526 // from that, if we have a collapsed track in the edges of the span we're co nsidering, we need
527 // to move forward (or backwards) in order to know whether the collapsed tra cks reach the end of
528 // the grid (so the gap becomes 0) or there is a non empty track before that .
529
530 LayoutUnit gutterAccumulator;
Manuel Rego 2016/07/08 11:12:34 Nit: You call this gapAccumulator in a different m
svillar 2016/07/11 12:46:19 Acknowledged.
531 size_t endLine = startLine + span;
532
533 for (size_t line = startLine; line < endLine - 1; ++line) {
534 if (!isEmptyAutoRepeatTrack(direction, line))
535 gutterAccumulator += gap;
536 }
537
538 // If the startLine is the start line of a collapsed track we need to go bac kwards till we reach
539 // a non collapsed track. Should we find a non collapsed track we need to ad d that gap.
Manuel Rego 2016/07/08 11:12:34 Nit: s/Should/If/ (it's clearer to me).
svillar 2016/07/11 12:46:18 Acknowledged.
Manuel Rego 2016/07/14 09:10:51 Ping ;)
540 if (startLine && isEmptyAutoRepeatTrack(direction, startLine)) {
541 size_t nonEmptyTracksBeforeStartLine = startLine;
542 auto begin = isRowAxis ? m_autoRepeatEmptyColumns->begin() : m_autoRepea tEmptyRows->begin();
543 for (auto it = begin; *it != startLine; ++it)
544 --nonEmptyTracksBeforeStartLine;
545 if (nonEmptyTracksBeforeStartLine)
546 gutterAccumulator += gap;
547 }
548
549 // If the endLine is the end line of a collapsed track we need to go forward till we reach a non
550 // collapsed track. Should we find a non collapsed track we need to add that gap.
Manuel Rego 2016/07/08 11:12:35 Ditto.
svillar 2016/07/11 12:46:19 Acknowledged.
551 if (isEmptyAutoRepeatTrack(direction, endLine - 1)) {
552 size_t nonEmptyTracksAfterEndLine = (isRowAxis ? gridColumnCount() : gri dRowCount()) - endLine;
553 auto currentEmptyLine = isRowAxis ? m_autoRepeatEmptyColumns->find(endLi ne - 1) : m_autoRepeatEmptyRows->find(endLine - 1);
554 auto endEmptyLine = isRowAxis ? m_autoRepeatEmptyColumns->end() : m_auto RepeatEmptyRows->end();
555 for (auto it = currentEmptyLine; it != endEmptyLine; ++it)
556 --nonEmptyTracksAfterEndLine;
557 if (nonEmptyTracksAfterEndLine)
558 gutterAccumulator += gap;
559 }
560
561 return gutterAccumulator;
510 } 562 }
511 563
512 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 564 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
513 { 565 {
514 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(); 566 const_cast<LayoutGrid*>(this)->placeItemsOnGrid();
515 567
516 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 568 GridSizingData sizingData(gridColumnCount(), gridRowCount());
517 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); 569 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit();
518 sizingData.sizingOperation = IntrinsicSizeComputation; 570 sizingData.sizingOperation = IntrinsicSizeComputation;
519 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth); 571 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth);
520 572
521 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size()); 573 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size());
522 minLogicalWidth += totalGuttersSize; 574 minLogicalWidth += totalGuttersSize;
523 maxLogicalWidth += totalGuttersSize; 575 maxLogicalWidth += totalGuttersSize;
524 576
525 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 577 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
526 minLogicalWidth += scrollbarWidth; 578 minLogicalWidth += scrollbarWidth;
527 maxLogicalWidth += scrollbarWidth; 579 maxLogicalWidth += scrollbarWidth;
528 } 580 }
529 581
530 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) 582 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData)
531 { 583 {
532 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); 584 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData));
533 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); 585 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit();
534 sizingData.sizingOperation = IntrinsicSizeComputation; 586 sizingData.sizingOperation = IntrinsicSizeComputation;
535 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); 587 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight);
536 588
537 LayoutUnit totalGuttersSize = guttersSize(ForRows, gridRowCount()); 589 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount());
538 m_minContentHeight += totalGuttersSize; 590 m_minContentHeight += totalGuttersSize;
539 m_maxContentHeight += totalGuttersSize; 591 m_maxContentHeight += totalGuttersSize;
540 592
541 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); 593 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData));
542 } 594 }
543 595
544 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const 596 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const
545 { 597 {
546 if (logicalHeightLength.isMinContent()) 598 if (logicalHeightLength.isMinContent())
547 return m_minContentHeight; 599 return m_minContentHeight;
(...skipping 24 matching lines...) Expand all
572 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); 624 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction);
573 const LayoutUnit initialFreeSpace = freeSpace; 625 const LayoutUnit initialFreeSpace = freeSpace;
574 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 626 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
575 Vector<size_t> flexibleSizedTracksIndex; 627 Vector<size_t> flexibleSizedTracksIndex;
576 sizingData.contentSizedTracksIndex.shrink(0); 628 sizingData.contentSizedTracksIndex.shrink(0);
577 629
578 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); 630 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace);
579 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. 631 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes.
580 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; 632 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing;
581 if (hasDefiniteFreeSpace) 633 if (hasDefiniteFreeSpace)
582 maxSize += guttersSize(direction, direction == ForRows ? gridRowCount() : gridColumnCount()); 634 maxSize += guttersSize(direction, 0, direction == ForRows ? gridRowCount () : gridColumnCount());
583 635
584 // 1. Initialize per Grid track variables. 636 // 1. Initialize per Grid track variables.
585 for (size_t i = 0; i < tracks.size(); ++i) { 637 for (size_t i = 0; i < tracks.size(); ++i) {
586 GridTrack& track = tracks[i]; 638 GridTrack& track = tracks[i];
587 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); 639 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration);
588 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); 640 const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
589 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); 641 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth();
590 642
591 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize )); 643 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize ));
592 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize)); 644 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 return trackStyles[untranslatedIndex]; 854 return trackStyles[untranslatedIndex];
803 855
804 if (untranslatedIndex < (insertionPoint + repetitions)) 856 if (untranslatedIndex < (insertionPoint + repetitions))
805 return autoRepeatTrackStyles[0]; 857 return autoRepeatTrackStyles[0];
806 858
807 return trackStyles[untranslatedIndex - repetitions]; 859 return trackStyles[untranslatedIndex - repetitions];
808 } 860 }
809 861
810 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, SizingOperation sizingOperation) const 862 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, SizingOperation sizingOperation) const
811 { 863 {
864 // Collapse empty auto repeat tracks if auto-fit
Manuel Rego 2016/07/08 11:12:34 Nit: Missing dot at the end.
svillar 2016/07/11 12:46:19 Acknowledged.
865 if ((direction == ForColumns && m_autoRepeatEmptyColumns && m_autoRepeatEmpt yColumns->contains(translatedIndex))
866 || (direction == ForRows && m_autoRepeatEmptyRows && m_autoRepeatEmptyRo ws->contains(translatedIndex)))
Manuel Rego 2016/07/08 11:12:34 Cannot we use isEmptyAutoRepeatTrack() here?
svillar 2016/07/11 12:46:19 Totally, but I still need the null check here (won
867 return GridTrackSize(Length(Fixed), Length(Fixed));
868
812 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex ); 869 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex );
813 870
814 GridLength minTrackBreadth = trackSize.minTrackBreadth(); 871 GridLength minTrackBreadth = trackSize.minTrackBreadth();
815 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); 872 GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
816 873
817 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. 874 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>.
818 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { 875 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) {
819 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite). 876 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite).
820 // For the block axis we check that the percentage height is resolvable on the first in-flow child. 877 // For the block axis we check that the percentage height is resolvable on the first in-flow child.
821 // TODO (lajava) This condition for determining whether a size is indefi nite or not is not working correctly for orthogonal flows. 878 // TODO (lajava) This condition for determining whether a size is indefi nite or not is not working correctly for orthogonal flows.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 1253
1197 sizingData.filteredTracks.append(&track); 1254 sizingData.filteredTracks.append(&track);
1198 1255
1199 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) 1256 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize))
1200 sizingData.growBeyondGrowthLimitsTracks.append(&track); 1257 sizingData.growBeyondGrowthLimitsTracks.append(&track);
1201 } 1258 }
1202 1259
1203 if (sizingData.filteredTracks.isEmpty()) 1260 if (sizingData.filteredTracks.isEmpty())
1204 continue; 1261 continue;
1205 1262
1206 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); 1263 DCHECK(itemSpan.isTranslatedDefinite());
Manuel Rego 2016/07/08 11:12:35 I don't believe we need this here. We've an ASSER
svillar 2016/07/11 12:46:19 Acknowledged.
1264 spanningTracksSize += guttersSize(direction, itemSpan.startLine(), itemS pan.integerSpan());
1207 1265
1208 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; 1266 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize;
1209 extraSpace = extraSpace.clampNegativeToZero(); 1267 extraSpace = extraSpace.clampNegativeToZero();
1210 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; 1268 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks;
1211 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); 1269 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace);
1212 } 1270 }
1213 1271
1214 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 1272 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
1215 GridTrack& track = tracks[trackIndex]; 1273 GridTrack& track = tracks[trackIndex];
1216 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); 1274 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows(); 1417 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows();
1360 1418
1361 for (const auto& track : trackSizes) { 1419 for (const auto& track : trackSizes) {
1362 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized(); 1420 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized();
1363 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized())); 1421 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized()));
1364 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize); 1422 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize);
1365 } 1423 }
1366 1424
1367 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when 1425 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when
1368 // computing the repetitions. 1426 // computing the repetitions.
1369 LayoutUnit gapSize = guttersSize(direction, 2); 1427 LayoutUnit gapSize = gridGapForDirection(direction);
1370 tracksSize += gapSize * trackSizes.size(); 1428 tracksSize += gapSize * trackSizes.size();
1371 1429
1372 LayoutUnit freeSpace = availableSize - tracksSize; 1430 LayoutUnit freeSpace = availableSize - tracksSize;
1373 if (freeSpace <= 0) 1431 if (freeSpace <= 0)
1374 return 1; 1432 return 1;
1375 1433
1376 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt (); 1434 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt ();
1377 1435
1378 // Provided the grid container does not have a definite size or max-size in the relevant axis, 1436 // Provided the grid container does not have a definite size or max-size in the relevant axis,
1379 // if the min size is definite then the number of repetitions is the largest possible positive 1437 // if the min size is definite then the number of repetitions is the largest possible positive
1380 // integer that fulfills that minimum requirement. 1438 // integer that fulfills that minimum requirement.
1381 if (needsToFulfillMinimumSize) 1439 if (needsToFulfillMinimumSize)
1382 ++repetitions; 1440 ++repetitions;
1383 1441
1384 return repetitions; 1442 return repetitions;
1385 } 1443 }
1386 1444
1445
1446 std::unique_ptr<LayoutGrid::TrackIndexSet> LayoutGrid::computeEmptyTracksForAuto Repeat(GridTrackSizingDirection direction) const
1447 {
1448 bool isRowAxis = direction == ForColumns;
1449 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit)
1450 || (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit))
1451 return nullptr;
1452
1453 std::unique_ptr<TrackIndexSet> emptyTrackIndexes;
Manuel Rego 2016/07/08 11:12:34 I guess you can initialize it here already so you
svillar 2016/07/11 12:46:19 What if there is no empty track? I'd need to creat
Manuel Rego 2016/07/14 09:10:50 True, I didn't realize before.
1454 size_t insertionPoint = isRowAxis ? styleRef().gridAutoRepeatColumnsInsertio nPoint() : styleRef().gridAutoRepeatRowsInsertionPoint();
1455 size_t repetitions = autoRepeatCountForDirection(direction);
1456 size_t firstAutoRepeatTrack = insertionPoint + std::abs(isRowAxis ? m_smalle stColumnStart : m_smallestRowStart);
1457 size_t lastAutoRepeatTrack = firstAutoRepeatTrack + repetitions;
1458
1459 if (m_gridItemArea.isEmpty()) {
1460 emptyTrackIndexes = wrapUnique(new TrackIndexSet);
1461 for (size_t trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepe atTrack; ++trackIndex)
1462 emptyTrackIndexes->add(trackIndex);
1463 } else {
1464 for (size_t trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepe atTrack; ++trackIndex) {
Manuel Rego 2016/07/08 11:12:35 The for is the same, maybe you can move the outer
svillar 2016/07/11 12:46:18 If I do that I'd evaluate the if() condition for e
1465 GridIterator iterator(m_grid, direction, trackIndex);
1466 if (!iterator.nextGridItem()) {
1467 if (!emptyTrackIndexes)
1468 emptyTrackIndexes = wrapUnique(new TrackIndexSet);
1469 emptyTrackIndexes->add(trackIndex);
1470 }
1471 }
1472 }
1473 return emptyTrackIndexes;
1474 }
1475
1387 void LayoutGrid::placeItemsOnGrid() 1476 void LayoutGrid::placeItemsOnGrid()
1388 { 1477 {
1389 if (!m_gridIsDirty) 1478 if (!m_gridIsDirty)
1390 return; 1479 return;
1391 1480
1392 ASSERT(m_gridItemArea.isEmpty()); 1481 ASSERT(m_gridItemArea.isEmpty());
1393 1482
1394 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); 1483 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
1395 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); 1484 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows);
1396 1485
(...skipping 30 matching lines...) Expand all
1427 } 1516 }
1428 1517
1429 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style (), m_autoRepeatRows)); 1518 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style (), m_autoRepeatRows));
1430 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( *style(), m_autoRepeatColumns)); 1519 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( *style(), m_autoRepeatColumns));
1431 1520
1432 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); 1521 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems);
1433 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); 1522 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems);
1434 1523
1435 m_grid.shrinkToFit(); 1524 m_grid.shrinkToFit();
1436 1525
1526 // Compute collapsable tracks for auto-fit
Manuel Rego 2016/07/08 11:12:34 Nit: Missing dot at the end.
1527 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns);
1528 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows);
1529
1437 #if ENABLE(ASSERT) 1530 #if ENABLE(ASSERT)
1438 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { 1531 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) {
1439 if (child->isOutOfFlowPositioned()) 1532 if (child->isOutOfFlowPositioned())
1440 continue; 1533 continue;
1441 1534
1442 GridArea area = cachedGridArea(*child); 1535 GridArea area = cachedGridArea(*child);
1443 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi nite()); 1536 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi nite());
1444 } 1537 }
1445 #endif 1538 #endif
1446 } 1539 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 // is still ongoing. 1718 // is still ongoing.
1626 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure 1719 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure
1627 // the grid and its children are correctly laid out according to the new sty le rules. 1720 // the grid and its children are correctly laid out according to the new sty le rules.
1628 setNeedsLayout(LayoutInvalidationReason::GridChanged); 1721 setNeedsLayout(LayoutInvalidationReason::GridChanged);
1629 1722
1630 m_grid.resize(0); 1723 m_grid.resize(0);
1631 m_gridItemArea.clear(); 1724 m_gridItemArea.clear();
1632 m_gridItemsOverflowingGridArea.resize(0); 1725 m_gridItemsOverflowingGridArea.resize(0);
1633 m_gridItemsIndexesMap.clear(); 1726 m_gridItemsIndexesMap.clear();
1634 m_gridIsDirty = true; 1727 m_gridIsDirty = true;
1728 m_autoRepeatEmptyColumns = nullptr;
1729 m_autoRepeatEmptyRows = nullptr;
1730 }
1731
1732 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle(GridTrackSizingDirecti on direction) const
Manuel Rego 2016/07/08 11:12:35 We've been computing almost the same information i
svillar 2016/07/11 12:46:19 In one method we're computing the line positions w
Manuel Rego 2016/07/14 09:10:51 Yeah I agree. My concern was that there're some du
1733 {
1734 bool isRowAxis = direction == ForColumns;
1735 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions;
1736 size_t numPositions = positions.size();
Manuel Rego 2016/07/08 11:12:34 Maybe we can rename numPositions to numTracks: n
svillar 2016/07/11 12:46:19 Hmm not sure what we would win with that, we still
1737 LayoutUnit offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offs etBetweenRows;
1738
1739 Vector<LayoutUnit> tracks;
1740 if (numPositions < 2)
1741 return tracks;
1742
1743 bool hasCollapsedTracks = isRowAxis ? !!m_autoRepeatEmptyColumns : !!m_autoR epeatEmptyRows;
1744 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : Layo utUnit();
1745 tracks.reserveCapacity(numPositions - 1);
1746 for (size_t i = 0; i < numPositions - 2; ++i)
1747 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - ga p);
1748 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]);
1749
1750 if (!hasCollapsedTracks)
1751 return tracks;
1752
1753 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() : m_autoRepeatEmptyRows->size();
1754 size_t lastLine = tracks.size();
Manuel Rego 2016/07/08 11:12:35 E.g. Here we'd already have the numTracks stored.
1755 gap = gridGapForDirection(direction);
1756 for (size_t i = 1; i < lastLine; ++i) {
1757 if (isEmptyAutoRepeatTrack(direction, i - 1)) {
1758 --remainingEmptyTracks;
1759 } else {
1760 // Remove the gap between consecutive non empty tracks. Remove it al so just once for an
1761 // arbitrary number of empty tracks between two non empty ones.
1762 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine - i);
1763 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(direction , i))
1764 tracks[i - 1] -= gap;
1765 }
Manuel Rego 2016/07/08 11:12:35 Could we early return if (remainingEmptyTracks ==
svillar 2016/07/11 12:46:19 Totally the opposite :). If none of the remaining
1766 }
1767
1768 return tracks;
1635 } 1769 }
1636 1770
1637 static const StyleContentAlignmentData& normalValueBehavior() 1771 static const StyleContentAlignmentData& normalValueBehavior()
1638 { 1772 {
1639 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; 1773 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch};
1640 return normalBehavior; 1774 return normalBehavior;
1641 } 1775 }
1642 1776
1643 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) 1777 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData)
1644 { 1778 {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 if (!endIsAuto) { 1947 if (!endIsAuto) {
1814 if (isForColumns) { 1948 if (isForColumns) {
1815 if (styleRef().isLeftToRightDirection()) 1949 if (styleRef().isLeftToRightDirection())
1816 end = m_columnPositions[endLine] - borderLogicalLeft(); 1950 end = m_columnPositions[endLine] - borderLogicalLeft();
1817 else 1951 else
1818 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight(); 1952 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight();
1819 } else { 1953 } else {
1820 end = m_rowPositions[endLine] - borderBefore(); 1954 end = m_rowPositions[endLine] - borderBefore();
1821 } 1955 }
1822 1956
1823 // These vectors store line positions including gaps, but we shouldn't c onsider them for the edges of the grid. 1957 // These vectors store line positions including gaps, but we shouldn't c onsider them for the
1824 if (endLine > 0 && endLine < lastLine) { 1958 // edges of the grid (note that a collapsed track at the end of the grid has its end line
1825 end -= guttersSize(direction, 2); 1959 // overlapping the grid'd edge).
Manuel Rego 2016/07/08 11:12:35 Apart from the typo "grid'd" I don't get the part
Manuel Rego 2016/07/14 09:10:51 Ping. I don't understand the part between parenthe
1960 if (endLine && (endLine < lastLine)) {
Manuel Rego 2016/07/08 11:12:35 Why you removed "> 0" for endLine? endLine is an i
svillar 2016/07/11 12:46:19 Oh my mistake, I did it due to the coding style
1961 end -= guttersSize(direction, endLine - 1, 2);
Manuel Rego 2016/07/08 11:12:34 Cannot we use gridGapForDirection(direction) like
svillar 2016/07/11 12:46:19 No we cannot. gridGapForDirection just returns the
1826 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; 1962 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows;
1827 } 1963 }
1828 } 1964 }
1829 1965
1830 breadth = end - start; 1966 breadth = end - start;
1831 offset = start; 1967 offset = start;
1832 1968
1833 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef( ).hasStaticInlinePosition(child.isHorizontalWritingMode())) { 1969 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef( ).hasStaticInlinePosition(child.isHorizontalWritingMode())) {
1834 // If the child doesn't have a static inline position (i.e. "left" and/o r "right" aren't "auto", 1970 // If the child doesn't have a static inline position (i.e. "left" and/o r "right" aren't "auto",
1835 // we need to calculate the offset from the left (even if we're in RTL). 1971 // we need to calculate the offset from the left (even if we're in RTL).
1836 if (endIsAuto) { 1972 if (endIsAuto) {
1837 offset = LayoutUnit(); 1973 offset = LayoutUnit();
1838 } else { 1974 } else {
1839 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border LogicalLeft(); 1975 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border LogicalLeft();
1840 1976
1841 if (endLine > 0 && endLine < lastLine) { 1977 if (endLine > 0 && endLine < lastLine) {
1842 offset += guttersSize(direction, 2); 1978 offset += gridGapForDirection(direction);
1843 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee nRows; 1979 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee nRows;
1844 } 1980 }
1845 } 1981 }
1846 } 1982 }
1847 1983
1848 } 1984 }
1849 1985
1850 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const 1986 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const
1851 { 1987 {
1852 ASSERT(m_gridItemArea.contains(&gridItem)); 1988 ASSERT(m_gridItemArea.contains(&gridItem));
(...skipping 14 matching lines...) Expand all
1867 bool gridAreaIsIndefinite = false; 2003 bool gridAreaIsIndefinite = false;
1868 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon tent(ExcludeMarginBorderPadding); 2004 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon tent(ExcludeMarginBorderPadding);
1869 for (auto trackPosition : span) { 2005 for (auto trackPosition : span) {
1870 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s izingOperation).maxTrackBreadth(); 2006 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s izingOperation).maxTrackBreadth();
1871 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) 2007 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex())
1872 gridAreaIsIndefinite = true; 2008 gridAreaIsIndefinite = true;
1873 else 2009 else
1874 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc kAvailableSize); 2010 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc kAvailableSize);
1875 } 2011 }
1876 2012
1877 gridAreaSize += guttersSize(ForRows, span.integerSpan()); 2013 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan());
1878 2014
1879 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri dAreaSize) : gridAreaSize; 2015 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri dAreaSize) : gridAreaSize;
1880 } 2016 }
1881 2017
1882 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const 2018 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const
1883 { 2019 {
1884 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which 2020 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which
1885 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet, 2021 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet,
1886 // so we will need to do an estimation. 2022 // so we will need to do an estimation.
1887 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration) 2023 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration)
1888 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati on); 2024 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati on);
1889 2025
1890 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; 2026 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks;
1891 const GridSpan& span = cachedGridSpan(child, direction); 2027 const GridSpan& span = cachedGridSpan(child, direction);
1892 LayoutUnit gridAreaBreadth; 2028 LayoutUnit gridAreaBreadth;
1893 for (const auto& trackPosition : span) 2029 for (const auto& trackPosition : span)
1894 gridAreaBreadth += tracks[trackPosition].baseSize(); 2030 gridAreaBreadth += tracks[trackPosition].baseSize();
1895 2031
1896 gridAreaBreadth += guttersSize(direction, span.integerSpan()); 2032 DCHECK(span.isTranslatedDefinite());
Manuel Rego 2016/07/08 11:12:34 Ditto.
2033 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan ());
1897 2034
1898 return gridAreaBreadth; 2035 return gridAreaBreadth;
1899 } 2036 }
1900 2037
1901 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const 2038 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const
1902 { 2039 {
1903 // We need the cached value when available because Content Distribution alig nment properties 2040 // We need the cached value when available because Content Distribution alig nment properties
1904 // may have some influence in the final grid area breadth. 2041 // may have some influence in the final grid area breadth.
1905 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; 2042 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1906 const GridSpan& span = cachedGridSpan(child, direction); 2043 const GridSpan& span = cachedGridSpan(child, direction);
(...skipping 12 matching lines...) Expand all
1919 2056
1920 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the 2057 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the
1921 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification 2058 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification
1922 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction. 2059 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction.
1923 bool isRowAxis = direction == ForColumns; 2060 bool isRowAxis = direction == ForColumns;
1924 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; 2061 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks;
1925 size_t numberOfTracks = tracks.size(); 2062 size_t numberOfTracks = tracks.size();
1926 size_t numberOfLines = numberOfTracks + 1; 2063 size_t numberOfLines = numberOfTracks + 1;
1927 size_t lastLine = numberOfLines - 1; 2064 size_t lastLine = numberOfLines - 1;
1928 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpaceForDirection(direction), numberOfTracks); 2065 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpaceForDirection(direction), numberOfTracks);
1929 LayoutUnit trackGap = guttersSize(direction, 2);
1930 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; 2066 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions;
1931 positions.resize(numberOfLines); 2067 positions.resize(numberOfLines);
1932 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore(); 2068 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore();
1933 positions[0] = borderAndPadding + offset.positionOffset; 2069 positions[0] = borderAndPadding + offset.positionOffset;
1934 if (numberOfLines > 1) { 2070 if (numberOfLines > 1) {
2071 // If we have collapsed tracks we just ignore gaps here and add them lat er as we might not
2072 // compute the gap between two consecutive tracks without examining the surrounding ones.
2073 bool hasEmptyLinesForDirection = isRowAxis ? !!m_autoRepeatEmptyColumns : !!m_autoRepeatEmptyRows;
Manuel Rego 2016/07/08 11:12:35 s/hasEmptyLinesForDirection/hasEmptyTracksForDirec
svillar 2016/07/11 12:46:19 Oh yeah, empty lines makes no sense indeed.
2074 LayoutUnit gap = !hasEmptyLinesForDirection ? gridGapForDirection(direct ion) : LayoutUnit();
1935 size_t nextToLastLine = numberOfLines - 2; 2075 size_t nextToLastLine = numberOfLines - 2;
1936 for (size_t i = 0; i < nextToLastLine; ++i) 2076 for (size_t i = 0; i < nextToLastLine; ++i)
1937 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + trackGap; 2077 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + gap;
1938 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize(); 2078 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize();
2079
2080 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to collapse (they
2081 // coincide exactly) except on the edges of the grid where they become 0 .
2082 if (hasEmptyLinesForDirection) {
2083 gap = gridGapForDirection(direction);
2084 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns-> size() : m_autoRepeatEmptyRows->size();
2085 LayoutUnit gapAccumulator;
2086 for (size_t i = 1; i < lastLine; ++i) {
2087 if (isEmptyAutoRepeatTrack(direction, i - 1)) {
2088 --remainingEmptyTracks;
2089 } else {
2090 // Add gap between consecutive non empty tracks. Add it also just once for an
2091 // arbitrary number of empty tracks between two non empty on es.
2092 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (l astLine - i);
2093 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(d irection, i))
2094 gapAccumulator += gap;
2095 }
2096 positions[i] += gapAccumulator;
2097 }
2098 positions[lastLine] += gapAccumulator;
2099 }
1939 } 2100 }
1940 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet weenRows; 2101 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet weenRows;
1941 offsetBetweenTracks = offset.distributionOffset; 2102 offsetBetweenTracks = offset.distributionOffset;
1942 } 2103 }
1943 2104
1944 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth) 2105 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth)
1945 { 2106 {
1946 LayoutUnit offset = trackBreadth - childBreadth; 2107 LayoutUnit offset = trackBreadth - childBreadth;
1947 switch (overflow) { 2108 switch (overflow) {
1948 case OverflowAlignmentSafe: 2109 case OverflowAlignmentSafe:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 switch (axisPosition) { 2340 switch (axisPosition) {
2180 case GridAxisStart: 2341 case GridAxisStart:
2181 return startPosition; 2342 return startPosition;
2182 case GridAxisEnd: 2343 case GridAxisEnd:
2183 case GridAxisCenter: { 2344 case GridAxisCenter: {
2184 size_t childEndLine = rowsSpan.endLine(); 2345 size_t childEndLine = rowsSpan.endLine();
2185 LayoutUnit endOfRow = m_rowPositions[childEndLine]; 2346 LayoutUnit endOfRow = m_rowPositions[childEndLine];
2186 // m_rowPositions include distribution offset (because of content alignm ent) and gutters 2347 // m_rowPositions include distribution offset (because of content alignm ent) and gutters
2187 // so we need to subtract them to get the actual end position for a give n row 2348 // so we need to subtract them to get the actual end position for a give n row
2188 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). 2349 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
2189 LayoutUnit trackGap = guttersSize(ForRows, 2); 2350 LayoutUnit trackGap = gridGapForDirection(ForRows);
2190 if (childEndLine < m_rowPositions.size() - 1) { 2351 if (childEndLine < m_rowPositions.size() - 1) {
2191 endOfRow -= trackGap; 2352 endOfRow -= trackGap;
2192 endOfRow -= m_offsetBetweenRows; 2353 endOfRow -= m_offsetBetweenRows;
2193 } 2354 }
2194 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); 2355 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght();
2195 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); 2356 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow();
2196 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth); 2357 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth);
2197 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 2358 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
2198 } 2359 }
2199 } 2360 }
(...skipping 14 matching lines...) Expand all
2214 switch (axisPosition) { 2375 switch (axisPosition) {
2215 case GridAxisStart: 2376 case GridAxisStart:
2216 return startPosition; 2377 return startPosition;
2217 case GridAxisEnd: 2378 case GridAxisEnd:
2218 case GridAxisCenter: { 2379 case GridAxisCenter: {
2219 size_t childEndLine = columnsSpan.endLine(); 2380 size_t childEndLine = columnsSpan.endLine();
2220 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; 2381 LayoutUnit endOfColumn = m_columnPositions[childEndLine];
2221 // m_columnPositions include distribution offset (because of content ali gnment) and gutters 2382 // m_columnPositions include distribution offset (because of content ali gnment) and gutters
2222 // so we need to subtract them to get the actual end position for a give n column 2383 // so we need to subtract them to get the actual end position for a give n column
2223 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). 2384 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it).
2224 LayoutUnit trackGap = guttersSize(ForColumns, 2); 2385 LayoutUnit trackGap = gridGapForDirection(ForColumns);
2225 if (childEndLine < m_columnPositions.size() - 1) { 2386 if (childEndLine < m_columnPositions.size() - 1) {
2226 endOfColumn -= trackGap; 2387 endOfColumn -= trackGap;
2227 endOfColumn -= m_offsetBetweenColumns; 2388 endOfColumn -= m_offsetBetweenColumns;
2228 } 2389 }
2229 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); 2390 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h();
2230 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); 2391 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth);
2231 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); 2392 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2);
2232 } 2393 }
2233 } 2394 }
2234 2395
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; 2524 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation;
2364 } 2525 }
2365 2526
2366 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2527 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2367 { 2528 {
2368 if (!m_gridItemArea.isEmpty()) 2529 if (!m_gridItemArea.isEmpty())
2369 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2530 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2370 } 2531 }
2371 2532
2372 } // namespace blink 2533 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698