Use more RenderBox references in RenderFlexibleBox

RenderFlexibleBox has several methods that take pointers to RenderBox instances
but those methods assumes that the objects will never be NULL. We should replace
them by references. This makes the caller code safer.

This is in continuation to the CL https://codereview.chromium.org/555213002/

Review URL: https://codereview.chromium.org/560583003

git-svn-id: svn://svn.chromium.org/blink/trunk@181922 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 389f72fd
...@@ -127,9 +127,9 @@ void RenderFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt ...@@ -127,9 +127,9 @@ void RenderFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt
minLogicalWidth += scrollbarWidth; minLogicalWidth += scrollbarWidth;
} }
static int synthesizedBaselineFromContentBox(const RenderBox* box, LineDirectionMode direction) static int synthesizedBaselineFromContentBox(const RenderBox& box, LineDirectionMode direction)
{ {
return direction == HorizontalLine ? box->borderTop() + box->paddingTop() + box->contentHeight() : box->borderRight() + box->paddingRight() + box->contentWidth(); return direction == HorizontalLine ? box.borderTop() + box.paddingTop() + box.contentHeight() : box.borderRight() + box.paddingRight() + box.contentWidth();
} }
int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode direction, LinePositionMode mode) const int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode direction, LinePositionMode mode) const
...@@ -137,7 +137,7 @@ int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di ...@@ -137,7 +137,7 @@ int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di
ASSERT(mode == PositionOnContainingLine); ASSERT(mode == PositionOnContainingLine);
int baseline = firstLineBoxBaseline(); int baseline = firstLineBoxBaseline();
if (baseline == -1) if (baseline == -1)
baseline = synthesizedBaselineFromContentBox(this, direction); baseline = synthesizedBaselineFromContentBox(*this, direction);
return beforeMarginInLineDirection(direction) + baseline; return beforeMarginInLineDirection(direction) + baseline;
} }
...@@ -151,7 +151,7 @@ int RenderFlexibleBox::firstLineBoxBaseline() const ...@@ -151,7 +151,7 @@ int RenderFlexibleBox::firstLineBoxBaseline() const
for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) { for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) {
if (child->isOutOfFlowPositioned()) if (child->isOutOfFlowPositioned())
continue; continue;
if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(child)) { if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(*child)) {
baselineChild = child; baselineChild = child;
break; break;
} }
...@@ -176,7 +176,7 @@ int RenderFlexibleBox::firstLineBoxBaseline() const ...@@ -176,7 +176,7 @@ int RenderFlexibleBox::firstLineBoxBaseline() const
// FIXME: We should pass |direction| into firstLineBoxBaseline and stop bailing out if we're a writing mode root. // FIXME: We should pass |direction| into firstLineBoxBaseline and stop bailing out if we're a writing mode root.
// This would also fix some cases where the flexbox is orthogonal to its container. // This would also fix some cases where the flexbox is orthogonal to its container.
LineDirectionMode direction = isHorizontalWritingMode() ? HorizontalLine : VerticalLine; LineDirectionMode direction = isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
return synthesizedBaselineFromContentBox(baselineChild, direction) + baselineChild->logicalTop(); return synthesizedBaselineFromContentBox(*baselineChild, direction) + baselineChild->logicalTop();
} }
return baseline + baselineChild->logicalTop(); return baseline + baselineChild->logicalTop();
...@@ -189,7 +189,7 @@ int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const ...@@ -189,7 +189,7 @@ int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const
return baseline; return baseline;
int marginAscent = direction == HorizontalLine ? marginTop() : marginRight(); int marginAscent = direction == HorizontalLine ? marginTop() : marginRight();
return synthesizedBaselineFromContentBox(this, direction) + marginAscent; return synthesizedBaselineFromContentBox(*this, direction) + marginAscent;
} }
static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const RenderStyle* childStyle) static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const RenderStyle* childStyle)
...@@ -536,39 +536,39 @@ LayoutUnit RenderFlexibleBox::flowAwarePaddingAfter() const ...@@ -536,39 +536,39 @@ LayoutUnit RenderFlexibleBox::flowAwarePaddingAfter() const
return paddingTop(); return paddingTop();
} }
LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(RenderBox& child) const
{ {
if (isHorizontalFlow()) if (isHorizontalFlow())
return isLeftToRightFlow() ? child->marginLeft() : child->marginRight(); return isLeftToRightFlow() ? child.marginLeft() : child.marginRight();
return isLeftToRightFlow() ? child->marginTop() : child->marginBottom(); return isLeftToRightFlow() ? child.marginTop() : child.marginBottom();
} }
LayoutUnit RenderFlexibleBox::flowAwareMarginEndForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::flowAwareMarginEndForChild(RenderBox& child) const
{ {
if (isHorizontalFlow()) if (isHorizontalFlow())
return isLeftToRightFlow() ? child->marginRight() : child->marginLeft(); return isLeftToRightFlow() ? child.marginRight() : child.marginLeft();
return isLeftToRightFlow() ? child->marginBottom() : child->marginTop(); return isLeftToRightFlow() ? child.marginBottom() : child.marginTop();
} }
LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(RenderBox& child) const
{ {
switch (transformedWritingMode()) { switch (transformedWritingMode()) {
case TopToBottomWritingMode: case TopToBottomWritingMode:
return child->marginTop(); return child.marginTop();
case BottomToTopWritingMode: case BottomToTopWritingMode:
return child->marginBottom(); return child.marginBottom();
case LeftToRightWritingMode: case LeftToRightWritingMode:
return child->marginLeft(); return child.marginLeft();
case RightToLeftWritingMode: case RightToLeftWritingMode:
return child->marginRight(); return child.marginRight();
} }
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
return marginTop(); return marginTop();
} }
LayoutUnit RenderFlexibleBox::crossAxisMarginExtentForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::crossAxisMarginExtentForChild(RenderBox& child) const
{ {
return isHorizontalFlow() ? child->marginHeight() : child->marginWidth(); return isHorizontalFlow() ? child.marginHeight() : child.marginWidth();
} }
LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const
...@@ -576,27 +576,27 @@ LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const ...@@ -576,27 +576,27 @@ LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const
return isHorizontalFlow() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); return isHorizontalFlow() ? horizontalScrollbarHeight() : verticalScrollbarWidth();
} }
LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtentForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtentForChild(RenderBox& child) const
{ {
return isHorizontalFlow() ? child->horizontalScrollbarHeight() : child->verticalScrollbarWidth(); return isHorizontalFlow() ? child.horizontalScrollbarHeight() : child.verticalScrollbarWidth();
} }
LayoutPoint RenderFlexibleBox::flowAwareLocationForChild(RenderBox* child) const LayoutPoint RenderFlexibleBox::flowAwareLocationForChild(RenderBox& child) const
{ {
return isHorizontalFlow() ? child->location() : child->location().transposedPoint(); return isHorizontalFlow() ? child.location() : child.location().transposedPoint();
} }
void RenderFlexibleBox::setFlowAwareLocationForChild(RenderBox* child, const LayoutPoint& location) void RenderFlexibleBox::setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint& location)
{ {
if (isHorizontalFlow()) if (isHorizontalFlow())
child->setLocation(location); child.setLocation(location);
else else
child->setLocation(location.transposedPoint()); child.setLocation(location.transposedPoint());
} }
LayoutUnit RenderFlexibleBox::mainAxisBorderAndPaddingExtentForChild(RenderBox* child) const LayoutUnit RenderFlexibleBox::mainAxisBorderAndPaddingExtentForChild(RenderBox& child) const
{ {
return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAndPaddingHeight(); return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndPaddingHeight();
} }
static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasis, bool hasInfiniteLineLength) static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasis, bool hasInfiniteLineLength)
...@@ -609,31 +609,31 @@ bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render ...@@ -609,31 +609,31 @@ bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render
return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasInfiniteLineLength) && hasOrthogonalFlow(child); return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasInfiniteLineLength) && hasOrthogonalFlow(child);
} }
LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength, bool relayoutChildren) LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox& child, bool hasInfiniteLineLength, bool relayoutChildren)
{ {
child->clearOverrideSize(); child.clearOverrideSize();
if (child->style()->hasAspectRatio() || child->isImage() || child->isVideo() || child->isCanvas()) if (child.style()->hasAspectRatio() || child.isImage() || child.isVideo() || child.isCanvas())
UseCounter::count(document(), UseCounter::AspectRatioFlexItem); UseCounter::count(document(), UseCounter::AspectRatioFlexItem);
Length flexBasis = flexBasisForChild(*child); Length flexBasis = flexBasisForChild(child);
if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)) { if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)) {
LayoutUnit mainAxisExtent; LayoutUnit mainAxisExtent;
if (hasOrthogonalFlow(*child)) { if (hasOrthogonalFlow(child)) {
if (child->needsLayout() || relayoutChildren) { if (child.needsLayout() || relayoutChildren) {
m_intrinsicSizeAlongMainAxis.remove(child); m_intrinsicSizeAlongMainAxis.remove(&child);
child->forceChildLayout(); child.forceChildLayout();
m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight()); m_intrinsicSizeAlongMainAxis.set(&child, child.logicalHeight());
} }
ASSERT(m_intrinsicSizeAlongMainAxis.contains(child)); ASSERT(m_intrinsicSizeAlongMainAxis.contains(&child));
mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child); mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child);
} else { } else {
mainAxisExtent = child->maxPreferredLogicalWidth(); mainAxisExtent = child.maxPreferredLogicalWidth();
} }
ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0); ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0);
return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child);
} }
return std::max(LayoutUnit(0), computeMainAxisExtentForChild(*child, MainOrPreferredSize, flexBasis)); return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPreferredSize, flexBasis));
} }
void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren) void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren)
...@@ -710,70 +710,70 @@ LayoutUnit RenderFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi ...@@ -710,70 +710,70 @@ LayoutUnit RenderFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi
return sizeOfAutoMargin; return sizeOfAutoMargin;
} }
void RenderFlexibleBox::updateAutoMarginsInMainAxis(RenderBox* child, LayoutUnit autoMarginOffset) void RenderFlexibleBox::updateAutoMarginsInMainAxis(RenderBox& child, LayoutUnit autoMarginOffset)
{ {
ASSERT(autoMarginOffset >= 0); ASSERT(autoMarginOffset >= 0);
if (isHorizontalFlow()) { if (isHorizontalFlow()) {
if (child->style()->marginLeft().isAuto()) if (child.style()->marginLeft().isAuto())
child->setMarginLeft(autoMarginOffset); child.setMarginLeft(autoMarginOffset);
if (child->style()->marginRight().isAuto()) if (child.style()->marginRight().isAuto())
child->setMarginRight(autoMarginOffset); child.setMarginRight(autoMarginOffset);
} else { } else {
if (child->style()->marginTop().isAuto()) if (child.style()->marginTop().isAuto())
child->setMarginTop(autoMarginOffset); child.setMarginTop(autoMarginOffset);
if (child->style()->marginBottom().isAuto()) if (child.style()->marginBottom().isAuto())
child->setMarginBottom(autoMarginOffset); child.setMarginBottom(autoMarginOffset);
} }
} }
bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(RenderBox* child) const bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(RenderBox& child) const
{ {
if (isHorizontalFlow()) if (isHorizontalFlow())
return child->style()->marginTop().isAuto() || child->style()->marginBottom().isAuto(); return child.style()->marginTop().isAuto() || child.style()->marginBottom().isAuto();
return child->style()->marginLeft().isAuto() || child->style()->marginRight().isAuto(); return child.style()->marginLeft().isAuto() || child.style()->marginRight().isAuto();
} }
LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox* child) LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox& child)
{ {
ASSERT(!child->isOutOfFlowPositioned()); ASSERT(!child.isOutOfFlowPositioned());
LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAxisExtentForChild(*child); LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAxisExtentForChild(child);
return lineCrossAxisExtent - childCrossExtent; return lineCrossAxisExtent - childCrossExtent;
} }
LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit lineCrossAxisExtent, RenderBox* child) LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit lineCrossAxisExtent, RenderBox& child)
{ {
ASSERT(!child->isOutOfFlowPositioned()); ASSERT(!child.isOutOfFlowPositioned());
LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAxisIntrinsicExtentForChild(*child); LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAxisIntrinsicExtentForChild(child);
return lineCrossAxisExtent - childCrossExtent; return lineCrossAxisExtent - childCrossExtent;
} }
bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUnit availableAlignmentSpace) bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox& child, LayoutUnit availableAlignmentSpace)
{ {
ASSERT(!child->isOutOfFlowPositioned()); ASSERT(!child.isOutOfFlowPositioned());
ASSERT(availableAlignmentSpace >= 0); ASSERT(availableAlignmentSpace >= 0);
bool isHorizontal = isHorizontalFlow(); bool isHorizontal = isHorizontalFlow();
Length topOrLeft = isHorizontal ? child->style()->marginTop() : child->style()->marginLeft(); Length topOrLeft = isHorizontal ? child.style()->marginTop() : child.style()->marginLeft();
Length bottomOrRight = isHorizontal ? child->style()->marginBottom() : child->style()->marginRight(); Length bottomOrRight = isHorizontal ? child.style()->marginBottom() : child.style()->marginRight();
if (topOrLeft.isAuto() && bottomOrRight.isAuto()) { if (topOrLeft.isAuto() && bottomOrRight.isAuto()) {
adjustAlignmentForChild(child, availableAlignmentSpace / 2); adjustAlignmentForChild(child, availableAlignmentSpace / 2);
if (isHorizontal) { if (isHorizontal) {
child->setMarginTop(availableAlignmentSpace / 2); child.setMarginTop(availableAlignmentSpace / 2);
child->setMarginBottom(availableAlignmentSpace / 2); child.setMarginBottom(availableAlignmentSpace / 2);
} else { } else {
child->setMarginLeft(availableAlignmentSpace / 2); child.setMarginLeft(availableAlignmentSpace / 2);
child->setMarginRight(availableAlignmentSpace / 2); child.setMarginRight(availableAlignmentSpace / 2);
} }
return true; return true;
} }
bool shouldAdjustTopOrLeft = true; bool shouldAdjustTopOrLeft = true;
if (isColumnFlow() && !child->style()->isLeftToRightDirection()) { if (isColumnFlow() && !child.style()->isLeftToRightDirection()) {
// For column flows, only make this adjustment if topOrLeft corresponds to the "before" margin, // For column flows, only make this adjustment if topOrLeft corresponds to the "before" margin,
// so that flipForRightToLeftColumn will do the right thing. // so that flipForRightToLeftColumn will do the right thing.
shouldAdjustTopOrLeft = false; shouldAdjustTopOrLeft = false;
} }
if (!isColumnFlow() && child->style()->isFlippedBlocksWritingMode()) { if (!isColumnFlow() && child.style()->isFlippedBlocksWritingMode()) {
// If we are a flipped writing mode, we need to adjust the opposite side. This is only needed // If we are a flipped writing mode, we need to adjust the opposite side. This is only needed
// for row flows because this only affects the block-direction axis. // for row flows because this only affects the block-direction axis.
shouldAdjustTopOrLeft = false; shouldAdjustTopOrLeft = false;
...@@ -784,9 +784,9 @@ bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUni ...@@ -784,9 +784,9 @@ bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUni
adjustAlignmentForChild(child, availableAlignmentSpace); adjustAlignmentForChild(child, availableAlignmentSpace);
if (isHorizontal) if (isHorizontal)
child->setMarginTop(availableAlignmentSpace); child.setMarginTop(availableAlignmentSpace);
else else
child->setMarginLeft(availableAlignmentSpace); child.setMarginLeft(availableAlignmentSpace);
return true; return true;
} }
if (bottomOrRight.isAuto()) { if (bottomOrRight.isAuto()) {
...@@ -794,19 +794,19 @@ bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUni ...@@ -794,19 +794,19 @@ bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUni
adjustAlignmentForChild(child, availableAlignmentSpace); adjustAlignmentForChild(child, availableAlignmentSpace);
if (isHorizontal) if (isHorizontal)
child->setMarginBottom(availableAlignmentSpace); child.setMarginBottom(availableAlignmentSpace);
else else
child->setMarginRight(availableAlignmentSpace); child.setMarginRight(availableAlignmentSpace);
return true; return true;
} }
return false; return false;
} }
LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox* child) LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox& child)
{ {
LayoutUnit ascent = child->firstLineBoxBaseline(); LayoutUnit ascent = child.firstLineBoxBaseline();
if (ascent == -1) if (ascent == -1)
ascent = crossAxisExtentForChild(*child); ascent = crossAxisExtentForChild(child);
return ascent + flowAwareMarginBeforeForChild(child); return ascent + flowAwareMarginBeforeForChild(child);
} }
...@@ -840,19 +840,19 @@ void RenderFlexibleBox::prepareOrderIteratorAndMargins() ...@@ -840,19 +840,19 @@ void RenderFlexibleBox::prepareOrderIteratorAndMargins()
} }
} }
LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, LayoutUnit childSize) LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox& child, LayoutUnit childSize)
{ {
Length max = isHorizontalFlow() ? child->style()->maxWidth() : child->style()->maxHeight(); Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()->maxHeight();
if (max.isSpecifiedOrIntrinsic()) { if (max.isSpecifiedOrIntrinsic()) {
LayoutUnit maxExtent = computeMainAxisExtentForChild(*child, MaxSize, max); LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
if (maxExtent != -1 && childSize > maxExtent) if (maxExtent != -1 && childSize > maxExtent)
childSize = maxExtent; childSize = maxExtent;
} }
Length min = isHorizontalFlow() ? child->style()->minWidth() : child->style()->minHeight(); Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()->minHeight();
LayoutUnit minExtent = 0; LayoutUnit minExtent = 0;
if (min.isSpecifiedOrIntrinsic()) if (min.isSpecifiedOrIntrinsic())
minExtent = computeMainAxisExtentForChild(*child, MinSize, min); minExtent = computeMainAxisExtentForChild(child, MinSize, min);
return std::max(childSize, minExtent); return std::max(childSize, minExtent);
} }
...@@ -877,12 +877,12 @@ bool RenderFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren ...@@ -877,12 +877,12 @@ bool RenderFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren
continue; continue;
} }
LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild(child, hasInfiniteLineLength, relayoutChildren); LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild(*child, hasInfiniteLineLength, relayoutChildren);
LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingExtentForChild(child) LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingExtentForChild(*child)
+ (isHorizontalFlow() ? child->marginWidth() : child->marginHeight()); + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight());
LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMarginBorderPadding; LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMarginBorderPadding;
LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(child, childMainAxisExtent); LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(*child, childMainAxisExtent);
LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding; LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding;
if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem) if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem)
...@@ -902,7 +902,7 @@ void RenderFlexibleBox::freezeViolations(const Vector<Violation>& violations, La ...@@ -902,7 +902,7 @@ void RenderFlexibleBox::freezeViolations(const Vector<Violation>& violations, La
for (size_t i = 0; i < violations.size(); ++i) { for (size_t i = 0; i < violations.size(); ++i) {
RenderBox* child = violations[i].child; RenderBox* child = violations[i].child;
LayoutUnit childSize = violations[i].childSize; LayoutUnit childSize = violations[i].childSize;
LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(child, hasInfiniteLineLength); LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(*child, hasInfiniteLineLength);
availableFreeSpace -= childSize - preferredChildSize; availableFreeSpace -= childSize - preferredChildSize;
totalFlexGrow -= child->style()->flexGrow(); totalFlexGrow -= child->style()->flexGrow();
totalWeightedFlexShrink -= child->style()->flexShrink() * preferredChildSize; totalWeightedFlexShrink -= child->style()->flexShrink() * preferredChildSize;
...@@ -928,7 +928,7 @@ bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF ...@@ -928,7 +928,7 @@ bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF
if (inflexibleItems.contains(child)) if (inflexibleItems.contains(child))
childSizes.append(inflexibleItems.get(child)); childSizes.append(inflexibleItems.get(child));
else { else {
LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(child, hasInfiniteLineLength); LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(*child, hasInfiniteLineLength);
LayoutUnit childSize = preferredChildSize; LayoutUnit childSize = preferredChildSize;
double extraSpace = 0; double extraSpace = 0;
if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveFlexibility && std::isfinite(totalFlexGrow)) if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveFlexibility && std::isfinite(totalFlexGrow))
...@@ -938,7 +938,7 @@ bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF ...@@ -938,7 +938,7 @@ bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF
if (std::isfinite(extraSpace)) if (std::isfinite(extraSpace))
childSize += LayoutUnit::fromFloatRound(extraSpace); childSize += LayoutUnit::fromFloatRound(extraSpace);
LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(child, childSize); LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, childSize);
childSizes.append(adjustedChildSize); childSizes.append(adjustedChildSize);
usedFreeSpace += adjustedChildSize - preferredChildSize; usedFreeSpace += adjustedChildSize - preferredChildSize;
...@@ -993,11 +993,11 @@ void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil ...@@ -993,11 +993,11 @@ void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil
child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAndPaddingLogicalWidth()); child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAndPaddingLogicalWidth());
} }
void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode) void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox& child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode)
{ {
ASSERT(child->isOutOfFlowPositioned()); ASSERT(child.isOutOfFlowPositioned());
child->containingBlock()->insertPositionedObject(child); child.containingBlock()->insertPositionedObject(&child);
RenderLayer* childLayer = child->layer(); RenderLayer* childLayer = child.layer();
LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffset; LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffset;
if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowReverse) if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowReverse)
inlinePosition = mainAxisExtent() - mainAxisOffset; inlinePosition = mainAxisExtent() - mainAxisOffset;
...@@ -1006,8 +1006,8 @@ void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox* child, Layout ...@@ -1006,8 +1006,8 @@ void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox* child, Layout
LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxisOffset; LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxisOffset;
if (childLayer->staticBlockPosition() != staticBlockPosition) { if (childLayer->staticBlockPosition() != staticBlockPosition) {
childLayer->setStaticBlockPosition(staticBlockPosition); childLayer->setStaticBlockPosition(staticBlockPosition);
if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode())) if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
child->setChildNeedsLayout(MarkOnlyThis); child.setChildNeedsLayout(MarkOnlyThis);
} }
} }
...@@ -1039,20 +1039,20 @@ size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem ...@@ -1039,20 +1039,20 @@ size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem
return count; return count;
} }
void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* child) void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox& child)
{ {
if (hasAutoMarginsInCrossAxis(child)) { if (hasAutoMarginsInCrossAxis(child)) {
child->updateLogicalHeight(); child.updateLogicalHeight();
if (isHorizontalFlow()) { if (isHorizontalFlow()) {
if (child->style()->marginTop().isAuto()) if (child.style()->marginTop().isAuto())
child->setMarginTop(0); child.setMarginTop(0);
if (child->style()->marginBottom().isAuto()) if (child.style()->marginBottom().isAuto())
child->setMarginBottom(0); child.setMarginBottom(0);
} else { } else {
if (child->style()->marginLeft().isAuto()) if (child.style()->marginLeft().isAuto())
child->setMarginLeft(0); child.setMarginLeft(0);
if (child->style()->marginRight().isAuto()) if (child.style()->marginRight().isAuto())
child->setMarginRight(0); child.setMarginRight(0);
} }
} }
} }
...@@ -1085,55 +1085,55 @@ void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons ...@@ -1085,55 +1085,55 @@ void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
RenderBox* child = children[i]; RenderBox* child = children[i];
if (child->isOutOfFlowPositioned()) { if (child->isOutOfFlowPositioned()) {
prepareChildForPositionedLayout(child, mainAxisOffset, crossAxisOffset, FlipForRowReverse); prepareChildForPositionedLayout(*child, mainAxisOffset, crossAxisOffset, FlipForRowReverse);
continue; continue;
} }
// FIXME Investigate if this can be removed based on other flags. crbug.com/370010 // FIXME Investigate if this can be removed based on other flags. crbug.com/370010
child->setMayNeedPaintInvalidation(true); child->setMayNeedPaintInvalidation(true);
LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPaddingExtentForChild(child); LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPaddingExtentForChild(*child);
setLogicalOverrideSize(*child, childPreferredSize); setLogicalOverrideSize(*child, childPreferredSize);
if (childPreferredSize != mainAxisExtentForChild(*child)) { if (childPreferredSize != mainAxisExtentForChild(*child)) {
child->setChildNeedsLayout(MarkOnlyThis); child->setChildNeedsLayout(MarkOnlyThis);
} else { } else {
// To avoid double applying margin changes in updateAutoMarginsInCrossAxis, we reset the margins here. // To avoid double applying margin changes in updateAutoMarginsInCrossAxis, we reset the margins here.
resetAutoMarginsAndLogicalTopInCrossAxis(child); resetAutoMarginsAndLogicalTopInCrossAxis(*child);
} }
// We may have already forced relayout for orthogonal flowing children in preferredMainAxisContentExtentForChild. // We may have already forced relayout for orthogonal flowing children in preferredMainAxisContentExtentForChild.
bool forceChildRelayout = relayoutChildren && !childPreferredMainAxisContentExtentRequiresLayout(*child, hasInfiniteLineLength); bool forceChildRelayout = relayoutChildren && !childPreferredMainAxisContentExtentRequiresLayout(*child, hasInfiniteLineLength);
updateBlockChildDirtyBitsBeforeLayout(forceChildRelayout, child); updateBlockChildDirtyBitsBeforeLayout(forceChildRelayout, child);
child->layoutIfNeeded(); child->layoutIfNeeded();
updateAutoMarginsInMainAxis(child, autoMarginOffset); updateAutoMarginsInMainAxis(*child, autoMarginOffset);
LayoutUnit childCrossAxisMarginBoxExtent; LayoutUnit childCrossAxisMarginBoxExtent;
if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(child)) { if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(*child)) {
LayoutUnit ascent = marginBoxAscentForChild(child); LayoutUnit ascent = marginBoxAscentForChild(*child);
LayoutUnit descent = (crossAxisMarginExtentForChild(child) + crossAxisExtentForChild(*child)) - ascent; LayoutUnit descent = (crossAxisMarginExtentForChild(*child) + crossAxisExtentForChild(*child)) - ascent;
maxAscent = std::max(maxAscent, ascent); maxAscent = std::max(maxAscent, ascent);
maxDescent = std::max(maxDescent, descent); maxDescent = std::max(maxDescent, descent);
childCrossAxisMarginBoxExtent = maxAscent + maxDescent; childCrossAxisMarginBoxExtent = maxAscent + maxDescent;
} else { } else {
childCrossAxisMarginBoxExtent = crossAxisIntrinsicExtentForChild(*child) + crossAxisMarginExtentForChild(child) + crossAxisScrollbarExtentForChild(child); childCrossAxisMarginBoxExtent = crossAxisIntrinsicExtentForChild(*child) + crossAxisMarginExtentForChild(*child) + crossAxisScrollbarExtentForChild(*child);
} }
if (!isColumnFlow()) if (!isColumnFlow())
setLogicalHeight(std::max(logicalHeight(), crossAxisOffset + flowAwareBorderAfter() + flowAwarePaddingAfter() + childCrossAxisMarginBoxExtent + crossAxisScrollbarExtent())); setLogicalHeight(std::max(logicalHeight(), crossAxisOffset + flowAwareBorderAfter() + flowAwarePaddingAfter() + childCrossAxisMarginBoxExtent + crossAxisScrollbarExtent()));
maxChildCrossAxisExtent = std::max(maxChildCrossAxisExtent, childCrossAxisMarginBoxExtent); maxChildCrossAxisExtent = std::max(maxChildCrossAxisExtent, childCrossAxisMarginBoxExtent);
mainAxisOffset += flowAwareMarginStartForChild(child); mainAxisOffset += flowAwareMarginStartForChild(*child);
LayoutUnit childMainExtent = mainAxisExtentForChild(*child); LayoutUnit childMainExtent = mainAxisExtentForChild(*child);
// In an RTL column situation, this will apply the margin-right/margin-end on the left. // In an RTL column situation, this will apply the margin-right/margin-end on the left.
// This will be fixed later in flipForRightToLeftColumn. // This will be fixed later in flipForRightToLeftColumn.
LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxisOffset - childMainExtent : mainAxisOffset, LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxisOffset - childMainExtent : mainAxisOffset,
crossAxisOffset + flowAwareMarginBeforeForChild(child)); crossAxisOffset + flowAwareMarginBeforeForChild(*child));
// FIXME: Supporting layout deltas. // FIXME: Supporting layout deltas.
setFlowAwareLocationForChild(child, childLocation); setFlowAwareLocationForChild(*child, childLocation);
mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(child); mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(*child);
++seenInFlowPositionedChildren; ++seenInFlowPositionedChildren;
if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent)
...@@ -1174,11 +1174,11 @@ void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, ...@@ -1174,11 +1174,11 @@ void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children,
child->layer()->setStaticBlockPosition(mainAxisOffset); child->layer()->setStaticBlockPosition(mainAxisOffset);
continue; continue;
} }
mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndForChild(child); mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndForChild(*child);
setFlowAwareLocationForChild(child, LayoutPoint(mainAxisOffset, crossAxisOffset + flowAwareMarginBeforeForChild(child))); setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAxisOffset + flowAwareMarginBeforeForChild(*child)));
mainAxisOffset -= flowAwareMarginStartForChild(child); mainAxisOffset -= flowAwareMarginStartForChild(*child);
++seenInFlowPositionedChildren; ++seenInFlowPositionedChildren;
if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent)
...@@ -1236,7 +1236,7 @@ void RenderFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts) ...@@ -1236,7 +1236,7 @@ void RenderFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts)
for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) { for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) {
lineContexts[lineNumber].crossAxisOffset += lineOffset; lineContexts[lineNumber].crossAxisOffset += lineOffset;
for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numberOfChildren; ++childNumber, child = m_orderIterator.next()) for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numberOfChildren; ++childNumber, child = m_orderIterator.next())
adjustAlignmentForChild(child, lineOffset); adjustAlignmentForChild(*child, lineOffset);
if (style()->alignContent() == AlignContentStretch && availableCrossAxisSpace > 0) if (style()->alignContent() == AlignContentStretch && availableCrossAxisSpace > 0)
lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size()); lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size());
...@@ -1245,11 +1245,11 @@ void RenderFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts) ...@@ -1245,11 +1245,11 @@ void RenderFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts)
} }
} }
void RenderFlexibleBox::adjustAlignmentForChild(RenderBox* child, LayoutUnit delta) void RenderFlexibleBox::adjustAlignmentForChild(RenderBox& child, LayoutUnit delta)
{ {
if (child->isOutOfFlowPositioned()) { if (child.isOutOfFlowPositioned()) {
LayoutUnit staticInlinePosition = child->layer()->staticInlinePosition(); LayoutUnit staticInlinePosition = child.layer()->staticInlinePosition();
LayoutUnit staticBlockPosition = child->layer()->staticBlockPosition(); LayoutUnit staticBlockPosition = child.layer()->staticBlockPosition();
LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlinePosition; LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlinePosition;
LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlockPosition; LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlockPosition;
crossAxis += delta; crossAxis += delta;
...@@ -1275,11 +1275,11 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) ...@@ -1275,11 +1275,11 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts)
ASSERT(child); ASSERT(child);
if (child->isOutOfFlowPositioned()) { if (child->isOutOfFlowPositioned()) {
if (style()->flexWrap() == FlexWrapReverse) if (style()->flexWrap() == FlexWrapReverse)
adjustAlignmentForChild(child, lineCrossAxisExtent); adjustAlignmentForChild(*child, lineCrossAxisExtent);
continue; continue;
} }
if (updateAutoMarginsInCrossAxis(child, std::max(LayoutUnit(0), availableAlignmentSpaceForChild(lineCrossAxisExtent, child)))) if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(0), availableAlignmentSpaceForChild(lineCrossAxisExtent, *child))))
continue; continue;
switch (alignmentForChild(*child)) { switch (alignmentForChild(*child)) {
...@@ -1287,29 +1287,29 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) ...@@ -1287,29 +1287,29 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts)
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
break; break;
case ItemPositionStretch: { case ItemPositionStretch: {
applyStretchAlignmentToChild(child, lineCrossAxisExtent); applyStretchAlignmentToChild(*child, lineCrossAxisExtent);
// Since wrap-reverse flips cross start and cross end, strech children should be aligned with the cross end. // Since wrap-reverse flips cross start and cross end, strech children should be aligned with the cross end.
if (style()->flexWrap() == FlexWrapReverse) if (style()->flexWrap() == FlexWrapReverse)
adjustAlignmentForChild(child, availableAlignmentSpaceForChild(lineCrossAxisExtent, child)); adjustAlignmentForChild(*child, availableAlignmentSpaceForChild(lineCrossAxisExtent, *child));
break; break;
} }
case ItemPositionFlexStart: case ItemPositionFlexStart:
break; break;
case ItemPositionFlexEnd: case ItemPositionFlexEnd:
adjustAlignmentForChild(child, availableAlignmentSpaceForChild(lineCrossAxisExtent, child)); adjustAlignmentForChild(*child, availableAlignmentSpaceForChild(lineCrossAxisExtent, *child));
break; break;
case ItemPositionCenter: case ItemPositionCenter:
adjustAlignmentForChild(child, availableAlignmentSpaceForChild(lineCrossAxisExtent, child) / 2); adjustAlignmentForChild(*child, availableAlignmentSpaceForChild(lineCrossAxisExtent, *child) / 2);
break; break;
case ItemPositionBaseline: { case ItemPositionBaseline: {
// 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. // 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 // https://bugs.webkit.org/show_bug.cgi?id=98076
LayoutUnit ascent = marginBoxAscentForChild(child); LayoutUnit ascent = marginBoxAscentForChild(*child);
LayoutUnit startOffset = maxAscent - ascent; LayoutUnit startOffset = maxAscent - ascent;
adjustAlignmentForChild(child, startOffset); adjustAlignmentForChild(*child, startOffset);
if (style()->flexWrap() == FlexWrapReverse) if (style()->flexWrap() == FlexWrapReverse)
minMarginAfterBaseline = std::min(minMarginAfterBaseline, availableAlignmentSpaceForChild(lineCrossAxisExtent, child) - startOffset); minMarginAfterBaseline = std::min(minMarginAfterBaseline, availableAlignmentSpaceForChild(lineCrossAxisExtent, *child) - startOffset);
break; break;
} }
case ItemPositionLastBaseline: case ItemPositionLastBaseline:
...@@ -1338,38 +1338,38 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) ...@@ -1338,38 +1338,38 @@ void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts)
LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber]; LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber];
for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numberOfChildren; ++childNumber, child = m_orderIterator.next()) { for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numberOfChildren; ++childNumber, child = m_orderIterator.next()) {
ASSERT(child); ASSERT(child);
if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(child) && minMarginAfterBaseline) if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMarginsInCrossAxis(*child) && minMarginAfterBaseline)
adjustAlignmentForChild(child, minMarginAfterBaseline); adjustAlignmentForChild(*child, minMarginAfterBaseline);
} }
} }
} }
void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox* child, LayoutUnit lineCrossAxisExtent) void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox& child, LayoutUnit lineCrossAxisExtent)
{ {
if (!isColumnFlow() && child->style()->logicalHeight().isAuto()) { if (!isColumnFlow() && child.style()->logicalHeight().isAuto()) {
// FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it.
if (!hasOrthogonalFlow(*child)) { if (!hasOrthogonalFlow(child)) {
LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(*child) ? constrainedChildIntrinsicContentLogicalHeight(*child) : child->logicalHeight(); LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHeight();
LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availableAlignmentSpaceForChildBeforeStretching(lineCrossAxisExtent, child); LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availableAlignmentSpaceForChildBeforeStretching(lineCrossAxisExtent, child);
ASSERT(!child->needsLayout()); ASSERT(!child.needsLayout());
LayoutUnit desiredLogicalHeight = child->constrainLogicalHeightByMinMax(stretchedLogicalHeight, heightBeforeStretching - child->borderAndPaddingLogicalHeight()); LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogicalHeight());
// FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905. // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905.
if (desiredLogicalHeight != child->logicalHeight()) { if (desiredLogicalHeight != child.logicalHeight()) {
child->setOverrideLogicalContentHeight(desiredLogicalHeight - child->borderAndPaddingLogicalHeight()); child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borderAndPaddingLogicalHeight());
child->setLogicalHeight(0); child.setLogicalHeight(0);
child->forceChildLayout(); child.forceChildLayout();
} }
} }
} else if (isColumnFlow() && child->style()->logicalWidth().isAuto()) { } else if (isColumnFlow() && child.style()->logicalWidth().isAuto()) {
// FIXME: If the child doesn't have orthogonal flow, then it already has an override width set, so use it. // FIXME: If the child doesn't have orthogonal flow, then it already has an override width set, so use it.
if (hasOrthogonalFlow(*child)) { if (hasOrthogonalFlow(child)) {
LayoutUnit childWidth = std::max<LayoutUnit>(0, lineCrossAxisExtent - crossAxisMarginExtentForChild(child)); LayoutUnit childWidth = std::max<LayoutUnit>(0, lineCrossAxisExtent - crossAxisMarginExtentForChild(child));
childWidth = child->constrainLogicalWidthByMinMax(childWidth, childWidth, this); childWidth = child.constrainLogicalWidthByMinMax(childWidth, childWidth, this);
if (childWidth != child->logicalWidth()) { if (childWidth != child.logicalWidth()) {
child->setOverrideLogicalContentWidth(childWidth - child->borderAndPaddingLogicalWidth()); child.setOverrideLogicalContentWidth(childWidth - child.borderAndPaddingLogicalWidth());
child->forceChildLayout(); child.forceChildLayout();
} }
} }
} }
...@@ -1384,11 +1384,11 @@ void RenderFlexibleBox::flipForRightToLeftColumn() ...@@ -1384,11 +1384,11 @@ void RenderFlexibleBox::flipForRightToLeftColumn()
for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) { for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) {
if (child->isOutOfFlowPositioned()) if (child->isOutOfFlowPositioned())
continue; continue;
LayoutPoint location = flowAwareLocationForChild(child); LayoutPoint location = flowAwareLocationForChild(*child);
// For vertical flows, setFlowAwareLocationForChild will transpose x and y, // For vertical flows, setFlowAwareLocationForChild will transpose x and y,
// so using the y axis for a column cross axis extent is correct. // so using the y axis for a column cross axis extent is correct.
location.setY(crossExtent - crossAxisExtentForChild(*child) - location.y()); location.setY(crossExtent - crossAxisExtentForChild(*child) - location.y());
setFlowAwareLocationForChild(child, location); setFlowAwareLocationForChild(*child, location);
} }
} }
...@@ -1402,7 +1402,7 @@ void RenderFlexibleBox::flipForWrapReverse(const Vector<LineContext>& lineContex ...@@ -1402,7 +1402,7 @@ void RenderFlexibleBox::flipForWrapReverse(const Vector<LineContext>& lineContex
LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExtent; LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExtent;
LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxisExtent; LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxisExtent;
adjustAlignmentForChild(child, newOffset - originalOffset); adjustAlignmentForChild(*child, newOffset - originalOffset);
} }
} }
} }
......
...@@ -107,53 +107,53 @@ private: ...@@ -107,53 +107,53 @@ private:
LayoutUnit flowAwarePaddingEnd() const; LayoutUnit flowAwarePaddingEnd() const;
LayoutUnit flowAwarePaddingBefore() const; LayoutUnit flowAwarePaddingBefore() const;
LayoutUnit flowAwarePaddingAfter() const; LayoutUnit flowAwarePaddingAfter() const;
LayoutUnit flowAwareMarginStartForChild(RenderBox* child) const; LayoutUnit flowAwareMarginStartForChild(RenderBox& child) const;
LayoutUnit flowAwareMarginEndForChild(RenderBox* child) const; LayoutUnit flowAwareMarginEndForChild(RenderBox& child) const;
LayoutUnit flowAwareMarginBeforeForChild(RenderBox* child) const; LayoutUnit flowAwareMarginBeforeForChild(RenderBox& child) const;
LayoutUnit crossAxisMarginExtentForChild(RenderBox* child) const; LayoutUnit crossAxisMarginExtentForChild(RenderBox& child) const;
LayoutUnit crossAxisScrollbarExtent() const; LayoutUnit crossAxisScrollbarExtent() const;
LayoutUnit crossAxisScrollbarExtentForChild(RenderBox* child) const; LayoutUnit crossAxisScrollbarExtentForChild(RenderBox& child) const;
LayoutPoint flowAwareLocationForChild(RenderBox* child) const; LayoutPoint flowAwareLocationForChild(RenderBox& child) const;
// FIXME: Supporting layout deltas. // FIXME: Supporting layout deltas.
void setFlowAwareLocationForChild(RenderBox* child, const LayoutPoint&); void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
void adjustAlignmentForChild(RenderBox* child, LayoutUnit); void adjustAlignmentForChild(RenderBox& child, LayoutUnit);
ItemPosition alignmentForChild(RenderBox& child) const; ItemPosition alignmentForChild(RenderBox& child) const;
LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox* child) const; LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox& child) const;
LayoutUnit preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength, bool relayoutChildren = false); LayoutUnit preferredMainAxisContentExtentForChild(RenderBox& child, bool hasInfiniteLineLength, bool relayoutChildren = false);
bool childPreferredMainAxisContentExtentRequiresLayout(RenderBox& child, bool hasInfiniteLineLength) const; bool childPreferredMainAxisContentExtentRequiresLayout(RenderBox& child, bool hasInfiniteLineLength) const;
bool needToStretchChildLogicalHeight(RenderBox& child) const; bool needToStretchChildLogicalHeight(RenderBox& child) const;
void layoutFlexItems(bool relayoutChildren); void layoutFlexItems(bool relayoutChildren);
LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace); LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
void updateAutoMarginsInMainAxis(RenderBox* child, LayoutUnit autoMarginOffset); void updateAutoMarginsInMainAxis(RenderBox& child, LayoutUnit autoMarginOffset);
bool hasAutoMarginsInCrossAxis(RenderBox* child) const; bool hasAutoMarginsInCrossAxis(RenderBox& child) const;
bool updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUnit availableAlignmentSpace); bool updateAutoMarginsInCrossAxis(RenderBox& child, LayoutUnit availableAlignmentSpace);
void repositionLogicalHeightDependentFlexItems(Vector<LineContext>&); void repositionLogicalHeightDependentFlexItems(Vector<LineContext>&);
LayoutUnit clientLogicalBottomAfterRepositioning(); LayoutUnit clientLogicalBottomAfterRepositioning();
void appendChildFrameRects(ChildFrameRects&); void appendChildFrameRects(ChildFrameRects&);
LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox*); LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox& child);
LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit lineCrossAxisExtent, RenderBox*); LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit lineCrossAxisExtent, RenderBox& child);
LayoutUnit marginBoxAscentForChild(RenderBox*); LayoutUnit marginBoxAscentForChild(RenderBox& child);
LayoutUnit computeChildMarginValue(Length margin); LayoutUnit computeChildMarginValue(Length margin);
void prepareOrderIteratorAndMargins(); void prepareOrderIteratorAndMargins();
LayoutUnit adjustChildSizeForMinAndMax(RenderBox*, LayoutUnit childSize); LayoutUnit adjustChildSizeForMinAndMax(RenderBox& child, LayoutUnit childSize);
// The hypothetical main size of an item is the flex base size clamped according to its min and max main size properties // The hypothetical main size of an item is the flex base size clamped according to its min and max main size properties
bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool& hasInfiniteLineLength, bool relayoutChildren); bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool& hasInfiniteLineLength, bool relayoutChildren);
bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, Vector<LayoutUnit, 16>& childSizes, bool hasInfiniteLineLength); bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, Vector<LayoutUnit, 16>& childSizes, bool hasInfiniteLineLength);
void freezeViolations(const Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, bool hasInfiniteLineLength); void freezeViolations(const Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, bool hasInfiniteLineLength);
void resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox*); void resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox& child);
void setLogicalOverrideSize(RenderBox& child, LayoutUnit childPreferredSize); void setLogicalOverrideSize(RenderBox& child, LayoutUnit childPreferredSize);
void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode); void prepareChildForPositionedLayout(RenderBox& child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
size_t numberOfInFlowPositionedChildren(const OrderedFlexItemList&) const; size_t numberOfInFlowPositionedChildren(const OrderedFlexItemList&) const;
void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const Vector<LayoutUnit, 16>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>&, bool hasInfiniteLineLength); void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const Vector<LayoutUnit, 16>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>&, bool hasInfiniteLineLength);
void layoutColumnReverse(const OrderedFlexItemList&, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace); void layoutColumnReverse(const OrderedFlexItemList&, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
void alignFlexLines(Vector<LineContext>&); void alignFlexLines(Vector<LineContext>&);
void alignChildren(const Vector<LineContext>&); void alignChildren(const Vector<LineContext>&);
void applyStretchAlignmentToChild(RenderBox*, LayoutUnit lineCrossAxisExtent); void applyStretchAlignmentToChild(RenderBox& child, LayoutUnit lineCrossAxisExtent);
void flipForRightToLeftColumn(); void flipForRightToLeftColumn();
void flipForWrapReverse(const Vector<LineContext>&, LayoutUnit crossAxisStartEdge); void flipForWrapReverse(const Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment