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