summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderFlexibleBox.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-10-17 16:21:14 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-10-17 16:21:14 +0200
commit8995b83bcbfbb68245f779b64e5517627c6cc6ea (patch)
tree17985605dab9263cc2444bd4d45f189e142cca7c /Source/WebCore/rendering/RenderFlexibleBox.cpp
parentb9c9652036d5e9f1e29c574f40bc73a35c81ace6 (diff)
downloadqtwebkit-8995b83bcbfbb68245f779b64e5517627c6cc6ea.tar.gz
Imported WebKit commit cf4f8fc6f19b0629f51860cb2d4b25e139d07e00 (http://svn.webkit.org/repository/webkit/trunk@131592)
New snapshot that includes the build fixes for Mac OS X 10.6 and earlier as well as the previously cherry-picked changes
Diffstat (limited to 'Source/WebCore/rendering/RenderFlexibleBox.cpp')
-rw-r--r--Source/WebCore/rendering/RenderFlexibleBox.cpp94
1 files changed, 78 insertions, 16 deletions
diff --git a/Source/WebCore/rendering/RenderFlexibleBox.cpp b/Source/WebCore/rendering/RenderFlexibleBox.cpp
index abc73dd83..baf7747b9 100644
--- a/Source/WebCore/rendering/RenderFlexibleBox.cpp
+++ b/Source/WebCore/rendering/RenderFlexibleBox.cpp
@@ -132,6 +132,7 @@ struct RenderFlexibleBox::Violation {
RenderFlexibleBox::RenderFlexibleBox(Node* node)
: RenderBlock(node)
+ , m_numberOfChildrenOnFirstLine(0)
{
setChildrenInline(false); // All of our children must be block-level.
}
@@ -234,6 +235,51 @@ void RenderFlexibleBox::computePreferredLogicalWidths()
setPreferredLogicalWidthsDirty(false);
}
+LayoutUnit RenderFlexibleBox::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
+{
+ LayoutUnit baseline = firstLineBoxBaseline();
+ if (baseline != -1) {
+ LayoutUnit marginAscent = direction == HorizontalLine ? marginTop() : marginRight();
+ return baseline + marginAscent;
+ }
+
+ return RenderBox::baselinePosition(baselineType, firstLine, direction, linePositionMode);
+}
+
+LayoutUnit RenderFlexibleBox::firstLineBoxBaseline() const
+{
+ ASSERT(m_orderIterator);
+
+ if (isWritingModeRoot() || !m_numberOfChildrenOnFirstLine)
+ return -1;
+ RenderBox* baselineChild = 0;
+ RenderBox* child = m_orderIterator->first();
+ for (size_t childNumber = 0; childNumber < m_numberOfChildrenOnFirstLine; ++childNumber, child = m_orderIterator->next()) {
+ if (child->isOutOfFlowPositioned())
+ continue;
+ if (alignmentForChild(child) == AlignBaseline && !hasAutoMarginsInCrossAxis(child)) {
+ baselineChild = child;
+ break;
+ }
+ if (!baselineChild)
+ baselineChild = child;
+ }
+
+ if (!baselineChild)
+ return -1;
+
+ if (!isColumnFlow() && hasOrthogonalFlow(baselineChild))
+ return crossAxisExtentForChild(baselineChild) + baselineChild->logicalTop();
+ if (isColumnFlow() && !hasOrthogonalFlow(baselineChild))
+ return mainAxisExtentForChild(baselineChild) + baselineChild->logicalTop();
+
+ LayoutUnit baseline = baselineChild->firstLineBoxBaseline();
+ if (baseline == -1)
+ return -1;
+
+ return baseline + baselineChild->logicalTop();
+}
+
void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
{
ASSERT(needsLayout());
@@ -258,6 +304,8 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
m_overflow.clear();
+ RenderBlock::startDelayUpdateScrollInfo();
+
WTF::Vector<LineContext> lineContexts;
OrderHashSet orderValues;
computeMainAxisPreferredSizes(relayoutChildren, orderValues);
@@ -268,12 +316,15 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
updateLogicalHeight();
repositionLogicalHeightDependentFlexItems(*m_orderIterator, lineContexts, oldClientAfterEdge);
+ RenderBlock::finishDelayUpdateScrollInfo();
+
if (size() != previousSize)
relayoutChildren = true;
layoutPositionedObjects(relayoutChildren || isRoot());
computeRegionRangeForBlock();
+ clearChildOverrideSizes();
// FIXME: css3/flexbox/repaint-rtl-column.html seems to repaint more overflow than it needs to.
computeOverflow(oldClientAfterEdge);
@@ -283,8 +334,7 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
// Update our scroll information if we're overflow:auto/scroll/hidden now that we know if
// we overflow or not.
- if (hasOverflowClip())
- layer()->updateScrollInfoAfterLayout();
+ updateScrollInfoAfterLayout();
repainter.repaintAfterLayout();
@@ -318,10 +368,18 @@ void RenderFlexibleBox::repositionLogicalHeightDependentFlexItems(OrderIterator&
flipForWrapReverse(iterator, lineContexts, crossAxisStartEdge);
}
+ m_numberOfChildrenOnFirstLine = lineContexts.isEmpty() ? 0 : lineContexts[0].numberOfChildren;
+
// direction:rtl + flex-direction:column means the cross-axis direction is flipped.
flipForRightToLeftColumn(iterator);
}
+void RenderFlexibleBox::clearChildOverrideSizes()
+{
+ for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox())
+ child->clearOverrideSize();
+}
+
bool RenderFlexibleBox::hasOrthogonalFlow(RenderBox* child) const
{
// FIXME: If the child is a flexbox, then we need to check isHorizontalFlow.
@@ -368,12 +426,12 @@ void RenderFlexibleBox::setCrossAxisExtent(LayoutUnit extent)
setWidth(extent);
}
-LayoutUnit RenderFlexibleBox::crossAxisExtentForChild(RenderBox* child)
+LayoutUnit RenderFlexibleBox::crossAxisExtentForChild(RenderBox* child) const
{
return isHorizontalFlow() ? child->height() : child->width();
}
-LayoutUnit RenderFlexibleBox::mainAxisExtentForChild(RenderBox* child)
+LayoutUnit RenderFlexibleBox::mainAxisExtentForChild(RenderBox* child) const
{
return isHorizontalFlow() ? child->width() : child->height();
}
@@ -615,8 +673,8 @@ void RenderFlexibleBox::layoutFlexItems(OrderIterator& iterator, WTF::Vector<Lin
{
OrderedFlexItemList orderedChildren;
LayoutUnit preferredMainAxisExtent;
- float totalFlexGrow;
- float totalWeightedFlexShrink;
+ double totalFlexGrow;
+ double totalWeightedFlexShrink;
LayoutUnit minMaxAppliedMainAxisExtent;
LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
@@ -680,7 +738,7 @@ void RenderFlexibleBox::updateAutoMarginsInMainAxis(RenderBox* child, LayoutUnit
}
}
-bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(RenderBox* child)
+bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(RenderBox* child) const
{
if (isHorizontalFlow())
return child->style()->marginTop().isAuto() || child->style()->marginBottom().isAuto();
@@ -734,7 +792,7 @@ LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox* child)
{
LayoutUnit ascent = child->firstLineBoxBaseline();
if (ascent == -1)
- ascent = crossAxisExtentForChild(child) + flowAwareMarginAfterForChild(child);
+ ascent = crossAxisExtentForChild(child);
return ascent + flowAwareMarginBeforeForChild(child);
}
@@ -755,7 +813,6 @@ void RenderFlexibleBox::computeMainAxisPreferredSizes(bool relayoutChildren, Ord
if (child->isOutOfFlowPositioned())
continue;
- child->clearOverrideSize();
// Only need to layout here if we will need to get the logicalHeight of the child in computeNextFlexLine.
Length childMainAxisMin = isHorizontalFlow() ? child->style()->minWidth() : child->style()->minHeight();
if (hasOrthogonalFlow(child) && (flexBasisForChild(child).isAuto() || childMainAxisMin.isAuto())) {
@@ -797,7 +854,7 @@ LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, Layo
return std::max(childSize, minExtent);
}
-bool RenderFlexibleBox::computeNextFlexLine(OrderIterator& iterator, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalFlexGrow, float& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent)
+bool RenderFlexibleBox::computeNextFlexLine(OrderIterator& iterator, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent)
{
orderedChildren.clear();
preferredMainAxisExtent = 0;
@@ -832,7 +889,7 @@ bool RenderFlexibleBox::computeNextFlexLine(OrderIterator& iterator, OrderedFlex
return true;
}
-void RenderFlexibleBox::freezeViolations(const WTF::Vector<Violation>& violations, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems)
+void RenderFlexibleBox::freezeViolations(const WTF::Vector<Violation>& violations, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems)
{
for (size_t i = 0; i < violations.size(); ++i) {
RenderBox* child = violations[i].child;
@@ -846,7 +903,7 @@ void RenderFlexibleBox::freezeViolations(const WTF::Vector<Violation>& violation
}
// Returns true if we successfully ran the algorithm and sized the flex items.
-bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedFlexItemList& children, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems, WTF::Vector<LayoutUnit>& childSizes)
+bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedFlexItemList& children, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems, WTF::Vector<LayoutUnit>& childSizes)
{
childSizes.clear();
LayoutUnit totalViolation = 0;
@@ -943,13 +1000,16 @@ void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox* child, Layout
}
}
-static EAlignItems alignmentForChild(RenderBox* child)
+EAlignItems RenderFlexibleBox::alignmentForChild(RenderBox* child) const
{
EAlignItems align = child->style()->alignSelf();
if (align == AlignAuto)
- align = child->parent()->style()->alignItems();
+ align = style()->alignItems();
+
+ if (align == AlignBaseline && hasOrthogonalFlow(child))
+ align = AlignFlexStart;
- if (child->parent()->style()->flexWrap() == FlexWrapReverse) {
+ if (style()->flexWrap() == FlexWrapReverse) {
if (align == AlignFlexStart)
align = AlignFlexEnd;
else if (align == AlignFlexEnd)
@@ -1189,6 +1249,8 @@ void RenderFlexibleBox::alignChildren(OrderIterator& iterator, const WTF::Vector
adjustAlignmentForChild(child, availableAlignmentSpaceForChild(lineCrossAxisExtent, child) / 2);
break;
case AlignBaseline: {
+ // FIXME: If we get here in columns, we want the use the descent, except we currently can't get the ascent/descent of orthogonal children.
+ // https://bugs.webkit.org/show_bug.cgi?id=98076
LayoutUnit ascent = marginBoxAscentForChild(child);
LayoutUnit startOffset = maxAscent - ascent;
adjustAlignmentForChild(child, startOffset);
@@ -1241,7 +1303,7 @@ void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox* child, LayoutUni
childWidth = child->constrainLogicalWidthInRegionByMinMax(childWidth, childWidth, this);
if (childWidth != child->logicalWidth()) {
- child->setOverrideLogicalContentWidth(childWidth);
+ child->setOverrideLogicalContentWidth(childWidth - child->borderAndPaddingLogicalWidth());
child->setChildNeedsLayout(true, MarkOnlyThis);
child->layoutIfNeeded();
}