Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Unified Diff: Source/core/layout/LayoutFlexibleBox.cpp

Issue 988523003: Reimplement min-width: auto (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaselined Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/layout/LayoutFlexibleBox.cpp
diff --git a/Source/core/layout/LayoutFlexibleBox.cpp b/Source/core/layout/LayoutFlexibleBox.cpp
index a748a9193fd9f5b3d77750cec992380119c0db2d..a5550220c738f7901e0e33c93e5ae060610dbc84 100644
--- a/Source/core/layout/LayoutFlexibleBox.cpp
+++ b/Source/core/layout/LayoutFlexibleBox.cpp
@@ -117,7 +117,6 @@ void LayoutFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt
maxLogicalWidth = std::max(maxPreferredLogicalWidth, maxLogicalWidth);
}
}
-
maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth();
@@ -339,6 +338,11 @@ Length LayoutFlexibleBox::flexBasisForChild(LayoutBox& child) const
return flexLength;
}
+bool LayoutFlexibleBox::percentageMainSizeIsResolvable()
+{
+ return isHorizontalFlow() ? hasDefiniteLogicalWidth() : hasDefiniteLogicalHeight();
+}
+
LayoutUnit LayoutFlexibleBox::crossAxisExtentForChild(LayoutBox& child) const
{
return isHorizontalFlow() ? child.size().height() : child.size().width();
@@ -411,7 +415,7 @@ LayoutUnit LayoutFlexibleBox::computeMainAxisExtentForChild(LayoutBox& child, Si
// We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway.
if (size.isIntrinsic())
child.layoutIfNeeded();
- return child.computeContentLogicalHeight(size, child.logicalHeight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight();
+ return child.computeContentLogicalHeight(sizeType, size, child.logicalHeight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight();
}
return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth();
}
@@ -827,19 +831,51 @@ void LayoutFlexibleBox::prepareOrderIteratorAndMargins()
}
}
-LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, LayoutUnit childSize)
+LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, LayoutUnit childSize, bool hasInfiniteLineLength)
{
Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()->maxHeight();
+ LayoutUnit maxExtent = -1;
if (max.isSpecifiedOrIntrinsic()) {
- LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
+ maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
if (maxExtent != -1 && childSize > maxExtent)
childSize = maxExtent;
}
Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()->minHeight();
LayoutUnit minExtent = 0;
- if (min.isSpecifiedOrIntrinsic())
+ if (min.isSpecifiedOrIntrinsic()) {
minExtent = computeMainAxisExtentForChild(child, MinSize, min);
+ // computeMainAxisExtentForChild can return -1 when the child has a percentage
+ // min size, but we have an indefinite size in that axis.
+ minExtent = std::max(LayoutUnit(0), minExtent);
+ } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) {
+ // css-flexbox section 4.5
+ LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, Length(MinContent));
+ ASSERT(contentSize >= 0);
+ if (maxExtent != -1 && contentSize > maxExtent)
+ contentSize = maxExtent;
+
+ bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout(child, hasInfiniteLineLength);
+ if (hasClampedSize) {
+ Length flexBasis = flexBasisForChild(child);
+ bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPercent() && percentageMainSizeIsResolvable());
+ if (flexBasisIsDefinite) {
+ LayoutUnit resolvedFlexBasis = computeMainAxisExtentForChild(child, MainOrPreferredSize, flexBasis);
+ ASSERT(resolvedFlexBasis >= 0);
+ LayoutUnit clampedSize = resolvedFlexBasis;
+ if (maxExtent != -1 && clampedSize > maxExtent)
+ clampedSize = maxExtent;
+
+ minExtent = std::min(clampedSize, contentSize);
+ } else {
+ minExtent = contentSize;
+ }
+ } else {
+ minExtent = contentSize;
+ }
+ // TODO(cbiesinger): Implement aspect ratio handling (here, transferred size)
leviw_travelin_and_unemployed 2015/04/02 22:14:36 Tracking bug?
cbiesinger 2015/04/03 18:49:17 Done.
+ }
+ ASSERT(minExtent >= 0);
return std::max(childSize, minExtent);
}
@@ -869,7 +905,7 @@ bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren
+ (isHorizontalFlow() ? child->marginWidth() : child->marginHeight());
LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMarginBorderPadding;
- LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(*child, childMainAxisExtent);
+ LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(*child, childMainAxisExtent, hasInfiniteLineLength);
LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding;
if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem)
@@ -925,7 +961,7 @@ bool LayoutFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF
if (std::isfinite(extraSpace))
childSize += LayoutUnit::fromFloatRound(extraSpace);
- LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, childSize);
+ LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, childSize, hasInfiniteLineLength);
childSizes.append(adjustedChildSize);
usedFreeSpace += adjustedChildSize - preferredChildSize;
@@ -1052,6 +1088,13 @@ bool LayoutFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const
return isHorizontalFlow() && child.style()->height().isAuto();
}
+EOverflow LayoutFlexibleBox::mainAxisOverflowForChild(LayoutBox& child) const
+{
+ if (isHorizontalFlow())
+ return child.styleRef().overflowX();
+ return child.styleRef().overflowY();
+}
+
void LayoutFlexibleBox::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());

Powered by Google App Engine
This is Rietveld 408576698