Modified: trunk/Source/WebCore/ChangeLog (112153 => 112154)
--- trunk/Source/WebCore/ChangeLog 2012-03-26 22:14:38 UTC (rev 112153)
+++ trunk/Source/WebCore/ChangeLog 2012-03-26 22:26:02 UTC (rev 112154)
@@ -1,3 +1,25 @@
+2012-03-26 Tony Chang <[email protected]>
+
+ apply cross axis constraints before aligning children in flexbox
+ https://bugs.webkit.org/show_bug.cgi?id=82240
+
+ Reviewed by Ojan Vafai.
+
+ We weren't applying max-height constraints before aligning children.
+ This would cause center, end, stretch alignment to be wrong if we hit
+ a max-height on a flexbox.
+
+ This patch also moves the repositioning logic to happen after
+ computeLogicalHeight, which will be useful for flex-line-pack.
+
+ New test case in css3/flexbox/flex-align.html
+
+ * rendering/RenderFlexibleBox.cpp:
+ (WebCore::RenderFlexibleBox::layoutBlock):
+ (WebCore::RenderFlexibleBox::layoutFlexItems):
+ (WebCore::RenderFlexibleBox::layoutAndPlaceChildren):
+ * rendering/RenderFlexibleBox.h:
+
2012-03-26 Anders Carlsson <[email protected]>
Find in page overlay and bouncy are not always positioned correctly
Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (112153 => 112154)
--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp 2012-03-26 22:14:38 UTC (rev 112153)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp 2012-03-26 22:26:02 UTC (rev 112154)
@@ -250,9 +250,7 @@
IntSize previousSize = size();
setLogicalHeight(0);
- // We need to call both of these because we grab both crossAxisExtent and mainAxisExtent in layoutFlexItems.
computeLogicalWidth();
- computeLogicalHeight();
m_overflow.clear();
@@ -264,10 +262,15 @@
layer()->setHasVerticalScrollbar(true);
}
- layoutFlexItems(relayoutChildren);
+ WTF::Vector<LineContext> lineContexts;
+ FlexOrderHashSet flexOrderValues;
+ computeMainAxisPreferredSizes(relayoutChildren, flexOrderValues);
+ FlexOrderIterator flexIterator(this, flexOrderValues);
+ layoutFlexItems(relayoutChildren, flexIterator, lineContexts);
LayoutUnit oldClientAfterEdge = clientLogicalBottom();
computeLogicalHeight();
+ repositionLogicalHeightDependentFlexItems(flexIterator, lineContexts, oldClientAfterEdge);
if (size() != previousSize)
relayoutChildren = true;
@@ -291,6 +294,24 @@
setNeedsLayout(false);
}
+void RenderFlexibleBox::repositionLogicalHeightDependentFlexItems(FlexOrderIterator& iterator, WTF::Vector<LineContext>& lineContexts, LayoutUnit& oldClientAfterEdge)
+{
+ // If we have a single line flexbox, the line height is all the available space.
+ // For flex-direction: row, this means we need to use the height, so we do this after calling computeLogicalHeight.
+ if (!isMultiline() && lineContexts.size() == 1)
+ lineContexts[0].crossAxisExtent = crossAxisContentExtent();
+ alignChildren(iterator, lineContexts);
+
+ if (style()->flexWrap() == FlexWrapReverse) {
+ if (isHorizontalFlow())
+ oldClientAfterEdge = clientLogicalBottom();
+ flipForWrapReverse(iterator, lineContexts);
+ }
+
+ // direction:rtl + flex-direction:column means the cross-axis direction is flipped.
+ flipForRightToLeftColumn(iterator);
+}
+
bool RenderFlexibleBox::hasOrthogonalFlow(RenderBox* child) const
{
// FIXME: If the child is a flexbox, then we need to check isHorizontalFlow.
@@ -589,21 +610,16 @@
return heightResult - preferredMainAxisExtent;
}
-void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren)
+void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren, FlexOrderIterator& iterator, WTF::Vector<LineContext>& lineContexts)
{
- FlexOrderHashSet flexOrderValues;
- computeMainAxisPreferredSizes(relayoutChildren, flexOrderValues);
-
OrderedFlexItemList orderedChildren;
LayoutUnit preferredMainAxisExtent;
float totalPositiveFlexibility;
float totalNegativeFlexibility;
LayoutUnit minMaxAppliedMainAxisExtent;
- WTF::Vector<LineContext> lineContexts;
- FlexOrderIterator flexIterator(this, flexOrderValues);
LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
- while (computeNextFlexLine(flexIterator, orderedChildren, preferredMainAxisExtent, totalPositiveFlexibility, totalNegativeFlexibility, minMaxAppliedMainAxisExtent)) {
+ while (computeNextFlexLine(iterator, orderedChildren, preferredMainAxisExtent, totalPositiveFlexibility, totalNegativeFlexibility, minMaxAppliedMainAxisExtent)) {
LayoutUnit availableFreeSpace = computeAvailableFreeSpace(preferredMainAxisExtent);
FlexSign flexSign = (minMaxAppliedMainAxisExtent < preferredMainAxisExtent + availableFreeSpace) ? PositiveFlexibility : NegativeFlexibility;
InflexibleFlexItemSize inflexibleItems;
@@ -615,14 +631,6 @@
layoutAndPlaceChildren(crossAxisOffset, orderedChildren, childSizes, availableFreeSpace, lineContexts);
}
-//
- alignChildren(flexIterator, lineContexts);
-
- if (style()->flexWrap() == FlexWrapReverse)
- flipForWrapReverse(flexIterator, lineContexts);
-
- // direction:rtl + flex-direction:column means the cross-axis direction is flipped.
- flipForRightToLeftColumn(flexIterator);
}
float RenderFlexibleBox::positiveFlexForChild(RenderBox* child) const
@@ -927,9 +935,8 @@
layoutColumnReverse(children, childSizes, crossAxisOffset, availableFreeSpace);
}
- LayoutUnit lineCrossAxisExtent = isMultiline() ? maxChildCrossAxisExtent : crossAxisContentExtent();
- lineContexts.append(LineContext(crossAxisOffset, lineCrossAxisExtent, children.size(), maxAscent));
- crossAxisOffset += lineCrossAxisExtent;
+ lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, children.size(), maxAscent));
+ crossAxisOffset += maxChildCrossAxisExtent;
}
void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace)
@@ -1076,9 +1083,6 @@
void RenderFlexibleBox::flipForWrapReverse(FlexOrderIterator& iterator, const WTF::Vector<LineContext>& lineContexts)
{
- if (!isColumnFlow())
- computeLogicalHeight();
-
LayoutUnit contentExtent = crossAxisContentExtent();
RenderBox* child = iterator.first();
for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) {
Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (112153 => 112154)
--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h 2012-03-26 22:14:38 UTC (rev 112153)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h 2012-03-26 22:26:02 UTC (rev 112154)
@@ -100,7 +100,8 @@
LayoutUnit mainAxisScrollbarExtentForChild(RenderBox* child) const;
LayoutUnit preferredMainAxisContentExtentForChild(RenderBox* child) const;
- void layoutFlexItems(bool relayoutChildren);
+ void layoutFlexItems(bool relayoutChildren, FlexOrderIterator&, WTF::Vector<LineContext>&);
+ void repositionLogicalHeightDependentFlexItems(FlexOrderIterator&, WTF::Vector<LineContext>&, LayoutUnit& oldClientAfterEdge);
float positiveFlexForChild(RenderBox* child) const;
float negativeFlexForChild(RenderBox* child) const;
@@ -119,7 +120,7 @@
void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset);
- void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, WTF::Vector<LineContext>& lineContexts);
+ void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, WTF::Vector<LineContext>&);
void layoutColumnReverse(const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
void alignChildren(FlexOrderIterator&, const WTF::Vector<LineContext>&);
void applyStretchAlignmentToChild(RenderBox*, LayoutUnit lineCrossAxisExtent);