| 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 size_t repetitions = | 540 size_t repetitions = |
| 541 1 + (freeSpace / (autoRepeatTracksSize + gapSize)).toInt(); | 541 1 + (freeSpace / (autoRepeatTracksSize + gapSize)).toInt(); |
| 542 | 542 |
| 543 // Provided the grid container does not have a definite size or max-size in | 543 // Provided the grid container does not have a definite size or max-size in |
| 544 // the relevant axis, if the min size is definite then the number of | 544 // the relevant axis, if the min size is definite then the number of |
| 545 // repetitions is the largest possible positive integer that fulfills that | 545 // repetitions is the largest possible positive integer that fulfills that |
| 546 // minimum requirement. | 546 // minimum requirement. |
| 547 if (needsToFulfillMinimumSize) | 547 if (needsToFulfillMinimumSize) |
| 548 ++repetitions; | 548 ++repetitions; |
| 549 | 549 |
| 550 // Clamp the number of repetitions so we don't end up with too many tracks. | |
| 551 if (repetitions > kGridMaxTracks) { | |
| 552 DCHECK_GT(autoRepeatTrackListLength, 0u); | |
| 553 repetitions = | |
| 554 (kGridMaxTracks - trackSizes.size()) / autoRepeatTrackListLength; | |
| 555 } | |
| 556 | |
| 557 return repetitions * autoRepeatTrackListLength; | 550 return repetitions * autoRepeatTrackListLength; |
| 558 } | 551 } |
| 559 | 552 |
| 560 std::unique_ptr<OrderedTrackIndexSet> | 553 std::unique_ptr<OrderedTrackIndexSet> |
| 561 LayoutGrid::computeEmptyTracksForAutoRepeat( | 554 LayoutGrid::computeEmptyTracksForAutoRepeat( |
| 562 Grid& grid, | 555 Grid& grid, |
| 563 GridTrackSizingDirection direction) const { | 556 GridTrackSizingDirection direction) const { |
| 564 bool isRowAxis = direction == ForColumns; | 557 bool isRowAxis = direction == ForColumns; |
| 565 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || | 558 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || |
| 566 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) | 559 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 587 if (!iterator.nextGridItem()) { | 580 if (!iterator.nextGridItem()) { |
| 588 if (!emptyTrackIndexes) | 581 if (!emptyTrackIndexes) |
| 589 emptyTrackIndexes = WTF::wrapUnique(new OrderedTrackIndexSet); | 582 emptyTrackIndexes = WTF::wrapUnique(new OrderedTrackIndexSet); |
| 590 emptyTrackIndexes->add(trackIndex); | 583 emptyTrackIndexes->add(trackIndex); |
| 591 } | 584 } |
| 592 } | 585 } |
| 593 } | 586 } |
| 594 return emptyTrackIndexes; | 587 return emptyTrackIndexes; |
| 595 } | 588 } |
| 596 | 589 |
| 590 size_t LayoutGrid::clampAutoRepeatTracks(GridTrackSizingDirection direction, |
| 591 size_t autoRepeatTracks) const { |
| 592 if (!autoRepeatTracks) |
| 593 return 0; |
| 594 |
| 595 size_t insertionPoint = direction == ForColumns |
| 596 ? styleRef().gridAutoRepeatColumnsInsertionPoint() |
| 597 : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| 598 |
| 599 if (insertionPoint == 0) |
| 600 return std::min<size_t>(autoRepeatTracks, kGridMaxTracks); |
| 601 |
| 602 if (insertionPoint >= kGridMaxTracks) |
| 603 return 0; |
| 604 |
| 605 return std::min(autoRepeatTracks, |
| 606 static_cast<size_t>(kGridMaxTracks) - insertionPoint); |
| 607 } |
| 608 |
| 597 void LayoutGrid::placeItemsOnGrid(Grid& grid, | 609 void LayoutGrid::placeItemsOnGrid(Grid& grid, |
| 598 SizingOperation sizingOperation) const { | 610 SizingOperation sizingOperation) const { |
| 599 size_t autoRepeatRows = | 611 size_t autoRepeatRows = |
| 600 computeAutoRepeatTracksCount(ForRows, sizingOperation); | 612 computeAutoRepeatTracksCount(ForRows, sizingOperation); |
| 601 size_t autoRepeatColumns = | 613 size_t autoRepeatColumns = |
| 602 computeAutoRepeatTracksCount(ForColumns, sizingOperation); | 614 computeAutoRepeatTracksCount(ForColumns, sizingOperation); |
| 615 |
| 616 autoRepeatRows = clampAutoRepeatTracks(ForRows, autoRepeatRows); |
| 617 autoRepeatColumns = clampAutoRepeatTracks(ForColumns, autoRepeatColumns); |
| 618 |
| 603 if (autoRepeatRows != grid.autoRepeatTracks(ForRows) || | 619 if (autoRepeatRows != grid.autoRepeatTracks(ForRows) || |
| 604 autoRepeatColumns != grid.autoRepeatTracks(ForColumns)) { | 620 autoRepeatColumns != grid.autoRepeatTracks(ForColumns)) { |
| 605 grid.setNeedsItemsPlacement(true); | 621 grid.setNeedsItemsPlacement(true); |
| 606 grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); | 622 grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); |
| 607 } | 623 } |
| 608 | 624 |
| 609 if (!grid.needsItemsPlacement()) | 625 if (!grid.needsItemsPlacement()) |
| 610 return; | 626 return; |
| 611 | 627 |
| 612 DCHECK(!grid.hasGridItems()); | 628 DCHECK(!grid.hasGridItems()); |
| (...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2075 if (direction == ForRows) | 2091 if (direction == ForRows) |
| 2076 return grid.numTracks(ForRows); | 2092 return grid.numTracks(ForRows); |
| 2077 | 2093 |
| 2078 return grid.numTracks(ForRows) | 2094 return grid.numTracks(ForRows) |
| 2079 ? grid.numTracks(ForColumns) | 2095 ? grid.numTracks(ForColumns) |
| 2080 : GridPositionsResolver::explicitGridColumnCount( | 2096 : GridPositionsResolver::explicitGridColumnCount( |
| 2081 styleRef(), grid.autoRepeatTracks(ForColumns)); | 2097 styleRef(), grid.autoRepeatTracks(ForColumns)); |
| 2082 } | 2098 } |
| 2083 | 2099 |
| 2084 } // namespace blink | 2100 } // namespace blink |
| OLD | NEW |