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

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

Issue 2216903004: [css-flexbox] Correctly implement contain: size on a flex item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 4 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 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (flexLength.isAuto()) 469 if (flexLength.isAuto())
470 flexLength = isHorizontalFlow() ? child.style()->width() : child.style() ->height(); 470 flexLength = isHorizontalFlow() ? child.style()->width() : child.style() ->height();
471 return flexLength; 471 return flexLength;
472 } 472 }
473 473
474 LayoutUnit LayoutFlexibleBox::crossAxisExtentForChild(const LayoutBox& child) co nst 474 LayoutUnit LayoutFlexibleBox::crossAxisExtentForChild(const LayoutBox& child) co nst
475 { 475 {
476 return isHorizontalFlow() ? child.size().height() : child.size().width(); 476 return isHorizontalFlow() ? child.size().height() : child.size().width();
477 } 477 }
478 478
479 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child) 479 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child, LayoutUnit childIntrinsicContentLogicalHeight)
480 { 480 {
481 // TODO(cbiesinger): scrollbar height? 481 // TODO(cbiesinger): scrollbar height?
482 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight();
483 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); 482 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight);
484 } 483 }
485 484
486 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalHeight(const LayoutBox& child ) const 485 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalHeight(const LayoutBox& child ) const
487 { 486 {
488 // This should only be called if the logical height is the cross size 487 // This should only be called if the logical height is the cross size
489 DCHECK(!hasOrthogonalFlow(child)); 488 DCHECK(!hasOrthogonalFlow(child));
490 if (needToStretchChildLogicalHeight(child)) 489 if (needToStretchChildLogicalHeight(child)) {
491 return constrainedChildIntrinsicContentLogicalHeight(child); 490 LayoutUnit childIntrinsicContentLogicalHeight;
491 if (!child.styleRef().containsSize())
492 childIntrinsicContentLogicalHeight = child.intrinsicContentLogicalHe ight();
493 return constrainedChildIntrinsicContentLogicalHeight(child, childIntrins icContentLogicalHeight);
494 }
492 return child.logicalHeight(); 495 return child.logicalHeight();
493 } 496 }
494 497
495 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalWidth(const LayoutBox& child) const 498 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalWidth(const LayoutBox& child) const
496 { 499 {
497 // This should only be called if the logical width is the cross size 500 // This should only be called if the logical width is the cross size
498 DCHECK(hasOrthogonalFlow(child)); 501 DCHECK(hasOrthogonalFlow(child));
499 // If our height is auto, make sure that our returned height is unaffected b y earlier layouts by 502 // If our height is auto, make sure that our returned height is unaffected b y earlier layouts by
500 // returning the max preferred logical width 503 // returning the max preferred logical width
501 if (!crossAxisLengthIsDefinite(child, child.styleRef().logicalWidth())) 504 if (!crossAxisLengthIsDefinite(child, child.styleRef().logicalWidth()))
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 { 855 {
853 child.clearOverrideSize(); 856 child.clearOverrideSize();
854 857
855 if (child.isImage() || child.isVideo() || child.isCanvas()) 858 if (child.isImage() || child.isVideo() || child.isCanvas())
856 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); 859 UseCounter::count(document(), UseCounter::AspectRatioFlexItem);
857 860
858 Length flexBasis = flexBasisForChild(child); 861 Length flexBasis = flexBasisForChild(child);
859 if (mainAxisLengthIsDefinite(child, flexBasis)) 862 if (mainAxisLengthIsDefinite(child, flexBasis))
860 return std::max(LayoutUnit(), computeMainAxisExtentForChild(child, MainO rPreferredSize, flexBasis)); 863 return std::max(LayoutUnit(), computeMainAxisExtentForChild(child, MainO rPreferredSize, flexBasis));
861 864
865 if (child.styleRef().containsSize())
866 return LayoutUnit();
867
862 LayoutUnit mainAxisExtent; 868 LayoutUnit mainAxisExtent;
863 if (childFlexBaseSizeRequiresLayout(child)) { 869 if (childFlexBaseSizeRequiresLayout(child)) {
864 if (childLayoutType == NeverLayout) 870 if (childLayoutType == NeverLayout)
865 return LayoutUnit(); 871 return LayoutUnit();
866 872
867 if (child.needsLayout() || childLayoutType == ForceLayout || !m_intrinsi cSizeAlongMainAxis.contains(&child)) { 873 if (child.needsLayout() || childLayoutType == ForceLayout || !m_intrinsi cSizeAlongMainAxis.contains(&child)) {
868 child.forceChildLayout(); 874 child.forceChildLayout();
869 cacheChildMainSize(child); 875 cacheChildMainSize(child);
870 } 876 }
871 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child); 877 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 childSize = maxExtent; 1113 childSize = maxExtent;
1108 } 1114 }
1109 1115
1110 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); 1116 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight();
1111 LayoutUnit minExtent; 1117 LayoutUnit minExtent;
1112 if (min.isSpecifiedOrIntrinsic()) { 1118 if (min.isSpecifiedOrIntrinsic()) {
1113 minExtent = computeMainAxisExtentForChild(child, MinSize, min); 1119 minExtent = computeMainAxisExtentForChild(child, MinSize, min);
1114 // computeMainAxisExtentForChild can return -1 when the child has a perc entage 1120 // computeMainAxisExtentForChild can return -1 when the child has a perc entage
1115 // min size, but we have an indefinite size in that axis. 1121 // min size, but we have an indefinite size in that axis.
1116 minExtent = std::max(LayoutUnit(), minExtent); 1122 minExtent = std::max(LayoutUnit(), minExtent);
1117 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OverflowVisibl e && !(isColumnFlow() && child.isFlexibleBox())) { 1123 } else if (min.isAuto() && !child.styleRef().containsSize() && mainAxisOverf lowForChild(child) == OverflowVisible && !(isColumnFlow() && child.isFlexibleBox ())) {
1118 // TODO(cbiesinger): For now, we do not handle min-height: auto for nest ed column flexboxes. We need 1124 // TODO(cbiesinger): For now, we do not handle min-height: auto for nest ed column flexboxes. We need
1119 // to implement https://drafts.csswg.org/css-flexbox/#intrinsic-sizes be fore that produces 1125 // to implement https://drafts.csswg.org/css-flexbox/#intrinsic-sizes be fore that produces
1120 // reasonable results. Tracking bug: https://crbug.com/581553 1126 // reasonable results. Tracking bug: https://crbug.com/581553
1121 // css-flexbox section 4.5 1127 // css-flexbox section 4.5
1122 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); 1128 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent));
1123 DCHECK_GE(contentSize, LayoutUnit()); 1129 DCHECK_GE(contentSize, LayoutUnit());
1124 if (hasAspectRatio(child) && child.intrinsicSize().height() > 0) 1130 if (hasAspectRatio(child) && child.intrinsicSize().height() > 0)
1125 contentSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, contentSize); 1131 contentSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, contentSize);
1126 if (maxExtent != -1 && contentSize > maxExtent) 1132 if (maxExtent != -1 && contentSize > maxExtent)
1127 contentSize = maxExtent; 1133 contentSize = maxExtent;
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 DCHECK(child); 1927 DCHECK(child);
1922 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1928 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1923 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1929 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1924 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1930 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1925 adjustAlignmentForChild(*child, newOffset - originalOffset); 1931 adjustAlignmentForChild(*child, newOffset - originalOffset);
1926 } 1932 }
1927 } 1933 }
1928 } 1934 }
1929 1935
1930 } // namespace blink 1936 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698