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

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

Issue 2096943004: [css-flexbox] Correctly implement freezing of inflexible items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ... Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 862
863 dirtyForLayoutFromPercentageHeightDescendants(layoutScope); 863 dirtyForLayoutFromPercentageHeightDescendants(layoutScope);
864 864
865 m_orderIterator.first(); 865 m_orderIterator.first();
866 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor e(); 866 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor e();
867 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild ren)) { 867 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild ren)) {
868 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica lMainSize); 868 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica lMainSize);
869 // availableFreeSpace is the initial amount of free space in this flexbo x. 869 // availableFreeSpace is the initial amount of free space in this flexbo x.
870 // remainingFreeSpace starts out at the same value but as we place and l ay out 870 // remainingFreeSpace starts out at the same value but as we place and l ay out
871 // flex items we subtract from it. Note that both values can be negative . 871 // flex items we subtract from it. Note that both values can be negative .
872 const LayoutUnit availableFreeSpace = containerMainInnerSize - sumFlexBa seSize; 872 LayoutUnit remainingFreeSpace = containerMainInnerSize - sumFlexBaseSize ;
873 LayoutUnit remainingFreeSpace = availableFreeSpace;
874 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ? PositiveFlexibility : NegativeFlexibility; 873 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ? PositiveFlexibility : NegativeFlexibility;
875 while (!resolveFlexibleLengths(flexSign, orderedChildren, availableFreeS pace, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrin k)) { 874 freezeInflexibleItems(flexSign, orderedChildren, remainingFreeSpace, tot alFlexGrow, totalFlexShrink, totalWeightedFlexShrink);
875 // The initial free space gets calculated after freezing inflexible item s. https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3
876 const LayoutUnit initialFreeSpace = remainingFreeSpace;
877 while (!resolveFlexibleLengths(flexSign, orderedChildren, initialFreeSpa ce, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink) ) {
876 ASSERT(totalFlexGrow >= 0 && totalWeightedFlexShrink >= 0); 878 ASSERT(totalFlexGrow >= 0 && totalWeightedFlexShrink >= 0);
877 } 879 }
878 880
879 // Recalculate the remaining free space. The adjustment for flex factors between 0..1 means we can't just 881 // Recalculate the remaining free space. The adjustment for flex factors between 0..1 means we can't just
880 // use remainingFreeSpace here. 882 // use remainingFreeSpace here.
881 remainingFreeSpace = containerMainInnerSize; 883 remainingFreeSpace = containerMainInnerSize;
882 for (size_t i = 0; i < orderedChildren.size(); ++i) { 884 for (size_t i = 0; i < orderedChildren.size(); ++i) {
883 LayoutBox* child = orderedChildren[i].box; 885 LayoutBox* child = orderedChildren[i].box;
884 if (child->isOutOfFlowPositioned()) 886 if (child->isOutOfFlowPositioned())
885 continue; 887 continue;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 totalFlexShrink -= child->style()->flexShrink(); 1242 totalFlexShrink -= child->style()->flexShrink();
1241 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]- >innerFlexBaseSize; 1243 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]- >innerFlexBaseSize;
1242 // totalWeightedFlexShrink can be negative when we exceed the precision of a double when we initially 1244 // totalWeightedFlexShrink can be negative when we exceed the precision of a double when we initially
1243 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh ted flex shrink with full precision, 1245 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh ted flex shrink with full precision,
1244 // now leading to a negative result. See css3/flexbox/large-flex-shrink- assert.html 1246 // now leading to a negative result. See css3/flexbox/large-flex-shrink- assert.html
1245 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0); 1247 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0);
1246 violations[i]->frozen = true; 1248 violations[i]->frozen = true;
1247 } 1249 }
1248 } 1250 }
1249 1251
1252 void LayoutFlexibleBox::freezeInflexibleItems(FlexSign flexSign, OrderedFlexItem List& children, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& t otalFlexShrink, double& totalWeightedFlexShrink)
1253 {
1254 // Per https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 2 ,
1255 // we freeze all items with a flex factor of 0 as well as this with a min/ma x size violation.
1256 Vector<FlexItem*> newInflexibleItems;
1257 for (size_t i = 0; i < children.size(); ++i) {
1258 FlexItem& flexItem = children[i];
1259 LayoutBox* child = flexItem.box;
1260 float flexFactor = (flexSign == PositiveFlexibility) ? child->style()->f lexGrow() : child->style()->flexShrink();
1261 if (flexFactor == 0
1262 || (flexSign == PositiveFlexibility && flexItem.innerFlexBaseSize > flexItem.hypotheticalMainSize)
1263 || (flexSign == NegativeFlexibility && flexItem.innerFlexBaseSize < flexItem.hypotheticalMainSize)) {
1264 flexItem.flexedContentSize = flexItem.hypotheticalMainSize;
1265 newInflexibleItems.append(&flexItem);
1266 }
1267 }
1268 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, tota lFlexShrink, totalWeightedFlexShrink);
1269 }
1270
1250 // Returns true if we successfully ran the algorithm and sized the flex items. 1271 // Returns true if we successfully ran the algorithm and sized the flex items.
1251 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte mList& children, LayoutUnit availableFreeSpace, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink) 1272 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte mList& children, LayoutUnit initialFreeSpace, LayoutUnit& remainingFreeSpace, do uble& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink)
1252 { 1273 {
1253 LayoutUnit totalViolation; 1274 LayoutUnit totalViolation;
1254 LayoutUnit usedFreeSpace; 1275 LayoutUnit usedFreeSpace;
1255 Vector<FlexItem*> minViolations; 1276 Vector<FlexItem*> minViolations;
1256 Vector<FlexItem*> maxViolations; 1277 Vector<FlexItem*> maxViolations;
1257 1278
1258 double sumFlexFactors = (flexSign == PositiveFlexibility) ? totalFlexGrow : totalFlexShrink; 1279 double sumFlexFactors = (flexSign == PositiveFlexibility) ? totalFlexGrow : totalFlexShrink;
1259 if (sumFlexFactors > 0 && sumFlexFactors < 1) { 1280 if (sumFlexFactors > 0 && sumFlexFactors < 1) {
1260 LayoutUnit fractional(availableFreeSpace * sumFlexFactors); 1281 LayoutUnit fractional(initialFreeSpace * sumFlexFactors);
1261 if (fractional.abs() < remainingFreeSpace.abs()) 1282 if (fractional.abs() < remainingFreeSpace.abs())
1262 remainingFreeSpace = fractional; 1283 remainingFreeSpace = fractional;
1263 } 1284 }
1264 1285
1265 for (size_t i = 0; i < children.size(); ++i) { 1286 for (size_t i = 0; i < children.size(); ++i) {
1266 FlexItem& flexItem = children[i]; 1287 FlexItem& flexItem = children[i];
1267 LayoutBox* child = flexItem.box; 1288 LayoutBox* child = flexItem.box;
1268 if (child->isOutOfFlowPositioned()) { 1289 if (child->isOutOfFlowPositioned()) {
1269 continue; 1290 continue;
1270 } 1291 }
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 ASSERT(child); 1882 ASSERT(child);
1862 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1883 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1863 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1884 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1864 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1885 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1865 adjustAlignmentForChild(*child, newOffset - originalOffset); 1886 adjustAlignmentForChild(*child, newOffset - originalOffset);
1866 } 1887 }
1867 } 1888 }
1868 } 1889 }
1869 1890
1870 } // namespace blink 1891 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698