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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // We have to reset this, because changes to our ancestors' style | 403 // We have to reset this, because changes to our ancestors' style |
404 // can affect this value. | 404 // can affect this value. |
405 m_hasDefiniteHeight = SizeDefiniteness::Unknown; | 405 m_hasDefiniteHeight = SizeDefiniteness::Unknown; |
406 } | 406 } |
407 | 407 |
408 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) const | 408 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) const |
409 { | 409 { |
410 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); | 410 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); |
411 } | 411 } |
412 | 412 |
413 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon
text>& lineContexts) | 413 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon
text>& lineContexts, LayoutObject* childToExclude) |
414 { | 414 { |
415 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line
Contexts[0].crossAxisOffset; | 415 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line
Contexts[0].crossAxisOffset; |
416 alignFlexLines(lineContexts); | 416 alignFlexLines(lineContexts); |
417 | 417 |
418 alignChildren(lineContexts); | 418 alignChildren(lineContexts, childToExclude); |
419 | 419 |
420 if (style()->flexWrap() == FlexWrapReverse) | 420 if (style()->flexWrap() == FlexWrapReverse) |
421 flipForWrapReverse(lineContexts, crossAxisStartEdge); | 421 flipForWrapReverse(lineContexts, crossAxisStartEdge); |
422 | 422 |
423 // direction:rtl + flex-direction:column means the cross-axis direction is f
lipped. | 423 // direction:rtl + flex-direction:column means the cross-axis direction is f
lipped. |
424 flipForRightToLeftColumn(); | 424 flipForRightToLeftColumn(); |
425 } | 425 } |
426 | 426 |
427 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning() | 427 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning() |
428 { | 428 { |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 Vector<LineContext> lineContexts; | 893 Vector<LineContext> lineContexts; |
894 OrderedFlexItemList orderedChildren; | 894 OrderedFlexItemList orderedChildren; |
895 LayoutUnit sumFlexBaseSize; | 895 LayoutUnit sumFlexBaseSize; |
896 double totalFlexGrow; | 896 double totalFlexGrow; |
897 double totalFlexShrink; | 897 double totalFlexShrink; |
898 double totalWeightedFlexShrink; | 898 double totalWeightedFlexShrink; |
899 LayoutUnit sumHypotheticalMainSize; | 899 LayoutUnit sumHypotheticalMainSize; |
900 | 900 |
901 PaintLayerScrollableArea::PreventRelayoutScope preventRelayoutScope(layoutSc
ope); | 901 PaintLayerScrollableArea::PreventRelayoutScope preventRelayoutScope(layoutSc
ope); |
902 | 902 |
| 903 // Fieldsets need to find their legend and position it inside the border of
the object. |
| 904 // The legend then gets skipped during normal layout. |
| 905 // It doesn't get included in the normal layout process but is instead skipp
ed. |
| 906 LayoutObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren,
layoutScope); |
| 907 |
903 m_orderIterator.first(); | 908 m_orderIterator.first(); |
904 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor
e(); | 909 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor
e(); |
905 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow,
totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild
ren)) { | 910 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow,
totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild
ren, childToExclude)) { |
906 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica
lMainSize); | 911 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica
lMainSize); |
907 // availableFreeSpace is the initial amount of free space in this flexbo
x. | 912 // availableFreeSpace is the initial amount of free space in this flexbo
x. |
908 // remainingFreeSpace starts out at the same value but as we place and l
ay out | 913 // remainingFreeSpace starts out at the same value but as we place and l
ay out |
909 // flex items we subtract from it. Note that both values can be negative
. | 914 // flex items we subtract from it. Note that both values can be negative
. |
910 LayoutUnit remainingFreeSpace = containerMainInnerSize - sumFlexBaseSize
; | 915 LayoutUnit remainingFreeSpace = containerMainInnerSize - sumFlexBaseSize
; |
911 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ?
PositiveFlexibility : NegativeFlexibility; | 916 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ?
PositiveFlexibility : NegativeFlexibility; |
912 freezeInflexibleItems(flexSign, orderedChildren, remainingFreeSpace, tot
alFlexGrow, totalFlexShrink, totalWeightedFlexShrink); | 917 freezeInflexibleItems(flexSign, orderedChildren, remainingFreeSpace, tot
alFlexGrow, totalFlexShrink, totalWeightedFlexShrink); |
913 // The initial free space gets calculated after freezing inflexible item
s. https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3 | 918 // The initial free space gets calculated after freezing inflexible item
s. https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3 |
914 const LayoutUnit initialFreeSpace = remainingFreeSpace; | 919 const LayoutUnit initialFreeSpace = remainingFreeSpace; |
915 while (!resolveFlexibleLengths(flexSign, orderedChildren, initialFreeSpa
ce, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink)
) { | 920 while (!resolveFlexibleLengths(flexSign, orderedChildren, initialFreeSpa
ce, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink)
) { |
(...skipping 17 matching lines...) Expand all Loading... |
933 // Even if computeNextFlexLine returns true, the flexbox might not have | 938 // Even if computeNextFlexLine returns true, the flexbox might not have |
934 // a line because all our children might be out of flow positioned. | 939 // a line because all our children might be out of flow positioned. |
935 // Instead of just checking if we have a line, make sure the flexbox | 940 // Instead of just checking if we have a line, make sure the flexbox |
936 // has at least a line's worth of height to cover this case. | 941 // has at least a line's worth of height to cover this case. |
937 LayoutUnit minHeight = minimumLogicalHeightForEmptyLine(); | 942 LayoutUnit minHeight = minimumLogicalHeightForEmptyLine(); |
938 if (size().height() < minHeight) | 943 if (size().height() < minHeight) |
939 setLogicalHeight(minHeight); | 944 setLogicalHeight(minHeight); |
940 } | 945 } |
941 | 946 |
942 updateLogicalHeight(); | 947 updateLogicalHeight(); |
943 repositionLogicalHeightDependentFlexItems(lineContexts); | 948 repositionLogicalHeightDependentFlexItems(lineContexts, childToExclude); |
944 } | 949 } |
945 | 950 |
946 LayoutUnit LayoutFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi
st& children, LayoutUnit& availableFreeSpace) | 951 LayoutUnit LayoutFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi
st& children, LayoutUnit& availableFreeSpace) |
947 { | 952 { |
948 if (availableFreeSpace <= LayoutUnit()) | 953 if (availableFreeSpace <= LayoutUnit()) |
949 return LayoutUnit(); | 954 return LayoutUnit(); |
950 | 955 |
951 int numberOfAutoMargins = 0; | 956 int numberOfAutoMargins = 0; |
952 bool isHorizontal = isHorizontalFlow(); | 957 bool isHorizontal = isHorizontalFlow(); |
953 for (size_t i = 0; i < children.size(); ++i) { | 958 for (size_t i = 0; i < children.size(); ++i) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 | 1227 |
1223 LayoutFlexibleBox::FlexItem LayoutFlexibleBox::constructFlexItem(LayoutBox& chil
d, ChildLayoutType layoutType) | 1228 LayoutFlexibleBox::FlexItem LayoutFlexibleBox::constructFlexItem(LayoutBox& chil
d, ChildLayoutType layoutType) |
1224 { | 1229 { |
1225 LayoutUnit borderAndPadding = isHorizontalFlow() ? child.borderAndPaddingWid
th() : child.borderAndPaddingHeight(); | 1230 LayoutUnit borderAndPadding = isHorizontalFlow() ? child.borderAndPaddingWid
th() : child.borderAndPaddingHeight(); |
1226 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child,
borderAndPadding, layoutType); | 1231 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child,
borderAndPadding, layoutType); |
1227 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(ch
ild, childInnerFlexBaseSize); | 1232 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(ch
ild, childInnerFlexBaseSize); |
1228 LayoutUnit margin = isHorizontalFlow() ? child.marginWidth() : child.marginH
eight(); | 1233 LayoutUnit margin = isHorizontalFlow() ? child.marginWidth() : child.marginH
eight(); |
1229 return FlexItem(&child, childInnerFlexBaseSize, childMinMaxAppliedMainAxisEx
tent, borderAndPadding, margin); | 1234 return FlexItem(&child, childInnerFlexBaseSize, childMinMaxAppliedMainAxisEx
tent, borderAndPadding, margin); |
1230 } | 1235 } |
1231 | 1236 |
1232 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren
, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalFlexShrink, d
ouble& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool relayo
utChildren) | 1237 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren
, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalFlexShrink, d
ouble& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool relayo
utChildren, LayoutObject* childToExclude) |
1233 { | 1238 { |
1234 orderedChildren.clear(); | 1239 orderedChildren.clear(); |
1235 sumFlexBaseSize = LayoutUnit(); | 1240 sumFlexBaseSize = LayoutUnit(); |
1236 totalFlexGrow = totalFlexShrink = totalWeightedFlexShrink = 0; | 1241 totalFlexGrow = totalFlexShrink = totalWeightedFlexShrink = 0; |
1237 sumHypotheticalMainSize = LayoutUnit(); | 1242 sumHypotheticalMainSize = LayoutUnit(); |
1238 | 1243 |
1239 if (!m_orderIterator.currentChild()) | 1244 if (!m_orderIterator.currentChild()) |
1240 return false; | 1245 return false; |
1241 | 1246 |
1242 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); | 1247 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); |
1243 | 1248 |
1244 bool lineHasInFlowItem = false; | 1249 bool lineHasInFlowItem = false; |
1245 | 1250 |
1246 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord
erIterator.next()) { | 1251 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord
erIterator.next()) { |
| 1252 |
| 1253 if (childToExclude == child) |
| 1254 continue; // Skip this child, since it will be positioned by the spe
cialized subclass (fieldsets runs). |
| 1255 |
1247 if (child->isOutOfFlowPositioned()) { | 1256 if (child->isOutOfFlowPositioned()) { |
1248 orderedChildren.append(FlexItem(child)); | 1257 orderedChildren.append(FlexItem(child)); |
1249 continue; | 1258 continue; |
1250 } | 1259 } |
1251 | 1260 |
1252 ChildLayoutType layoutType = relayoutChildren ? ForceLayout : LayoutIfNe
eded; | 1261 ChildLayoutType layoutType = relayoutChildren ? ForceLayout : LayoutIfNe
eded; |
1253 | 1262 |
1254 // If this condition is true, then computeMainAxisExtentForChild will ca
ll child.intrinsicContentLogicalHeight() | 1263 // If this condition is true, then computeMainAxisExtentForChild will ca
ll child.intrinsicContentLogicalHeight() |
1255 // and child.scrollbarLogicalHeight(), so if the child has intrinsic min
/max/preferred size, | 1264 // and child.scrollbarLogicalHeight(), so if the child has intrinsic min
/max/preferred size, |
1256 // run layout on it now to make sure its logical height and scroll bars
are up to date. | 1265 // run layout on it now to make sure its logical height and scroll bars
are up to date. |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 } | 1817 } |
1809 | 1818 |
1810 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del
ta) | 1819 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del
ta) |
1811 { | 1820 { |
1812 if (child.isOutOfFlowPositioned()) | 1821 if (child.isOutOfFlowPositioned()) |
1813 return; | 1822 return; |
1814 | 1823 |
1815 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou
tSize(LayoutUnit(), delta)); | 1824 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou
tSize(LayoutUnit(), delta)); |
1816 } | 1825 } |
1817 | 1826 |
1818 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) | 1827 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts, L
ayoutObject* childToExclude) |
1819 { | 1828 { |
1820 // Keep track of the space between the baseline edge and the after edge of t
he box for each line. | 1829 // Keep track of the space between the baseline edge and the after edge of t
he box for each line. |
1821 Vector<LayoutUnit> minMarginAfterBaselines; | 1830 Vector<LayoutUnit> minMarginAfterBaselines; |
1822 | 1831 |
1823 LayoutBox* child = m_orderIterator.first(); | 1832 LayoutBox* child = m_orderIterator.first(); |
1824 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ | 1833 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ |
1825 LayoutUnit minMarginAfterBaseline = LayoutUnit::max(); | 1834 LayoutUnit minMarginAfterBaseline = LayoutUnit::max(); |
1826 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten
t; | 1835 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten
t; |
1827 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent; | 1836 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent; |
1828 | 1837 |
1829 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { | 1838 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { |
1830 DCHECK(child); | 1839 DCHECK(child); |
| 1840 if (child == childToExclude) |
| 1841 continue; |
1831 if (child->isOutOfFlowPositioned()) { | 1842 if (child->isOutOfFlowPositioned()) { |
1832 if (style()->flexWrap() == FlexWrapReverse) | 1843 if (style()->flexWrap() == FlexWrapReverse) |
1833 adjustAlignmentForChild(*child, lineCrossAxisExtent); | 1844 adjustAlignmentForChild(*child, lineCrossAxisExtent); |
1834 continue; | 1845 continue; |
1835 } | 1846 } |
1836 | 1847 |
1837 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, *child)))) | 1848 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, *child)))) |
1838 continue; | 1849 continue; |
1839 | 1850 |
1840 ItemPosition position = alignmentForChild(*child); | 1851 ItemPosition position = alignmentForChild(*child); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 DCHECK(child); | 1942 DCHECK(child); |
1932 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1943 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1933 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1944 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1934 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1945 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1935 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1946 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1936 } | 1947 } |
1937 } | 1948 } |
1938 } | 1949 } |
1939 | 1950 |
1940 } // namespace blink | 1951 } // namespace blink |
OLD | NEW |