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