Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (249902 => 249903)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-09-16 16:56:35 UTC (rev 249903)
@@ -245,11 +245,10 @@
return left - paddingBoxLeft;
}
-LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingRoot, UsedHorizontalValues usedValues)
+LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingRoot, UsedHorizontalValues usedHorizontalValues)
{
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width] -> shrink to fit -> unsupported -> width(" << LayoutUnit { } << "px) layoutBox: " << &formattingRoot << ")");
ASSERT(formattingRoot.establishesFormattingContext());
- ASSERT(usedValues.containingBlockWidth.hasValue());
// Calculation of the shrink-to-fit width is similar to calculating the width of a table cell using the automatic table layout algorithm.
// Roughly: calculate the preferred width by formatting the content without breaking lines other than where explicit line breaks occur,
@@ -268,7 +267,7 @@
else
intrinsicWidthConstraints = *precomputedIntrinsicWidthConstraints;
}
- auto availableWidth = *usedValues.containingBlockWidth;
+ auto availableWidth = usedHorizontalValues.containingBlockWidth;
return std::min(std::max(intrinsicWidthConstraints.minimum, availableWidth), intrinsicWidthConstraints.maximum);
}
@@ -276,7 +275,6 @@
{
ASSERT(layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced());
ASSERT(usedVerticalValues.containingBlockHeight);
- ASSERT(usedHorizontalValues.containingBlockWidth);
// 10.6.4 Absolutely positioned, non-replaced elements
//
@@ -306,7 +304,7 @@
auto& style = layoutBox.style();
auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
- auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -396,7 +394,7 @@
return { *top, *bottom, { contentHeight(), usedVerticalMargin } };
}
-HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedValues)
+HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
{
ASSERT(layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced());
@@ -429,15 +427,13 @@
auto& formattingContext = this->formattingContext();
auto& style = layoutBox.style();
auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
- auto& containingBlock = *layoutBox.containingBlock();
- auto& containingBlockGeometry = formattingContext.geometryForBox(containingBlock);
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
- auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+ auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
auto right = computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
- auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
- auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+ auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
+ auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
UsedHorizontalMargin usedHorizontalMargin;
auto paddingLeft = boxGeometry.paddingLeft().valueOr(0);
auto paddingRight = boxGeometry.paddingRight().valueOr(0);
@@ -502,7 +498,7 @@
// Calculate the available width by solving for 'width' after setting 'left' (in case 1) to 0
left = LayoutUnit { 0 };
auto availableWidth = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + paddingRight + borderRight + usedHorizontalMargin.end + *right);
- width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedValues.width, usedValues.margin });
+ width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedHorizontalValues.width, usedHorizontalValues.margin });
left = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight + usedHorizontalMargin.end + *right);
} else if (!left && !right && width) {
// #2
@@ -519,7 +515,7 @@
// Calculate the available width by solving for 'width' after setting 'right' (in case 3) to 0
right = LayoutUnit { 0 };
auto availableWidth = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + paddingRight + borderRight + usedHorizontalMargin.end + *right);
- width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedValues.width, usedValues.margin });
+ width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedHorizontalValues.width, usedHorizontalValues.margin });
right = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight + usedHorizontalMargin.end);
} else if (!left && width && right) {
// #4
@@ -538,7 +534,7 @@
// For out-of-flow elements the containing block is formed by the padding edge of the ancestor.
// At this point the positioned value is in the coordinate system of the padding box. Let's convert it to border box coordinate system.
- auto containingBlockPaddingVerticalEdge = containingBlockGeometry.paddingBoxLeft();
+ auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(*layoutBox.containingBlock()).paddingBoxLeft();
*left += containingBlockPaddingVerticalEdge;
*right += containingBlockPaddingVerticalEdge;
@@ -550,7 +546,6 @@
{
ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
ASSERT(usedVerticalValues.containingBlockHeight);
- ASSERT(usedHorizontalValues.containingBlockWidth);
// 10.6.5 Absolutely positioned, replaced elements
//
@@ -566,7 +561,7 @@
auto& style = layoutBox.style();
auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
- auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -629,7 +624,7 @@
return { *top, *bottom, { height, { *usedMarginBefore, *usedMarginAfter } } };
}
-HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedValues) const
+HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
@@ -650,16 +645,15 @@
auto& formattingContext = this->formattingContext();
auto& style = layoutBox.style();
auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
- auto& containingBlock = *layoutBox.containingBlock();
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
- auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+ auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
auto right = computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
- auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+ auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
Optional<LayoutUnit> usedMarginStart = computedHorizontalMargin.start;
Optional<LayoutUnit> usedMarginEnd = computedHorizontalMargin.end;
- auto width = inlineReplacedWidthAndMargin(layoutBox, usedValues).width;
+ auto width = inlineReplacedWidthAndMargin(layoutBox, usedHorizontalValues).width;
auto paddingLeft = boxGeometry.paddingLeft().valueOr(0);
auto paddingRight = boxGeometry.paddingRight().valueOr(0);
auto borderLeft = boxGeometry.borderLeft();
@@ -726,7 +720,7 @@
// For out-of-flow elements the containing block is formed by the padding edge of the ancestor.
// At this point the positioned value is in the coordinate system of the padding box. Let's convert it to border box coordinate system.
- auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(containingBlock).paddingBoxLeft();
+ auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(*layoutBox.containingBlock()).paddingBoxLeft();
*left += containingBlockPaddingVerticalEdge;
*right += containingBlockPaddingVerticalEdge;
@@ -765,7 +759,7 @@
return HeightAndMargin { *height, usedVerticalMargin };
}
-WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues)
+WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
{
ASSERT(layoutBox.isFloatingPositioned() && !layoutBox.replaced());
@@ -774,14 +768,14 @@
// 1. If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'.
// 2. If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
- auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+ auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
// #1
auto usedHorizontallMargin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) };
// #2
- auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedValues.containingBlockWidth.valueOr(0));
+ auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedHorizontalValues.containingBlockWidth);
if (!width)
- width = shrinkToFitWidth(layoutBox, usedValues);
+ width = shrinkToFitWidth(layoutBox, usedHorizontalValues);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << *width << "px) margin(" << usedHorizontallMargin.start << "px, " << usedHorizontallMargin.end << "px) -> layoutBox(" << &layoutBox << ")");
return WidthAndMargin { *width, usedHorizontallMargin, computedHorizontalMargin };
@@ -797,7 +791,7 @@
return inlineReplacedHeightAndMargin(layoutBox, usedHorizontalValues, usedVerticalValues);
}
-WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
@@ -805,11 +799,11 @@
//
// 1. If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.
// 2. The used value of 'width' is determined as for inline replaced elements.
- auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+ auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating replaced -> redirected to inline replaced");
- return inlineReplacedWidthAndMargin(layoutBox, UsedHorizontalValues { usedValues.containingBlockWidth.valueOr(0),
- usedValues.width, UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) } });
+ return inlineReplacedWidthAndMargin(layoutBox, UsedHorizontalValues { usedHorizontalValues.containingBlockWidth,
+ usedHorizontalValues.width, UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) } });
}
VerticalGeometry FormattingContext::Geometry::outOfFlowVerticalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues, UsedVerticalValues usedVerticalValues) const
@@ -851,7 +845,6 @@
HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues, UsedVerticalValues usedVerticalValues) const
{
ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
- ASSERT(usedHorizontalValues.containingBlockWidth);
// 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
//
@@ -895,7 +888,7 @@
return { *height, usedVerticalMargin };
}
-WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
@@ -919,18 +912,18 @@
// If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
auto& style = layoutBox.style();
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
- auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+ auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
auto usedMarginStart = [&] {
- if (usedValues.margin)
- return usedValues.margin->start;
+ if (usedHorizontalValues.margin)
+ return usedHorizontalValues.margin->start;
return computedHorizontalMargin.start.valueOr(0_lu);
};
auto usedMarginEnd = [&] {
- if (usedValues.margin)
- return usedValues.margin->end;
+ if (usedHorizontalValues.margin)
+ return usedHorizontalValues.margin->end;
return computedHorizontalMargin.end.valueOr(0_lu);
};
@@ -937,7 +930,7 @@
auto replaced = layoutBox.replaced();
ASSERT(replaced);
- auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
+ auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
auto heightIsAuto = isHeightAuto(layoutBox);
auto height = computedHeightValue(layoutBox, HeightType::Normal);
@@ -969,7 +962,6 @@
LayoutSize FormattingContext::Geometry::inFlowPositionedPositionOffset(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
ASSERT(layoutBox.isInFlowPositioned());
- ASSERT(usedHorizontalValues.containingBlockWidth);
// 9.4.3 Relative positioning
//
@@ -981,8 +973,7 @@
// 3. If neither is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').
auto& style = layoutBox.style();
- auto& containingBlock = *layoutBox.containingBlock();
- auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -1026,7 +1017,7 @@
right = -*left;
} else {
// #4
- auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+ auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
if (isLeftToRightDirection)
right = -*left;
else
@@ -1053,13 +1044,13 @@
};
}
-Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBox, UsedHorizontalValues usedValues) const
+Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
if (!layoutBox.isPaddingApplicable())
return WTF::nullopt;
auto& style = layoutBox.style();
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Padding] -> layoutBox: " << &layoutBox);
return Edges {
{ valueForLength(style.paddingLeft(), containingBlockWidth), valueForLength(style.paddingRight(), containingBlockWidth) },
@@ -1067,17 +1058,17 @@
};
}
-ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
auto& style = layoutBox.style();
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
return { computedValueIfNotAuto(style.marginStart(), containingBlockWidth), computedValueIfNotAuto(style.marginEnd(), containingBlockWidth) };
}
-ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
{
auto& style = layoutBox.style();
- auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+ auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
return { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth), computedValueIfNotAuto(style.marginAfter(), containingBlockWidth) };
}