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

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

Issue 2670363003: [css-grid] Clamp the number of auto repeat tracks in all cases (Closed)
Patch Set: Created 3 years, 10 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 bool isRowAxis = direction == ForColumns;
596 size_t otherTracks = isRowAxis ? styleRef().gridTemplateColumns().size()
597 : styleRef().gridTemplateRows().size();
598 size_t totalTracks = autoRepeatTracks + otherTracks;
599
600 if (totalTracks <= kGridMaxTracks)
601 return autoRepeatTracks;
602
603 if (otherTracks >= kGridMaxTracks)
Manuel Rego 2017/02/06 09:51:12 We can move this if above.
svillar 2017/02/06 10:06:03 Acknowledged.
604 return 0;
605
606 size_t autoRepeatTrackListLength =
607 isRowAxis ? styleRef().gridAutoRepeatColumns().size()
608 : styleRef().gridAutoRepeatRows().size();
609 DCHECK_GT(autoRepeatTrackListLength, 0u);
610
611 size_t repetitions =
612 (kGridMaxTracks - otherTracks) / autoRepeatTrackListLength;
613 return repetitions * autoRepeatTrackListLength;
Manuel Rego 2017/02/06 09:51:12 Might be worth to explain here that we've decided
svillar 2017/02/06 10:06:03 Yeah, you're right. As this is not in the specs we
Manuel Rego 2017/02/06 10:09:52 Oops, sorry but I believe this is against the spec
614 }
615
597 void LayoutGrid::placeItemsOnGrid(Grid& grid, 616 void LayoutGrid::placeItemsOnGrid(Grid& grid,
598 SizingOperation sizingOperation) const { 617 SizingOperation sizingOperation) const {
599 size_t autoRepeatRows = 618 size_t autoRepeatRows =
600 computeAutoRepeatTracksCount(ForRows, sizingOperation); 619 computeAutoRepeatTracksCount(ForRows, sizingOperation);
601 size_t autoRepeatColumns = 620 size_t autoRepeatColumns =
602 computeAutoRepeatTracksCount(ForColumns, sizingOperation); 621 computeAutoRepeatTracksCount(ForColumns, sizingOperation);
622
623 autoRepeatRows = clampAutoRepeatTracks(ForRows, autoRepeatRows);
624 autoRepeatColumns = clampAutoRepeatTracks(ForColumns, autoRepeatColumns);
625
603 if (autoRepeatRows != grid.autoRepeatTracks(ForRows) || 626 if (autoRepeatRows != grid.autoRepeatTracks(ForRows) ||
604 autoRepeatColumns != grid.autoRepeatTracks(ForColumns)) { 627 autoRepeatColumns != grid.autoRepeatTracks(ForColumns)) {
605 grid.setNeedsItemsPlacement(true); 628 grid.setNeedsItemsPlacement(true);
606 grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); 629 grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns);
607 } 630 }
608 631
609 if (!grid.needsItemsPlacement()) 632 if (!grid.needsItemsPlacement())
610 return; 633 return;
611 634
612 DCHECK(!grid.hasGridItems()); 635 DCHECK(!grid.hasGridItems());
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 if (direction == ForRows) 2098 if (direction == ForRows)
2076 return grid.numTracks(ForRows); 2099 return grid.numTracks(ForRows);
2077 2100
2078 return grid.numTracks(ForRows) 2101 return grid.numTracks(ForRows)
2079 ? grid.numTracks(ForColumns) 2102 ? grid.numTracks(ForColumns)
2080 : GridPositionsResolver::explicitGridColumnCount( 2103 : GridPositionsResolver::explicitGridColumnCount(
2081 styleRef(), grid.autoRepeatTracks(ForColumns)); 2104 styleRef(), grid.autoRepeatTracks(ForColumns));
2082 } 2105 }
2083 2106
2084 } // namespace blink 2107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698