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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 if (minTrackBreadth.hasPercentage()) | 597 if (minTrackBreadth.hasPercentage()) |
598 minTrackBreadth = Length(Auto); | 598 minTrackBreadth = Length(Auto); |
599 if (maxTrackBreadth.hasPercentage()) | 599 if (maxTrackBreadth.hasPercentage()) |
600 maxTrackBreadth = Length(Auto); | 600 maxTrackBreadth = Length(Auto); |
601 } | 601 } |
602 } | 602 } |
603 | 603 |
604 return GridTrackSize(minTrackBreadth, maxTrackBreadth); | 604 return GridTrackSize(minTrackBreadth, maxTrackBreadth); |
605 } | 605 } |
606 | 606 |
607 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack> & columnTracks) | 607 LayoutUnit LayoutGrid::overrideContainingBlockLogicalBreadthInlineDirection(cons t LayoutBox& child) const |
cbiesinger
2015/11/13 03:25:48
Hmm, this is the grid's inline direction, not the
| |
608 { | 608 { |
609 SubtreeLayoutScope layoutScope(child); | 609 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
610 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit(); | 610 if (hasOrthogonalWritingMode) |
611 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); | 611 return child.hasOverrideContainingBlockLogicalHeight() ? child.overrideC ontainingBlockContentLogicalHeight() : LayoutUnit(); |
612 if (child.hasRelativeLogicalHeight() || oldOverrideContainingBlockContentLog icalWidth != overrideContainingBlockContentLogicalWidth) { | 612 return child.hasOverrideContainingBlockLogicalWidth() ? child.overrideContai ningBlockContentLogicalWidth() : LayoutUnit(); |
613 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged ); | 613 } |
614 | |
615 void LayoutGrid::setOverrideContainingBlockLogicalBreadthInlineDirection(LayoutB ox& child, LayoutUnit breadthInLine) | |
616 { | |
617 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | |
618 bool hasRelativeBreadthInBlockDirection = hasOrthogonalWritingMode ? child.h asRelativeLogicalWidth() : child.hasRelativeLogicalHeight(); | |
619 // If |child| has a percentage logical breadth in block direction, we should n't let it override its intrinsic size, which is | |
620 // what we are interested in here. Thus we need to set the override logical height/width to -1 (no possible resolution). | |
621 if (hasOrthogonalWritingMode) { | |
622 child.setOverrideContainingBlockContentLogicalHeight(breadthInLine); | |
623 if (hasRelativeBreadthInBlockDirection) | |
624 child.setOverrideContainingBlockContentLogicalWidth(-1); | |
625 } else { | |
626 child.setOverrideContainingBlockContentLogicalWidth(breadthInLine); | |
627 if (hasRelativeBreadthInBlockDirection) | |
628 child.setOverrideContainingBlockContentLogicalHeight(-1); | |
614 } | 629 } |
615 | |
616 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight(); | |
617 // We need to clear the stretched height to properly compute logical height during layout. | |
618 if (hasOverrideHeight && child.needsLayout()) | |
619 child.clearOverrideLogicalContentHeight(); | |
620 | |
621 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth); | |
622 // If |child| has a relative logical height, we shouldn't let it override it s intrinsic height, which is | |
623 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). | |
624 if (child.hasRelativeLogicalHeight()) | |
625 child.setOverrideContainingBlockContentLogicalHeight(-1); | |
626 child.layoutIfNeeded(); | |
627 // If the child was stretched we should use its intrinsic height. | |
628 return (hasOverrideHeight ? childIntrinsicHeight(child) : child.logicalHeigh t()) + child.marginLogicalHeight(); | |
629 } | 630 } |
630 | 631 |
631 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, Vector<GridTrack>& columnTracks) | 632 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, Vector<GridTrack>& columnTracks) |
632 { | 633 { |
633 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 634 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
634 // TODO(svillar): Properly support orthogonal writing mode. | 635 // TODO(svillar): Properly support orthogonal writing mode. |
635 if (hasOrthogonalWritingMode) | 636 if (hasOrthogonalWritingMode) |
636 return LayoutUnit(); | 637 return LayoutUnit(); |
637 | 638 |
638 const Length& childMinSize = direction == ForColumns ? child.style()->logica lMinWidth() : child.style()->logicalMinHeight(); | 639 const Length& childMinSize = direction == ForColumns ? child.style()->logica lMinWidth() : child.style()->logicalMinHeight(); |
639 if (childMinSize.isAuto()) { | 640 if (childMinSize.isAuto()) { |
640 // TODO(svillar): Implement intrinsic aspect ratio support (transferred size in specs). | 641 // TODO(svillar): Implement intrinsic aspect ratio support (transferred size in specs). |
641 return minContentForChild(child, direction, columnTracks); | 642 return minContentForChild(child, direction, columnTracks); |
642 } | 643 } |
643 | 644 |
644 if (direction == ForColumns) | 645 if (direction == ForColumns) |
645 return child.computeLogicalWidthUsing(MinSize, childMinSize, contentLogi calWidth(), this); | 646 return child.computeLogicalWidthUsing(MinSize, childMinSize, contentLogi calWidth(), this); |
646 | 647 |
647 return child.computeContentLogicalHeight(MinSize, childMinSize, child.logica lHeight()) + child.scrollbarLogicalHeight(); | 648 return child.computeContentLogicalHeight(MinSize, childMinSize, child.logica lHeight()) + child.scrollbarLogicalHeight(); |
648 } | 649 } |
649 | 650 |
650 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& columnTracks) | 651 LayoutUnit LayoutGrid::gridAreaBreadthForChildInlineDirection(const LayoutBox& c hild, Vector<GridTrack>& tracksInlineDirection) const |
651 { | 652 { |
652 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 653 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
653 // FIXME: Properly support orthogonal writing mode. | |
654 if (hasOrthogonalWritingMode) | 654 if (hasOrthogonalWritingMode) |
655 return 0; | 655 return gridAreaBreadthForChild(child, ForRows, tracksInlineDirection); |
656 return gridAreaBreadthForChild(child, ForColumns, tracksInlineDirection); | |
657 } | |
658 | |
659 | |
660 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack> & tracksInlineDirection) | |
661 { | |
662 SubtreeLayoutScope layoutScope(child); | |
663 LayoutUnit oldOverrideContainingBlockContentLogicalBreadthInlineDirection = overrideContainingBlockLogicalBreadthInlineDirection(child); | |
664 LayoutUnit overrideContainingBlockContentLogicalBreadthInlineDirection = gri dAreaBreadthForChildInlineDirection(child, tracksInlineDirection); | |
esprehn
2015/10/30 23:21:31
longest variable names ever :P
| |
665 if (child.hasRelativeLogicalHeight() || oldOverrideContainingBlockContentLog icalBreadthInlineDirection != overrideContainingBlockContentLogicalBreadthInline Direction) { | |
666 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged ); | |
667 } | |
668 | |
669 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight(); | |
670 // We need to clear the stretched height to properly compute logical height during layout. | |
671 if (hasOverrideHeight && child.needsLayout()) | |
672 child.clearOverrideLogicalContentHeight(); | |
673 | |
674 setOverrideContainingBlockLogicalBreadthInlineDirection(child, overrideConta iningBlockContentLogicalBreadthInlineDirection); | |
675 child.layoutIfNeeded(); | |
676 // If the child was stretched we should use its intrinsic height. | |
677 return (hasOverrideHeight ? childIntrinsicHeight(child) : child.logicalHeigh t()) + child.marginLogicalHeight(); | |
esprehn
2015/10/30 23:21:31
I find this ternary + expr thing hard to read, can
| |
678 } | |
679 | |
680 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& tracksInTheInlineDirection) | |
681 { | |
682 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | |
683 if (hasOrthogonalWritingMode) | |
684 direction = direction == ForColumns ? ForRows : ForColumns; | |
656 | 685 |
657 if (direction == ForColumns) { | 686 if (direction == ForColumns) { |
658 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 687 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
659 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). | 688 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). |
660 if (child.hasRelativeLogicalWidth()) | 689 if (child.hasRelativeLogicalWidth()) |
661 child.setOverrideContainingBlockContentLogicalWidth(-1); | 690 child.setOverrideContainingBlockContentLogicalWidth(-1); |
662 | 691 |
663 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 692 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
664 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 693 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
665 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 694 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
666 } | 695 } |
667 | 696 |
668 return logicalHeightForChild(child, columnTracks); | 697 return logicalHeightForChild(child, tracksInTheInlineDirection); |
669 } | 698 } |
670 | 699 |
671 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& columnTracks) | 700 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& tracksInlineDirection) |
672 { | 701 { |
673 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 702 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
674 // FIXME: Properly support orthogonal writing mode. | |
675 if (hasOrthogonalWritingMode) | 703 if (hasOrthogonalWritingMode) |
676 return LayoutUnit(); | 704 direction = direction == ForColumns ? ForRows : ForColumns; |
677 | 705 |
678 if (direction == ForColumns) { | 706 if (direction == ForColumns) { |
679 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 707 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
680 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). | 708 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). |
681 if (child.hasRelativeLogicalWidth()) | 709 if (child.hasRelativeLogicalWidth()) |
682 child.setOverrideContainingBlockContentLogicalWidth(-1); | 710 child.setOverrideContainingBlockContentLogicalWidth(-1); |
683 | 711 |
684 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 712 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
685 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 713 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
686 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 714 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
687 } | 715 } |
688 | 716 |
689 return logicalHeightForChild(child, columnTracks); | 717 return logicalHeightForChild(child, tracksInlineDirection); |
690 } | 718 } |
691 | 719 |
692 // We're basically using a class instead of a std::pair for two reasons. First o f all, accessing gridItem() or | 720 // We're basically using a class instead of a std::pair for two reasons. First o f all, accessing gridItem() or |
693 // coordinate() is much more self-explanatory that using .first or .second membe rs in the pair. Secondly the class | 721 // coordinate() is much more self-explanatory that using .first or .second membe rs in the pair. Secondly the class |
694 // allows us to precompute the value of the span, something which is quite conve nient for the sorting. Having a | 722 // allows us to precompute the value of the span, something which is quite conve nient for the sorting. Having a |
695 // std::pair<LayoutBox*, size_t> does not work either because we still need the GridCoordinate so we'd have to add an | 723 // std::pair<LayoutBox*, size_t> does not work either because we still need the GridCoordinate so we'd have to add an |
696 // extra hash lookup for each item at the beginning of LayoutGrid::resolveConten tBasedTrackSizingFunctionsForItems(). | 724 // extra hash lookup for each item at the beginning of LayoutGrid::resolveConten tBasedTrackSizingFunctionsForItems(). |
697 class GridItemWithSpan { | 725 class GridItemWithSpan { |
698 public: | 726 public: |
699 GridItemWithSpan(LayoutBox& gridItem, const GridCoordinate& coordinate, Grid TrackSizingDirection direction) | 727 GridItemWithSpan(LayoutBox& gridItem, const GridCoordinate& coordinate, Grid TrackSizingDirection direction) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 766 } |
739 | 767 |
740 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) | 768 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) |
741 { | 769 { |
742 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 770 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
743 HashSet<LayoutBox*> itemsSet; | 771 HashSet<LayoutBox*> itemsSet; |
744 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 772 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
745 GridIterator iterator(m_grid, direction, trackIndex); | 773 GridIterator iterator(m_grid, direction, trackIndex); |
746 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; | 774 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; |
747 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 775 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
776 bool hasOrthogonalWritingMode = gridItem->isHorizontalWritingMode() != isHorizontalWritingMode(); | |
748 if (itemsSet.add(gridItem).isNewEntry) { | 777 if (itemsSet.add(gridItem).isNewEntry) { |
749 const GridCoordinate& coordinate = cachedGridCoordinate(*gridIte m); | 778 const GridCoordinate& coordinate = cachedGridCoordinate(*gridIte m); |
750 if (integerSpanForDirection(coordinate, direction) == 1) { | 779 if (integerSpanForDirection(coordinate, direction) == 1) { |
751 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, coordinate, *gridItem, track, sizingData.columnTracks); | 780 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, coordinate, *gridItem, track, hasOrthogonalWritingMode ? sizingData.ro wTracks : sizingData.columnTracks); |
752 } else if (!spanningItemCrossesFlexibleSizedTracks(coordinate, d irection)) { | 781 } else if (!spanningItemCrossesFlexibleSizedTracks(coordinate, d irection)) { |
753 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, coordinate, direction)); | 782 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, coordinate, direction)); |
754 } | 783 } |
755 } | 784 } |
756 } | 785 } |
757 } | 786 } |
758 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end()); | 787 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end()); |
759 | 788 |
760 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); | 789 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); |
761 auto end = sizingData.itemsSortedByIncreasingSpan.end(); | 790 auto end = sizingData.itemsSortedByIncreasingSpan.end(); |
762 while (it != end) { | 791 while (it != end) { |
763 GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) }; | 792 GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) }; |
764 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange); | 793 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange); |
765 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange); | 794 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange); |
766 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange); | 795 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange); |
767 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange); | 796 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange); |
768 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange); | 797 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange); |
769 it = spanGroupRange.rangeEnd; | 798 it = spanGroupRange.rangeEnd; |
770 } | 799 } |
771 | 800 |
772 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 801 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
773 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; | 802 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; |
774 if (track.growthLimitIsInfinite()) | 803 if (track.growthLimitIsInfinite()) |
775 track.setGrowthLimit(track.baseSize()); | 804 track.setGrowthLimit(track.baseSize()); |
776 } | 805 } |
777 } | 806 } |
778 | 807 |
779 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridCoordinate& coordinate, LayoutBox& gri dItem, GridTrack& track, Vector<GridTrack>& columnTracks) | 808 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridCoordinate& coordinate, LayoutBox& gri dItem, GridTrack& track, Vector<GridTrack>& tracksInlineDirection) |
780 { | 809 { |
781 const GridResolvedPosition trackPosition = (direction == ForColumns) ? coord inate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPosition; | 810 const GridResolvedPosition trackPosition = (direction == ForColumns) ? coord inate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPosition; |
782 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); | 811 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); |
783 | 812 |
784 if (trackSize.hasMinContentMinTrackBreadth()) | 813 if (trackSize.hasMinContentMinTrackBreadth()) |
785 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, columnTracks))); | 814 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, tracksInlineDirection))); |
786 else if (trackSize.hasMaxContentMinTrackBreadth()) | 815 else if (trackSize.hasMaxContentMinTrackBreadth()) |
787 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, columnTracks))); | 816 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, tracksInlineDirection))); |
788 else if (trackSize.hasAutoMinTrackBreadth()) | 817 else if (trackSize.hasAutoMinTrackBreadth()) |
789 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, columnTracks))); | 818 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, tracksInlineDirection))); |
790 | 819 |
791 if (trackSize.hasMinContentMaxTrackBreadth()) | 820 if (trackSize.hasMinContentMaxTrackBreadth()) |
792 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, columnTracks))); | 821 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, tracksInlineDirection))); |
793 else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) | 822 else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) |
794 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, columnTracks))); | 823 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, tracksInlineDirection))); |
795 } | 824 } |
796 | 825 |
797 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) | 826 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) |
798 { | 827 { |
799 switch (phase) { | 828 switch (phase) { |
800 case ResolveIntrinsicMinimums: | 829 case ResolveIntrinsicMinimums: |
801 case ResolveContentBasedMinimums: | 830 case ResolveContentBasedMinimums: |
802 case ResolveMaxContentMinimums: | 831 case ResolveMaxContentMinimums: |
803 case MaximizeTracks: | 832 case MaximizeTracks: |
804 return track.baseSize(); | 833 return track.baseSize(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 | 977 |
949 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) | 978 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) |
950 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 979 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
951 } | 980 } |
952 | 981 |
953 if (sizingData.filteredTracks.isEmpty()) | 982 if (sizingData.filteredTracks.isEmpty()) |
954 continue; | 983 continue; |
955 | 984 |
956 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); | 985 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); |
957 | 986 |
958 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTr acksSize; | 987 bool hasOrthogonalWritingMode = gridItemWithSpan.gridItem().isHorizontal WritingMode() != isHorizontalWritingMode(); |
988 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, hasOrthogonalWritingMode ? sizingData .rowTracks : sizingData.columnTracks) - spanningTracksSize; | |
959 extraSpace = std::max<LayoutUnit>(extraSpace, 0); | 989 extraSpace = std::max<LayoutUnit>(extraSpace, 0); |
960 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; | 990 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; |
961 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); | 991 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); |
962 } | 992 } |
963 | 993 |
964 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 994 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
965 GridTrack& track = tracks[trackIndex]; | 995 GridTrack& track = tracks[trackIndex]; |
966 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); | 996 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); |
967 updateTrackSizeForTrackSizeComputationPhase(phase, track); | 997 updateTrackSizeForTrackSizeComputationPhase(phase, track); |
968 } | 998 } |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 | 1333 |
1304 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 1334 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; |
1305 for (const auto& trackIndex : autoSizedTracksIndex) { | 1335 for (const auto& trackIndex : autoSizedTracksIndex) { |
1306 GridTrack* track = tracks.data() + trackIndex; | 1336 GridTrack* track = tracks.data() + trackIndex; |
1307 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; | 1337 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; |
1308 track->setBaseSize(baseSize); | 1338 track->setBaseSize(baseSize); |
1309 } | 1339 } |
1310 availableSpace = 0; | 1340 availableSpace = 0; |
1311 } | 1341 } |
1312 | 1342 |
1343 bool LayoutGrid::childOverflowingContainingBlockHeight(const LayoutBox& child) c onst | |
esprehn
2015/10/30 23:21:31
static? or static and file level?
| |
1344 { | |
1345 LayoutUnit containingBlockContentHeight = child.hasOverrideContainingBlockHe ight() ? child.overrideContainingBlockContentHeight() : LayoutUnit(); | |
1346 return child.size().height() > containingBlockContentHeight; | |
1347 } | |
1348 | |
1349 bool LayoutGrid::childOverflowingContainingBlockWidth(const LayoutBox& child) co nst | |
esprehn
2015/10/30 23:21:31
these methods don't appear to use any internal sta
| |
1350 { | |
1351 LayoutUnit containingBlockContentWidth = child.hasOverrideContainingBlockWid th() ? child.overrideContainingBlockContentWidth() : LayoutUnit(); | |
1352 return child.size().width() > containingBlockContentWidth; | |
1353 } | |
1354 | |
1313 void LayoutGrid::layoutGridItems() | 1355 void LayoutGrid::layoutGridItems() |
1314 { | 1356 { |
1315 placeItemsOnGrid(); | 1357 placeItemsOnGrid(); |
1316 | 1358 |
1317 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 1359 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
1318 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde rPadding); | 1360 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde rPadding); |
1319 | 1361 |
1320 // Remove space consumed by gutters from the available logical space. | 1362 // Remove space consumed by gutters from the available logical space. |
1321 availableSpaceForColumns -= guttersSize(ForColumns, gridColumnCount()); | 1363 availableSpaceForColumns -= guttersSize(ForColumns, gridColumnCount()); |
1322 availableSpaceForRows -= guttersSize(ForRows, gridRowCount()); | 1364 availableSpaceForRows -= guttersSize(ForRows, gridRowCount()); |
1323 | 1365 |
1324 GridSizingData sizingData(gridColumnCount(), gridRowCount(), availableSpaceF orColumns, availableSpaceForRows); | 1366 GridSizingData sizingData(gridColumnCount(), gridRowCount(), availableSpaceF orColumns, availableSpaceForRows); |
1367 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. | |
1325 computeUsedBreadthOfGridTracks(ForColumns, sizingData); | 1368 computeUsedBreadthOfGridTracks(ForColumns, sizingData); |
1326 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks )); | 1369 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks )); |
1370 // 2- Next, the track sizing algorithm resolves the sizes of the grid rows, using the | |
1371 // grid column sizes calculated in the previous step. | |
1327 computeUsedBreadthOfGridTracks(ForRows, sizingData); | 1372 computeUsedBreadthOfGridTracks(ForRows, sizingData); |
1328 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); | 1373 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); |
1374 // 3- If the min-content contribution of any grid items have changed based o n the row | |
1375 // sizes calculated in step 2, steps 1 and 2 are repeated with the new min-c ontent | |
1376 // contribution (once only). | |
1377 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { | |
1378 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHo rizontalWritingMode(); | |
1379 // In orthogonal flow cases column tracks size is determined based on th e computed | |
1380 // row track sizes, hence we need to repeat computeUsedBreadthOfGridTrac ks for columns. | |
1381 if (hasOrthogonalWritingMode) { | |
1382 LayoutUnit& currentAvailableSpaceForColumns = sizingData.freeSpaceFo rDirection(ForColumns); | |
1383 currentAvailableSpaceForColumns = availableSpaceForColumns; | |
1384 computeUsedBreadthOfGridTracks(ForColumns, sizingData); | |
1385 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.colu mnTracks)); | |
1386 break; | |
1387 } | |
1388 } | |
1329 | 1389 |
1330 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); | 1390 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); |
1331 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); | 1391 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); |
1332 | 1392 |
1333 populateGridPositions(sizingData); | 1393 populateGridPositions(sizingData); |
1334 m_gridItemsOverflowingGridArea.resize(0); | 1394 m_gridItemsOverflowingGridArea.resize(0); |
1335 | 1395 |
1336 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { | 1396 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { |
1337 if (child->isOutOfFlowPositioned()) { | 1397 if (child->isOutOfFlowPositioned()) { |
1338 prepareChildForPositionedLayout(*child); | 1398 prepareChildForPositionedLayout(*child); |
(...skipping 27 matching lines...) Expand all Loading... | |
1366 updateAutoMarginsInRowAxisIfNeeded(*child); | 1426 updateAutoMarginsInRowAxisIfNeeded(*child); |
1367 | 1427 |
1368 #if ENABLE(ASSERT) | 1428 #if ENABLE(ASSERT) |
1369 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1429 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
1370 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); | 1430 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); |
1371 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); | 1431 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); |
1372 #endif | 1432 #endif |
1373 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1433 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1374 | 1434 |
1375 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is | 1435 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is |
1376 // not visible | 1436 // not visible. |
1377 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1437 // Using physical dimensions for simplicity, so we can forget about orth ogonalty. |
1378 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h) | 1438 if (childOverflowingContainingBlockHeight(*child) |
1439 || childOverflowingContainingBlockWidth(*child)) | |
1379 m_gridItemsOverflowingGridArea.append(child); | 1440 m_gridItemsOverflowingGridArea.append(child); |
1380 } | 1441 } |
1381 | 1442 |
1382 LayoutUnit height = borderAndPaddingLogicalHeight() + scrollbarLogicalHeight (); | 1443 LayoutUnit height = borderAndPaddingLogicalHeight() + scrollbarLogicalHeight (); |
1383 for (const auto& row : sizingData.rowTracks) | 1444 for (const auto& row : sizingData.rowTracks) |
1384 height += row.baseSize(); | 1445 height += row.baseSize(); |
1385 | 1446 |
1386 height += guttersSize(ForRows, sizingData.rowTracks.size()); | 1447 height += guttersSize(ForRows, sizingData.rowTracks.size()); |
1387 | 1448 |
1388 if (hasLineIfEmpty()) | 1449 if (hasLineIfEmpty()) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 | 1712 |
1652 auto& childStyle = child.styleRef(); | 1713 auto& childStyle = child.styleRef(); |
1653 bool isHorizontalMode = isHorizontalWritingMode(); | 1714 bool isHorizontalMode = isHorizontalWritingMode(); |
1654 bool hasAutoSizeInRowAxis = isHorizontalMode ? childStyle.width().isAuto() : childStyle.height().isAuto(); | 1715 bool hasAutoSizeInRowAxis = isHorizontalMode ? childStyle.width().isAuto() : childStyle.height().isAuto(); |
1655 bool allowedToStretchChildAlongRowAxis = hasAutoSizeInRowAxis && !childStyle .marginStartUsing(style()).isAuto() && !childStyle.marginEndUsing(style()).isAut o(); | 1716 bool allowedToStretchChildAlongRowAxis = hasAutoSizeInRowAxis && !childStyle .marginStartUsing(style()).isAuto() && !childStyle.marginEndUsing(style()).isAut o(); |
1656 if (!allowedToStretchChildAlongRowAxis || ComputedStyle::resolveJustificatio n(styleRef(), childStyle, ItemPositionStretch) != ItemPositionStretch) { | 1717 if (!allowedToStretchChildAlongRowAxis || ComputedStyle::resolveJustificatio n(styleRef(), childStyle, ItemPositionStretch) != ItemPositionStretch) { |
1657 bool hasAutoMinSizeInRowAxis = isHorizontalMode ? childStyle.minWidth(). isAuto() : childStyle.minHeight().isAuto(); | 1718 bool hasAutoMinSizeInRowAxis = isHorizontalMode ? childStyle.minWidth(). isAuto() : childStyle.minHeight().isAuto(); |
1658 bool canShrinkToFitInRowAxisForChild = !hasAutoMinSizeInRowAxis || child .minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth( ); | 1719 bool canShrinkToFitInRowAxisForChild = !hasAutoMinSizeInRowAxis || child .minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth( ); |
1659 // TODO(lajava): how to handle orthogonality in this case ?. | 1720 // TODO(lajava): how to handle orthogonality in this case ?. |
1660 // TODO(lajava): grid track sizing and positioning do not support orthog onal modes yet. | 1721 // TODO(lajava): grid track sizing and positioning do not support orthog onal modes yet. |
1661 if (hasAutoSizeInRowAxis && canShrinkToFitInRowAxisForChild) { | 1722 if (child.isHorizontalWritingMode() == isHorizontalMode) { |
1662 LayoutUnit childWidthToFitContent = std::max(std::min(child.maxPrefe rredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - child. marginLogicalWidth()), child.minPreferredLogicalWidth()); | 1723 if (hasAutoSizeInRowAxis && canShrinkToFitInRowAxisForChild) { |
1663 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMa x(childWidthToFitContent, -1); | 1724 LayoutUnit childWidthToFitContent = std::max(std::min(child.maxP referredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - ch ild.marginLogicalWidth()), child.minPreferredLogicalWidth()); |
1664 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.bor derAndPaddingLogicalWidth()); | 1725 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByM inMax(childWidthToFitContent, -1); |
1665 if (desiredLogicalWidth != child.logicalWidth()) | 1726 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child .borderAndPaddingLogicalWidth()); |
1666 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1727 if (desiredLogicalWidth != child.logicalWidth()) |
1728 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | |
1729 } | |
1667 } | 1730 } |
1668 } | 1731 } |
1669 | 1732 |
1670 bool hasAutoSizeInColumnAxis = isHorizontalMode ? childStyle.height().isAuto () : childStyle.width().isAuto(); | 1733 bool hasAutoSizeInColumnAxis = isHorizontalMode ? childStyle.height().isAuto () : childStyle.width().isAuto(); |
1671 bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !chil dStyle.marginBeforeUsing(style()).isAuto() && !childStyle.marginAfterUsing(style ()).isAuto(); | 1734 bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !chil dStyle.marginBeforeUsing(style()).isAuto() && !childStyle.marginAfterUsing(style ()).isAuto(); |
1672 if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment( styleRef(), childStyle, ItemPositionStretch) == ItemPositionStretch) { | 1735 if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment( styleRef(), childStyle, ItemPositionStretch) == ItemPositionStretch) { |
1673 // TODO (lajava): If the child has orthogonal flow, then it already has an override height set, so use it. | 1736 // TODO (lajava): If the child has orthogonal flow, then it already has an override height set, so use it. |
1674 // TODO (lajava): grid track sizing and positioning do not support ortho gonal modes yet. | 1737 // TODO (lajava): grid track sizing and positioning do not support ortho gonal modes yet. |
1675 if (child.isHorizontalWritingMode() == isHorizontalMode) { | 1738 if (child.isHorizontalWritingMode() == isHorizontalMode) { |
1676 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildB eforeStretching(child.overrideContainingBlockContentLogicalHeight(), child); | 1739 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildB eforeStretching(child.overrideContainingBlockContentLogicalHeight(), child); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2013 case ContentPositionAuto: | 2076 case ContentPositionAuto: |
2014 break; | 2077 break; |
2015 } | 2078 } |
2016 | 2079 |
2017 ASSERT_NOT_REACHED(); | 2080 ASSERT_NOT_REACHED(); |
2018 return {0, 0}; | 2081 return {0, 0}; |
2019 } | 2082 } |
2020 | 2083 |
2021 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const | 2084 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const |
2022 { | 2085 { |
2086 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child); | |
2023 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child); | 2087 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child); |
2024 // We stored m_columnPosition s's data ignoring the direction, hence we migh t need now | 2088 // We stored m_columnPositions's data ignoring the direction, hence we might need now |
2025 // to translate positions from RTL to LTR, as it's more convenient for paint ing. | 2089 // to translate positions from RTL to LTR, as it's more convenient for paint ing. |
2026 if (!style()->isLeftToRightDirection()) { | 2090 if (!style()->isLeftToRightDirection()) { |
2027 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); | 2091 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); |
2028 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); | 2092 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); |
2029 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); | 2093 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); |
2030 } | 2094 } |
2031 | 2095 |
2032 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 2096 |
2097 // "In the positioning phase [...] calculations are performed according to t he writing mode | |
2098 // of the containing block of the box establishing the orthogonal flow." How ever, the | |
2099 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's | |
2100 // logical position, which will only take into account the child's writing-m ode. | |
2101 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); | |
2102 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | |
2103 return hasOrthogonalWritingMode ? childLocation.transposedPoint() : childLoc ation; | |
2033 } | 2104 } |
2034 | 2105 |
2035 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2106 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2036 { | 2107 { |
2037 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2108 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2038 } | 2109 } |
2039 | 2110 |
2040 } // namespace blink | 2111 } // namespace blink |
OLD | NEW |