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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi
s, bool hasInfiniteLineLength) | 603 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi
s, bool hasInfiniteLineLength) |
604 { | 604 { |
605 return flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && h
asInfiniteLineLength); | 605 return flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && h
asInfiniteLineLength); |
606 } | 606 } |
607 | 607 |
608 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render
Box* child, bool hasInfiniteLineLength) const | 608 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render
Box* child, bool hasInfiniteLineLength) const |
609 { | 609 { |
610 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI
nfiniteLineLength) && hasOrthogonalFlow(child); | 610 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI
nfiniteLineLength) && hasOrthogonalFlow(child); |
611 } | 611 } |
612 | 612 |
| 613 bool RenderFlexibleBox::childHasFiniteCrossSize(RenderBox* child) const |
| 614 { |
| 615 Length crossAxisExtentForChild = isHorizontalFlow() ? child->style()->height
() : child->style()->width(); |
| 616 Length crossAxisExtent = isHorizontalFlow() ? style()->height() : style()->w
idth(); |
| 617 |
| 618 if (crossAxisExtentForChild.isFixed()) |
| 619 return true; |
| 620 |
| 621 if (!crossAxisExtent.isFixed()) |
| 622 return false; |
| 623 |
| 624 if (crossAxisExtentForChild.isPercent()) |
| 625 return true; |
| 626 |
| 627 if (!isMultiline() && needToStretchChildLogicalHeight(child)) |
| 628 return true; |
| 629 |
| 630 if (!isMultiline() && needToStretchChildLogicalWidth(child)) |
| 631 return true; |
| 632 |
| 633 return false; |
| 634 } |
| 635 |
| 636 void RenderFlexibleBox::computeAspectRatioOfChild(RenderBox* child, double& aspe
ctRatio) |
| 637 { |
| 638 if (child->style()->hasAspectRatio()) |
| 639 aspectRatio = child->style()->aspectRatio(); |
| 640 else if (child->hasAspectRatio() && child->intrinsicLogicalHeight()) |
| 641 aspectRatio = child->intrinsicLogicalWidth().rawValue() / child->intrins
icLogicalHeight().rawValue(); |
| 642 } |
| 643 |
613 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
child, bool hasInfiniteLineLength, bool relayoutChildren) | 644 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
child, bool hasInfiniteLineLength, bool relayoutChildren) |
614 { | 645 { |
615 child->clearOverrideSize(); | 646 child->clearOverrideSize(); |
616 | 647 |
617 if (child->style()->hasAspectRatio() || child->isImage() || child->isVideo()
|| child->isCanvas()) | 648 if (child->style()->hasAspectRatio() || child->hasAspectRatio()) |
618 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); | 649 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); |
619 | 650 |
620 Length flexBasis = flexBasisForChild(child); | 651 Length flexBasis = flexBasisForChild(child); |
| 652 double aspectRatio = -1.0; |
| 653 computeAspectRatioOfChild(child, aspectRatio); |
| 654 |
| 655 if (aspectRatio >= 0 && flexBasis.isAuto() && childHasFiniteCrossSize(child)
) { |
| 656 if (!isMultiline()) { |
| 657 if (needToStretchChildLogicalHeight(child)) |
| 658 return aspectRatio * style()->height().value(); |
| 659 if (needToStretchChildLogicalWidth(child)) |
| 660 return style()->width().value() / aspectRatio; |
| 661 } |
| 662 return isHorizontalFlow() ? aspectRatio * crossAxisIntrinsicExtentForChi
ld(child) : crossAxisIntrinsicExtentForChild(child) / aspectRatio; |
| 663 } |
| 664 |
621 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)
) { | 665 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)
) { |
622 LayoutUnit mainAxisExtent; | 666 LayoutUnit mainAxisExtent; |
623 if (hasOrthogonalFlow(child)) { | 667 if (hasOrthogonalFlow(child)) { |
624 if (child->needsLayout() || relayoutChildren) { | 668 if (child->needsLayout() || relayoutChildren) { |
625 m_intrinsicSizeAlongMainAxis.remove(child); | 669 m_intrinsicSizeAlongMainAxis.remove(child); |
626 child->forceChildLayout(); | 670 child->forceChildLayout(); |
627 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight()); | 671 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight()); |
628 } | 672 } |
629 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child)); | 673 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child)); |
630 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child); | 674 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 } | 1103 } |
1060 | 1104 |
1061 bool RenderFlexibleBox::needToStretchChildLogicalHeight(RenderBox* child) const | 1105 bool RenderFlexibleBox::needToStretchChildLogicalHeight(RenderBox* child) const |
1062 { | 1106 { |
1063 if (alignmentForChild(child) != ItemPositionStretch) | 1107 if (alignmentForChild(child) != ItemPositionStretch) |
1064 return false; | 1108 return false; |
1065 | 1109 |
1066 return isHorizontalFlow() && child->style()->height().isAuto(); | 1110 return isHorizontalFlow() && child->style()->height().isAuto(); |
1067 } | 1111 } |
1068 | 1112 |
| 1113 bool RenderFlexibleBox::needToStretchChildLogicalWidth(RenderBox* child) const |
| 1114 { |
| 1115 if (alignmentForChild(child) != ItemPositionStretch) |
| 1116 return false; |
| 1117 |
| 1118 return isColumnFlow() && child->style()->width().isAuto(); |
| 1119 } |
| 1120 |
1069 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou
tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex
ts, bool hasInfiniteLineLength) | 1121 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou
tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex
ts, bool hasInfiniteLineLength) |
1070 { | 1122 { |
1071 ASSERT(childSizes.size() == children.size()); | 1123 ASSERT(childSizes.size() == children.size()); |
1072 | 1124 |
1073 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1125 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
1074 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); | 1126 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); |
1075 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; | 1127 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; |
1076 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1128 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); |
1077 if (style()->flexDirection() == FlowRowReverse) | 1129 if (style()->flexDirection() == FlowRowReverse) |
1078 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); | 1130 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 ASSERT(child); | 1454 ASSERT(child); |
1403 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1455 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1404 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1456 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1405 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1457 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1406 adjustAlignmentForChild(child, newOffset - originalOffset); | 1458 adjustAlignmentForChild(child, newOffset - originalOffset); |
1407 } | 1459 } |
1408 } | 1460 } |
1409 } | 1461 } |
1410 | 1462 |
1411 } | 1463 } |
OLD | NEW |