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

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

Issue 2146603007: [css-flexbox] freezeInflexibleItems has to skip out-of-flow boxes (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/LayoutTests/css3/flexbox/max-width-violation.html ('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 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 totalFlexShrink += child->style()->flexShrink(); 1244 totalFlexShrink += child->style()->flexShrink();
1245 totalWeightedFlexShrink += child->style()->flexShrink() * childInnerFlex BaseSize; 1245 totalWeightedFlexShrink += child->style()->flexShrink() * childInnerFlex BaseSize;
1246 sumHypotheticalMainSize += childHypotheticalMainSize; 1246 sumHypotheticalMainSize += childHypotheticalMainSize;
1247 } 1247 }
1248 return true; 1248 return true;
1249 } 1249 }
1250 1250
1251 void LayoutFlexibleBox::freezeViolations(Vector<FlexItem*>& violations, LayoutUn it& availableFreeSpace, double& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink) 1251 void LayoutFlexibleBox::freezeViolations(Vector<FlexItem*>& violations, LayoutUn it& availableFreeSpace, double& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink)
1252 { 1252 {
1253 for (size_t i = 0; i < violations.size(); ++i) { 1253 for (size_t i = 0; i < violations.size(); ++i) {
1254 DCHECK(!violations[i]->frozen) << i;
1254 LayoutBox* child = violations[i]->box; 1255 LayoutBox* child = violations[i]->box;
1255 LayoutUnit childSize = violations[i]->flexedContentSize; 1256 LayoutUnit childSize = violations[i]->flexedContentSize;
1256 availableFreeSpace -= childSize - violations[i]->innerFlexBaseSize; 1257 availableFreeSpace -= childSize - violations[i]->innerFlexBaseSize;
1257 totalFlexGrow -= child->style()->flexGrow(); 1258 totalFlexGrow -= child->style()->flexGrow();
1258 totalFlexShrink -= child->style()->flexShrink(); 1259 totalFlexShrink -= child->style()->flexShrink();
1259 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]- >innerFlexBaseSize; 1260 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]- >innerFlexBaseSize;
1260 // totalWeightedFlexShrink can be negative when we exceed the precision of a double when we initially 1261 // totalWeightedFlexShrink can be negative when we exceed the precision of a double when we initially
1261 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh ted flex shrink with full precision, 1262 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh ted flex shrink with full precision,
1262 // now leading to a negative result. See css3/flexbox/large-flex-shrink- assert.html 1263 // now leading to a negative result. See css3/flexbox/large-flex-shrink- assert.html
1263 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0); 1264 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0);
1264 violations[i]->frozen = true; 1265 violations[i]->frozen = true;
1265 } 1266 }
1266 } 1267 }
1267 1268
1268 void LayoutFlexibleBox::freezeInflexibleItems(FlexSign flexSign, OrderedFlexItem List& children, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& t otalFlexShrink, double& totalWeightedFlexShrink) 1269 void LayoutFlexibleBox::freezeInflexibleItems(FlexSign flexSign, OrderedFlexItem List& children, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& t otalFlexShrink, double& totalWeightedFlexShrink)
1269 { 1270 {
1270 // Per https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 2 , 1271 // Per https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 2 ,
1271 // we freeze all items with a flex factor of 0 as well as this with a min/ma x size violation. 1272 // we freeze all items with a flex factor of 0 as well as this with a min/ma x size violation.
1272 Vector<FlexItem*> newInflexibleItems; 1273 Vector<FlexItem*> newInflexibleItems;
1273 for (size_t i = 0; i < children.size(); ++i) { 1274 for (size_t i = 0; i < children.size(); ++i) {
1274 FlexItem& flexItem = children[i]; 1275 FlexItem& flexItem = children[i];
1275 LayoutBox* child = flexItem.box; 1276 LayoutBox* child = flexItem.box;
1277 if (child->isOutOfFlowPositioned())
1278 continue;
1279 DCHECK(!flexItem.frozen) << i;
1276 float flexFactor = (flexSign == PositiveFlexibility) ? child->style()->f lexGrow() : child->style()->flexShrink(); 1280 float flexFactor = (flexSign == PositiveFlexibility) ? child->style()->f lexGrow() : child->style()->flexShrink();
1277 if (flexFactor == 0 1281 if (flexFactor == 0
1278 || (flexSign == PositiveFlexibility && flexItem.innerFlexBaseSize > flexItem.hypotheticalMainSize) 1282 || (flexSign == PositiveFlexibility && flexItem.innerFlexBaseSize > flexItem.hypotheticalMainSize)
1279 || (flexSign == NegativeFlexibility && flexItem.innerFlexBaseSize < flexItem.hypotheticalMainSize)) { 1283 || (flexSign == NegativeFlexibility && flexItem.innerFlexBaseSize < flexItem.hypotheticalMainSize)) {
1280 flexItem.flexedContentSize = flexItem.hypotheticalMainSize; 1284 flexItem.flexedContentSize = flexItem.hypotheticalMainSize;
1281 newInflexibleItems.append(&flexItem); 1285 newInflexibleItems.append(&flexItem);
1282 } 1286 }
1283 } 1287 }
1284 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, tota lFlexShrink, totalWeightedFlexShrink); 1288 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, tota lFlexShrink, totalWeightedFlexShrink);
1285 } 1289 }
1286 1290
1287 // Returns true if we successfully ran the algorithm and sized the flex items. 1291 // Returns true if we successfully ran the algorithm and sized the flex items.
1288 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte mList& children, LayoutUnit initialFreeSpace, LayoutUnit& remainingFreeSpace, do uble& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink) 1292 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte mList& children, LayoutUnit initialFreeSpace, LayoutUnit& remainingFreeSpace, do uble& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink)
1289 { 1293 {
1290 LayoutUnit totalViolation; 1294 LayoutUnit totalViolation;
1291 LayoutUnit usedFreeSpace; 1295 LayoutUnit usedFreeSpace;
1292 Vector<FlexItem*> minViolations; 1296 Vector<FlexItem*> minViolations;
1293 Vector<FlexItem*> maxViolations; 1297 Vector<FlexItem*> maxViolations;
1294 1298
1295 double sumFlexFactors = (flexSign == PositiveFlexibility) ? totalFlexGrow : totalFlexShrink; 1299 double sumFlexFactors = (flexSign == PositiveFlexibility) ? totalFlexGrow : totalFlexShrink;
1296 if (sumFlexFactors > 0 && sumFlexFactors < 1) { 1300 if (sumFlexFactors > 0 && sumFlexFactors < 1) {
1297 LayoutUnit fractional(initialFreeSpace * sumFlexFactors); 1301 LayoutUnit fractional(initialFreeSpace * sumFlexFactors);
1298 if (fractional.abs() < remainingFreeSpace.abs()) 1302 if (fractional.abs() < remainingFreeSpace.abs())
1299 remainingFreeSpace = fractional; 1303 remainingFreeSpace = fractional;
1300 } 1304 }
1301 1305
1302 for (size_t i = 0; i < children.size(); ++i) { 1306 for (size_t i = 0; i < children.size(); ++i) {
1303 FlexItem& flexItem = children[i]; 1307 FlexItem& flexItem = children[i];
1304 LayoutBox* child = flexItem.box; 1308 LayoutBox* child = flexItem.box;
1305 if (child->isOutOfFlowPositioned()) { 1309 if (child->isOutOfFlowPositioned())
1306 continue; 1310 continue;
1307 }
1308 1311
1309 if (flexItem.frozen) 1312 if (flexItem.frozen)
1310 continue; 1313 continue;
1314
1311 LayoutUnit childSize = flexItem.innerFlexBaseSize; 1315 LayoutUnit childSize = flexItem.innerFlexBaseSize;
1312 double extraSpace = 0; 1316 double extraSpace = 0;
1313 if (remainingFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveF lexibility && std::isfinite(totalFlexGrow)) { 1317 if (remainingFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveF lexibility && std::isfinite(totalFlexGrow)) {
1314 extraSpace = remainingFreeSpace * child->style()->flexGrow() / total FlexGrow; 1318 extraSpace = remainingFreeSpace * child->style()->flexGrow() / total FlexGrow;
1315 } else if (remainingFreeSpace < 0 && totalWeightedFlexShrink > 0 && flex Sign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && child-> style()->flexShrink()) { 1319 } else if (remainingFreeSpace < 0 && totalWeightedFlexShrink > 0 && flex Sign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && child-> style()->flexShrink()) {
1316 extraSpace = remainingFreeSpace * child->style()->flexShrink() * fle xItem.innerFlexBaseSize / totalWeightedFlexShrink; 1320 extraSpace = remainingFreeSpace * child->style()->flexShrink() * fle xItem.innerFlexBaseSize / totalWeightedFlexShrink;
1317 } 1321 }
1318 if (std::isfinite(extraSpace)) 1322 if (std::isfinite(extraSpace))
1319 childSize += LayoutUnit::fromFloatRound(extraSpace); 1323 childSize += LayoutUnit::fromFloatRound(extraSpace);
1320 1324
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 ASSERT(child); 1902 ASSERT(child);
1899 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1903 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1900 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1904 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1901 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1905 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1902 adjustAlignmentForChild(*child, newOffset - originalOffset); 1906 adjustAlignmentForChild(*child, newOffset - originalOffset);
1903 } 1907 }
1904 } 1908 }
1905 } 1909 }
1906 1910
1907 } // namespace blink 1911 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/css3/flexbox/max-width-violation.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698