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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 GridTrackSizingDirection m_direction; | 232 GridTrackSizingDirection m_direction; |
233 size_t m_rowIndex; | 233 size_t m_rowIndex; |
234 size_t m_columnIndex; | 234 size_t m_columnIndex; |
235 size_t m_childIndex; | 235 size_t m_childIndex; |
236 }; | 236 }; |
237 | 237 |
238 struct LayoutGrid::GridSizingData { | 238 struct LayoutGrid::GridSizingData { |
239 WTF_MAKE_NONCOPYABLE(GridSizingData); | 239 WTF_MAKE_NONCOPYABLE(GridSizingData); |
240 STACK_ALLOCATED(); | 240 STACK_ALLOCATED(); |
241 public: | 241 public: |
242 GridSizingData(size_t gridColumnCount, size_t gridRowCount) | 242 GridSizingData(size_t gridColumnCount, size_t gridRowCount, bool definiteLog icalHeight) |
jfernandez
2016/09/14 10:29:37
better use 'hasDefiniteLogicalHeigth" as variable
| |
243 : columnTracks(gridColumnCount) | 243 : columnTracks(gridColumnCount) |
244 , rowTracks(gridRowCount) | 244 , rowTracks(gridRowCount) |
245 , m_definiteLogicalHeight(definiteLogicalHeight) | |
jfernandez
2016/09/14 10:29:37
Again, better use the 'has' prefix in the attribut
| |
245 { | 246 { |
246 } | 247 } |
247 | 248 |
248 Vector<GridTrack> columnTracks; | 249 Vector<GridTrack> columnTracks; |
249 Vector<GridTrack> rowTracks; | 250 Vector<GridTrack> rowTracks; |
250 Vector<size_t> contentSizedTracksIndex; | 251 Vector<size_t> contentSizedTracksIndex; |
251 | 252 |
252 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. | 253 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. |
253 Vector<GridTrack*> filteredTracks; | 254 Vector<GridTrack*> filteredTracks; |
254 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 255 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
255 Vector<GridTrack*> growBeyondGrowthLimitsTracks; | 256 Vector<GridTrack*> growBeyondGrowthLimitsTracks; |
256 | 257 |
257 LayoutUnit& freeSpace(GridTrackSizingDirection direction) { return direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } | 258 LayoutUnit& freeSpace(GridTrackSizingDirection direction) { return direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } |
258 | 259 |
259 LayoutUnit availableSpace() const { return m_availableSpace; } | 260 LayoutUnit availableSpace() const { return m_availableSpace; } |
260 void setAvailableSpace(LayoutUnit availableSpace) { m_availableSpace = avail ableSpace; } | 261 void setAvailableSpace(LayoutUnit availableSpace) { m_availableSpace = avail ableSpace; } |
262 bool hasDefiniteLogicalHeight() const { return m_definiteLogicalHeight; } | |
261 | 263 |
262 SizingOperation sizingOperation { TrackSizing }; | 264 SizingOperation sizingOperation { TrackSizing }; |
263 enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, Colu mnSizingSecondIteration, RowSizingSecondIteration}; | 265 enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, Colu mnSizingSecondIteration, RowSizingSecondIteration}; |
264 SizingState sizingState { ColumnSizingFirstIteration }; | 266 SizingState sizingState { ColumnSizingFirstIteration }; |
265 void nextState() | 267 void nextState() |
266 { | 268 { |
267 switch (sizingState) { | 269 switch (sizingState) { |
268 case ColumnSizingFirstIteration: | 270 case ColumnSizingFirstIteration: |
269 sizingState = RowSizingFirstIteration; | 271 sizingState = RowSizingFirstIteration; |
270 return; | 272 return; |
(...skipping 22 matching lines...) Expand all Loading... | |
293 } | 295 } |
294 NOTREACHED(); | 296 NOTREACHED(); |
295 return false; | 297 return false; |
296 } | 298 } |
297 private: | 299 private: |
298 LayoutUnit freeSpaceForColumns { }; | 300 LayoutUnit freeSpaceForColumns { }; |
299 LayoutUnit freeSpaceForRows { }; | 301 LayoutUnit freeSpaceForRows { }; |
300 // No need to store one per direction as it will be only used for computatio ns during each axis | 302 // No need to store one per direction as it will be only used for computatio ns during each axis |
301 // track sizing. It's cached here because we need it to compute relative siz es. | 303 // track sizing. It's cached here because we need it to compute relative siz es. |
302 LayoutUnit m_availableSpace; | 304 LayoutUnit m_availableSpace; |
305 | |
306 bool m_definiteLogicalHeight; | |
303 }; | 307 }; |
304 | 308 |
305 struct GridItemsSpanGroupRange { | 309 struct GridItemsSpanGroupRange { |
306 Vector<GridItemWithSpan>::iterator rangeStart; | 310 Vector<GridItemWithSpan>::iterator rangeStart; |
307 Vector<GridItemWithSpan>::iterator rangeEnd; | 311 Vector<GridItemWithSpan>::iterator rangeEnd; |
308 }; | 312 }; |
309 | 313 |
310 LayoutGrid::LayoutGrid(Element* element) | 314 LayoutGrid::LayoutGrid(Element* element) |
311 : LayoutBlock(element) | 315 : LayoutBlock(element) |
312 , m_gridIsDirty(true) | 316 , m_gridIsDirty(true) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 SubtreeLayoutScope layoutScope(*this); | 450 SubtreeLayoutScope layoutScope(*this); |
447 | 451 |
448 { | 452 { |
449 // LayoutState needs this deliberate scope to pop before updating scroll information (which | 453 // LayoutState needs this deliberate scope to pop before updating scroll information (which |
450 // may trigger relayout). | 454 // may trigger relayout). |
451 LayoutState state(*this, locationOffset()); | 455 LayoutState state(*this, locationOffset()); |
452 | 456 |
453 LayoutSize previousSize = size(); | 457 LayoutSize previousSize = size(); |
454 | 458 |
455 updateLogicalWidth(); | 459 updateLogicalWidth(); |
456 bool logicalHeightWasIndefinite = !hasDefiniteLogicalHeight(); | |
457 | |
458 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); | 460 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); |
459 | 461 |
460 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated | 462 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated |
461 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) | 463 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) |
462 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing)) | 464 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing)) |
463 dirtyGrid(); | 465 dirtyGrid(); |
464 placeItemsOnGrid(TrackSizing); | 466 placeItemsOnGrid(TrackSizing); |
465 | 467 |
466 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 468 GridSizingData sizingData(gridColumnCount(), gridRowCount(), hasDefinite LogicalHeight()); |
jfernandez
2016/09/14 10:29:37
Are we suer we want to store this information in t
Manuel Rego
2016/09/15 06:35:28
Ok, I've moved it to an attribute called m_hasDefi
| |
467 | 469 |
468 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. | 470 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. |
469 // At this point the logical width is always definite as the above call to updateLogicalWidth() | 471 // At this point the logical width is always definite as the above call to updateLogicalWidth() |
470 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code | 472 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code |
471 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve | 473 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve |
472 // heights properly (like for positioned items for example). | 474 // heights properly (like for positioned items for example). |
473 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 475 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
474 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | 476 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); |
475 | 477 |
476 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the | 478 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the |
477 // grid column sizes calculated in the previous step. | 479 // grid column sizes calculated in the previous step. |
478 if (logicalHeightWasIndefinite) | 480 if (sizingData.hasDefiniteLogicalHeight()) |
481 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); | |
482 else | |
479 computeIntrinsicLogicalHeight(sizingData); | 483 computeIntrinsicLogicalHeight(sizingData); |
480 else | |
481 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); | |
482 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); | 484 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); |
483 | 485 |
484 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); | 486 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
485 updateLogicalHeight(); | 487 updateLogicalHeight(); |
486 | 488 |
487 // The above call might have changed the grid's logical height depending on min|max height restrictions. | 489 // The above call might have changed the grid's logical height depending on min|max height restrictions. |
488 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). | 490 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). |
489 LayoutUnit availableSpaceForRows = contentLogicalHeight(); | 491 LayoutUnit availableSpaceForRows = contentLogicalHeight(); |
490 if (logicalHeightWasIndefinite) | 492 if (!sizingData.hasDefiniteLogicalHeight()) |
491 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); | 493 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); |
492 | 494 |
493 // 3- If the min-content contribution of any grid items have changed bas ed on the row | 495 // 3- If the min-content contribution of any grid items have changed bas ed on the row |
494 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content | 496 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content |
495 // contribution (once only). | 497 // contribution (once only). |
496 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); | 498 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); |
497 | 499 |
498 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. | 500 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. |
499 if (hasLineIfEmpty()) | 501 if (hasLineIfEmpty()) |
500 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); | 502 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 gapAccumulator += gap; | 594 gapAccumulator += gap; |
593 } | 595 } |
594 | 596 |
595 return gapAccumulator; | 597 return gapAccumulator; |
596 } | 598 } |
597 | 599 |
598 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const | 600 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const |
599 { | 601 { |
600 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); | 602 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); |
601 | 603 |
602 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 604 GridSizingData sizingData(gridColumnCount(), gridRowCount(), false); |
603 sizingData.setAvailableSpace(LayoutUnit()); | 605 sizingData.setAvailableSpace(LayoutUnit()); |
604 sizingData.freeSpace(ForColumns) = LayoutUnit(); | 606 sizingData.freeSpace(ForColumns) = LayoutUnit(); |
605 sizingData.sizingOperation = IntrinsicSizeComputation; | 607 sizingData.sizingOperation = IntrinsicSizeComputation; |
606 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL ogicalWidth); | 608 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL ogicalWidth); |
607 | 609 |
608 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size(), sizingData.sizingOperation); | 610 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size(), sizingData.sizingOperation); |
609 minLogicalWidth += totalGuttersSize; | 611 minLogicalWidth += totalGuttersSize; |
610 maxLogicalWidth += totalGuttersSize; | 612 maxLogicalWidth += totalGuttersSize; |
611 | 613 |
612 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 614 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 Vector<size_t> flexibleSizedTracksIndex; | 665 Vector<size_t> flexibleSizedTracksIndex; |
664 sizingData.contentSizedTracksIndex.shrink(0); | 666 sizingData.contentSizedTracksIndex.shrink(0); |
665 | 667 |
666 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. | 668 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. |
667 LayoutUnit maxSize = sizingData.availableSpace().clampNegativeToZero(); | 669 LayoutUnit maxSize = sizingData.availableSpace().clampNegativeToZero(); |
668 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; | 670 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; |
669 | 671 |
670 // 1. Initialize per Grid track variables. | 672 // 1. Initialize per Grid track variables. |
671 for (size_t i = 0; i < tracks.size(); ++i) { | 673 for (size_t i = 0; i < tracks.size(); ++i) { |
672 GridTrack& track = tracks[i]; | 674 GridTrack& track = tracks[i]; |
673 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); | 675 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData); |
674 | 676 |
675 track.setBaseSize(computeUsedBreadthOfMinLength(trackSize, maxSize)); | 677 track.setBaseSize(computeUsedBreadthOfMinLength(trackSize, maxSize)); |
676 track.setGrowthLimit(computeUsedBreadthOfMaxLength(trackSize, track.base Size(), maxSize)); | 678 track.setGrowthLimit(computeUsedBreadthOfMaxLength(trackSize, track.base Size(), maxSize)); |
677 track.setInfinitelyGrowable(false); | 679 track.setInfinitelyGrowable(false); |
678 | 680 |
679 if (trackSize.isFitContent()) { | 681 if (trackSize.isFitContent()) { |
680 GridLength gridLength = trackSize.fitContentTrackBreadth(); | 682 GridLength gridLength = trackSize.fitContentTrackBreadth(); |
681 if (!gridLength.hasPercentage() || hasDefiniteFreeSpace) | 683 if (!gridLength.hasPercentage() || hasDefiniteFreeSpace) |
682 track.setGrowthLimitCap(valueForLength(gridLength.length(), maxS ize)); | 684 track.setGrowthLimitCap(valueForLength(gridLength.length(), maxS ize)); |
683 } | 685 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 for (auto& track : tracks) | 726 for (auto& track : tracks) |
725 track.setBaseSize(track.growthLimit()); | 727 track.setBaseSize(track.growthLimit()); |
726 } | 728 } |
727 | 729 |
728 if (flexibleSizedTracksIndex.isEmpty()) | 730 if (flexibleSizedTracksIndex.isEmpty()) |
729 return; | 731 return; |
730 | 732 |
731 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. | 733 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. |
732 double flexFraction = 0; | 734 double flexFraction = 0; |
733 if (hasDefiniteFreeSpace) { | 735 if (hasDefiniteFreeSpace) { |
734 flexFraction = findFlexFactorUnitSize(tracks, GridSpan::translatedDefini teGridSpan(0, tracks.size()), direction, initialFreeSpace); | 736 flexFraction = findFlexFactorUnitSize(tracks, GridSpan::translatedDefini teGridSpan(0, tracks.size()), direction, sizingData, initialFreeSpace); |
735 } else { | 737 } else { |
736 for (const auto& trackIndex : flexibleSizedTracksIndex) | 738 for (const auto& trackIndex : flexibleSizedTracksIndex) |
737 flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[ trackIndex], gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); | 739 flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[ trackIndex], gridTrackSize(direction, trackIndex, sizingData).maxTrackBreadth(). flex())); |
738 | 740 |
739 if (!m_gridItemArea.isEmpty()) { | 741 if (!m_gridItemArea.isEmpty()) { |
740 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 742 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
741 GridIterator iterator(m_grid, direction, flexibleSizedTracksInde x[i]); | 743 GridIterator iterator(m_grid, direction, flexibleSizedTracksInde x[i]); |
742 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 744 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
743 const GridSpan span = cachedGridSpan(*gridItem, direction); | 745 const GridSpan span = cachedGridSpan(*gridItem, direction); |
744 | 746 |
745 // Do not include already processed items. | 747 // Do not include already processed items. |
746 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) | 748 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) |
747 continue; | 749 continue; |
748 | 750 |
749 flexFraction = std::max(flexFraction, findFlexFactorUnitSize (tracks, span, direction, maxContentForChild(*gridItem, direction, sizingData))) ; | 751 flexFraction = std::max(flexFraction, findFlexFactorUnitSize (tracks, span, direction, sizingData, maxContentForChild(*gridItem, direction, s izingData))); |
750 } | 752 } |
751 } | 753 } |
752 } | 754 } |
753 } | 755 } |
754 | 756 |
755 for (const auto& trackIndex : flexibleSizedTracksIndex) { | 757 for (const auto& trackIndex : flexibleSizedTracksIndex) { |
756 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 758 GridTrackSize trackSize = gridTrackSize(direction, trackIndex, sizingDat a); |
757 | 759 |
758 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize(); | 760 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize(); |
759 LayoutUnit baseSize = std::max(oldBaseSize, LayoutUnit(flexFraction * tr ackSize.maxTrackBreadth().flex())); | 761 LayoutUnit baseSize = std::max(oldBaseSize, LayoutUnit(flexFraction * tr ackSize.maxTrackBreadth().flex())); |
760 if (LayoutUnit increment = baseSize - oldBaseSize) { | 762 if (LayoutUnit increment = baseSize - oldBaseSize) { |
761 tracks[trackIndex].setBaseSize(baseSize); | 763 tracks[trackIndex].setBaseSize(baseSize); |
762 freeSpace -= increment; | 764 freeSpace -= increment; |
763 | 765 |
764 baseSizesWithoutMaximization += increment; | 766 baseSizesWithoutMaximization += increment; |
765 growthLimitsWithoutMaximization += increment; | 767 growthLimitsWithoutMaximization += increment; |
766 } | 768 } |
(...skipping 21 matching lines...) Expand all Loading... | |
788 return usedBreadth; | 790 return usedBreadth; |
789 | 791 |
790 const Length& trackLength = gridLength.length(); | 792 const Length& trackLength = gridLength.length(); |
791 if (trackLength.isSpecified()) | 793 if (trackLength.isSpecified()) |
792 return valueForLength(trackLength, maxSize); | 794 return valueForLength(trackLength, maxSize); |
793 | 795 |
794 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); | 796 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); |
795 return LayoutUnit(infinity); | 797 return LayoutUnit(infinity); |
796 } | 798 } |
797 | 799 |
798 double LayoutGrid::computeFlexFactorUnitSize(const Vector<GridTrack>& tracks, Gr idTrackSizingDirection direction, double flexFactorSum, LayoutUnit& leftOverSpac e, const Vector<size_t, 8>& flexibleTracksIndexes, std::unique_ptr<TrackIndexSet > tracksToTreatAsInflexible) const | 800 double LayoutGrid::computeFlexFactorUnitSize(const Vector<GridTrack>& tracks, Gr idTrackSizingDirection direction, const GridSizingData& sizingData, double flexF actorSum, LayoutUnit& leftOverSpace, const Vector<size_t, 8>& flexibleTracksInde xes, std::unique_ptr<TrackIndexSet> tracksToTreatAsInflexible) const |
799 { | 801 { |
800 // We want to avoid the effect of flex factors sum below 1 making the factor unit size to grow exponentially. | 802 // We want to avoid the effect of flex factors sum below 1 making the factor unit size to grow exponentially. |
801 double hypotheticalFactorUnitSize = leftOverSpace / std::max<double>(1, flex FactorSum); | 803 double hypotheticalFactorUnitSize = leftOverSpace / std::max<double>(1, flex FactorSum); |
802 | 804 |
803 // product of the hypothetical "flex factor unit" and any flexible track's " flex factor" must be grater than such track's "base size". | 805 // product of the hypothetical "flex factor unit" and any flexible track's " flex factor" must be grater than such track's "base size". |
804 std::unique_ptr<TrackIndexSet> additionalTracksToTreatAsInflexible = std::mo ve(tracksToTreatAsInflexible); | 806 std::unique_ptr<TrackIndexSet> additionalTracksToTreatAsInflexible = std::mo ve(tracksToTreatAsInflexible); |
805 bool validFlexFactorUnit = true; | 807 bool validFlexFactorUnit = true; |
806 for (auto index : flexibleTracksIndexes) { | 808 for (auto index : flexibleTracksIndexes) { |
807 if (additionalTracksToTreatAsInflexible && additionalTracksToTreatAsInfl exible->contains(index)) | 809 if (additionalTracksToTreatAsInflexible && additionalTracksToTreatAsInfl exible->contains(index)) |
808 continue; | 810 continue; |
809 LayoutUnit baseSize = tracks[index].baseSize(); | 811 LayoutUnit baseSize = tracks[index].baseSize(); |
810 double flexFactor = gridTrackSize(direction, index).maxTrackBreadth().fl ex(); | 812 double flexFactor = gridTrackSize(direction, index, sizingData).maxTrack Breadth().flex(); |
811 // treating all such tracks as inflexible. | 813 // treating all such tracks as inflexible. |
812 if (baseSize > hypotheticalFactorUnitSize * flexFactor) { | 814 if (baseSize > hypotheticalFactorUnitSize * flexFactor) { |
813 leftOverSpace -= baseSize; | 815 leftOverSpace -= baseSize; |
814 flexFactorSum -= flexFactor; | 816 flexFactorSum -= flexFactor; |
815 if (!additionalTracksToTreatAsInflexible) | 817 if (!additionalTracksToTreatAsInflexible) |
816 additionalTracksToTreatAsInflexible = wrapUnique(new TrackIndexS et()); | 818 additionalTracksToTreatAsInflexible = wrapUnique(new TrackIndexS et()); |
817 additionalTracksToTreatAsInflexible->add(index); | 819 additionalTracksToTreatAsInflexible->add(index); |
818 validFlexFactorUnit = false; | 820 validFlexFactorUnit = false; |
819 } | 821 } |
820 } | 822 } |
821 if (!validFlexFactorUnit) | 823 if (!validFlexFactorUnit) |
822 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftO verSpace, flexibleTracksIndexes, std::move(additionalTracksToTreatAsInflexible)) ; | 824 return computeFlexFactorUnitSize(tracks, direction, sizingData, flexFact orSum, leftOverSpace, flexibleTracksIndexes, std::move(additionalTracksToTreatAs Inflexible)); |
823 return hypotheticalFactorUnitSize; | 825 return hypotheticalFactorUnitSize; |
824 } | 826 } |
825 | 827 |
826 double LayoutGrid::findFlexFactorUnitSize(const Vector<GridTrack>& tracks, const GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit leftOverSp ace) const | 828 double LayoutGrid::findFlexFactorUnitSize(const Vector<GridTrack>& tracks, const GridSpan& tracksSpan, GridTrackSizingDirection direction, const GridSizingData& sizingData, LayoutUnit leftOverSpace) const |
jfernandez
2016/09/14 10:29:37
an example of why I don't like a lot the approach
| |
827 { | 829 { |
828 if (leftOverSpace <= 0) | 830 if (leftOverSpace <= 0) |
829 return 0; | 831 return 0; |
830 | 832 |
831 double flexFactorSum = 0; | 833 double flexFactorSum = 0; |
832 Vector<size_t, 8> flexibleTracksIndexes; | 834 Vector<size_t, 8> flexibleTracksIndexes; |
833 for (const auto& trackIndex : tracksSpan) { | 835 for (const auto& trackIndex : tracksSpan) { |
834 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 836 GridTrackSize trackSize = gridTrackSize(direction, trackIndex, sizingDat a); |
835 if (!trackSize.maxTrackBreadth().isFlex()) { | 837 if (!trackSize.maxTrackBreadth().isFlex()) { |
836 leftOverSpace -= tracks[trackIndex].baseSize(); | 838 leftOverSpace -= tracks[trackIndex].baseSize(); |
837 } else { | 839 } else { |
838 flexibleTracksIndexes.append(trackIndex); | 840 flexibleTracksIndexes.append(trackIndex); |
839 flexFactorSum += trackSize.maxTrackBreadth().flex(); | 841 flexFactorSum += trackSize.maxTrackBreadth().flex(); |
840 } | 842 } |
841 } | 843 } |
842 | 844 |
843 // The function is not called if we don't have <flex> grid tracks | 845 // The function is not called if we don't have <flex> grid tracks |
844 ASSERT(!flexibleTracksIndexes.isEmpty()); | 846 ASSERT(!flexibleTracksIndexes.isEmpty()); |
845 | 847 |
846 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); | 848 return computeFlexFactorUnitSize(tracks, direction, sizingData, flexFactorSu m, leftOverSpace, flexibleTracksIndexes); |
847 } | 849 } |
848 | 850 |
849 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) | 851 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) |
850 { | 852 { |
851 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.hasOverrideContainingBlockLogicalHeight(); | 853 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.hasOverrideContainingBlockLogicalHeight(); |
852 } | 854 } |
853 | 855 |
854 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) | 856 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) |
855 { | 857 { |
856 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); | 858 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 return trackStyles[untranslatedIndex]; | 904 return trackStyles[untranslatedIndex]; |
903 | 905 |
904 if (untranslatedIndex < (insertionPoint + autoRepeatTracksCount)) { | 906 if (untranslatedIndex < (insertionPoint + autoRepeatTracksCount)) { |
905 size_t autoRepeatLocalIndex = untranslatedIndexAsInt - insertionPoint; | 907 size_t autoRepeatLocalIndex = untranslatedIndexAsInt - insertionPoint; |
906 return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyle s.size()]; | 908 return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyle s.size()]; |
907 } | 909 } |
908 | 910 |
909 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; | 911 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; |
910 } | 912 } |
911 | 913 |
912 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, SizingOperation sizingOperation) const | 914 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, const GridSizingData& sizingData) const |
913 { | 915 { |
914 // Collapse empty auto repeat tracks if auto-fit. | 916 // Collapse empty auto repeat tracks if auto-fit. |
915 if (hasAutoRepeatEmptyTracks(direction) && isEmptyAutoRepeatTrack(direction, translatedIndex)) | 917 if (hasAutoRepeatEmptyTracks(direction) && isEmptyAutoRepeatTrack(direction, translatedIndex)) |
916 return { Length(Fixed), LengthTrackSizing }; | 918 return { Length(Fixed), LengthTrackSizing }; |
917 | 919 |
918 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex ); | 920 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex ); |
919 if (trackSize.isFitContent()) | 921 if (trackSize.isFitContent()) |
920 return trackSize; | 922 return trackSize; |
921 | 923 |
922 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 924 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
923 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 925 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
924 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. | 926 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. |
925 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { | 927 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { |
926 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite). | 928 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite). |
927 if ((sizingOperation == IntrinsicSizeComputation) || (direction == ForRo ws && !hasDefiniteLogicalHeight())) { | 929 if ((sizingData.sizingOperation == IntrinsicSizeComputation) || (directi on == ForRows && !sizingData.hasDefiniteLogicalHeight())) { |
jfernandez
2016/09/14 10:29:37
If I understood it correctly, you have passed 'fal
Manuel Rego
2016/09/15 06:35:28
The possibilities are:
* IntrinsicSizeComputation:
| |
928 if (minTrackBreadth.hasPercentage()) | 930 if (minTrackBreadth.hasPercentage()) |
929 minTrackBreadth = Length(Auto); | 931 minTrackBreadth = Length(Auto); |
930 if (maxTrackBreadth.hasPercentage()) | 932 if (maxTrackBreadth.hasPercentage()) |
931 maxTrackBreadth = Length(Auto); | 933 maxTrackBreadth = Length(Auto); |
932 } | 934 } |
933 } | 935 } |
934 | 936 |
935 // Flex sizes are invalid as a min sizing function. However we still can hav e a flexible |minTrackBreadth| | 937 // Flex sizes are invalid as a min sizing function. However we still can hav e a flexible |minTrackBreadth| |
936 // if the track had a flex size directly (e.g. "1fr"), the spec says that in this case it implies an automatic minimum. | 938 // if the track had a flex size directly (e.g. "1fr"), the spec says that in this case it implies an automatic minimum. |
937 if (minTrackBreadth.isFlex()) | 939 if (minTrackBreadth.isFlex()) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 LayoutBox& gridItem() const { return *m_gridItem; } | 1075 LayoutBox& gridItem() const { return *m_gridItem; } |
1074 GridSpan getGridSpan() const { return m_gridSpan; } | 1076 GridSpan getGridSpan() const { return m_gridSpan; } |
1075 | 1077 |
1076 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); } | 1078 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); } |
1077 | 1079 |
1078 private: | 1080 private: |
1079 LayoutBox* m_gridItem; | 1081 LayoutBox* m_gridItem; |
1080 GridSpan m_gridSpan; | 1082 GridSpan m_gridSpan; |
1081 }; | 1083 }; |
1082 | 1084 |
1083 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan& span, Gr idTrackSizingDirection direction, SizingOperation sizingOperation) const | 1085 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan& span, Gr idTrackSizingDirection direction, const GridSizingData& sizingData) const |
jfernandez
2016/09/14 10:29:37
isn't this another example of a method just forwar
| |
1084 { | 1086 { |
1085 for (const auto& trackPosition : span) { | 1087 for (const auto& trackPosition : span) { |
1086 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition, sizingOperation); | 1088 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition, sizingData); |
1087 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()) | 1089 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()) |
1088 return true; | 1090 return true; |
1089 } | 1091 } |
1090 | 1092 |
1091 return false; | 1093 return false; |
1092 } | 1094 } |
1093 | 1095 |
1094 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) const | 1096 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) const |
1095 { | 1097 { |
1096 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 1098 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
1097 if (!m_gridItemArea.isEmpty()) { | 1099 if (!m_gridItemArea.isEmpty()) { |
1098 HashSet<LayoutBox*> itemsSet; | 1100 HashSet<LayoutBox*> itemsSet; |
1099 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1101 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
1100 GridIterator iterator(m_grid, direction, trackIndex); | 1102 GridIterator iterator(m_grid, direction, trackIndex); |
1101 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackIndex] : sizingData.rowTracks[trackIndex]; | 1103 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackIndex] : sizingData.rowTracks[trackIndex]; |
1102 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 1104 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
1103 if (itemsSet.add(gridItem).isNewEntry) { | 1105 if (itemsSet.add(gridItem).isNewEntry) { |
1104 const GridSpan& span = cachedGridSpan(*gridItem, direction); | 1106 const GridSpan& span = cachedGridSpan(*gridItem, direction); |
1105 if (span.integerSpan() == 1) { | 1107 if (span.integerSpan() == 1) { |
1106 resolveContentBasedTrackSizingFunctionsForNonSpanningIte ms(direction, span, *gridItem, track, sizingData); | 1108 resolveContentBasedTrackSizingFunctionsForNonSpanningIte ms(direction, span, *gridItem, track, sizingData); |
1107 } else if (!spanningItemCrossesFlexibleSizedTracks(span, dir ection, sizingData.sizingOperation)) { | 1109 } else if (!spanningItemCrossesFlexibleSizedTracks(span, dir ection, sizingData)) { |
1108 sizingData.itemsSortedByIncreasingSpan.append(GridItemWi thSpan(*gridItem, span)); | 1110 sizingData.itemsSortedByIncreasingSpan.append(GridItemWi thSpan(*gridItem, span)); |
1109 } | 1111 } |
1110 } | 1112 } |
1111 } | 1113 } |
1112 } | 1114 } |
1113 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.ite msSortedByIncreasingSpan.end()); | 1115 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.ite msSortedByIncreasingSpan.end()); |
1114 } | 1116 } |
1115 | 1117 |
1116 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); | 1118 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); |
1117 auto end = sizingData.itemsSortedByIncreasingSpan.end(); | 1119 auto end = sizingData.itemsSortedByIncreasingSpan.end(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1128 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1130 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
1129 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; | 1131 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; |
1130 if (track.growthLimit() == infinity) | 1132 if (track.growthLimit() == infinity) |
1131 track.setGrowthLimit(track.baseSize()); | 1133 track.setGrowthLimit(track.baseSize()); |
1132 } | 1134 } |
1133 } | 1135 } |
1134 | 1136 |
1135 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, GridSizingData& sizingData) const | 1137 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, GridSizingData& sizingData) const |
1136 { | 1138 { |
1137 const size_t trackPosition = span.startLine(); | 1139 const size_t trackPosition = span.startLine(); |
1138 GridTrackSize trackSize = gridTrackSize(direction, trackPosition, sizingData .sizingOperation); | 1140 GridTrackSize trackSize = gridTrackSize(direction, trackPosition, sizingData ); |
1139 | 1141 |
1140 if (trackSize.hasMinContentMinTrackBreadth()) | 1142 if (trackSize.hasMinContentMinTrackBreadth()) |
1141 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, sizingData))); | 1143 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, sizingData))); |
1142 else if (trackSize.hasMaxContentMinTrackBreadth()) | 1144 else if (trackSize.hasMaxContentMinTrackBreadth()) |
1143 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, sizingData))); | 1145 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, sizingData))); |
1144 else if (trackSize.hasAutoMinTrackBreadth()) | 1146 else if (trackSize.hasAutoMinTrackBreadth()) |
1145 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, sizingData))); | 1147 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, sizingData))); |
1146 | 1148 |
1147 if (trackSize.hasMinContentMaxTrackBreadth()) { | 1149 if (trackSize.hasMinContentMaxTrackBreadth()) { |
1148 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, sizingData))); | 1150 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, sizingData))); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 | 1292 |
1291 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { | 1293 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { |
1292 GridItemWithSpan& gridItemWithSpan = *it; | 1294 GridItemWithSpan& gridItemWithSpan = *it; |
1293 ASSERT(gridItemWithSpan.getGridSpan().integerSpan() > 1); | 1295 ASSERT(gridItemWithSpan.getGridSpan().integerSpan() > 1); |
1294 const GridSpan& itemSpan = gridItemWithSpan.getGridSpan(); | 1296 const GridSpan& itemSpan = gridItemWithSpan.getGridSpan(); |
1295 | 1297 |
1296 sizingData.growBeyondGrowthLimitsTracks.shrink(0); | 1298 sizingData.growBeyondGrowthLimitsTracks.shrink(0); |
1297 sizingData.filteredTracks.shrink(0); | 1299 sizingData.filteredTracks.shrink(0); |
1298 LayoutUnit spanningTracksSize; | 1300 LayoutUnit spanningTracksSize; |
1299 for (const auto& trackPosition : itemSpan) { | 1301 for (const auto& trackPosition : itemSpan) { |
1300 GridTrackSize trackSize = gridTrackSize(direction, trackPosition); | 1302 GridTrackSize trackSize = gridTrackSize(direction, trackPosition, si zingData); |
1301 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition] : sizingData.rowTracks[trackPosition]; | 1303 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition] : sizingData.rowTracks[trackPosition]; |
1302 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); | 1304 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); |
1303 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) | 1305 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) |
1304 continue; | 1306 continue; |
1305 | 1307 |
1306 sizingData.filteredTracks.append(&track); | 1308 sizingData.filteredTracks.append(&track); |
1307 | 1309 |
1308 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) | 1310 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) |
1309 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 1311 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
1310 } | 1312 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 for (auto* track : tracks) | 1403 for (auto* track : tracks) |
1402 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); | 1404 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); |
1403 } | 1405 } |
1404 | 1406 |
1405 #if ENABLE(ASSERT) | 1407 #if ENABLE(ASSERT) |
1406 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) | 1408 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) |
1407 { | 1409 { |
1408 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; | 1410 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; |
1409 LayoutUnit& maxSize = sizingData.freeSpace(direction); | 1411 LayoutUnit& maxSize = sizingData.freeSpace(direction); |
1410 for (size_t i = 0; i < tracks.size(); ++i) { | 1412 for (size_t i = 0; i < tracks.size(); ++i) { |
1411 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); | 1413 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData); |
1412 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze()) | 1414 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze()) |
1413 return false; | 1415 return false; |
1414 } | 1416 } |
1415 return true; | 1417 return true; |
1416 } | 1418 } |
1417 #endif | 1419 #endif |
1418 | 1420 |
1419 void LayoutGrid::ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize) | 1421 void LayoutGrid::ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize) |
1420 { | 1422 { |
1421 const size_t oldRowSize = gridRowCount(); | 1423 const size_t oldRowSize = gridRowCount(); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1861 LayoutUnit& availableSpace = sizingData.freeSpace(direction); | 1863 LayoutUnit& availableSpace = sizingData.freeSpace(direction); |
1862 if (availableSpace <= 0 | 1864 if (availableSpace <= 0 |
1863 || (direction == ForColumns && styleRef().resolvedJustifyContentDistribu tion(contentAlignmentNormalBehavior()) != ContentDistributionStretch) | 1865 || (direction == ForColumns && styleRef().resolvedJustifyContentDistribu tion(contentAlignmentNormalBehavior()) != ContentDistributionStretch) |
1864 || (direction == ForRows && styleRef().resolvedAlignContentDistribution( contentAlignmentNormalBehavior()) != ContentDistributionStretch)) | 1866 || (direction == ForRows && styleRef().resolvedAlignContentDistribution( contentAlignmentNormalBehavior()) != ContentDistributionStretch)) |
1865 return; | 1867 return; |
1866 | 1868 |
1867 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion. | 1869 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion. |
1868 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; | 1870 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; |
1869 Vector<unsigned> autoSizedTracksIndex; | 1871 Vector<unsigned> autoSizedTracksIndex; |
1870 for (unsigned i = 0; i < tracks.size(); ++i) { | 1872 for (unsigned i = 0; i < tracks.size(); ++i) { |
1871 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 1873 const GridTrackSize& trackSize = gridTrackSize(direction, i, sizingData) ; |
1872 if (trackSize.hasAutoMaxTrackBreadth()) | 1874 if (trackSize.hasAutoMaxTrackBreadth()) |
1873 autoSizedTracksIndex.append(i); | 1875 autoSizedTracksIndex.append(i); |
1874 } | 1876 } |
1875 | 1877 |
1876 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); | 1878 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); |
1877 if (numberOfAutoSizedTracks < 1) | 1879 if (numberOfAutoSizedTracks < 1) |
1878 return; | 1880 return; |
1879 | 1881 |
1880 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 1882 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; |
1881 for (const auto& trackIndex : autoSizedTracksIndex) { | 1883 for (const auto& trackIndex : autoSizedTracksIndex) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2070 ASSERT(m_gridItemArea.contains(&gridItem)); | 2072 ASSERT(m_gridItemArea.contains(&gridItem)); |
2071 return m_gridItemArea.get(&gridItem); | 2073 return m_gridItemArea.get(&gridItem); |
2072 } | 2074 } |
2073 | 2075 |
2074 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const | 2076 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const |
2075 { | 2077 { |
2076 GridArea area = cachedGridArea(gridItem); | 2078 GridArea area = cachedGridArea(gridItem); |
2077 return direction == ForColumns ? area.columns : area.rows; | 2079 return direction == ForColumns ? area.columns : area.rows; |
2078 } | 2080 } |
2079 | 2081 |
2080 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild(const LayoutBox& child, SizingOperation sizingOperation) const | 2082 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild(const LayoutBox& child, const GridSizingData& sizingData) const |
2081 { | 2083 { |
2082 DCHECK(isOrthogonalChild(child)); | 2084 DCHECK(isOrthogonalChild(child)); |
2083 const GridSpan& span = cachedGridSpan(child, ForRows); | 2085 const GridSpan& span = cachedGridSpan(child, ForRows); |
2084 LayoutUnit gridAreaSize; | 2086 LayoutUnit gridAreaSize; |
2085 bool gridAreaIsIndefinite = false; | 2087 bool gridAreaIsIndefinite = false; |
2086 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon tent(ExcludeMarginBorderPadding); | 2088 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon tent(ExcludeMarginBorderPadding); |
2087 for (auto trackPosition : span) { | 2089 for (auto trackPosition : span) { |
2088 GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition, sizingOp eration).maxTrackBreadth(); | 2090 GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition, sizingDa ta).maxTrackBreadth(); |
2089 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) | 2091 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) |
2090 gridAreaIsIndefinite = true; | 2092 gridAreaIsIndefinite = true; |
2091 else | 2093 else |
2092 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc kAvailableSize); | 2094 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc kAvailableSize); |
2093 } | 2095 } |
2094 | 2096 |
2095 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan(), s izingOperation); | 2097 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan(), s izingData.sizingOperation); |
2096 | 2098 |
2097 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri dAreaSize) : gridAreaSize; | 2099 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri dAreaSize) : gridAreaSize; |
2098 } | 2100 } |
2099 | 2101 |
2100 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const | 2102 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const |
2101 { | 2103 { |
2102 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which | 2104 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which |
2103 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet, | 2105 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet, |
2104 // so we will need to do an estimation. | 2106 // so we will need to do an estimation. |
2105 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration) | 2107 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration) |
2106 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati on); | 2108 return assumedRowsSizeForOrthogonalChild(child, sizingData); |
2107 | 2109 |
2108 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; | 2110 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; |
2109 const GridSpan& span = cachedGridSpan(child, direction); | 2111 const GridSpan& span = cachedGridSpan(child, direction); |
2110 LayoutUnit gridAreaBreadth; | 2112 LayoutUnit gridAreaBreadth; |
2111 for (const auto& trackPosition : span) | 2113 for (const auto& trackPosition : span) |
2112 gridAreaBreadth += tracks[trackPosition].baseSize(); | 2114 gridAreaBreadth += tracks[trackPosition].baseSize(); |
2113 | 2115 |
2114 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan (), sizingData.sizingOperation); | 2116 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan (), sizingData.sizingOperation); |
2115 | 2117 |
2116 return gridAreaBreadth; | 2118 return gridAreaBreadth; |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2661 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | 2663 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; |
2662 } | 2664 } |
2663 | 2665 |
2664 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2666 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2665 { | 2667 { |
2666 if (!m_gridItemArea.isEmpty()) | 2668 if (!m_gridItemArea.isEmpty()) |
2667 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2669 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2668 } | 2670 } |
2669 | 2671 |
2670 } // namespace blink | 2672 } // namespace blink |
OLD | NEW |