Index: Source/core/rendering/RenderFlexibleBox.cpp |
diff --git a/Source/core/rendering/RenderFlexibleBox.cpp b/Source/core/rendering/RenderFlexibleBox.cpp |
index d71accfa31a8cca3c227a327e50373efdec09540..86a698fb6fc33934e4e9a9245ebd938ed7078613 100644 |
--- a/Source/core/rendering/RenderFlexibleBox.cpp |
+++ b/Source/core/rendering/RenderFlexibleBox.cpp |
@@ -610,14 +610,58 @@ bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render |
return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasInfiniteLineLength) && hasOrthogonalFlow(child); |
} |
+bool RenderFlexibleBox::childHasFiniteCrossSize(RenderBox* child) const |
+{ |
+ Length crossAxisExtentForChild = isHorizontalFlow() ? child->style()->height() : child->style()->width(); |
+ Length crossAxisExtent = isHorizontalFlow() ? style()->height() : style()->width(); |
+ |
+ if (crossAxisExtentForChild.isFixed()) |
+ return true; |
+ |
+ if (!crossAxisExtent.isFixed()) |
+ return false; |
+ |
+ if (crossAxisExtentForChild.isPercent()) |
+ return true; |
+ |
+ if (!isMultiline() && needToStretchChildLogicalHeight(child)) |
+ return true; |
+ |
+ if (!isMultiline() && needToStretchChildLogicalWidth(child)) |
+ return true; |
+ |
+ return false; |
+} |
+ |
+void RenderFlexibleBox::computeAspectRatioOfChild(RenderBox* child, double& aspectRatio) |
+{ |
+ if (child->style()->hasAspectRatio()) |
+ aspectRatio = child->style()->aspectRatio(); |
+ else if (child->hasAspectRatio() && child->intrinsicLogicalHeight()) |
+ aspectRatio = child->intrinsicLogicalWidth().rawValue() / child->intrinsicLogicalHeight().rawValue(); |
+} |
+ |
LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength, bool relayoutChildren) |
{ |
child->clearOverrideSize(); |
- if (child->style()->hasAspectRatio() || child->isImage() || child->isVideo() || child->isCanvas()) |
+ if (child->style()->hasAspectRatio() || child->hasAspectRatio()) |
UseCounter::count(document(), UseCounter::AspectRatioFlexItem); |
Length flexBasis = flexBasisForChild(child); |
+ double aspectRatio = -1.0; |
+ computeAspectRatioOfChild(child, aspectRatio); |
+ |
+ if (aspectRatio >= 0 && flexBasis.isAuto() && childHasFiniteCrossSize(child)) { |
+ if (!isMultiline()) { |
+ if (needToStretchChildLogicalHeight(child)) |
+ return aspectRatio * style()->height().value(); |
+ if (needToStretchChildLogicalWidth(child)) |
+ return style()->width().value() / aspectRatio; |
+ } |
+ return isHorizontalFlow() ? aspectRatio * crossAxisIntrinsicExtentForChild(child) : crossAxisIntrinsicExtentForChild(child) / aspectRatio; |
+ } |
+ |
if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)) { |
LayoutUnit mainAxisExtent; |
if (hasOrthogonalFlow(child)) { |
@@ -1066,6 +1110,14 @@ bool RenderFlexibleBox::needToStretchChildLogicalHeight(RenderBox* child) const |
return isHorizontalFlow() && child->style()->height().isAuto(); |
} |
+bool RenderFlexibleBox::needToStretchChildLogicalWidth(RenderBox* child) const |
+{ |
+ if (alignmentForChild(child) != ItemPositionStretch) |
+ return false; |
+ |
+ return isColumnFlow() && child->style()->width().isAuto(); |
+} |
+ |
void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContexts, bool hasInfiniteLineLength) |
{ |
ASSERT(childSizes.size() == children.size()); |