| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 LayoutUnit crossAxisOffset; | 59 LayoutUnit crossAxisOffset; |
| 60 LayoutUnit crossAxisExtent; | 60 LayoutUnit crossAxisExtent; |
| 61 size_t numberOfChildren; | 61 size_t numberOfChildren; |
| 62 LayoutUnit maxAscent; | 62 LayoutUnit maxAscent; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 struct LayoutFlexibleBox::FlexItem { | 65 struct LayoutFlexibleBox::FlexItem { |
| 66 FlexItem(LayoutBox* box, LayoutUnit innerFlexBaseSize, LayoutUnit hypothetic
alMainSize) | 66 FlexItem(LayoutBox* box, LayoutUnit flexBaseContentSize, LayoutUnit hypothet
icalMainContentSize) |
| 67 : box(box) | 67 : box(box) |
| 68 , innerFlexBaseSize(innerFlexBaseSize) | 68 , flexBaseContentSize(flexBaseContentSize) |
| 69 , hypotheticalMainSize(hypotheticalMainSize) | 69 , hypotheticalMainContentSize(hypotheticalMainContentSize) |
| 70 , frozen(false) | 70 , frozen(false) |
| 71 { | 71 { |
| 72 } | 72 } |
| 73 | 73 |
| 74 // This constructor is used for out-of-flow children | 74 // This constructor is used for out-of-flow children |
| 75 explicit FlexItem(LayoutBox* box) | 75 explicit FlexItem(LayoutBox* box) |
| 76 : box(box) | 76 : box(box) |
| 77 , innerFlexBaseSize() | 77 , flexBaseContentSize() |
| 78 , hypotheticalMainSize() | 78 , hypotheticalMainContentSize() |
| 79 , frozen(true) | 79 , frozen(true) |
| 80 { | 80 { |
| 81 } | 81 } |
| 82 LayoutBox* box; | 82 LayoutBox* box; |
| 83 const LayoutUnit innerFlexBaseSize; | 83 const LayoutUnit flexBaseContentSize; |
| 84 const LayoutUnit hypotheticalMainSize; | 84 const LayoutUnit hypotheticalMainContentSize; |
| 85 LayoutUnit flexedContentSize; | 85 LayoutUnit flexedContentSize; |
| 86 bool frozen; | 86 bool frozen; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 LayoutFlexibleBox::LayoutFlexibleBox(Element* element) | 89 LayoutFlexibleBox::LayoutFlexibleBox(Element* element) |
| 90 : LayoutBlock(element) | 90 : LayoutBlock(element) |
| 91 , m_orderIterator(this) | 91 , m_orderIterator(this) |
| 92 , m_numberOfInFlowChildrenOnFirstLine(-1) | 92 , m_numberOfInFlowChildrenOnFirstLine(-1) |
| 93 , m_hasDefiniteHeight(SizeDefiniteness::Unknown) | 93 , m_hasDefiniteHeight(SizeDefiniteness::Unknown) |
| 94 { | 94 { |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 } | 1252 } |
| 1253 return true; | 1253 return true; |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 void LayoutFlexibleBox::freezeViolations(Vector<FlexItem*>& violations, LayoutUn
it& availableFreeSpace, double& totalFlexGrow, double& totalFlexShrink, double&
totalWeightedFlexShrink) | 1256 void LayoutFlexibleBox::freezeViolations(Vector<FlexItem*>& violations, LayoutUn
it& availableFreeSpace, double& totalFlexGrow, double& totalFlexShrink, double&
totalWeightedFlexShrink) |
| 1257 { | 1257 { |
| 1258 for (size_t i = 0; i < violations.size(); ++i) { | 1258 for (size_t i = 0; i < violations.size(); ++i) { |
| 1259 DCHECK(!violations[i]->frozen) << i; | 1259 DCHECK(!violations[i]->frozen) << i; |
| 1260 LayoutBox* child = violations[i]->box; | 1260 LayoutBox* child = violations[i]->box; |
| 1261 LayoutUnit childSize = violations[i]->flexedContentSize; | 1261 LayoutUnit childSize = violations[i]->flexedContentSize; |
| 1262 availableFreeSpace -= childSize - violations[i]->innerFlexBaseSize; | 1262 availableFreeSpace -= childSize - violations[i]->flexBaseContentSize; |
| 1263 totalFlexGrow -= child->style()->flexGrow(); | 1263 totalFlexGrow -= child->style()->flexGrow(); |
| 1264 totalFlexShrink -= child->style()->flexShrink(); | 1264 totalFlexShrink -= child->style()->flexShrink(); |
| 1265 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]-
>innerFlexBaseSize; | 1265 totalWeightedFlexShrink -= child->style()->flexShrink() * violations[i]-
>flexBaseContentSize; |
| 1266 // totalWeightedFlexShrink can be negative when we exceed the precision
of a double when we initially | 1266 // totalWeightedFlexShrink can be negative when we exceed the precision
of a double when we initially |
| 1267 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh
ted flex shrink with full precision, | 1267 // calcuate totalWeightedFlexShrink. We then subtract each child's weigh
ted flex shrink with full precision, |
| 1268 // now leading to a negative result. See css3/flexbox/large-flex-shrink-
assert.html | 1268 // now leading to a negative result. See css3/flexbox/large-flex-shrink-
assert.html |
| 1269 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0); | 1269 totalWeightedFlexShrink = std::max(totalWeightedFlexShrink, 0.0); |
| 1270 violations[i]->frozen = true; | 1270 violations[i]->frozen = true; |
| 1271 } | 1271 } |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 void LayoutFlexibleBox::freezeInflexibleItems(FlexSign flexSign, OrderedFlexItem
List& children, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& t
otalFlexShrink, double& totalWeightedFlexShrink) | 1274 void LayoutFlexibleBox::freezeInflexibleItems(FlexSign flexSign, OrderedFlexItem
List& children, LayoutUnit& remainingFreeSpace, double& totalFlexGrow, double& t
otalFlexShrink, double& totalWeightedFlexShrink) |
| 1275 { | 1275 { |
| 1276 // Per https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 2
, | 1276 // Per https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 2
, |
| 1277 // we freeze all items with a flex factor of 0 as well as this with a min/ma
x size violation. | 1277 // we freeze all items with a flex factor of 0 as well as this with a min/ma
x size violation. |
| 1278 Vector<FlexItem*> newInflexibleItems; | 1278 Vector<FlexItem*> newInflexibleItems; |
| 1279 for (size_t i = 0; i < children.size(); ++i) { | 1279 for (size_t i = 0; i < children.size(); ++i) { |
| 1280 FlexItem& flexItem = children[i]; | 1280 FlexItem& flexItem = children[i]; |
| 1281 LayoutBox* child = flexItem.box; | 1281 LayoutBox* child = flexItem.box; |
| 1282 if (child->isOutOfFlowPositioned()) | 1282 if (child->isOutOfFlowPositioned()) |
| 1283 continue; | 1283 continue; |
| 1284 DCHECK(!flexItem.frozen) << i; | 1284 DCHECK(!flexItem.frozen) << i; |
| 1285 float flexFactor = (flexSign == PositiveFlexibility) ? child->style()->f
lexGrow() : child->style()->flexShrink(); | 1285 float flexFactor = (flexSign == PositiveFlexibility) ? child->style()->f
lexGrow() : child->style()->flexShrink(); |
| 1286 if (flexFactor == 0 | 1286 if (flexFactor == 0 |
| 1287 || (flexSign == PositiveFlexibility && flexItem.innerFlexBaseSize >
flexItem.hypotheticalMainSize) | 1287 || (flexSign == PositiveFlexibility && flexItem.flexBaseContentSize
> flexItem.hypotheticalMainContentSize) |
| 1288 || (flexSign == NegativeFlexibility && flexItem.innerFlexBaseSize <
flexItem.hypotheticalMainSize)) { | 1288 || (flexSign == NegativeFlexibility && flexItem.flexBaseContentSize
< flexItem.hypotheticalMainContentSize)) { |
| 1289 flexItem.flexedContentSize = flexItem.hypotheticalMainSize; | 1289 flexItem.flexedContentSize = flexItem.hypotheticalMainContentSize; |
| 1290 newInflexibleItems.append(&flexItem); | 1290 newInflexibleItems.append(&flexItem); |
| 1291 } | 1291 } |
| 1292 } | 1292 } |
| 1293 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, tota
lFlexShrink, totalWeightedFlexShrink); | 1293 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, tota
lFlexShrink, totalWeightedFlexShrink); |
| 1294 } | 1294 } |
| 1295 | 1295 |
| 1296 // Returns true if we successfully ran the algorithm and sized the flex items. | 1296 // Returns true if we successfully ran the algorithm and sized the flex items. |
| 1297 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte
mList& children, LayoutUnit initialFreeSpace, LayoutUnit& remainingFreeSpace, do
uble& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink) | 1297 bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, OrderedFlexIte
mList& children, LayoutUnit initialFreeSpace, LayoutUnit& remainingFreeSpace, do
uble& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink) |
| 1298 { | 1298 { |
| 1299 LayoutUnit totalViolation; | 1299 LayoutUnit totalViolation; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1310 | 1310 |
| 1311 for (size_t i = 0; i < children.size(); ++i) { | 1311 for (size_t i = 0; i < children.size(); ++i) { |
| 1312 FlexItem& flexItem = children[i]; | 1312 FlexItem& flexItem = children[i]; |
| 1313 LayoutBox* child = flexItem.box; | 1313 LayoutBox* child = flexItem.box; |
| 1314 if (child->isOutOfFlowPositioned()) | 1314 if (child->isOutOfFlowPositioned()) |
| 1315 continue; | 1315 continue; |
| 1316 | 1316 |
| 1317 if (flexItem.frozen) | 1317 if (flexItem.frozen) |
| 1318 continue; | 1318 continue; |
| 1319 | 1319 |
| 1320 LayoutUnit childSize = flexItem.innerFlexBaseSize; | 1320 LayoutUnit childSize = flexItem.flexBaseContentSize; |
| 1321 double extraSpace = 0; | 1321 double extraSpace = 0; |
| 1322 if (remainingFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveF
lexibility && std::isfinite(totalFlexGrow)) { | 1322 if (remainingFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveF
lexibility && std::isfinite(totalFlexGrow)) { |
| 1323 extraSpace = remainingFreeSpace * child->style()->flexGrow() / total
FlexGrow; | 1323 extraSpace = remainingFreeSpace * child->style()->flexGrow() / total
FlexGrow; |
| 1324 } else if (remainingFreeSpace < 0 && totalWeightedFlexShrink > 0 && flex
Sign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && child->
style()->flexShrink()) { | 1324 } else if (remainingFreeSpace < 0 && totalWeightedFlexShrink > 0 && flex
Sign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && child->
style()->flexShrink()) { |
| 1325 extraSpace = remainingFreeSpace * child->style()->flexShrink() * fle
xItem.innerFlexBaseSize / totalWeightedFlexShrink; | 1325 extraSpace = remainingFreeSpace * child->style()->flexShrink() * fle
xItem.flexBaseContentSize / totalWeightedFlexShrink; |
| 1326 } | 1326 } |
| 1327 if (std::isfinite(extraSpace)) | 1327 if (std::isfinite(extraSpace)) |
| 1328 childSize += LayoutUnit::fromFloatRound(extraSpace); | 1328 childSize += LayoutUnit::fromFloatRound(extraSpace); |
| 1329 | 1329 |
| 1330 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, child
Size); | 1330 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, child
Size); |
| 1331 DCHECK_GE(adjustedChildSize, 0); | 1331 DCHECK_GE(adjustedChildSize, 0); |
| 1332 flexItem.flexedContentSize = adjustedChildSize; | 1332 flexItem.flexedContentSize = adjustedChildSize; |
| 1333 usedFreeSpace += adjustedChildSize - flexItem.innerFlexBaseSize; | 1333 usedFreeSpace += adjustedChildSize - flexItem.flexBaseContentSize; |
| 1334 | 1334 |
| 1335 LayoutUnit violation = adjustedChildSize - childSize; | 1335 LayoutUnit violation = adjustedChildSize - childSize; |
| 1336 if (violation > 0) | 1336 if (violation > 0) |
| 1337 minViolations.append(&flexItem); | 1337 minViolations.append(&flexItem); |
| 1338 else if (violation < 0) | 1338 else if (violation < 0) |
| 1339 maxViolations.append(&flexItem); | 1339 maxViolations.append(&flexItem); |
| 1340 totalViolation += violation; | 1340 totalViolation += violation; |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 if (totalViolation) | 1343 if (totalViolation) |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 ASSERT(child); | 1906 ASSERT(child); |
| 1907 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1907 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1908 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1908 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1909 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1909 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1910 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1910 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1911 } | 1911 } |
| 1912 } | 1912 } |
| 1913 } | 1913 } |
| 1914 | 1914 |
| 1915 } // namespace blink | 1915 } // namespace blink |
| OLD | NEW |