#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/TextAutosizer.h"
+#include "core/rendering/style/RenderStyle.h"
#include "platform/LengthFunctions.h"
#include "wtf/MathExtras.h"
#include <limits>
return synthesizedBaselineFromContentBox(*this, direction) + marginAscent;
}
-static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const RenderStyle* childStyle)
-{
- ItemPosition align = childStyle->alignSelf();
- if (align == ItemPositionAuto)
- align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionStretch : parentStyle->alignItems();
- return align;
-}
-
void RenderFlexibleBox::removeChild(RenderObject* child)
{
RenderBlock::removeChild(child);
// Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space.
// This is only necessary for stretching since other alignment values don't change the size of the box.
for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
- ItemPosition previousAlignment = resolveAlignment(oldStyle, child->style());
- if (previousAlignment == ItemPositionStretch && previousAlignment != resolveAlignment(style(), child->style()))
+ ItemPosition previousAlignment = RenderStyle::resolveAlignment(oldStyle, child->style(), ItemPositionStretch);
+ if (previousAlignment == ItemPositionStretch && previousAlignment != RenderStyle::resolveAlignment(style(), child->style(), ItemPositionStretch))
child->setChildNeedsLayout(MarkOnlyThis);
}
}
{
child.clearOverrideSize();
- if (child.style()->hasAspectRatio() || child.isImage() || child.isVideo() || child.isCanvas())
+ if (child.isImage() || child.isVideo() || child.isCanvas())
UseCounter::count(document(), UseCounter::AspectRatioFlexItem);
Length flexBasis = flexBasisForChild(child);
if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)) {
LayoutUnit mainAxisExtent;
if (hasOrthogonalFlow(child)) {
- if (child.needsLayout() || relayoutChildren) {
+ if (child.needsLayout() || relayoutChildren || !m_intrinsicSizeAlongMainAxis.contains(&child)) {
m_intrinsicSizeAlongMainAxis.remove(&child);
child.forceChildLayout();
m_intrinsicSizeAlongMainAxis.set(&child, child.logicalHeight());
}
- ASSERT(m_intrinsicSizeAlongMainAxis.contains(&child));
mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child);
} else {
mainAxisExtent = child.maxPreferredLogicalWidth();
// so that flipForRightToLeftColumn will do the right thing.
shouldAdjustTopOrLeft = false;
}
- if (!isColumnFlow() && child.style()->isFlippedBlocksWritingMode()) {
+ if (!isColumnFlow() && child.style()->slowIsFlippedBlocksWritingMode()) {
// 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.
shouldAdjustTopOrLeft = false;
return !totalViolation;
}
-static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, EJustifyContent justifyContent, unsigned numberOfChildren)
+static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, ContentPosition justifyContent, ContentDistributionType justifyContentDistribution, unsigned numberOfChildren)
{
- if (justifyContent == JustifyFlexEnd)
+ if (justifyContent == ContentPositionFlexEnd)
return availableFreeSpace;
- if (justifyContent == JustifyCenter)
+ if (justifyContent == ContentPositionCenter)
return availableFreeSpace / 2;
- if (justifyContent == JustifySpaceAround) {
+ if (justifyContentDistribution == ContentDistributionSpaceAround) {
if (availableFreeSpace > 0 && numberOfChildren)
return availableFreeSpace / (2 * numberOfChildren);
else
return 0;
}
-static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpace, EJustifyContent justifyContent, unsigned numberOfChildren)
+static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpace, ContentDistributionType justifyContentDistribution, unsigned numberOfChildren)
{
if (availableFreeSpace > 0 && numberOfChildren > 1) {
- if (justifyContent == JustifySpaceBetween)
+ if (justifyContentDistribution == ContentDistributionSpaceBetween)
return availableFreeSpace / (numberOfChildren - 1);
- if (justifyContent == JustifySpaceAround)
+ if (justifyContentDistribution == ContentDistributionSpaceAround)
return availableFreeSpace / numberOfChildren;
}
return 0;
ItemPosition RenderFlexibleBox::alignmentForChild(RenderBox& child) const
{
- ItemPosition align = resolveAlignment(style(), child.style());
+ ItemPosition align = RenderStyle::resolveAlignment(style(), child.style(), ItemPositionStretch);
if (align == ItemPositionBaseline && hasOrthogonalFlow(child))
align = ItemPositionFlexStart;
size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(children);
LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, availableFreeSpace);
LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart();
- mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->justifyContent(), numberOfChildrenForJustifyContent);
+ mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->justifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJustifyContent);
if (style()->flexDirection() == FlowRowReverse)
mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizontalScrollbarHeight();
++seenInFlowPositionedChildren;
if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent)
- mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSpace, style()->justifyContent(), numberOfChildrenForJustifyContent);
+ mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSpace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent);
}
if (isColumnFlow())
// just moving the children to a new position.
size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(children);
LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwarePaddingEnd();
- mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->justifyContent(), numberOfChildrenForJustifyContent);
+ mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->justifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJustifyContent);
mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontalScrollbarHeight();
size_t seenInFlowPositionedChildren = 0;
++seenInFlowPositionedChildren;
if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent)
- mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSpace, style()->justifyContent(), numberOfChildrenForJustifyContent);
+ mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSpace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent);
}
}
LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogicalHeight());
// FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905.
- if (desiredLogicalHeight != child.logicalHeight()) {
+ bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight();
+ if (childNeedsRelayout || !child.hasOverrideHeight())
child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borderAndPaddingLogicalHeight());
+ if (childNeedsRelayout) {
child.setLogicalHeight(0);
+ // We cache the child's intrinsic content logical height to avoid it being reset to the stretched height.
+ // FIXME: This is fragile. RenderBoxes should be smart enough to determine their intrinsic content logical
+ // height correctly even when there's an overrideHeight.
+ LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogicalHeight();
child.forceChildLayout();
+ child.updateIntrinsicContentLogicalHeight(childIntrinsicContentLogicalHeight);
}
}
} else if (isColumnFlow() && child.style()->logicalWidth().isAuto()) {