Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "wtf/PtrUtil.h" | 35 #include "wtf/PtrUtil.h" |
| 36 #include <algorithm> | 36 #include <algorithm> |
| 37 #include <memory> | 37 #include <memory> |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 static const int infinity = -1; | 41 static const int infinity = -1; |
| 42 | 42 |
| 43 class GridItemWithSpan; | 43 class GridItemWithSpan; |
| 44 | 44 |
| 45 size_t LayoutGrid::Grid::numTracks(GridTrackSizingDirection direction) const { | |
| 46 if (direction == ForRows) | |
| 47 return m_grid.size(); | |
| 48 return m_grid.size() ? m_grid[0].size() : 0; | |
| 49 } | |
| 50 | |
| 45 void LayoutGrid::Grid::ensureGridSize(size_t maximumRowSize, | 51 void LayoutGrid::Grid::ensureGridSize(size_t maximumRowSize, |
| 46 size_t maximumColumnSize) { | 52 size_t maximumColumnSize) { |
| 47 const size_t oldRowSize = numRows(); | 53 const size_t oldRowSize = numTracks(ForRows); |
| 48 if (maximumRowSize > oldRowSize) { | 54 if (maximumRowSize > oldRowSize) { |
| 49 m_grid.grow(maximumRowSize); | 55 m_grid.grow(maximumRowSize); |
| 50 for (size_t row = oldRowSize; row < numRows(); ++row) | 56 for (size_t row = oldRowSize; row < numTracks(ForRows); ++row) |
| 51 m_grid[row].grow(numColumns()); | 57 m_grid[row].grow(numTracks(ForColumns)); |
| 52 } | 58 } |
| 53 | 59 |
| 54 if (maximumColumnSize > numColumns()) { | 60 if (maximumColumnSize > numTracks(ForColumns)) { |
| 55 for (size_t row = 0; row < numRows(); ++row) | 61 for (size_t row = 0; row < numTracks(ForRows); ++row) |
| 56 m_grid[row].grow(maximumColumnSize); | 62 m_grid[row].grow(maximumColumnSize); |
| 57 } | 63 } |
| 58 } | 64 } |
| 59 | 65 |
| 60 void LayoutGrid::Grid::insert(LayoutBox& child, | 66 void LayoutGrid::Grid::insert(LayoutBox& child, |
| 61 const GridArea& area, | 67 const GridArea& area, |
| 62 bool isOrthogonalChild) { | 68 bool isOrthogonalChild) { |
| 63 DCHECK(area.rows.isTranslatedDefinite() && | 69 DCHECK(area.rows.isTranslatedDefinite() && |
| 64 area.columns.isTranslatedDefinite()); | 70 area.columns.isTranslatedDefinite()); |
| 65 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 71 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 size_t order) { | 107 size_t order) { |
| 102 m_gridItemsIndexesMap.set(&item, order); | 108 m_gridItemsIndexesMap.set(&item, order); |
| 103 } | 109 } |
| 104 | 110 |
| 105 #if ENABLE(ASSERT) | 111 #if ENABLE(ASSERT) |
| 106 bool LayoutGrid::Grid::hasAnyGridItemPaintOrder() const { | 112 bool LayoutGrid::Grid::hasAnyGridItemPaintOrder() const { |
| 107 return !m_gridItemsIndexesMap.isEmpty(); | 113 return !m_gridItemsIndexesMap.isEmpty(); |
| 108 } | 114 } |
| 109 #endif | 115 #endif |
| 110 | 116 |
| 117 void LayoutGrid::Grid::setAutoRepeatTracks(size_t autoRepeatRows, | |
| 118 size_t autoRepeatColumns) { | |
| 119 m_autoRepeatRows = autoRepeatRows; | |
| 120 m_autoRepeatColumns = autoRepeatColumns; | |
| 121 } | |
| 122 | |
| 123 size_t LayoutGrid::Grid::autoRepeatTracks( | |
| 124 GridTrackSizingDirection direction) const { | |
| 125 return direction == ForRows ? m_autoRepeatRows : m_autoRepeatColumns; | |
| 126 } | |
| 127 | |
| 128 void LayoutGrid::Grid::setAutoRepeatEmptyColumns( | |
| 129 std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyColumns) { | |
| 130 m_autoRepeatEmptyColumns = std::move(autoRepeatEmptyColumns); | |
| 131 } | |
| 132 | |
| 133 void LayoutGrid::Grid::setAutoRepeatEmptyRows( | |
| 134 std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyRows) { | |
| 135 m_autoRepeatEmptyRows = std::move(autoRepeatEmptyRows); | |
| 136 } | |
| 137 | |
| 138 bool LayoutGrid::Grid::hasAutoRepeatEmptyTracks( | |
| 139 GridTrackSizingDirection direction) const { | |
| 140 return direction == ForColumns ? !!m_autoRepeatEmptyColumns | |
| 141 : !!m_autoRepeatEmptyRows; | |
| 142 } | |
| 143 | |
| 144 bool LayoutGrid::Grid::isEmptyAutoRepeatTrack( | |
| 145 GridTrackSizingDirection direction, | |
| 146 size_t line) const { | |
| 147 DCHECK(hasAutoRepeatEmptyTracks(direction)); | |
| 148 return autoRepeatEmptyTracks(direction)->contains(line); | |
| 149 } | |
| 150 | |
| 151 LayoutGrid::OrderedTrackIndexSet* LayoutGrid::Grid::autoRepeatEmptyTracks( | |
| 152 GridTrackSizingDirection direction) const { | |
| 153 DCHECK(hasAutoRepeatEmptyTracks(direction)); | |
| 154 return direction == ForColumns ? m_autoRepeatEmptyColumns.get() | |
| 155 : m_autoRepeatEmptyRows.get(); | |
| 156 } | |
| 157 | |
| 158 GridSpan LayoutGrid::Grid::gridItemSpan( | |
| 159 const LayoutBox& gridItem, | |
| 160 GridTrackSizingDirection direction) const { | |
| 161 GridArea area = gridItemArea(gridItem); | |
| 162 return direction == ForColumns ? area.columns : area.rows; | |
| 163 } | |
| 164 | |
| 111 void LayoutGrid::Grid::clear() { | 165 void LayoutGrid::Grid::clear() { |
| 112 m_grid.resize(0); | 166 m_grid.resize(0); |
| 113 m_gridItemArea.clear(); | 167 m_gridItemArea.clear(); |
| 114 m_gridItemsIndexesMap.clear(); | 168 m_gridItemsIndexesMap.clear(); |
| 115 m_hasAnyOrthogonalChildren = false; | 169 m_hasAnyOrthogonalChildren = false; |
| 116 m_smallestRowStart = 0; | 170 m_smallestRowStart = 0; |
| 117 m_smallestColumnStart = 0; | 171 m_smallestColumnStart = 0; |
| 172 m_autoRepeatColumns = 0; | |
| 173 m_autoRepeatRows = 0; | |
| 174 m_autoRepeatEmptyColumns = nullptr; | |
| 175 m_autoRepeatEmptyRows = nullptr; | |
| 118 } | 176 } |
| 119 | 177 |
| 120 class GridTrack { | 178 class GridTrack { |
| 121 public: | 179 public: |
| 122 GridTrack() : m_infinitelyGrowable(false) {} | 180 GridTrack() : m_infinitelyGrowable(false) {} |
| 123 | 181 |
| 124 LayoutUnit baseSize() const { | 182 LayoutUnit baseSize() const { |
| 125 DCHECK(isGrowthLimitBiggerThanBaseSize()); | 183 DCHECK(isGrowthLimitBiggerThanBaseSize()); |
| 126 return m_baseSize; | 184 return m_baseSize; |
| 127 } | 185 } |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 // compute relative sizes. | 454 // compute relative sizes. |
| 397 LayoutUnit m_availableSpace; | 455 LayoutUnit m_availableSpace; |
| 398 }; | 456 }; |
| 399 | 457 |
| 400 struct GridItemsSpanGroupRange { | 458 struct GridItemsSpanGroupRange { |
| 401 Vector<GridItemWithSpan>::iterator rangeStart; | 459 Vector<GridItemWithSpan>::iterator rangeStart; |
| 402 Vector<GridItemWithSpan>::iterator rangeEnd; | 460 Vector<GridItemWithSpan>::iterator rangeEnd; |
| 403 }; | 461 }; |
| 404 | 462 |
| 405 LayoutGrid::LayoutGrid(Element* element) | 463 LayoutGrid::LayoutGrid(Element* element) |
| 406 : LayoutBlock(element), m_gridIsDirty(true), m_orderIterator(this) { | 464 : LayoutBlock(element), m_grid(this), m_gridIsDirty(true) { |
| 407 ASSERT(!childrenInline()); | 465 ASSERT(!childrenInline()); |
| 408 } | 466 } |
| 409 | 467 |
| 410 LayoutGrid::~LayoutGrid() {} | 468 LayoutGrid::~LayoutGrid() {} |
| 411 | 469 |
| 412 LayoutGrid* LayoutGrid::createAnonymous(Document* document) { | 470 LayoutGrid* LayoutGrid::createAnonymous(Document* document) { |
| 413 LayoutGrid* layoutGrid = new LayoutGrid(nullptr); | 471 LayoutGrid* layoutGrid = new LayoutGrid(nullptr); |
| 414 layoutGrid->setDocumentForAnonymous(document); | 472 layoutGrid->setDocumentForAnonymous(document); |
| 415 return layoutGrid; | 473 return layoutGrid; |
| 416 } | 474 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 oldStyle.gridAutoRepeatRows().size() != | 524 oldStyle.gridAutoRepeatRows().size() != |
| 467 styleRef().gridAutoRepeatRows().size(); | 525 styleRef().gridAutoRepeatRows().size(); |
| 468 } | 526 } |
| 469 | 527 |
| 470 bool LayoutGrid::namedGridLinesDefinitionDidChange( | 528 bool LayoutGrid::namedGridLinesDefinitionDidChange( |
| 471 const ComputedStyle& oldStyle) const { | 529 const ComputedStyle& oldStyle) const { |
| 472 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || | 530 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || |
| 473 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); | 531 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); |
| 474 } | 532 } |
| 475 | 533 |
| 476 size_t LayoutGrid::gridColumnCount() const { | |
| 477 DCHECK(!m_gridIsDirty); | |
| 478 return m_grid.numColumns(); | |
| 479 } | |
| 480 | |
| 481 size_t LayoutGrid::gridRowCount() const { | |
| 482 DCHECK(!m_gridIsDirty); | |
| 483 return m_grid.numRows(); | |
| 484 } | |
| 485 | |
| 486 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( | 534 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( |
| 487 const GridSizingData& sizingData) const { | 535 const GridSizingData& sizingData) const { |
| 488 LayoutUnit logicalHeight; | 536 LayoutUnit logicalHeight; |
| 489 | 537 |
| 490 for (const auto& row : sizingData.rowTracks) | 538 for (const auto& row : sizingData.rowTracks) |
| 491 logicalHeight += row.baseSize(); | 539 logicalHeight += row.baseSize(); |
| 492 | 540 |
| 493 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), | 541 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), |
| 494 sizingData.sizingOperation); | 542 sizingData.sizingOperation); |
| 495 | 543 |
| 496 return logicalHeight; | 544 return logicalHeight; |
| 497 } | 545 } |
| 498 | 546 |
| 499 void LayoutGrid::computeTrackSizesForDefiniteSize( | 547 void LayoutGrid::computeTrackSizesForDefiniteSize( |
| 500 GridTrackSizingDirection direction, | 548 GridTrackSizingDirection direction, |
| 501 GridSizingData& sizingData, | 549 GridSizingData& sizingData, |
| 502 LayoutUnit availableSpace) const { | 550 LayoutUnit availableSpace) const { |
| 503 DCHECK(sizingData.isValidTransition(direction)); | 551 DCHECK(sizingData.isValidTransition(direction)); |
| 504 sizingData.setAvailableSpace(availableSpace); | 552 sizingData.setAvailableSpace(availableSpace); |
| 505 sizingData.freeSpace(direction) = | 553 sizingData.freeSpace(direction) = |
| 506 availableSpace - | 554 availableSpace - guttersSize(direction, 0, m_grid.numTracks(direction), |
| 507 guttersSize(direction, 0, | 555 sizingData.sizingOperation); |
| 508 direction == ForRows ? gridRowCount() : gridColumnCount(), | |
| 509 sizingData.sizingOperation); | |
| 510 sizingData.sizingOperation = TrackSizing; | 556 sizingData.sizingOperation = TrackSizing; |
| 511 | 557 |
| 512 LayoutUnit baseSizes, growthLimits; | 558 LayoutUnit baseSizes, growthLimits; |
| 513 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, | 559 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, |
| 514 growthLimits); | 560 growthLimits); |
| 515 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 561 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
| 516 sizingData.nextState(); | 562 sizingData.nextState(); |
| 517 } | 563 } |
| 518 | 564 |
| 519 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, | 565 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 } | 619 } |
| 574 | 620 |
| 575 updateLogicalWidth(); | 621 updateLogicalWidth(); |
| 576 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight(); | 622 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight(); |
| 577 | 623 |
| 578 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); | 624 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); |
| 579 | 625 |
| 580 // TODO(svillar): we won't need to do this once the intrinsic width | 626 // TODO(svillar): we won't need to do this once the intrinsic width |
| 581 // computation is isolated from the LayoutGrid object state (it should not | 627 // computation is isolated from the LayoutGrid object state (it should not |
| 582 // touch any attribute) (see crbug.com/627812) | 628 // touch any attribute) (see crbug.com/627812) |
| 583 if (m_autoRepeatColumns && | 629 size_t autoRepeatColumns = m_grid.autoRepeatTracks(ForColumns); |
| 584 m_autoRepeatColumns != | 630 if (autoRepeatColumns && |
| 631 autoRepeatColumns != | |
| 585 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) | 632 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) |
| 586 dirtyGrid(); | 633 dirtyGrid(); |
| 587 placeItemsOnGrid(TrackSizing); | 634 placeItemsOnGrid(TrackSizing); |
| 588 | 635 |
| 589 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); | 636 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); |
| 590 | 637 |
| 591 // 1- First, the track sizing algorithm is used to resolve the sizes of the | 638 // 1- First, the track sizing algorithm is used to resolve the sizes of the |
| 592 // grid columns. | 639 // grid columns. |
| 593 // At this point the logical width is always definite as the above call to | 640 // At this point the logical width is always definite as the above call to |
| 594 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the | 641 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 | 695 |
| 649 computeOverflow(oldClientAfterEdge); | 696 computeOverflow(oldClientAfterEdge); |
| 650 } | 697 } |
| 651 | 698 |
| 652 updateLayerTransformAfterLayout(); | 699 updateLayerTransformAfterLayout(); |
| 653 updateAfterLayout(); | 700 updateAfterLayout(); |
| 654 | 701 |
| 655 clearNeedsLayout(); | 702 clearNeedsLayout(); |
| 656 } | 703 } |
| 657 | 704 |
| 658 bool LayoutGrid::hasAutoRepeatEmptyTracks( | |
| 659 GridTrackSizingDirection direction) const { | |
| 660 return direction == ForColumns ? !!m_autoRepeatEmptyColumns | |
| 661 : !!m_autoRepeatEmptyRows; | |
| 662 } | |
| 663 | |
| 664 bool LayoutGrid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, | |
| 665 size_t line) const { | |
| 666 DCHECK(hasAutoRepeatEmptyTracks(direction)); | |
| 667 return direction == ForColumns ? m_autoRepeatEmptyColumns->contains(line) | |
| 668 : m_autoRepeatEmptyRows->contains(line); | |
| 669 } | |
| 670 | |
| 671 LayoutUnit LayoutGrid::gridGapForDirection( | 705 LayoutUnit LayoutGrid::gridGapForDirection( |
| 672 GridTrackSizingDirection direction, | 706 GridTrackSizingDirection direction, |
| 673 SizingOperation sizingOperation) const { | 707 SizingOperation sizingOperation) const { |
| 674 LayoutUnit availableSize; | 708 LayoutUnit availableSize; |
| 675 const Length& gap = direction == ForColumns ? styleRef().gridColumnGap() | 709 const Length& gap = direction == ForColumns ? styleRef().gridColumnGap() |
| 676 : styleRef().gridRowGap(); | 710 : styleRef().gridRowGap(); |
| 677 if (sizingOperation == TrackSizing && gap.isPercent()) | 711 if (sizingOperation == TrackSizing && gap.isPercent()) |
| 678 availableSize = direction == ForColumns | 712 availableSize = direction == ForColumns |
| 679 ? availableLogicalWidth() | 713 ? availableLogicalWidth() |
| 680 : availableLogicalHeightForPercentageComputation(); | 714 : availableLogicalHeightForPercentageComputation(); |
| 681 | 715 |
| 682 // TODO(rego): Maybe we could cache the computed percentage as a performance | 716 // TODO(rego): Maybe we could cache the computed percentage as a performance |
| 683 // improvement. | 717 // improvement. |
| 684 return valueForLength(gap, availableSize); | 718 return valueForLength(gap, availableSize); |
| 685 } | 719 } |
| 686 | 720 |
| 687 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, | 721 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, |
| 688 size_t startLine, | 722 size_t startLine, |
| 689 size_t span, | 723 size_t span, |
| 690 SizingOperation sizingOperation) const { | 724 SizingOperation sizingOperation) const { |
| 691 if (span <= 1) | 725 if (span <= 1) |
| 692 return LayoutUnit(); | 726 return LayoutUnit(); |
| 693 | 727 |
| 694 bool isRowAxis = direction == ForColumns; | |
| 695 LayoutUnit gap = gridGapForDirection(direction, sizingOperation); | 728 LayoutUnit gap = gridGapForDirection(direction, sizingOperation); |
| 696 | 729 |
| 697 // Fast path, no collapsing tracks. | 730 // Fast path, no collapsing tracks. |
| 698 if (!hasAutoRepeatEmptyTracks(direction)) | 731 if (!m_grid.hasAutoRepeatEmptyTracks(direction)) |
| 699 return gap * (span - 1); | 732 return gap * (span - 1); |
| 700 | 733 |
| 701 // If there are collapsing tracks we need to be sure that gutters are properly | 734 // If there are collapsing tracks we need to be sure that gutters are properly |
| 702 // collapsed. Apart from that, if we have a collapsed track in the edges of | 735 // collapsed. Apart from that, if we have a collapsed track in the edges of |
| 703 // the span we're considering, we need to move forward (or backwards) in order | 736 // the span we're considering, we need to move forward (or backwards) in order |
| 704 // to know whether the collapsed tracks reach the end of the grid (so the gap | 737 // to know whether the collapsed tracks reach the end of the grid (so the gap |
| 705 // becomes 0) or there is a non empty track before that. | 738 // becomes 0) or there is a non empty track before that. |
| 706 | 739 |
| 707 LayoutUnit gapAccumulator; | 740 LayoutUnit gapAccumulator; |
| 708 size_t endLine = startLine + span; | 741 size_t endLine = startLine + span; |
| 709 | 742 |
| 710 for (size_t line = startLine; line < endLine - 1; ++line) { | 743 for (size_t line = startLine; line < endLine - 1; ++line) { |
| 711 if (!isEmptyAutoRepeatTrack(direction, line)) | 744 if (!m_grid.isEmptyAutoRepeatTrack(direction, line)) |
| 712 gapAccumulator += gap; | 745 gapAccumulator += gap; |
| 713 } | 746 } |
| 714 | 747 |
| 715 // The above loop adds one extra gap for trailing collapsed tracks. | 748 // The above loop adds one extra gap for trailing collapsed tracks. |
| 716 if (gapAccumulator && isEmptyAutoRepeatTrack(direction, endLine - 1)) { | 749 if (gapAccumulator && m_grid.isEmptyAutoRepeatTrack(direction, endLine - 1)) { |
| 717 DCHECK_GE(gapAccumulator, gap); | 750 DCHECK_GE(gapAccumulator, gap); |
| 718 gapAccumulator -= gap; | 751 gapAccumulator -= gap; |
| 719 } | 752 } |
| 720 | 753 |
| 721 // If the startLine is the start line of a collapsed track we need to go | 754 // If the startLine is the start line of a collapsed track we need to go |
| 722 // backwards till we reach a non collapsed track. If we find a non collapsed | 755 // backwards till we reach a non collapsed track. If we find a non collapsed |
| 723 // track we need to add that gap. | 756 // track we need to add that gap. |
| 724 if (startLine && isEmptyAutoRepeatTrack(direction, startLine)) { | 757 if (startLine && m_grid.isEmptyAutoRepeatTrack(direction, startLine)) { |
| 725 size_t nonEmptyTracksBeforeStartLine = startLine; | 758 size_t nonEmptyTracksBeforeStartLine = startLine; |
| 726 auto begin = isRowAxis ? m_autoRepeatEmptyColumns->begin() | 759 auto begin = m_grid.autoRepeatEmptyTracks(direction)->begin(); |
| 727 : m_autoRepeatEmptyRows->begin(); | |
| 728 for (auto it = begin; *it != startLine; ++it) { | 760 for (auto it = begin; *it != startLine; ++it) { |
| 729 DCHECK(nonEmptyTracksBeforeStartLine); | 761 DCHECK(nonEmptyTracksBeforeStartLine); |
| 730 --nonEmptyTracksBeforeStartLine; | 762 --nonEmptyTracksBeforeStartLine; |
| 731 } | 763 } |
| 732 if (nonEmptyTracksBeforeStartLine) | 764 if (nonEmptyTracksBeforeStartLine) |
| 733 gapAccumulator += gap; | 765 gapAccumulator += gap; |
| 734 } | 766 } |
| 735 | 767 |
| 736 // If the endLine is the end line of a collapsed track we need to go forward | 768 // If the endLine is the end line of a collapsed track we need to go forward |
| 737 // till we reach a non collapsed track. If we find a non collapsed track we | 769 // till we reach a non collapsed track. If we find a non collapsed track we |
| 738 // need to add that gap. | 770 // need to add that gap. |
| 739 if (isEmptyAutoRepeatTrack(direction, endLine - 1)) { | 771 if (m_grid.isEmptyAutoRepeatTrack(direction, endLine - 1)) { |
| 740 size_t nonEmptyTracksAfterEndLine = | 772 size_t nonEmptyTracksAfterEndLine = m_grid.numTracks(direction) - endLine; |
| 741 (isRowAxis ? gridColumnCount() : gridRowCount()) - endLine; | 773 auto currentEmptyTrack = |
| 742 auto currentEmptyTrack = isRowAxis | 774 m_grid.autoRepeatEmptyTracks(direction)->find(endLine - 1); |
| 743 ? m_autoRepeatEmptyColumns->find(endLine - 1) | 775 auto endEmptyTrack = m_grid.autoRepeatEmptyTracks(direction)->end(); |
| 744 : m_autoRepeatEmptyRows->find(endLine - 1); | |
| 745 auto endEmptyTrack = isRowAxis ? m_autoRepeatEmptyColumns->end() | |
| 746 : m_autoRepeatEmptyRows->end(); | |
| 747 // HashSet iterators do not implement operator- so we have to manually | 776 // HashSet iterators do not implement operator- so we have to manually |
| 748 // iterate to know the number of remaining empty tracks. | 777 // iterate to know the number of remaining empty tracks. |
| 749 for (auto it = ++currentEmptyTrack; it != endEmptyTrack; ++it) { | 778 for (auto it = ++currentEmptyTrack; it != endEmptyTrack; ++it) { |
| 750 DCHECK(nonEmptyTracksAfterEndLine); | 779 DCHECK(nonEmptyTracksAfterEndLine); |
| 751 --nonEmptyTracksAfterEndLine; | 780 --nonEmptyTracksAfterEndLine; |
| 752 } | 781 } |
| 753 if (nonEmptyTracksAfterEndLine) | 782 if (nonEmptyTracksAfterEndLine) |
| 754 gapAccumulator += gap; | 783 gapAccumulator += gap; |
| 755 } | 784 } |
| 756 | 785 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 flexFraction = std::max( | 953 flexFraction = std::max( |
| 925 flexFraction, | 954 flexFraction, |
| 926 normalizedFlexFraction( | 955 normalizedFlexFraction( |
| 927 tracks[trackIndex], | 956 tracks[trackIndex], |
| 928 gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); | 957 gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); |
| 929 | 958 |
| 930 if (m_grid.hasInFlowGridItems()) { | 959 if (m_grid.hasInFlowGridItems()) { |
| 931 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 960 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
| 932 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); | 961 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); |
| 933 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 962 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 934 const GridSpan span = cachedGridSpan(*gridItem, direction); | 963 const GridSpan span = m_grid.gridItemSpan(*gridItem, direction); |
|
jfernandez
2016/11/24 17:28:14
Why not using const GridSpan& span like you do som
svillar
2016/11/25 12:31:42
I'm not changing that, it was in the original code
| |
| 935 | 964 |
| 936 // Do not include already processed items. | 965 // Do not include already processed items. |
| 937 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) | 966 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) |
| 938 continue; | 967 continue; |
| 939 | 968 |
| 940 flexFraction = std::max( | 969 flexFraction = std::max( |
| 941 flexFraction, | 970 flexFraction, |
| 942 findFlexFactorUnitSize( | 971 findFlexFactorUnitSize( |
| 943 tracks, span, direction, | 972 tracks, span, direction, |
| 944 maxContentForChild(*gridItem, direction, sizingData))); | 973 maxContentForChild(*gridItem, direction, sizingData))); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 965 | 994 |
| 966 // Redo the flex fraction computation using min|max-height as definite | 995 // Redo the flex fraction computation using min|max-height as definite |
| 967 // available space in case the total height is smaller than min-height or | 996 // available space in case the total height is smaller than min-height or |
| 968 // larger than max-height. | 997 // larger than max-height. |
| 969 LayoutUnit rowsSize = | 998 LayoutUnit rowsSize = |
| 970 totalGrowth + computeTrackBasedLogicalHeight(sizingData); | 999 totalGrowth + computeTrackBasedLogicalHeight(sizingData); |
| 971 bool checkMinSize = minSize && rowsSize < minSize; | 1000 bool checkMinSize = minSize && rowsSize < minSize; |
| 972 bool checkMaxSize = maxSize != -1 && rowsSize > maxSize; | 1001 bool checkMaxSize = maxSize != -1 && rowsSize > maxSize; |
| 973 if (checkMinSize || checkMaxSize) { | 1002 if (checkMinSize || checkMaxSize) { |
| 974 LayoutUnit freeSpace = checkMaxSize ? maxSize : LayoutUnit(-1); | 1003 LayoutUnit freeSpace = checkMaxSize ? maxSize : LayoutUnit(-1); |
| 975 freeSpace = | 1004 freeSpace = std::max(freeSpace, minSize) - |
| 976 std::max(freeSpace, minSize) - | 1005 guttersSize(ForRows, 0, m_grid.numTracks(ForRows), |
| 977 guttersSize(ForRows, 0, gridRowCount(), sizingData.sizingOperation); | 1006 sizingData.sizingOperation); |
| 978 | 1007 |
| 979 flexFraction = findFlexFactorUnitSize( | 1008 flexFraction = findFlexFactorUnitSize( |
| 980 tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), | 1009 tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), |
| 981 ForRows, freeSpace); | 1010 ForRows, freeSpace); |
| 982 | 1011 |
| 983 totalGrowth = LayoutUnit(0); | 1012 totalGrowth = LayoutUnit(0); |
| 984 computeFlexSizedTracksGrowth(ForRows, tracks, flexibleSizedTracksIndex, | 1013 computeFlexSizedTracksGrowth(ForRows, tracks, flexibleSizedTracksIndex, |
| 985 flexFraction, increments, totalGrowth); | 1014 flexFraction, increments, totalGrowth); |
| 986 } | 1015 } |
| 987 } | 1016 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1202 autoRepeatTrackStyles.size()]; | 1231 autoRepeatTrackStyles.size()]; |
| 1203 } | 1232 } |
| 1204 | 1233 |
| 1205 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; | 1234 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; |
| 1206 } | 1235 } |
| 1207 | 1236 |
| 1208 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, | 1237 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, |
| 1209 size_t translatedIndex, | 1238 size_t translatedIndex, |
| 1210 SizingOperation sizingOperation) const { | 1239 SizingOperation sizingOperation) const { |
| 1211 // Collapse empty auto repeat tracks if auto-fit. | 1240 // Collapse empty auto repeat tracks if auto-fit. |
| 1212 if (hasAutoRepeatEmptyTracks(direction) && | 1241 if (m_grid.hasAutoRepeatEmptyTracks(direction) && |
| 1213 isEmptyAutoRepeatTrack(direction, translatedIndex)) | 1242 m_grid.isEmptyAutoRepeatTrack(direction, translatedIndex)) |
| 1214 return {Length(Fixed), LengthTrackSizing}; | 1243 return {Length(Fixed), LengthTrackSizing}; |
| 1215 | 1244 |
| 1216 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex); | 1245 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex); |
| 1217 if (trackSize.isFitContent()) | 1246 if (trackSize.isFitContent()) |
| 1218 return trackSize; | 1247 return trackSize; |
| 1219 | 1248 |
| 1220 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 1249 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
| 1221 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 1250 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
| 1222 // If the logical width/height of the grid container is indefinite, percentage | 1251 // If the logical width/height of the grid container is indefinite, percentage |
| 1223 // values are treated as <auto>. | 1252 // values are treated as <auto>. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1454 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 1483 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
| 1455 if (m_grid.hasInFlowGridItems()) { | 1484 if (m_grid.hasInFlowGridItems()) { |
| 1456 HashSet<LayoutBox*> itemsSet; | 1485 HashSet<LayoutBox*> itemsSet; |
| 1457 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1486 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 1458 GridIterator iterator(m_grid, direction, trackIndex); | 1487 GridIterator iterator(m_grid, direction, trackIndex); |
| 1459 GridTrack& track = (direction == ForColumns) | 1488 GridTrack& track = (direction == ForColumns) |
| 1460 ? sizingData.columnTracks[trackIndex] | 1489 ? sizingData.columnTracks[trackIndex] |
| 1461 : sizingData.rowTracks[trackIndex]; | 1490 : sizingData.rowTracks[trackIndex]; |
| 1462 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 1491 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 1463 if (itemsSet.add(gridItem).isNewEntry) { | 1492 if (itemsSet.add(gridItem).isNewEntry) { |
| 1464 const GridSpan& span = cachedGridSpan(*gridItem, direction); | 1493 const GridSpan& span = m_grid.gridItemSpan(*gridItem, direction); |
| 1465 if (span.integerSpan() == 1) { | 1494 if (span.integerSpan() == 1) { |
| 1466 resolveContentBasedTrackSizingFunctionsForNonSpanningItems( | 1495 resolveContentBasedTrackSizingFunctionsForNonSpanningItems( |
| 1467 direction, span, *gridItem, track, sizingData); | 1496 direction, span, *gridItem, track, sizingData); |
| 1468 } else if (!spanningItemCrossesFlexibleSizedTracks( | 1497 } else if (!spanningItemCrossesFlexibleSizedTracks( |
| 1469 span, direction, sizingData.sizingOperation)) { | 1498 span, direction, sizingData.sizingOperation)) { |
| 1470 sizingData.itemsSortedByIncreasingSpan.append( | 1499 sizingData.itemsSortedByIncreasingSpan.append( |
| 1471 GridItemWithSpan(*gridItem, span)); | 1500 GridItemWithSpan(*gridItem, span)); |
| 1472 } | 1501 } |
| 1473 } | 1502 } |
| 1474 } | 1503 } |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2009 } | 2038 } |
| 2010 return emptyTrackIndexes; | 2039 return emptyTrackIndexes; |
| 2011 } | 2040 } |
| 2012 | 2041 |
| 2013 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) { | 2042 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) { |
| 2014 if (!m_gridIsDirty) | 2043 if (!m_gridIsDirty) |
| 2015 return; | 2044 return; |
| 2016 | 2045 |
| 2017 DCHECK(!m_grid.hasInFlowGridItems()); | 2046 DCHECK(!m_grid.hasInFlowGridItems()); |
| 2018 | 2047 |
| 2048 size_t autoRepeatColumns; | |
|
jfernandez
2016/11/24 17:28:14
I guess it's not that important, but we could save
svillar
2016/11/25 12:31:42
Yeah I like the ternary too. The thing is that wit
| |
| 2049 size_t autoRepeatRows = | |
| 2050 computeAutoRepeatTracksCount(ForRows, sizingOperation); | |
| 2019 if (sizingOperation == IntrinsicSizeComputation) { | 2051 if (sizingOperation == IntrinsicSizeComputation) { |
| 2020 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); | 2052 autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); |
| 2021 } else { | 2053 } else { |
| 2022 m_autoRepeatColumns = | 2054 autoRepeatColumns = |
| 2023 computeAutoRepeatTracksCount(ForColumns, sizingOperation); | 2055 computeAutoRepeatTracksCount(ForColumns, sizingOperation); |
| 2024 } | 2056 } |
| 2025 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation); | 2057 m_grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); |
| 2026 | 2058 |
| 2027 populateExplicitGridAndOrderIterator(); | 2059 populateExplicitGridAndOrderIterator(); |
| 2028 | 2060 |
| 2029 // We clear the dirty bit here as the grid sizes have been updated. | 2061 // We clear the dirty bit here as the grid sizes have been updated. |
| 2030 m_gridIsDirty = false; | 2062 m_gridIsDirty = false; |
| 2031 | 2063 |
| 2032 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 2064 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
| 2033 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 2065 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
| 2034 #if ENABLE(ASSERT) | 2066 #if ENABLE(ASSERT) |
| 2035 DCHECK(!m_grid.hasAnyGridItemPaintOrder()); | 2067 DCHECK(!m_grid.hasAnyGridItemPaintOrder()); |
| 2036 #endif | 2068 #endif |
| 2037 DCHECK(!m_grid.hasAnyOrthogonalChildren()); | 2069 DCHECK(!m_grid.hasAnyOrthogonalChildren()); |
| 2038 size_t childIndex = 0; | 2070 size_t childIndex = 0; |
| 2039 for (LayoutBox* child = m_orderIterator.first(); child; | 2071 for (LayoutBox* child = m_grid.orderIterator().first(); child; |
| 2040 child = m_orderIterator.next()) { | 2072 child = m_grid.orderIterator().next()) { |
| 2041 if (child->isOutOfFlowPositioned()) | 2073 if (child->isOutOfFlowPositioned()) |
| 2042 continue; | 2074 continue; |
| 2043 | 2075 |
| 2044 m_grid.setGridItemPaintOrder(*child, childIndex++); | 2076 m_grid.setGridItemPaintOrder(*child, childIndex++); |
| 2045 | 2077 |
| 2046 GridArea area = m_grid.gridItemArea(*child); | 2078 GridArea area = m_grid.gridItemArea(*child); |
| 2047 if (!area.rows.isIndefinite()) | 2079 if (!area.rows.isIndefinite()) |
| 2048 area.rows.translate(abs(m_grid.smallestTrackStart(ForRows))); | 2080 area.rows.translate(abs(m_grid.smallestTrackStart(ForRows))); |
| 2049 if (!area.columns.isIndefinite()) | 2081 if (!area.columns.isIndefinite()) |
| 2050 area.columns.translate(abs(m_grid.smallestTrackStart(ForColumns))); | 2082 area.columns.translate(abs(m_grid.smallestTrackStart(ForColumns))); |
| 2051 | 2083 |
| 2052 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 2084 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 2053 m_grid.setGridItemArea(*child, area); | 2085 m_grid.setGridItemArea(*child, area); |
| 2054 GridSpan majorAxisPositions = | 2086 GridSpan majorAxisPositions = |
| 2055 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns | 2087 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns |
| 2056 : area.rows; | 2088 : area.rows; |
| 2057 if (majorAxisPositions.isIndefinite()) | 2089 if (majorAxisPositions.isIndefinite()) |
| 2058 autoMajorAxisAutoGridItems.append(child); | 2090 autoMajorAxisAutoGridItems.append(child); |
| 2059 else | 2091 else |
| 2060 specifiedMajorAxisAutoGridItems.append(child); | 2092 specifiedMajorAxisAutoGridItems.append(child); |
| 2061 continue; | 2093 continue; |
| 2062 } | 2094 } |
| 2063 m_grid.insert(*child, area, isOrthogonalChild(*child)); | 2095 m_grid.insert(*child, area, isOrthogonalChild(*child)); |
| 2064 } | 2096 } |
| 2065 | 2097 |
| 2066 #if ENABLE(ASSERT) | 2098 #if ENABLE(ASSERT) |
| 2067 if (m_grid.hasInFlowGridItems()) { | 2099 if (m_grid.hasInFlowGridItems()) { |
| 2068 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( | 2100 DCHECK_GE(m_grid.numTracks(ForRows), |
| 2069 *style(), m_autoRepeatRows)); | 2101 GridPositionsResolver::explicitGridRowCount( |
| 2070 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( | 2102 *style(), m_grid.autoRepeatTracks(ForRows))); |
| 2071 *style(), m_autoRepeatColumns)); | 2103 DCHECK_GE(m_grid.numTracks(ForColumns), |
| 2104 GridPositionsResolver::explicitGridColumnCount( | |
| 2105 *style(), m_grid.autoRepeatTracks(ForColumns))); | |
| 2072 } | 2106 } |
| 2073 #endif | 2107 #endif |
| 2074 | 2108 |
| 2075 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 2109 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 2076 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 2110 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 2077 | 2111 |
| 2078 m_grid.shrinkToFit(); | 2112 m_grid.shrinkToFit(); |
| 2079 | 2113 |
| 2080 // Compute collapsable tracks for auto-fit. | 2114 // Compute collapsable tracks for auto-fit. |
| 2081 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); | 2115 m_grid.setAutoRepeatEmptyColumns(computeEmptyTracksForAutoRepeat(ForColumns)); |
| 2082 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); | 2116 m_grid.setAutoRepeatEmptyRows(computeEmptyTracksForAutoRepeat(ForRows)); |
| 2083 | 2117 |
| 2084 #if ENABLE(ASSERT) | 2118 #if ENABLE(ASSERT) |
| 2085 for (LayoutBox* child = m_orderIterator.first(); child; | 2119 for (LayoutBox* child = m_grid.orderIterator().first(); child; |
| 2086 child = m_orderIterator.next()) { | 2120 child = m_grid.orderIterator().next()) { |
| 2087 if (child->isOutOfFlowPositioned()) | 2121 if (child->isOutOfFlowPositioned()) |
| 2088 continue; | 2122 continue; |
| 2089 | 2123 |
| 2090 GridArea area = m_grid.gridItemArea(*child); | 2124 GridArea area = m_grid.gridItemArea(*child); |
| 2091 ASSERT(area.rows.isTranslatedDefinite() && | 2125 ASSERT(area.rows.isTranslatedDefinite() && |
| 2092 area.columns.isTranslatedDefinite()); | 2126 area.columns.isTranslatedDefinite()); |
| 2093 } | 2127 } |
| 2094 #endif | 2128 #endif |
| 2095 } | 2129 } |
| 2096 | 2130 |
| 2097 void LayoutGrid::populateExplicitGridAndOrderIterator() { | 2131 void LayoutGrid::populateExplicitGridAndOrderIterator() { |
| 2098 OrderIteratorPopulator populator(m_orderIterator); | 2132 OrderIteratorPopulator populator(m_grid.orderIterator()); |
| 2099 int smallestRowStart = 0; | 2133 int smallestRowStart = 0; |
| 2100 int smallestColumnStart = 0; | 2134 int smallestColumnStart = 0; |
| 2101 | 2135 |
| 2136 size_t autoRepeatRows = m_grid.autoRepeatTracks(ForRows); | |
| 2137 size_t autoRepeatColumns = m_grid.autoRepeatTracks(ForColumns); | |
| 2102 size_t maximumRowIndex = | 2138 size_t maximumRowIndex = |
| 2103 GridPositionsResolver::explicitGridRowCount(*style(), m_autoRepeatRows); | 2139 GridPositionsResolver::explicitGridRowCount(*style(), autoRepeatRows); |
| 2104 size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount( | 2140 size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount( |
| 2105 *style(), m_autoRepeatColumns); | 2141 *style(), autoRepeatColumns); |
| 2106 | 2142 |
| 2107 for (LayoutBox* child = firstInFlowChildBox(); child; | 2143 for (LayoutBox* child = firstInFlowChildBox(); child; |
| 2108 child = child->nextInFlowSiblingBox()) { | 2144 child = child->nextInFlowSiblingBox()) { |
| 2109 populator.collectChild(child); | 2145 populator.collectChild(child); |
| 2110 | 2146 |
| 2111 // This function bypasses the cache (gridItemArea()) as it is used to | 2147 // This function bypasses the cache (gridItemArea()) as it is used to |
| 2112 // build it. | 2148 // build it. |
| 2113 GridSpan rowPositions = | 2149 GridSpan rowPositions = |
| 2114 GridPositionsResolver::resolveGridPositionsFromStyle( | 2150 GridPositionsResolver::resolveGridPositionsFromStyle( |
| 2115 *style(), *child, ForRows, m_autoRepeatRows); | 2151 *style(), *child, ForRows, autoRepeatRows); |
| 2116 GridSpan columnPositions = | 2152 GridSpan columnPositions = |
| 2117 GridPositionsResolver::resolveGridPositionsFromStyle( | 2153 GridPositionsResolver::resolveGridPositionsFromStyle( |
| 2118 *style(), *child, ForColumns, m_autoRepeatColumns); | 2154 *style(), *child, ForColumns, autoRepeatColumns); |
| 2119 m_grid.setGridItemArea(*child, GridArea(rowPositions, columnPositions)); | 2155 m_grid.setGridItemArea(*child, GridArea(rowPositions, columnPositions)); |
| 2120 | 2156 |
| 2121 // |positions| is 0 if we need to run the auto-placement algorithm. | 2157 // |positions| is 0 if we need to run the auto-placement algorithm. |
| 2122 if (!rowPositions.isIndefinite()) { | 2158 if (!rowPositions.isIndefinite()) { |
| 2123 smallestRowStart = | 2159 smallestRowStart = |
| 2124 std::min(smallestRowStart, rowPositions.untranslatedStartLine()); | 2160 std::min(smallestRowStart, rowPositions.untranslatedStartLine()); |
| 2125 maximumRowIndex = | 2161 maximumRowIndex = |
| 2126 std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine()); | 2162 std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine()); |
| 2127 } else { | 2163 } else { |
| 2128 // Grow the grid for items with a definite row span, getting the largest | 2164 // Grow the grid for items with a definite row span, getting the largest |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2151 maximumColumnIndex + abs(smallestColumnStart)); | 2187 maximumColumnIndex + abs(smallestColumnStart)); |
| 2152 } | 2188 } |
| 2153 | 2189 |
| 2154 std::unique_ptr<GridArea> | 2190 std::unique_ptr<GridArea> |
| 2155 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2191 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2156 const LayoutBox& gridItem, | 2192 const LayoutBox& gridItem, |
| 2157 GridTrackSizingDirection specifiedDirection, | 2193 GridTrackSizingDirection specifiedDirection, |
| 2158 const GridSpan& specifiedPositions) const { | 2194 const GridSpan& specifiedPositions) const { |
| 2159 GridTrackSizingDirection crossDirection = | 2195 GridTrackSizingDirection crossDirection = |
| 2160 specifiedDirection == ForColumns ? ForRows : ForColumns; | 2196 specifiedDirection == ForColumns ? ForRows : ForColumns; |
| 2161 const size_t endOfCrossDirection = | 2197 const size_t endOfCrossDirection = m_grid.numTracks(crossDirection); |
| 2162 crossDirection == ForColumns ? gridColumnCount() : gridRowCount(); | |
| 2163 size_t crossDirectionSpanSize = | 2198 size_t crossDirectionSpanSize = |
| 2164 GridPositionsResolver::spanSizeForAutoPlacedItem(*style(), gridItem, | 2199 GridPositionsResolver::spanSizeForAutoPlacedItem(*style(), gridItem, |
| 2165 crossDirection); | 2200 crossDirection); |
| 2166 GridSpan crossDirectionPositions = GridSpan::translatedDefiniteGridSpan( | 2201 GridSpan crossDirectionPositions = GridSpan::translatedDefiniteGridSpan( |
| 2167 endOfCrossDirection, endOfCrossDirection + crossDirectionSpanSize); | 2202 endOfCrossDirection, endOfCrossDirection + crossDirectionSpanSize); |
| 2168 return wrapUnique( | 2203 return wrapUnique( |
| 2169 new GridArea(specifiedDirection == ForColumns ? crossDirectionPositions | 2204 new GridArea(specifiedDirection == ForColumns ? crossDirectionPositions |
| 2170 : specifiedPositions, | 2205 : specifiedPositions, |
| 2171 specifiedDirection == ForColumns ? specifiedPositions | 2206 specifiedDirection == ForColumns ? specifiedPositions |
| 2172 : crossDirectionPositions)); | 2207 : crossDirectionPositions)); |
| 2173 } | 2208 } |
| 2174 | 2209 |
| 2175 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid( | 2210 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid( |
| 2176 const Vector<LayoutBox*>& autoGridItems) { | 2211 const Vector<LayoutBox*>& autoGridItems) { |
| 2177 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; | 2212 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; |
| 2178 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 2213 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 2179 | 2214 |
| 2180 // Mapping between the major axis tracks (rows or columns) and the last | 2215 // Mapping between the major axis tracks (rows or columns) and the last |
| 2181 // auto-placed item's position inserted on that track. This is needed to | 2216 // auto-placed item's position inserted on that track. This is needed to |
| 2182 // implement "sparse" packing for items locked to a given track. | 2217 // implement "sparse" packing for items locked to a given track. |
| 2183 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo | 2218 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo |
| 2184 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, | 2219 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, |
| 2185 WTF::UnsignedWithZeroKeyHashTraits<unsigned>> | 2220 WTF::UnsignedWithZeroKeyHashTraits<unsigned>> |
| 2186 minorAxisCursors; | 2221 minorAxisCursors; |
| 2187 | 2222 |
| 2188 for (const auto& autoGridItem : autoGridItems) { | 2223 for (const auto& autoGridItem : autoGridItems) { |
| 2189 GridSpan majorAxisPositions = | 2224 GridSpan majorAxisPositions = |
| 2190 cachedGridSpan(*autoGridItem, autoPlacementMajorAxisDirection()); | 2225 m_grid.gridItemSpan(*autoGridItem, autoPlacementMajorAxisDirection()); |
| 2191 ASSERT(majorAxisPositions.isTranslatedDefinite()); | 2226 ASSERT(majorAxisPositions.isTranslatedDefinite()); |
| 2192 ASSERT(!cachedGridSpan(*autoGridItem, autoPlacementMinorAxisDirection()) | 2227 DCHECK( |
| 2193 .isTranslatedDefinite()); | 2228 !m_grid.gridItemSpan(*autoGridItem, autoPlacementMinorAxisDirection()) |
| 2229 .isTranslatedDefinite()); | |
| 2194 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2230 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2195 *style(), *autoGridItem, autoPlacementMinorAxisDirection()); | 2231 *style(), *autoGridItem, autoPlacementMinorAxisDirection()); |
| 2196 unsigned majorAxisInitialPosition = majorAxisPositions.startLine(); | 2232 unsigned majorAxisInitialPosition = majorAxisPositions.startLine(); |
| 2197 | 2233 |
| 2198 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), | 2234 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), |
| 2199 majorAxisPositions.startLine(), | 2235 majorAxisPositions.startLine(), |
| 2200 isGridAutoFlowDense | 2236 isGridAutoFlowDense |
| 2201 ? 0 | 2237 ? 0 |
| 2202 : minorAxisCursors.get(majorAxisInitialPosition)); | 2238 : minorAxisCursors.get(majorAxisInitialPosition)); |
| 2203 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( | 2239 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2229 autoPlacementCursor.first = 0; | 2265 autoPlacementCursor.first = 0; |
| 2230 autoPlacementCursor.second = 0; | 2266 autoPlacementCursor.second = 0; |
| 2231 } | 2267 } |
| 2232 } | 2268 } |
| 2233 } | 2269 } |
| 2234 | 2270 |
| 2235 void LayoutGrid::placeAutoMajorAxisItemOnGrid( | 2271 void LayoutGrid::placeAutoMajorAxisItemOnGrid( |
| 2236 LayoutBox& gridItem, | 2272 LayoutBox& gridItem, |
| 2237 std::pair<size_t, size_t>& autoPlacementCursor) { | 2273 std::pair<size_t, size_t>& autoPlacementCursor) { |
| 2238 GridSpan minorAxisPositions = | 2274 GridSpan minorAxisPositions = |
| 2239 cachedGridSpan(gridItem, autoPlacementMinorAxisDirection()); | 2275 m_grid.gridItemSpan(gridItem, autoPlacementMinorAxisDirection()); |
| 2240 ASSERT(!cachedGridSpan(gridItem, autoPlacementMajorAxisDirection()) | 2276 DCHECK(!m_grid.gridItemSpan(gridItem, autoPlacementMajorAxisDirection()) |
| 2241 .isTranslatedDefinite()); | 2277 .isTranslatedDefinite()); |
| 2242 size_t majorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2278 size_t majorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2243 *style(), gridItem, autoPlacementMajorAxisDirection()); | 2279 *style(), gridItem, autoPlacementMajorAxisDirection()); |
| 2244 | 2280 |
| 2245 const size_t endOfMajorAxis = | 2281 const size_t endOfMajorAxis = |
| 2246 (autoPlacementMajorAxisDirection() == ForColumns) ? gridColumnCount() | 2282 m_grid.numTracks(autoPlacementMajorAxisDirection()); |
| 2247 : gridRowCount(); | |
| 2248 size_t majorAxisAutoPlacementCursor = | 2283 size_t majorAxisAutoPlacementCursor = |
| 2249 autoPlacementMajorAxisDirection() == ForColumns | 2284 autoPlacementMajorAxisDirection() == ForColumns |
| 2250 ? autoPlacementCursor.second | 2285 ? autoPlacementCursor.second |
| 2251 : autoPlacementCursor.first; | 2286 : autoPlacementCursor.first; |
| 2252 size_t minorAxisAutoPlacementCursor = | 2287 size_t minorAxisAutoPlacementCursor = |
| 2253 autoPlacementMajorAxisDirection() == ForColumns | 2288 autoPlacementMajorAxisDirection() == ForColumns |
| 2254 ? autoPlacementCursor.first | 2289 ? autoPlacementCursor.first |
| 2255 : autoPlacementCursor.second; | 2290 : autoPlacementCursor.second; |
| 2256 | 2291 |
| 2257 std::unique_ptr<GridArea> emptyGridArea; | 2292 std::unique_ptr<GridArea> emptyGridArea; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2285 | 2320 |
| 2286 if (emptyGridArea) { | 2321 if (emptyGridArea) { |
| 2287 // Check that it fits in the minor axis direction, as we shouldn't grow | 2322 // Check that it fits in the minor axis direction, as we shouldn't grow |
| 2288 // in that direction here (it was already managed in | 2323 // in that direction here (it was already managed in |
| 2289 // populateExplicitGridAndOrderIterator()). | 2324 // populateExplicitGridAndOrderIterator()). |
| 2290 size_t minorAxisFinalPositionIndex = | 2325 size_t minorAxisFinalPositionIndex = |
| 2291 autoPlacementMinorAxisDirection() == ForColumns | 2326 autoPlacementMinorAxisDirection() == ForColumns |
| 2292 ? emptyGridArea->columns.endLine() | 2327 ? emptyGridArea->columns.endLine() |
| 2293 : emptyGridArea->rows.endLine(); | 2328 : emptyGridArea->rows.endLine(); |
| 2294 const size_t endOfMinorAxis = | 2329 const size_t endOfMinorAxis = |
| 2295 autoPlacementMinorAxisDirection() == ForColumns ? gridColumnCount() | 2330 m_grid.numTracks(autoPlacementMinorAxisDirection()); |
| 2296 : gridRowCount(); | |
| 2297 if (minorAxisFinalPositionIndex <= endOfMinorAxis) | 2331 if (minorAxisFinalPositionIndex <= endOfMinorAxis) |
| 2298 break; | 2332 break; |
| 2299 | 2333 |
| 2300 // Discard empty grid area as it does not fit in the minor axis | 2334 // Discard empty grid area as it does not fit in the minor axis |
| 2301 // direction. We don't need to create a new empty grid area yet as we | 2335 // direction. We don't need to create a new empty grid area yet as we |
| 2302 // might find a valid one in the next iteration. | 2336 // might find a valid one in the next iteration. |
| 2303 emptyGridArea = nullptr; | 2337 emptyGridArea = nullptr; |
| 2304 } | 2338 } |
| 2305 | 2339 |
| 2306 // As we're moving to the next track in the major axis we should reset the | 2340 // As we're moving to the next track in the major axis we should reset the |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2327 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { | 2361 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { |
| 2328 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 2362 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| 2329 } | 2363 } |
| 2330 | 2364 |
| 2331 void LayoutGrid::dirtyGrid() { | 2365 void LayoutGrid::dirtyGrid() { |
| 2332 if (m_gridIsDirty) | 2366 if (m_gridIsDirty) |
| 2333 return; | 2367 return; |
| 2334 | 2368 |
| 2335 m_grid.clear(); | 2369 m_grid.clear(); |
| 2336 m_gridItemsOverflowingGridArea.resize(0); | 2370 m_gridItemsOverflowingGridArea.resize(0); |
| 2337 m_autoRepeatColumns = 0; | |
| 2338 m_autoRepeatRows = 0; | |
| 2339 m_gridIsDirty = true; | 2371 m_gridIsDirty = true; |
| 2340 m_autoRepeatEmptyColumns = nullptr; | |
| 2341 m_autoRepeatEmptyRows = nullptr; | |
| 2342 } | 2372 } |
| 2343 | 2373 |
| 2344 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( | 2374 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( |
| 2345 GridTrackSizingDirection direction) const { | 2375 GridTrackSizingDirection direction) const { |
| 2346 bool isRowAxis = direction == ForColumns; | 2376 bool isRowAxis = direction == ForColumns; |
| 2347 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2377 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 2348 size_t numPositions = positions.size(); | 2378 size_t numPositions = positions.size(); |
| 2349 LayoutUnit offsetBetweenTracks = | 2379 LayoutUnit offsetBetweenTracks = |
| 2350 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2380 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 2351 | 2381 |
| 2352 Vector<LayoutUnit> tracks; | 2382 Vector<LayoutUnit> tracks; |
| 2353 if (numPositions < 2) | 2383 if (numPositions < 2) |
| 2354 return tracks; | 2384 return tracks; |
| 2355 | 2385 |
| 2356 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); | 2386 bool hasCollapsedTracks = m_grid.hasAutoRepeatEmptyTracks(direction); |
| 2357 LayoutUnit gap = !hasCollapsedTracks | 2387 LayoutUnit gap = !hasCollapsedTracks |
| 2358 ? gridGapForDirection(direction, TrackSizing) | 2388 ? gridGapForDirection(direction, TrackSizing) |
| 2359 : LayoutUnit(); | 2389 : LayoutUnit(); |
| 2360 tracks.reserveCapacity(numPositions - 1); | 2390 tracks.reserveCapacity(numPositions - 1); |
| 2361 for (size_t i = 0; i < numPositions - 2; ++i) | 2391 for (size_t i = 0; i < numPositions - 2; ++i) |
| 2362 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - gap); | 2392 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - gap); |
| 2363 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); | 2393 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); |
| 2364 | 2394 |
| 2365 if (!hasCollapsedTracks) | 2395 if (!hasCollapsedTracks) |
| 2366 return tracks; | 2396 return tracks; |
| 2367 | 2397 |
| 2368 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() | 2398 size_t remainingEmptyTracks = m_grid.autoRepeatEmptyTracks(direction)->size(); |
| 2369 : m_autoRepeatEmptyRows->size(); | |
| 2370 size_t lastLine = tracks.size(); | 2399 size_t lastLine = tracks.size(); |
| 2371 gap = gridGapForDirection(direction, TrackSizing); | 2400 gap = gridGapForDirection(direction, TrackSizing); |
| 2372 for (size_t i = 1; i < lastLine; ++i) { | 2401 for (size_t i = 1; i < lastLine; ++i) { |
| 2373 if (isEmptyAutoRepeatTrack(direction, i - 1)) { | 2402 if (m_grid.isEmptyAutoRepeatTrack(direction, i - 1)) { |
| 2374 --remainingEmptyTracks; | 2403 --remainingEmptyTracks; |
| 2375 } else { | 2404 } else { |
| 2376 // Remove the gap between consecutive non empty tracks. Remove it also | 2405 // Remove the gap between consecutive non empty tracks. Remove it also |
| 2377 // just once for an arbitrary number of empty tracks between two non empty | 2406 // just once for an arbitrary number of empty tracks between two non empty |
| 2378 // ones. | 2407 // ones. |
| 2379 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine - i); | 2408 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine - i); |
| 2380 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(direction, i)) | 2409 if (!allRemainingTracksAreEmpty || |
| 2410 !m_grid.isEmptyAutoRepeatTrack(direction, i)) | |
| 2381 tracks[i - 1] -= gap; | 2411 tracks[i - 1] -= gap; |
| 2382 } | 2412 } |
| 2383 } | 2413 } |
| 2384 | 2414 |
| 2385 return tracks; | 2415 return tracks; |
| 2386 } | 2416 } |
| 2387 | 2417 |
| 2388 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() { | 2418 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() { |
| 2389 static const StyleContentAlignmentData normalBehavior = { | 2419 static const StyleContentAlignmentData normalBehavior = { |
| 2390 ContentPositionNormal, ContentDistributionStretch}; | 2420 ContentPositionNormal, ContentDistributionStretch}; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2647 borderLogicalLeft(); | 2677 borderLogicalLeft(); |
| 2648 | 2678 |
| 2649 if (endLine > 0 && endLine < lastLine) { | 2679 if (endLine > 0 && endLine < lastLine) { |
| 2650 offset += guttersSize(direction, endLine - 1, 2, TrackSizing); | 2680 offset += guttersSize(direction, endLine - 1, 2, TrackSizing); |
| 2651 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2681 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 2652 } | 2682 } |
| 2653 } | 2683 } |
| 2654 } | 2684 } |
| 2655 } | 2685 } |
| 2656 | 2686 |
| 2657 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, | |
| 2658 GridTrackSizingDirection direction) const { | |
| 2659 GridArea area = m_grid.gridItemArea(gridItem); | |
| 2660 return direction == ForColumns ? area.columns : area.rows; | |
| 2661 } | |
| 2662 | |
| 2663 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild( | 2687 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild( |
| 2664 const LayoutBox& child, | 2688 const LayoutBox& child, |
| 2665 SizingOperation sizingOperation) const { | 2689 SizingOperation sizingOperation) const { |
| 2666 DCHECK(isOrthogonalChild(child)); | 2690 DCHECK(isOrthogonalChild(child)); |
| 2667 const GridSpan& span = cachedGridSpan(child, ForRows); | 2691 const GridSpan& span = m_grid.gridItemSpan(child, ForRows); |
| 2668 LayoutUnit gridAreaSize; | 2692 LayoutUnit gridAreaSize; |
| 2669 bool gridAreaIsIndefinite = false; | 2693 bool gridAreaIsIndefinite = false; |
| 2670 LayoutUnit containingBlockAvailableSize = | 2694 LayoutUnit containingBlockAvailableSize = |
| 2671 containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding); | 2695 containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding); |
| 2672 for (auto trackPosition : span) { | 2696 for (auto trackPosition : span) { |
| 2673 GridLength maxTrackSize = | 2697 GridLength maxTrackSize = |
| 2674 gridTrackSize(ForRows, trackPosition, sizingOperation) | 2698 gridTrackSize(ForRows, trackPosition, sizingOperation) |
| 2675 .maxTrackBreadth(); | 2699 .maxTrackBreadth(); |
| 2676 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) | 2700 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) |
| 2677 gridAreaIsIndefinite = true; | 2701 gridAreaIsIndefinite = true; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2695 // To determine the column track's size based on an orthogonal grid item we | 2719 // To determine the column track's size based on an orthogonal grid item we |
| 2696 // need it's logical height, which may depend on the row track's size. It's | 2720 // need it's logical height, which may depend on the row track's size. It's |
| 2697 // possible that the row tracks sizing logic has not been performed yet, so we | 2721 // possible that the row tracks sizing logic has not been performed yet, so we |
| 2698 // will need to do an estimation. | 2722 // will need to do an estimation. |
| 2699 if (direction == ForRows && | 2723 if (direction == ForRows && |
| 2700 sizingData.sizingState == GridSizingData::ColumnSizingFirstIteration) | 2724 sizingData.sizingState == GridSizingData::ColumnSizingFirstIteration) |
| 2701 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperation); | 2725 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperation); |
| 2702 | 2726 |
| 2703 const Vector<GridTrack>& tracks = | 2727 const Vector<GridTrack>& tracks = |
| 2704 direction == ForColumns ? sizingData.columnTracks : sizingData.rowTracks; | 2728 direction == ForColumns ? sizingData.columnTracks : sizingData.rowTracks; |
| 2705 const GridSpan& span = cachedGridSpan(child, direction); | 2729 const GridSpan& span = m_grid.gridItemSpan(child, direction); |
| 2706 LayoutUnit gridAreaBreadth; | 2730 LayoutUnit gridAreaBreadth; |
| 2707 for (const auto& trackPosition : span) | 2731 for (const auto& trackPosition : span) |
| 2708 gridAreaBreadth += tracks[trackPosition].baseSize(); | 2732 gridAreaBreadth += tracks[trackPosition].baseSize(); |
| 2709 | 2733 |
| 2710 gridAreaBreadth += | 2734 gridAreaBreadth += |
| 2711 guttersSize(direction, span.startLine(), span.integerSpan(), | 2735 guttersSize(direction, span.startLine(), span.integerSpan(), |
| 2712 sizingData.sizingOperation); | 2736 sizingData.sizingOperation); |
| 2713 | 2737 |
| 2714 return gridAreaBreadth; | 2738 return gridAreaBreadth; |
| 2715 } | 2739 } |
| 2716 | 2740 |
| 2717 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets( | 2741 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets( |
| 2718 const LayoutBox& child, | 2742 const LayoutBox& child, |
| 2719 GridTrackSizingDirection direction, | 2743 GridTrackSizingDirection direction, |
| 2720 const GridSizingData& sizingData) const { | 2744 const GridSizingData& sizingData) const { |
| 2721 // We need the cached value when available because Content Distribution | 2745 // We need the cached value when available because Content Distribution |
| 2722 // alignment properties may have some influence in the final grid area | 2746 // alignment properties may have some influence in the final grid area |
| 2723 // breadth. | 2747 // breadth. |
| 2724 const Vector<GridTrack>& tracks = (direction == ForColumns) | 2748 const Vector<GridTrack>& tracks = (direction == ForColumns) |
| 2725 ? sizingData.columnTracks | 2749 ? sizingData.columnTracks |
| 2726 : sizingData.rowTracks; | 2750 : sizingData.rowTracks; |
| 2727 const GridSpan& span = cachedGridSpan(child, direction); | 2751 const GridSpan& span = m_grid.gridItemSpan(child, direction); |
| 2728 const Vector<LayoutUnit>& linePositions = | 2752 const Vector<LayoutUnit>& linePositions = |
| 2729 (direction == ForColumns) ? m_columnPositions : m_rowPositions; | 2753 (direction == ForColumns) ? m_columnPositions : m_rowPositions; |
| 2730 LayoutUnit initialTrackPosition = linePositions[span.startLine()]; | 2754 LayoutUnit initialTrackPosition = linePositions[span.startLine()]; |
| 2731 LayoutUnit finalTrackPosition = linePositions[span.endLine() - 1]; | 2755 LayoutUnit finalTrackPosition = linePositions[span.endLine() - 1]; |
| 2732 // Track Positions vector stores the 'start' grid line of each track, so we | 2756 // Track Positions vector stores the 'start' grid line of each track, so we |
| 2733 // have to add last track's baseSize. | 2757 // have to add last track's baseSize. |
| 2734 return finalTrackPosition - initialTrackPosition + | 2758 return finalTrackPosition - initialTrackPosition + |
| 2735 tracks[span.endLine() - 1].baseSize(); | 2759 tracks[span.endLine() - 1].baseSize(); |
| 2736 } | 2760 } |
| 2737 | 2761 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2757 direction, sizingData.freeSpace(direction), numberOfTracks); | 2781 direction, sizingData.freeSpace(direction), numberOfTracks); |
| 2758 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2782 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 2759 positions.resize(numberOfLines); | 2783 positions.resize(numberOfLines); |
| 2760 auto borderAndPadding = | 2784 auto borderAndPadding = |
| 2761 isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore(); | 2785 isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore(); |
| 2762 positions[0] = borderAndPadding + offset.positionOffset; | 2786 positions[0] = borderAndPadding + offset.positionOffset; |
| 2763 if (numberOfLines > 1) { | 2787 if (numberOfLines > 1) { |
| 2764 // If we have collapsed tracks we just ignore gaps here and add them later | 2788 // If we have collapsed tracks we just ignore gaps here and add them later |
| 2765 // as we might not compute the gap between two consecutive tracks without | 2789 // as we might not compute the gap between two consecutive tracks without |
| 2766 // examining the surrounding ones. | 2790 // examining the surrounding ones. |
| 2767 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); | 2791 bool hasCollapsedTracks = m_grid.hasAutoRepeatEmptyTracks(direction); |
| 2768 LayoutUnit gap = | 2792 LayoutUnit gap = |
| 2769 !hasCollapsedTracks | 2793 !hasCollapsedTracks |
| 2770 ? gridGapForDirection(direction, sizingData.sizingOperation) | 2794 ? gridGapForDirection(direction, sizingData.sizingOperation) |
| 2771 : LayoutUnit(); | 2795 : LayoutUnit(); |
| 2772 size_t nextToLastLine = numberOfLines - 2; | 2796 size_t nextToLastLine = numberOfLines - 2; |
| 2773 for (size_t i = 0; i < nextToLastLine; ++i) | 2797 for (size_t i = 0; i < nextToLastLine; ++i) |
| 2774 positions[i + 1] = | 2798 positions[i + 1] = |
| 2775 positions[i] + offset.distributionOffset + tracks[i].baseSize() + gap; | 2799 positions[i] + offset.distributionOffset + tracks[i].baseSize() + gap; |
| 2776 positions[lastLine] = | 2800 positions[lastLine] = |
| 2777 positions[nextToLastLine] + tracks[nextToLastLine].baseSize(); | 2801 positions[nextToLastLine] + tracks[nextToLastLine].baseSize(); |
| 2778 | 2802 |
| 2779 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to | 2803 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to |
| 2780 // collapse (they coincide exactly) except on the edges of the grid where | 2804 // collapse (they coincide exactly) except on the edges of the grid where |
| 2781 // they become 0. | 2805 // they become 0. |
| 2782 if (hasCollapsedTracks) { | 2806 if (hasCollapsedTracks) { |
| 2783 gap = gridGapForDirection(direction, sizingData.sizingOperation); | 2807 gap = gridGapForDirection(direction, sizingData.sizingOperation); |
| 2784 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() | 2808 size_t remainingEmptyTracks = |
| 2785 : m_autoRepeatEmptyRows->size(); | 2809 m_grid.autoRepeatEmptyTracks(direction)->size(); |
| 2786 LayoutUnit gapAccumulator; | 2810 LayoutUnit gapAccumulator; |
| 2787 for (size_t i = 1; i < lastLine; ++i) { | 2811 for (size_t i = 1; i < lastLine; ++i) { |
| 2788 if (isEmptyAutoRepeatTrack(direction, i - 1)) { | 2812 if (m_grid.isEmptyAutoRepeatTrack(direction, i - 1)) { |
| 2789 --remainingEmptyTracks; | 2813 --remainingEmptyTracks; |
| 2790 } else { | 2814 } else { |
| 2791 // Add gap between consecutive non empty tracks. Add it also just once | 2815 // Add gap between consecutive non empty tracks. Add it also just once |
| 2792 // for an arbitrary number of empty tracks between two non empty ones. | 2816 // for an arbitrary number of empty tracks between two non empty ones. |
| 2793 bool allRemainingTracksAreEmpty = | 2817 bool allRemainingTracksAreEmpty = |
| 2794 remainingEmptyTracks == (lastLine - i); | 2818 remainingEmptyTracks == (lastLine - i); |
| 2795 if (!allRemainingTracksAreEmpty || | 2819 if (!allRemainingTracksAreEmpty || |
| 2796 !isEmptyAutoRepeatTrack(direction, i)) | 2820 !m_grid.isEmptyAutoRepeatTrack(direction, i)) |
| 2797 gapAccumulator += gap; | 2821 gapAccumulator += gap; |
| 2798 } | 2822 } |
| 2799 positions[i] += gapAccumulator; | 2823 positions[i] += gapAccumulator; |
| 2800 } | 2824 } |
| 2801 positions[lastLine] += gapAccumulator; | 2825 positions[lastLine] += gapAccumulator; |
| 2802 } | 2826 } |
| 2803 } | 2827 } |
| 2804 auto& offsetBetweenTracks = | 2828 auto& offsetBetweenTracks = |
| 2805 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2829 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 2806 offsetBetweenTracks = offset.distributionOffset; | 2830 offsetBetweenTracks = offset.distributionOffset; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3036 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); | 3060 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); |
| 3037 } | 3061 } |
| 3038 | 3062 |
| 3039 int LayoutGrid::firstLineBoxBaseline() const { | 3063 int LayoutGrid::firstLineBoxBaseline() const { |
| 3040 if (isWritingModeRoot() || !m_grid.hasInFlowGridItems()) | 3064 if (isWritingModeRoot() || !m_grid.hasInFlowGridItems()) |
| 3041 return -1; | 3065 return -1; |
| 3042 const LayoutBox* baselineChild = nullptr; | 3066 const LayoutBox* baselineChild = nullptr; |
| 3043 const LayoutBox* firstChild = nullptr; | 3067 const LayoutBox* firstChild = nullptr; |
| 3044 bool isBaselineAligned = false; | 3068 bool isBaselineAligned = false; |
| 3045 // Finding the first grid item in grid order. | 3069 // Finding the first grid item in grid order. |
| 3046 for (size_t column = 0; !isBaselineAligned && column < m_grid.numColumns(); | 3070 for (size_t column = 0; |
| 3047 column++) { | 3071 !isBaselineAligned && column < m_grid.numTracks(ForColumns); column++) { |
| 3048 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { | 3072 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { |
| 3049 const LayoutBox* child = m_grid.cell(0, column)[index]; | 3073 const LayoutBox* child = m_grid.cell(0, column)[index]; |
| 3050 DCHECK(!child->isOutOfFlowPositioned()); | 3074 DCHECK(!child->isOutOfFlowPositioned()); |
| 3051 // If an item participates in baseline alignmen, we select such item. | 3075 // If an item participates in baseline alignmen, we select such item. |
| 3052 if (isInlineBaselineAlignedChild(child)) { | 3076 if (isInlineBaselineAlignedChild(child)) { |
| 3053 // TODO (lajava): self-baseline and content-baseline alignment | 3077 // TODO (lajava): self-baseline and content-baseline alignment |
| 3054 // still not implemented. | 3078 // still not implemented. |
| 3055 baselineChild = child; | 3079 baselineChild = child; |
| 3056 isBaselineAligned = true; | 3080 isBaselineAligned = true; |
| 3057 break; | 3081 break; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3255 break; | 3279 break; |
| 3256 } | 3280 } |
| 3257 | 3281 |
| 3258 ASSERT_NOT_REACHED(); | 3282 ASSERT_NOT_REACHED(); |
| 3259 return GridAxisStart; | 3283 return GridAxisStart; |
| 3260 } | 3284 } |
| 3261 | 3285 |
| 3262 LayoutUnit LayoutGrid::columnAxisOffsetForChild( | 3286 LayoutUnit LayoutGrid::columnAxisOffsetForChild( |
| 3263 const LayoutBox& child, | 3287 const LayoutBox& child, |
| 3264 GridSizingData& sizingData) const { | 3288 GridSizingData& sizingData) const { |
| 3265 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); | 3289 const GridSpan& rowsSpan = m_grid.gridItemSpan(child, ForRows); |
| 3266 size_t childStartLine = rowsSpan.startLine(); | 3290 size_t childStartLine = rowsSpan.startLine(); |
| 3267 LayoutUnit startOfRow = m_rowPositions[childStartLine]; | 3291 LayoutUnit startOfRow = m_rowPositions[childStartLine]; |
| 3268 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); | 3292 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); |
| 3269 if (hasAutoMarginsInColumnAxis(child)) | 3293 if (hasAutoMarginsInColumnAxis(child)) |
| 3270 return startPosition; | 3294 return startPosition; |
| 3271 GridAxisPosition axisPosition = columnAxisPositionForChild(child); | 3295 GridAxisPosition axisPosition = columnAxisPositionForChild(child); |
| 3272 switch (axisPosition) { | 3296 switch (axisPosition) { |
| 3273 case GridAxisStart: | 3297 case GridAxisStart: |
| 3274 return startPosition; | 3298 return startPosition; |
| 3275 case GridAxisEnd: | 3299 case GridAxisEnd: |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 3298 : offsetFromStartPosition / 2); | 3322 : offsetFromStartPosition / 2); |
| 3299 } | 3323 } |
| 3300 } | 3324 } |
| 3301 | 3325 |
| 3302 ASSERT_NOT_REACHED(); | 3326 ASSERT_NOT_REACHED(); |
| 3303 return LayoutUnit(); | 3327 return LayoutUnit(); |
| 3304 } | 3328 } |
| 3305 | 3329 |
| 3306 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, | 3330 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, |
| 3307 GridSizingData& sizingData) const { | 3331 GridSizingData& sizingData) const { |
| 3308 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); | 3332 const GridSpan& columnsSpan = m_grid.gridItemSpan(child, ForColumns); |
| 3309 size_t childStartLine = columnsSpan.startLine(); | 3333 size_t childStartLine = columnsSpan.startLine(); |
| 3310 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; | 3334 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; |
| 3311 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); | 3335 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); |
| 3312 if (hasAutoMarginsInRowAxis(child)) | 3336 if (hasAutoMarginsInRowAxis(child)) |
| 3313 return startPosition; | 3337 return startPosition; |
| 3314 GridAxisPosition axisPosition = rowAxisPositionForChild(child); | 3338 GridAxisPosition axisPosition = rowAxisPositionForChild(child); |
| 3315 switch (axisPosition) { | 3339 switch (axisPosition) { |
| 3316 case GridAxisStart: | 3340 case GridAxisStart: |
| 3317 return startPosition; | 3341 return startPosition; |
| 3318 case GridAxisEnd: | 3342 case GridAxisEnd: |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3532 } | 3556 } |
| 3533 | 3557 |
| 3534 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { | 3558 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { |
| 3535 // Due to limitations in our internal representation, we cannot know the | 3559 // Due to limitations in our internal representation, we cannot know the |
| 3536 // number of columns from m_grid *if* there is no row (because m_grid would be | 3560 // number of columns from m_grid *if* there is no row (because m_grid would be |
| 3537 // empty). That's why in that case we need to get it from the style. Note that | 3561 // empty). That's why in that case we need to get it from the style. Note that |
| 3538 // we know for sure that there are't any implicit tracks, because not having | 3562 // we know for sure that there are't any implicit tracks, because not having |
| 3539 // rows implies that there are no "normal" children (out-of-flow children are | 3563 // rows implies that there are no "normal" children (out-of-flow children are |
| 3540 // not stored in m_grid). | 3564 // not stored in m_grid). |
| 3541 if (direction == ForRows) | 3565 if (direction == ForRows) |
| 3542 return m_grid.numRows(); | 3566 return m_grid.numTracks(ForRows); |
| 3543 | 3567 |
| 3544 return m_grid.numRows() ? m_grid.numColumns() | 3568 return m_grid.numTracks(ForRows) |
|
jfernandez
2016/11/24 17:28:14
It's not the first time I see this pattern I I hav
svillar
2016/11/25 12:31:42
Yeah you're right. This method is basically the on
| |
| 3545 : GridPositionsResolver::explicitGridColumnCount( | 3569 ? m_grid.numTracks(ForColumns) |
| 3546 styleRef(), m_autoRepeatColumns); | 3570 : GridPositionsResolver::explicitGridColumnCount( |
| 3571 styleRef(), m_grid.autoRepeatTracks(ForColumns)); | |
| 3547 } | 3572 } |
| 3548 | 3573 |
| 3549 } // namespace blink | 3574 } // namespace blink |
| OLD | NEW |