| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 static EAlignItems resolveAlignment(const RenderStyle* parentStyle, const Render
Style* childStyle) | 200 static EAlignItems resolveAlignment(const RenderStyle* parentStyle, const Render
Style* childStyle) |
| 201 { | 201 { |
| 202 EAlignItems align = childStyle->alignSelf(); | 202 EAlignItems align = childStyle->alignSelf(); |
| 203 if (align == AlignAuto) | 203 if (align == AlignAuto) |
| 204 align = parentStyle->alignItems(); | 204 align = parentStyle->alignItems(); |
| 205 return align; | 205 return align; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void RenderFlexibleBox::removeChild(RenderObject* child) |
| 209 { |
| 210 RenderBlock::removeChild(child); |
| 211 m_intrinsicSizeAlongMainAxis.remove(child); |
| 212 } |
| 213 |
| 208 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) | 214 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) |
| 209 { | 215 { |
| 210 RenderBlock::styleDidChange(diff, oldStyle); | 216 RenderBlock::styleDidChange(diff, oldStyle); |
| 211 | 217 |
| 212 if (oldStyle && oldStyle->alignItems() == AlignStretch && diff == StyleDiffe
renceLayout) { | 218 if (oldStyle && oldStyle->alignItems() == AlignStretch && diff == StyleDiffe
renceLayout) { |
| 213 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. | 219 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. |
| 214 // This is only necessary for stretching since other alignment values do
n't change the size of the box. | 220 // This is only necessary for stretching since other alignment values do
n't change the size of the box. |
| 215 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { | 221 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { |
| 216 EAlignItems previousAlignment = resolveAlignment(oldStyle, child->st
yle()); | 222 EAlignItems previousAlignment = resolveAlignment(oldStyle, child->st
yle()); |
| 217 if (previousAlignment == AlignStretch && previousAlignment != resolv
eAlignment(style(), child->style())) | 223 if (previousAlignment == AlignStretch && previousAlignment != resolv
eAlignment(style(), child->style())) |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAn
dPaddingHeight(); | 637 return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAn
dPaddingHeight(); |
| 632 } | 638 } |
| 633 | 639 |
| 634 LayoutUnit RenderFlexibleBox::mainAxisScrollbarExtentForChild(RenderBox* child)
const | 640 LayoutUnit RenderFlexibleBox::mainAxisScrollbarExtentForChild(RenderBox* child)
const |
| 635 { | 641 { |
| 636 return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizon
talScrollbarHeight(); | 642 return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizon
talScrollbarHeight(); |
| 637 } | 643 } |
| 638 | 644 |
| 639 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
child, bool hasInfiniteLineLength) | 645 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
child, bool hasInfiniteLineLength) |
| 640 { | 646 { |
| 641 bool hasOverrideSize = child->hasOverrideWidth() || child->hasOverrideHeight
(); | 647 child->clearOverrideSize(); |
| 642 if (hasOverrideSize) | |
| 643 child->clearOverrideSize(); | |
| 644 | 648 |
| 645 Length flexBasis = flexBasisForChild(child); | 649 Length flexBasis = flexBasisForChild(child); |
| 646 if (flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && hasI
nfiniteLineLength)) { | 650 if (flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && hasI
nfiniteLineLength)) { |
| 651 LayoutUnit mainAxisExtent; |
| 647 if (hasOrthogonalFlow(child)) { | 652 if (hasOrthogonalFlow(child)) { |
| 648 if (hasOverrideSize) | 653 if (child->needsLayout()) { |
| 649 child->setChildNeedsLayout(MarkOnlyThis); | 654 m_intrinsicSizeAlongMainAxis.remove(child); |
| 650 child->layoutIfNeeded(); | 655 child->layout(); |
| 656 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight()); |
| 657 } |
| 658 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child)); |
| 659 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child); |
| 660 } else { |
| 661 mainAxisExtent = child->maxPreferredLogicalWidth(); |
| 651 } | 662 } |
| 652 LayoutUnit mainAxisExtent = hasOrthogonalFlow(child) ? child->logicalHei
ght() : child->maxPreferredLogicalWidth(); | |
| 653 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >=
0); | 663 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >=
0); |
| 654 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); | 664 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); |
| 655 } | 665 } |
| 656 return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPr
eferredSize, flexBasis)); | 666 return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPr
eferredSize, flexBasis)); |
| 657 } | 667 } |
| 658 | 668 |
| 659 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren, Vector<LineContex
t>& lineContexts) | 669 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren, Vector<LineContex
t>& lineContexts) |
| 660 { | 670 { |
| 661 OrderedFlexItemList orderedChildren; | 671 OrderedFlexItemList orderedChildren; |
| 662 LayoutUnit sumFlexBaseSize; | 672 LayoutUnit sumFlexBaseSize; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 for (size_t i = 0; i < children.size(); ++i) { | 1051 for (size_t i = 0; i < children.size(); ++i) { |
| 1042 RenderBox* child = children[i]; | 1052 RenderBox* child = children[i]; |
| 1043 if (!child->isOutOfFlowPositioned()) | 1053 if (!child->isOutOfFlowPositioned()) |
| 1044 ++count; | 1054 ++count; |
| 1045 } | 1055 } |
| 1046 return count; | 1056 return count; |
| 1047 } | 1057 } |
| 1048 | 1058 |
| 1049 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* chil
d) | 1059 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* chil
d) |
| 1050 { | 1060 { |
| 1051 if (hasAutoMarginsInCrossAxis(child)) | 1061 if (hasAutoMarginsInCrossAxis(child)) { |
| 1052 child->updateLogicalHeight(); | 1062 child->updateLogicalHeight(); |
| 1063 if (isHorizontalFlow()) { |
| 1064 if (child->style()->marginTop().isAuto()) |
| 1065 child->setMarginTop(0); |
| 1066 if (child->style()->marginBottom().isAuto()) |
| 1067 child->setMarginBottom(0); |
| 1068 } else { |
| 1069 if (child->style()->marginLeft().isAuto()) |
| 1070 child->setMarginLeft(0); |
| 1071 if (child->style()->marginRight().isAuto()) |
| 1072 child->setMarginRight(0); |
| 1073 } |
| 1074 } |
| 1053 } | 1075 } |
| 1054 | 1076 |
| 1055 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit>& childSizes, LayoutUni
t availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContexts) | 1077 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit>& childSizes, LayoutUni
t availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContexts) |
| 1056 { | 1078 { |
| 1057 ASSERT(childSizes.size() == children.size()); | 1079 ASSERT(childSizes.size() == children.size()); |
| 1058 | 1080 |
| 1059 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1081 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
| 1060 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); | 1082 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); |
| 1061 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; | 1083 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; |
| 1062 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1084 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 ASSERT(child); | 1384 ASSERT(child); |
| 1363 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1385 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1364 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1386 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1365 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1387 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1366 adjustAlignmentForChild(child, newOffset - originalOffset); | 1388 adjustAlignmentForChild(child, newOffset - originalOffset); |
| 1367 } | 1389 } |
| 1368 } | 1390 } |
| 1369 } | 1391 } |
| 1370 | 1392 |
| 1371 } | 1393 } |
| OLD | NEW |