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

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

Issue 1778853002: [css-grid] Fix height computation for items with intrinsic aspect ratios (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 } 678 }
679 679
680 return GridTrackSize(minTrackBreadth, maxTrackBreadth); 680 return GridTrackSize(minTrackBreadth, maxTrackBreadth);
681 } 681 }
682 682
683 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack> & columnTracks) 683 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack> & columnTracks)
684 { 684 {
685 SubtreeLayoutScope layoutScope(child); 685 SubtreeLayoutScope layoutScope(child);
686 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit(); 686 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit();
687 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); 687 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks);
688 if (child.hasRelativeLogicalHeight() || oldOverrideContainingBlockContentLog icalWidth != overrideContainingBlockContentLogicalWidth) { 688 bool shouldClearContainingBlockLogicalHeight = child.hasRelativeLogicalHeigh t()
689 || (!child.styleRef().logicalHeight().isSpecified() && itemSpansContentS izedOrFlexibleSizedTracks(cachedGridSpan(child, ForRows), ForRows, ContentSizedA ndFlexible));
Manuel Rego 2016/03/14 14:38:09 I've a hard time trying to understand the 2nd part
svillar 2016/03/17 13:33:54 Isn't the function name explicit enough?
690 if (shouldClearContainingBlockLogicalHeight || oldOverrideContainingBlockCon tentLogicalWidth != overrideContainingBlockContentLogicalWidth)
689 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged ); 691 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged );
690 }
691 692
692 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight(); 693 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight();
693 // We need to clear the stretched height to properly compute logical height during layout. 694 // We need to clear the stretched height to properly compute logical height during layout.
694 if (hasOverrideHeight && child.needsLayout()) 695 if (hasOverrideHeight && child.needsLayout())
695 child.clearOverrideLogicalContentHeight(); 696 child.clearOverrideLogicalContentHeight();
696 697
697 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth); 698 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth);
698 // If |child| has a relative logical height, we shouldn't let it override it s intrinsic height, which is 699 // If |child| has a relative logical height, we shouldn't let it override it s intrinsic height, which is
699 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). 700 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution).
700 if (child.hasRelativeLogicalHeight()) 701 if (shouldClearContainingBlockLogicalHeight)
701 child.setOverrideContainingBlockContentLogicalHeight(LayoutUnit(-1)); 702 child.setOverrideContainingBlockContentLogicalHeight(LayoutUnit(-1));
702 child.layoutIfNeeded(); 703 child.layoutIfNeeded();
703 // If the child was stretched we should use its intrinsic height. 704 // If the child was stretched we should use its intrinsic height.
704 return (hasOverrideHeight ? childIntrinsicHeight(child) : child.logicalHeigh t()) + child.marginLogicalHeight(); 705 return child.logicalHeight() + child.marginLogicalHeight();
705 } 706 }
706 707
707 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, Vector<GridTrack>& columnTracks) 708 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, Vector<GridTrack>& columnTracks)
708 { 709 {
709 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 710 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
710 // TODO(svillar): Properly support orthogonal writing mode. 711 // TODO(svillar): Properly support orthogonal writing mode.
711 if (hasOrthogonalWritingMode) 712 if (hasOrthogonalWritingMode)
712 return LayoutUnit(); 713 return LayoutUnit();
713 714
714 bool isRowAxis = direction == ForColumns; 715 bool isRowAxis = direction == ForColumns;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 LayoutBox& gridItem() const { return *m_gridItem; } 781 LayoutBox& gridItem() const { return *m_gridItem; }
781 GridSpan getGridSpan() const { return m_gridSpan; } 782 GridSpan getGridSpan() const { return m_gridSpan; }
782 783
783 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); } 784 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); }
784 785
785 private: 786 private:
786 LayoutBox* m_gridItem; 787 LayoutBox* m_gridItem;
787 GridSpan m_gridSpan; 788 GridSpan m_gridSpan;
788 }; 789 };
789 790
790 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan& span, Gr idTrackSizingDirection direction) const 791 bool LayoutGrid::itemSpansContentSizedOrFlexibleSizedTracks(const GridSpan& span , GridTrackSizingDirection direction, SpanMode spanMode) const
791 { 792 {
793 bool checkContentSized = spanMode == ContentSizedAndFlexible;
792 for (const auto& trackPosition : span) { 794 for (const auto& trackPosition : span) {
793 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition) ; 795 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition) ;
794 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()) 796 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()
797 || (checkContentSized && (trackSize.minTrackBreadth().isContentSized () || trackSize.maxTrackBreadth().isContentSized())))
795 return true; 798 return true;
796 } 799 }
797 800
798 return false; 801 return false;
799 } 802 }
800 803
801 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) 804 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData)
802 { 805 {
803 sizingData.itemsSortedByIncreasingSpan.shrink(0); 806 sizingData.itemsSortedByIncreasingSpan.shrink(0);
804 HashSet<LayoutBox*> itemsSet; 807 HashSet<LayoutBox*> itemsSet;
805 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 808 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
806 GridIterator iterator(m_grid, direction, trackIndex); 809 GridIterator iterator(m_grid, direction, trackIndex);
807 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; 810 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex];
808 while (LayoutBox* gridItem = iterator.nextGridItem()) { 811 while (LayoutBox* gridItem = iterator.nextGridItem()) {
809 if (itemsSet.add(gridItem).isNewEntry) { 812 if (itemsSet.add(gridItem).isNewEntry) {
810 const GridSpan& span = cachedGridSpan(*gridItem, direction); 813 const GridSpan& span = cachedGridSpan(*gridItem, direction);
811 if (span.integerSpan() == 1) { 814 if (span.integerSpan() == 1) {
812 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, span, *gridItem, track, sizingData.columnTracks); 815 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, span, *gridItem, track, sizingData.columnTracks);
813 } else if (!spanningItemCrossesFlexibleSizedTracks(span, directi on)) { 816 } else if (!itemSpansContentSizedOrFlexibleSizedTracks(span, dir ection, FlexibleOnly)) {
814 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, span)); 817 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, span));
815 } 818 }
816 } 819 }
817 } 820 }
818 } 821 }
819 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end()); 822 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end());
820 823
821 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); 824 auto it = sizingData.itemsSortedByIncreasingSpan.begin();
822 auto end = sizingData.itemsSortedByIncreasingSpan.end(); 825 auto end = sizingData.itemsSortedByIncreasingSpan.end();
823 while (it != end) { 826 while (it != end) {
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 // If we overflow our alignment container and overflow is 'true' (defaul t), we 1638 // If we overflow our alignment container and overflow is 'true' (defaul t), we
1636 // ignore the overflow and just return the value regardless (which may c ause data 1639 // ignore the overflow and just return the value regardless (which may c ause data
1637 // loss as we overflow the 'start' edge). 1640 // loss as we overflow the 'start' edge).
1638 return offset; 1641 return offset;
1639 } 1642 }
1640 1643
1641 ASSERT_NOT_REACHED(); 1644 ASSERT_NOT_REACHED();
1642 return LayoutUnit(); 1645 return LayoutUnit();
1643 } 1646 }
1644 1647
1645 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child)
1646 {
1647 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight();
1648 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight);
1649 }
1650
1651 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1652 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const
1653 {
Manuel Rego 2016/03/14 14:38:09 Shouldn't you remove the method signature in the h
svillar 2016/03/17 13:33:54 Ups forgot about that.
1654 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch)
1655 return false;
1656
1657 return isHorizontalWritingMode() && child.style()->height().isAuto();
1658 }
1659
1660 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1661 LayoutUnit LayoutGrid::childIntrinsicHeight(const LayoutBox& child) const
Manuel Rego 2016/03/14 14:38:09 Ditto.
1662 {
1663 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child ))
1664 return constrainedChildIntrinsicContentLogicalHeight(child);
1665 return child.size().height();
1666 }
1667
1668 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1669 LayoutUnit LayoutGrid::childIntrinsicWidth(const LayoutBox& child) const
Manuel Rego 2016/03/14 14:38:09 Ditto.
1670 {
1671 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil d))
1672 return constrainedChildIntrinsicContentLogicalHeight(child);
1673 return child.size().width();
1674 }
1675
1676 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1677 LayoutUnit LayoutGrid::intrinsicLogicalHeightForChild(const LayoutBox& child) co nst
Manuel Rego 2016/03/14 14:38:09 Ditto.
1678 {
1679 return isHorizontalWritingMode() ? childIntrinsicHeight(child) : childIntrin sicWidth(child);
1680 }
1681
1682 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. 1648 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1683 LayoutUnit LayoutGrid::marginLogicalHeightForChild(const LayoutBox& child) const 1649 LayoutUnit LayoutGrid::marginLogicalHeightForChild(const LayoutBox& child) const
1684 { 1650 {
1685 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth( ); 1651 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth( );
1686 } 1652 }
1687 1653
1688 LayoutUnit LayoutGrid::computeMarginLogicalHeightForChild(const LayoutBox& child ) const 1654 LayoutUnit LayoutGrid::computeMarginLogicalHeightForChild(const LayoutBox& child ) const
1689 { 1655 {
1690 if (!child.styleRef().hasMargin()) 1656 if (!child.styleRef().hasMargin())
1691 return LayoutUnit(); 1657 return LayoutUnit();
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2035
2070 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); 2036 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child));
2071 } 2037 }
2072 2038
2073 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2039 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2074 { 2040 {
2075 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2041 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2076 } 2042 }
2077 2043
2078 } // namespace blink 2044 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698