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

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

Issue 1098593002: [css-flexbox] Performance optimization: Only apply min-width: auto when flex-shrinking an item (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comment 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') | no next file » | 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 if (isHorizontalFlow()) { 827 if (isHorizontalFlow()) {
828 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft())); 828 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft()));
829 child->setMarginRight(computeChildMarginValue(child->style()->margin Right())); 829 child->setMarginRight(computeChildMarginValue(child->style()->margin Right()));
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, bool childShrunk)
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 LayoutUnit maxExtent = -1;
841 if (max.isSpecifiedOrIntrinsic()) { 841 if (max.isSpecifiedOrIntrinsic()) {
842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); 842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
843 if (maxExtent != -1 && childSize > maxExtent) 843 if (maxExtent != -1 && childSize > maxExtent)
844 childSize = maxExtent; 844 childSize = maxExtent;
845 } 845 }
846 846
847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); 847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight();
848 LayoutUnit minExtent = 0; 848 LayoutUnit minExtent = 0;
849 if (min.isSpecifiedOrIntrinsic()) { 849 if (min.isSpecifiedOrIntrinsic()) {
850 minExtent = computeMainAxisExtentForChild(child, MinSize, min); 850 minExtent = computeMainAxisExtentForChild(child, MinSize, min);
851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage 851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage
852 // min size, but we have an indefinite size in that axis. 852 // min size, but we have an indefinite size in that axis.
853 minExtent = std::max(LayoutUnit(), minExtent); 853 minExtent = std::max(LayoutUnit(), minExtent);
854 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { 854 } else if (childShrunk && min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) {
855 // css-flexbox section 4.5 855 // css-flexbox section 4.5
856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); 856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent));
857 ASSERT(contentSize >= 0); 857 ASSERT(contentSize >= 0);
858 if (maxExtent != -1 && contentSize > maxExtent) 858 if (maxExtent != -1 && contentSize > maxExtent)
859 contentSize = maxExtent; 859 contentSize = maxExtent;
860 860
861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child); 861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child);
862 if (hasClampedSize) { 862 if (hasClampedSize) {
863 const Length& flexBasis = flexBasisForChild(child); 863 const Length& flexBasis = flexBasisForChild(child);
864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite()); 864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 childSizes.append(0); 947 childSizes.append(0);
948 continue; 948 continue;
949 } 949 }
950 950
951 if (inflexibleItems.contains(child)) { 951 if (inflexibleItems.contains(child)) {
952 childSizes.append(inflexibleItems.get(child)); 952 childSizes.append(inflexibleItems.get(child));
953 } else { 953 } else {
954 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi ld(*child); 954 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi ld(*child);
955 LayoutUnit childSize = preferredChildSize; 955 LayoutUnit childSize = preferredChildSize;
956 double extraSpace = 0; 956 double extraSpace = 0;
957 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) 957 bool childShrunk = false;
958 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) {
958 extraSpace = availableFreeSpace * child->style()->flexGrow() / t otalFlexGrow; 959 extraSpace = availableFreeSpace * child->style()->flexGrow() / t otalFlexGrow;
959 else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && fl exSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink)) 960 } else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && flexSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && chi ld->style()->flexShrink()) {
960 extraSpace = availableFreeSpace * child->style()->flexShrink() * preferredChildSize / totalWeightedFlexShrink; 961 extraSpace = availableFreeSpace * child->style()->flexShrink() * preferredChildSize / totalWeightedFlexShrink;
962 childShrunk = true;
963 }
961 if (std::isfinite(extraSpace)) 964 if (std::isfinite(extraSpace))
962 childSize += LayoutUnit::fromFloatRound(extraSpace); 965 childSize += LayoutUnit::fromFloatRound(extraSpace);
963 966
964 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize); 967 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize, childShrunk);
965 ASSERT(adjustedChildSize >= 0); 968 ASSERT(adjustedChildSize >= 0);
966 childSizes.append(adjustedChildSize); 969 childSizes.append(adjustedChildSize);
967 usedFreeSpace += adjustedChildSize - preferredChildSize; 970 usedFreeSpace += adjustedChildSize - preferredChildSize;
968 971
969 LayoutUnit violation = adjustedChildSize - childSize; 972 LayoutUnit violation = adjustedChildSize - childSize;
970 if (violation > 0) 973 if (violation > 0)
971 minViolations.append(Violation(child, adjustedChildSize)); 974 minViolations.append(Violation(child, adjustedChildSize));
972 else if (violation < 0) 975 else if (violation < 0)
973 maxViolations.append(Violation(child, adjustedChildSize)); 976 maxViolations.append(Violation(child, adjustedChildSize));
974 totalViolation += violation; 977 totalViolation += violation;
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 ASSERT(child); 1442 ASSERT(child);
1440 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1443 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1441 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1444 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1442 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1445 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1443 adjustAlignmentForChild(*child, newOffset - originalOffset); 1446 adjustAlignmentForChild(*child, newOffset - originalOffset);
1444 } 1447 }
1445 } 1448 }
1446 } 1449 }
1447 1450
1448 } 1451 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698