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

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

Issue 988523003: Reimplement min-width: auto (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/LayoutFlexibleBox.h ('k') | Source/core/layout/LayoutGrid.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 { 412 {
413 // If we have a horizontal flow, that means the main size is the width. 413 // If we have a horizontal flow, that means the main size is the width.
414 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. 414 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes.
415 // For a vertical flow, main size is the height, so it's the inverse. 415 // For a vertical flow, main size is the height, so it's the inverse.
416 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. 416 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode.
417 // Otherwise we need the logical height. 417 // Otherwise we need the logical height.
418 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { 418 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) {
419 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. 419 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway.
420 if (size.isIntrinsic()) 420 if (size.isIntrinsic())
421 child.layoutIfNeeded(); 421 child.layoutIfNeeded();
422 return child.computeContentLogicalHeight(size, child.logicalHeight() - c hild.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight(); 422 return child.computeContentLogicalHeight(sizeType, size, child.logicalHe ight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight() ;
423 } 423 }
424 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); 424 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth();
425 } 425 }
426 426
427 WritingMode LayoutFlexibleBox::transformedWritingMode() const 427 WritingMode LayoutFlexibleBox::transformedWritingMode() const
428 { 428 {
429 WritingMode mode = style()->writingMode(); 429 WritingMode mode = style()->writingMode();
430 if (!isColumnFlow()) 430 if (!isColumnFlow())
431 return mode; 431 return mode;
432 432
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } else { 830 } else {
831 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p())); 831 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p()));
832 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom())); 832 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom()));
833 } 833 }
834 } 834 }
835 } 835 }
836 836
837 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, Layo utUnit childSize) 837 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, Layo utUnit childSize)
838 { 838 {
839 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight(); 839 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight();
840 LayoutUnit maxExtent = -1;
840 if (max.isSpecifiedOrIntrinsic()) { 841 if (max.isSpecifiedOrIntrinsic()) {
841 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max ); 842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
842 if (maxExtent != -1 && childSize > maxExtent) 843 if (maxExtent != -1 && childSize > maxExtent)
843 childSize = maxExtent; 844 childSize = maxExtent;
844 } 845 }
845 846
846 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); 847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight();
847 LayoutUnit minExtent = 0; 848 LayoutUnit minExtent = 0;
848 if (min.isSpecifiedOrIntrinsic()) { 849 if (min.isSpecifiedOrIntrinsic()) {
849 minExtent = computeMainAxisExtentForChild(child, MinSize, min); 850 minExtent = computeMainAxisExtentForChild(child, MinSize, min);
850 // computeMainAxisExtentForChild can return -1 when the child has a perc entage 851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage
851 // min size, but we have an indefinite size in that axis. 852 // min size, but we have an indefinite size in that axis.
852 minExtent = std::max(LayoutUnit(), minExtent); 853 minExtent = std::max(LayoutUnit(), minExtent);
854 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) {
855 // css-flexbox section 4.5
856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent));
857 ASSERT(contentSize >= 0);
858 if (maxExtent != -1 && contentSize > maxExtent)
859 contentSize = maxExtent;
860
861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child);
862 if (hasClampedSize) {
863 const Length& flexBasis = flexBasisForChild(child);
864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite());
865 if (flexBasisIsDefinite) {
866 LayoutUnit resolvedFlexBasis = computeMainAxisExtentForChild(chi ld, MainOrPreferredSize, flexBasis);
867 ASSERT(resolvedFlexBasis >= 0);
868 LayoutUnit clampedSize = maxExtent != -1 ? std::min(resolvedFlex Basis, maxExtent) : resolvedFlexBasis;
869
870 minExtent = std::min(clampedSize, contentSize);
871 } else {
872 minExtent = contentSize;
873 }
874 } else {
875 minExtent = contentSize;
876 }
877 // TODO(cbiesinger): Implement aspect ratio handling (here, transferred size) - crbug.com/249112
853 } 878 }
879 ASSERT(minExtent >= 0);
854 return std::max(childSize, minExtent); 880 return std::max(childSize, minExtent);
855 } 881 }
856 882
857 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexS hrink, LayoutUnit& sumHypotheticalMainSize, bool relayoutChildren) 883 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexS hrink, LayoutUnit& sumHypotheticalMainSize, bool relayoutChildren)
858 { 884 {
859 orderedChildren.clear(); 885 orderedChildren.clear();
860 sumFlexBaseSize = 0; 886 sumFlexBaseSize = 0;
861 totalFlexGrow = totalWeightedFlexShrink = 0; 887 totalFlexGrow = totalWeightedFlexShrink = 0;
862 sumHypotheticalMainSize = 0; 888 sumHypotheticalMainSize = 0;
863 889
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 } 1082 }
1057 1083
1058 bool LayoutFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const 1084 bool LayoutFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const
1059 { 1085 {
1060 if (alignmentForChild(child) != ItemPositionStretch) 1086 if (alignmentForChild(child) != ItemPositionStretch)
1061 return false; 1087 return false;
1062 1088
1063 return isHorizontalFlow() && child.style()->height().isAuto(); 1089 return isHorizontalFlow() && child.style()->height().isAuto();
1064 } 1090 }
1065 1091
1092 EOverflow LayoutFlexibleBox::mainAxisOverflowForChild(LayoutBox& child) const
1093 {
1094 if (isHorizontalFlow())
1095 return child.styleRef().overflowX();
1096 return child.styleRef().overflowY();
1097 }
1098
1066 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts) 1099 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts)
1067 { 1100 {
1068 ASSERT(childSizes.size() == children.size()); 1101 ASSERT(childSizes.size() == children.size());
1069 1102
1070 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1103 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1071 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); 1104 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace);
1072 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; 1105 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ;
1073 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent); 1106 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent);
1074 if (style()->flexDirection() == FlowRowReverse) 1107 if (style()->flexDirection() == FlowRowReverse)
1075 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); 1108 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 ASSERT(child); 1439 ASSERT(child);
1407 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1440 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1408 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1441 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1409 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1442 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1410 adjustAlignmentForChild(*child, newOffset - originalOffset); 1443 adjustAlignmentForChild(*child, newOffset - originalOffset);
1411 } 1444 }
1412 } 1445 }
1413 } 1446 }
1414 1447
1415 } 1448 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutFlexibleBox.h ('k') | Source/core/layout/LayoutGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698