+2011-09-22 Ojan Vafai <ojan@chromium.org>
+
+ refactor RenderFlexibleBox to use flex-flow aware methods
+ https://bugs.webkit.org/show_bug.cgi?id=68665
+
+ Reviewed by Tony Chang.
+
+ This is just a refactor. Just move the all the code that needs to
+ be flow aware into helper functions. Actually making them flow-aware
+ can be done in a followup patch.
+
+ * rendering/RenderBlock.cpp:
+ * rendering/RenderBlock.h:
+ Moved setLogicalLocationForChild into RenderFlexibleBox since that was the only caller.
+ * rendering/RenderFlexibleBox.cpp:
+ (WebCore::RenderFlexibleBox::hasOrthogonalFlow):
+ (WebCore::RenderFlexibleBox::isHorizontalFlow):
+ (WebCore::RenderFlexibleBox::isLeftToRightFlow):
+ (WebCore::RenderFlexibleBox::setFlowAwareLogicalHeight):
+ (WebCore::RenderFlexibleBox::flowAwareLogicalHeightForChild):
+ (WebCore::RenderFlexibleBox::flowAwareLogicalWidthForChild):
+ (WebCore::RenderFlexibleBox::flowAwareLogicalHeight):
+ (WebCore::RenderFlexibleBox::flowAwareContentLogicalWidth):
+ (WebCore::RenderFlexibleBox::flowAwareAvailableLogicalWidth):
+ (WebCore::RenderFlexibleBox::flowAwareBorderStart):
+ (WebCore::RenderFlexibleBox::flowAwareBorderBefore):
+ (WebCore::RenderFlexibleBox::flowAwareBorderAfter):
+ (WebCore::RenderFlexibleBox::flowAwarePaddingStart):
+ (WebCore::RenderFlexibleBox::flowAwarePaddingBefore):
+ (WebCore::RenderFlexibleBox::flowAwarePaddingAfter):
+ (WebCore::RenderFlexibleBox::flowAwareMarginStartForChild):
+ (WebCore::RenderFlexibleBox::flowAwareMarginBeforeForChild):
+ (WebCore::RenderFlexibleBox::flowAwareMarginAfterForChild):
+ (WebCore::RenderFlexibleBox::setFlowAwareMarginStartForChild):
+ (WebCore::RenderFlexibleBox::setFlowAwareMarginEndForChild):
+ (WebCore::RenderFlexibleBox::setFlowAwareLogicalLocationForChild):
+ (WebCore::RenderFlexibleBox::logicalBorderAndPaddingWidthForChild):
+ (WebCore::RenderFlexibleBox::logicalScrollbarHeightForChild):
+ (WebCore::RenderFlexibleBox::marginStartStyleForChild):
+ (WebCore::RenderFlexibleBox::marginEndStyleForChild):
+ (WebCore::RenderFlexibleBox::preferredLogicalContentWidthForFlexItem):
+ (WebCore::RenderFlexibleBox::layoutInlineDirection):
+ (WebCore::RenderFlexibleBox::logicalPositiveFlexForChild):
+ (WebCore::RenderFlexibleBox::logicalNegativeFlexForChild):
+ (WebCore::RenderFlexibleBox::computePreferredLogicalWidth):
+ (WebCore::RenderFlexibleBox::runFreeSpaceAllocationAlgorithmInlineDirection):
+ (WebCore::RenderFlexibleBox::setLogicalOverrideSize):
+ (WebCore::RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection):
+ * rendering/RenderFlexibleBox.h:
+
2011-09-23 David Hyatt <hyatt@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=68719
setNeedsLayout(false);
}
-LayoutUnit RenderFlexibleBox::logicalBorderAndPaddingWidthForChild(RenderBox* child)
+bool RenderFlexibleBox::hasOrthogonalFlow(RenderBox* child) const
{
- return isHorizontalWritingMode() ? child->borderAndPaddingWidth() : child->borderAndPaddingHeight();
+ // FIXME: Is the child->isHorizontalWritingMode() check correct if the child is a flexbox?
+ // Should it be using child->isHorizontalFlow in that case?
+ // Or do we only care about the parent's writing mode?
+ return isHorizontalFlow() != child->isHorizontalWritingMode();
}
-LayoutUnit RenderFlexibleBox::logicalScrollbarHeightForChild(RenderBox* child)
+bool RenderFlexibleBox::isHorizontalFlow() const
{
- return isHorizontalWritingMode() ? child->verticalScrollbarWidth() : child->horizontalScrollbarHeight();
+ // FIXME: Take flex-flow value into account.
+ return isHorizontalWritingMode();
}
-Length RenderFlexibleBox::marginStartStyleForChild(RenderBox* child)
+bool RenderFlexibleBox::isLeftToRightFlow() const
{
- if (isHorizontalWritingMode())
- return style()->isLeftToRightDirection() ? child->style()->marginLeft() : child->style()->marginRight();
- return style()->isLeftToRightDirection() ? child->style()->marginTop() : child->style()->marginBottom();
+ // FIXME: Take flex-flow value into account.
+ return style()->isLeftToRightDirection();
}
-Length RenderFlexibleBox::marginEndStyleForChild(RenderBox* child)
+// FIXME: Make all these flow aware methods actually be flow aware.
+
+void RenderFlexibleBox::setFlowAwareLogicalHeight(LayoutUnit size)
+{
+ setLogicalHeight(size);
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareLogicalHeightForChild(RenderBox* child)
+{
+ return logicalHeightForChild(child);
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareLogicalWidthForChild(RenderBox* child)
+{
+ return logicalWidthForChild(child);
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareLogicalHeight() const
+{
+ return logicalHeight();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareContentLogicalWidth() const
+{
+ return contentLogicalWidth();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareAvailableLogicalWidth() const
+{
+ return availableLogicalWidth();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareBorderStart() const
+{
+ return borderStart();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareBorderBefore() const
+{
+ return borderBefore();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareBorderAfter() const
+{
+ return borderAfter();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwarePaddingStart() const
+{
+ return paddingStart();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwarePaddingBefore() const
+{
+ return paddingBefore();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwarePaddingAfter() const
+{
+ return paddingAfter();
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(RenderBox* child) const
+{
+ return marginStartForChild(child);
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(RenderBox* child) const
+{
+ return marginBeforeForChild(child);
+}
+
+LayoutUnit RenderFlexibleBox::flowAwareMarginAfterForChild(RenderBox* child) const
+{
+ return marginAfterForChild(child);
+}
+
+void RenderFlexibleBox::setFlowAwareMarginStartForChild(RenderBox* child, LayoutUnit margin)
+{
+ setMarginStartForChild(child, margin);
+}
+
+void RenderFlexibleBox::setFlowAwareMarginEndForChild(RenderBox* child, LayoutUnit margin)
+{
+ setMarginEndForChild(child, margin);
+}
+
+void RenderFlexibleBox::setFlowAwareLogicalLocationForChild(RenderBox* child, const LayoutPoint& location)
+{
+ if (isHorizontalFlow())
+ child->setLocation(location);
+ else
+ child->setLocation(location.transposedPoint());
+}
+
+LayoutUnit RenderFlexibleBox::logicalBorderAndPaddingWidthForChild(RenderBox* child) const
+{
+ return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAndPaddingHeight();
+}
+
+LayoutUnit RenderFlexibleBox::logicalScrollbarHeightForChild(RenderBox* child) const
+{
+ return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizontalScrollbarHeight();
+}
+
+Length RenderFlexibleBox::marginStartStyleForChild(RenderBox* child) const
+{
+ if (isHorizontalFlow())
+ return isLeftToRightFlow() ? child->style()->marginLeft() : child->style()->marginRight();
+ return isLeftToRightFlow() ? child->style()->marginTop() : child->style()->marginBottom();
+}
+
+Length RenderFlexibleBox::marginEndStyleForChild(RenderBox* child) const
{
- if (isHorizontalWritingMode())
- return style()->isLeftToRightDirection() ? child->style()->marginRight() : child->style()->marginLeft();
- return style()->isLeftToRightDirection() ? child->style()->marginBottom() : child->style()->marginTop();
+ if (isHorizontalFlow())
+ return isLeftToRightFlow() ? child->style()->marginRight() : child->style()->marginLeft();
+ return isLeftToRightFlow() ? child->style()->marginBottom() : child->style()->marginTop();
}
-LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child)
+LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) const
{
- Length width = isHorizontalWritingMode() ? child->style()->width() : child->style()->height();
+ Length width = isHorizontalFlow() ? child->style()->width() : child->style()->height();
if (width.isAuto()) {
- LayoutUnit logicalWidth = isHorizontalWritingMode() == child->isHorizontalWritingMode() ? child->maxPreferredLogicalWidth() : child->logicalHeight();
+ LayoutUnit logicalWidth = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth();
return logicalWidth - logicalBorderAndPaddingWidthForChild(child) - logicalScrollbarHeightForChild(child);
}
- return isHorizontalWritingMode() ? child->contentWidth() : child->contentHeight();
+ return isHorizontalFlow() ? child->contentWidth() : child->contentHeight();
}
void RenderFlexibleBox::layoutInlineDirection(bool relayoutChildren)
TreeOrderIterator treeIterator(this);
computePreferredLogicalWidth(relayoutChildren, treeIterator, preferredLogicalWidth, totalPositiveFlexibility, totalNegativeFlexibility);
- LayoutUnit availableFreeSpace = contentLogicalWidth() - preferredLogicalWidth;
+ LayoutUnit availableFreeSpace = flowAwareContentLogicalWidth() - preferredLogicalWidth;
FlexOrderIterator flexIterator(this, treeIterator.flexOrderValues());
InflexibleFlexItemSize inflexibleItems;
// FIXME: Handle distribution of cross-axis space (third distribution round).
}
-float RenderFlexibleBox::logicalPositiveFlexForChild(RenderBox* child)
+float RenderFlexibleBox::logicalPositiveFlexForChild(RenderBox* child) const
{
- return isHorizontalWritingMode() ? child->style()->flexboxWidthPositiveFlex() : child->style()->flexboxHeightPositiveFlex();
+ return isHorizontalFlow() ? child->style()->flexboxWidthPositiveFlex() : child->style()->flexboxHeightPositiveFlex();
}
-float RenderFlexibleBox::logicalNegativeFlexForChild(RenderBox* child)
+float RenderFlexibleBox::logicalNegativeFlexForChild(RenderBox* child) const
{
- return isHorizontalWritingMode() ? child->style()->flexboxWidthNegativeFlex() : child->style()->flexboxHeightNegativeFlex();
+ return isHorizontalFlow() ? child->style()->flexboxWidthNegativeFlex() : child->style()->flexboxHeightNegativeFlex();
}
void RenderFlexibleBox::computePreferredLogicalWidth(bool relayoutChildren, TreeOrderIterator& iterator, LayoutUnit& preferredLogicalWidth, float& totalPositiveFlexibility, float& totalNegativeFlexibility)
preferredLogicalWidth = 0;
totalPositiveFlexibility = totalNegativeFlexibility = 0;
- LayoutUnit flexboxAvailableLogicalWidth = availableLogicalWidth();
+ LayoutUnit flexboxAvailableLogicalWidth = flowAwareAvailableLogicalWidth();
for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
// We always have to lay out flexible objects again, since the flex distribution
// may have changed, and we need to reallocate space.
child->layoutIfNeeded();
// We can't just use marginStartForChild, et. al. because "auto" needs to be treated as 0.
- if (isHorizontalWritingMode()) {
+ if (isHorizontalFlow()) {
preferredLogicalWidth += child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth);
preferredLogicalWidth += child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth);
} else {
{
childSizes.clear();
- LayoutUnit flexboxAvailableLogicalWidth = availableLogicalWidth();
+ LayoutUnit flexboxAvailableLogicalWidth = flowAwareAvailableLogicalWidth();
for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
LayoutUnit childPreferredSize;
if (inflexibleItems.contains(child))
if (availableFreeSpace > 0 && totalPositiveFlexibility > 0) {
childPreferredSize += lroundf(availableFreeSpace * logicalPositiveFlexForChild(child) / totalPositiveFlexibility);
- Length childLogicalMaxWidth = isHorizontalWritingMode() ? child->style()->maxWidth() : child->style()->maxHeight();
+ Length childLogicalMaxWidth = isHorizontalFlow() ? child->style()->maxWidth() : child->style()->maxHeight();
if (!childLogicalMaxWidth.isUndefined() && childLogicalMaxWidth.isSpecified() && childPreferredSize > childLogicalMaxWidth.calcValue(flexboxAvailableLogicalWidth)) {
childPreferredSize = childLogicalMaxWidth.calcValue(flexboxAvailableLogicalWidth);
availableFreeSpace -= childPreferredSize - preferredLogicalContentWidthForFlexItem(child);
} else if (availableFreeSpace < 0 && totalNegativeFlexibility > 0) {
childPreferredSize += lroundf(availableFreeSpace * logicalNegativeFlexForChild(child) / totalNegativeFlexibility);
- Length childLogicalMinWidth = isHorizontalWritingMode() ? child->style()->minWidth() : child->style()->minHeight();
+ Length childLogicalMinWidth = isHorizontalFlow() ? child->style()->minWidth() : child->style()->minHeight();
if (!childLogicalMinWidth.isUndefined() && childLogicalMinWidth.isSpecified() && childPreferredSize < childLogicalMinWidth.calcValue(flexboxAvailableLogicalWidth)) {
childPreferredSize = childLogicalMinWidth.calcValue(flexboxAvailableLogicalWidth);
availableFreeSpace += preferredLogicalContentWidthForFlexItem(child) - childPreferredSize;
void RenderFlexibleBox::setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize)
{
// FIXME: Rename setOverrideWidth/setOverrideHeight to setOverrideLogicalWidth/setOverrideLogicalHeight.
- if (isHorizontalWritingMode())
- child->isHorizontalWritingMode() ? child->setOverrideWidth(childPreferredSize) : child->setOverrideHeight(childPreferredSize);
+ if (hasOrthogonalFlow(child))
+ child->setOverrideHeight(childPreferredSize);
else
- child->isHorizontalWritingMode() ? child->setOverrideHeight(childPreferredSize) : child->setOverrideWidth(childPreferredSize);
+ child->setOverrideWidth(childPreferredSize);
}
void RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection(FlexOrderIterator& iterator, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, float totalPositiveFlexibility)
{
- LayoutUnit startEdge = borderStart() + paddingStart();
+ LayoutUnit startEdge = flowAwareBorderStart() + flowAwarePaddingStart();
if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility)) {
if (style()->flexPack() == PackEnd)
startEdge += availableFreeSpace / 2;
}
- LayoutUnit logicalTop = borderBefore() + paddingBefore();
- LayoutUnit totalAvailableLogicalWidth = availableLogicalWidth();
- setLogicalHeight(0);
+ LayoutUnit logicalTop = flowAwareBorderBefore() + flowAwarePaddingBefore();
+ LayoutUnit totalAvailableLogicalWidth = flowAwareAvailableLogicalWidth();
+ setFlowAwareLogicalHeight(0);
size_t i = 0;
for (RenderBox* child = iterator.first(); child; child = iterator.next(), ++i) {
// FIXME: Does this need to take the scrollbar width into account?
child->setChildNeedsLayout(true);
child->layoutIfNeeded();
- setLogicalHeight(std::max(logicalHeight(), borderBefore() + paddingBefore() + marginBeforeForChild(child) + logicalHeightForChild(child) + marginAfterForChild(child) + paddingAfter() + borderAfter() + scrollbarLogicalHeight()));
+ setFlowAwareLogicalHeight(std::max(flowAwareLogicalHeight(), flowAwareBorderBefore() + flowAwarePaddingBefore() + flowAwareMarginBeforeForChild(child) + flowAwareLogicalHeightForChild(child) + flowAwareMarginAfterForChild(child) + flowAwarePaddingAfter() + flowAwareBorderAfter() + scrollbarLogicalHeight()));
if (marginStartStyleForChild(child).isAuto())
- setMarginStartForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);
+ setFlowAwareMarginStartForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);
if (marginEndStyleForChild(child).isAuto())
- setMarginEndForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);
+ setFlowAwareMarginEndForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);
- startEdge += marginStartForChild(child);
+ startEdge += flowAwareMarginStartForChild(child);
- LayoutUnit childLogicalWidth = logicalWidthForChild(child);
- LayoutUnit logicalLeft = style()->isLeftToRightDirection() ? startEdge : totalAvailableLogicalWidth - startEdge - childLogicalWidth;
+ LayoutUnit childLogicalWidth = flowAwareLogicalWidthForChild(child);
+ LayoutUnit logicalLeft = isLeftToRightFlow() ? startEdge : totalAvailableLogicalWidth - startEdge - childLogicalWidth;
// FIXME: Do repaintDuringLayoutIfMoved.
// FIXME: Supporting layout deltas.
- setLogicalLocationForChild(child, IntPoint(logicalLeft, logicalTop));
+ setFlowAwareLogicalLocationForChild(child, IntPoint(logicalLeft, logicalTop));
startEdge += childLogicalWidth + marginEndForChild(child);
if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility) && style()->flexPack() == PackJustify && childSizes.size() > 1)
class FlexOrderIterator;
typedef WTF::HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
- LayoutUnit logicalBorderAndPaddingWidthForChild(RenderBox* child);
- LayoutUnit logicalScrollbarHeightForChild(RenderBox* child);
- Length marginStartStyleForChild(RenderBox* child);
- Length marginEndStyleForChild(RenderBox* child);
- LayoutUnit preferredLogicalContentWidthForFlexItem(RenderBox* child);
+ bool hasOrthogonalFlow(RenderBox* child) const;
+ bool isHorizontalFlow() const;
+ bool isLeftToRightFlow() const;
+ void setFlowAwareLogicalHeight(LayoutUnit);
+ LayoutUnit flowAwareLogicalHeightForChild(RenderBox* child);
+ LayoutUnit flowAwareLogicalWidthForChild(RenderBox* child);
+ LayoutUnit flowAwareLogicalHeight() const;
+ LayoutUnit flowAwareContentLogicalWidth() const;
+ LayoutUnit flowAwareAvailableLogicalWidth() const;
+ LayoutUnit flowAwareBorderStart() const;
+ LayoutUnit flowAwareBorderBefore() const;
+ LayoutUnit flowAwareBorderAfter() const;
+ LayoutUnit flowAwarePaddingStart() const;
+ LayoutUnit flowAwarePaddingBefore() const;
+ LayoutUnit flowAwarePaddingAfter() const;
+ LayoutUnit flowAwareMarginStartForChild(RenderBox* child) const;
+ LayoutUnit flowAwareMarginBeforeForChild(RenderBox* child) const;
+ LayoutUnit flowAwareMarginAfterForChild(RenderBox* child) const;
+ void setFlowAwareMarginStartForChild(RenderBox* child, LayoutUnit);
+ void setFlowAwareMarginEndForChild(RenderBox* child, LayoutUnit);
+ // FIXME: Supporting layout deltas.
+ void setFlowAwareLogicalLocationForChild(RenderBox* child, const LayoutPoint&);
+ LayoutUnit logicalBorderAndPaddingWidthForChild(RenderBox* child) const;
+ LayoutUnit logicalScrollbarHeightForChild(RenderBox* child) const;
+ Length marginStartStyleForChild(RenderBox* child) const;
+ Length marginEndStyleForChild(RenderBox* child) const;
+ LayoutUnit preferredLogicalContentWidthForFlexItem(RenderBox* child) const;
void layoutInlineDirection(bool relayoutChildren);
- float logicalPositiveFlexForChild(RenderBox* child);
- float logicalNegativeFlexForChild(RenderBox* child);
+ float logicalPositiveFlexForChild(RenderBox* child) const;
+ float logicalNegativeFlexForChild(RenderBox* child) const;
void computePreferredLogicalWidth(bool relayoutChildren, TreeOrderIterator&, LayoutUnit&, float& totalPositiveFlexibility, float& totalNegativeFlexibility);
bool runFreeSpaceAllocationAlgorithmInlineDirection(FlexOrderIterator&, LayoutUnit& availableFreeSpace, float& totalPositiveFlexibility, float& totalNegativeFlexibility, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);