Skip to content

Commit

Permalink
[LFC][IFC] Figure out the logicalTopForNextLine without passing in th…
Browse files Browse the repository at this point in the history
…e initial line rect

https://bugs.webkit.org/show_bug.cgi?id=246416

Reviewed by Antti Koivisto.

This is in preparation for using 0px as the initial line height to find correct vertical position for inline content when float boxes are vertically stacked within the line.
This patch preserves the current behavior where we move the line down by the computed line height to probe for floats.

* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::lineLayout):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp:
(WebCore::Layout::InlineFormattingGeometry::logicalTopForNextLine const):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h:

Canonical link: https://commits.webkit.org/255479@main
  • Loading branch information
alanbaradlay committed Oct 13, 2022
1 parent c73a0fb commit 05aed3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Expand Up @@ -231,14 +231,14 @@ void InlineFormattingContext::lineLayout(InlineItems& inlineItems, const LineBui
auto lineContent = lineBuilder.layoutInlineContent({ firstInlineItemNeedsLayout, needsLayoutRange.end }, lineInitialRect, previousLine);
auto lineLogicalRect = computeGeometryForLineContent(lineContent);
if (lineContent.isLastLineWithInlineContent)
formattingState.setClearGapAfterLastLine(formattingGeometry().logicalTopForNextLine(lineContent, lineInitialRect, lineLogicalRect, floatingContext) - lineLogicalRect.bottom());
formattingState.setClearGapAfterLastLine(formattingGeometry().logicalTopForNextLine(lineContent, lineLogicalRect, floatingContext) - lineLogicalRect.bottom());

firstInlineItemNeedsLayout = indexOfFirstInlineItemForNextLine(lineContent, previousLine, previousLineLastInlineItemIndex);
auto isAtEnd = firstInlineItemNeedsLayout == needsLayoutRange.end && lineContent.overflowingFloats.isEmpty();
if (isAtEnd)
break;

lineLogicalTop = formattingGeometry().logicalTopForNextLine(lineContent, lineInitialRect, lineLogicalRect, floatingContext);
lineLogicalTop = formattingGeometry().logicalTopForNextLine(lineContent, lineLogicalRect, floatingContext);
previousLine = LineBuilder::PreviousLine { !lineContent.runs.isEmpty() && lineContent.runs.last().isLineBreak(), lineContent.inlineBaseDirection, lineContent.partialOverflowingContent, WTFMove(lineContent.overflowingFloats), lineContent.trailingOverflowingContentWidth };
previousLineLastInlineItemIndex = lineContent.inlineItemRange.end;
}
Expand Down
Expand Up @@ -44,7 +44,7 @@ InlineFormattingGeometry::InlineFormattingGeometry(const InlineFormattingContext
{
}

InlineLayoutUnit InlineFormattingGeometry::logicalTopForNextLine(const LineBuilder::LineContent& lineContent, const InlineRect& lineInitialRect, const InlineRect& lineLogicalRect, const FloatingContext& floatingContext) const
InlineLayoutUnit InlineFormattingGeometry::logicalTopForNextLine(const LineBuilder::LineContent& lineContent, const InlineRect& lineLogicalRect, const FloatingContext& floatingContext) const
{
if (!lineContent.inlineItemRange.isEmpty()) {
// Normally the next line's logical top is the previous line's logical bottom, but when the line ends
Expand All @@ -59,11 +59,14 @@ InlineLayoutUnit InlineFormattingGeometry::logicalTopForNextLine(const LineBuild
return lineLogicalRect.bottom();
return std::max(lineLogicalRect.bottom(), InlineLayoutUnit(positionWithClearance->position));
}
// Floats must have prevented us placing any content on the line.
// Move the next line below the intrusive float(s).
ASSERT(lineContent.runs.isEmpty() || lineContent.runs[0].isLineSpanningInlineBoxStart());
ASSERT(lineContent.hasIntrusiveFloat);
auto lineBottomWithNoInlineContent = std::max(lineLogicalRect.bottom(), lineInitialRect.bottom());
auto floatConstraints = floatingContext.constraints(toLayoutUnit(lineInitialRect.top()), toLayoutUnit(lineBottomWithNoInlineContent), FloatingContext::MayBeAboveLastFloat::Yes);
// FIXME: Moving the bottom position by the initial line height may be too much meaning that we miss vertical positions where atomic inline content could very well fit.
// The spec is unclear of how much we should move down at this point and while 1px should be the most precise it's also rather expensive.
auto inflatedLineRectBottom = lineLogicalRect.top() + formattingContext().root().style().computedLineHeight();
auto floatConstraints = floatingContext.constraints(toLayoutUnit(lineLogicalRect.top()), toLayoutUnit(inflatedLineRectBottom), FloatingContext::MayBeAboveLastFloat::Yes);
ASSERT(floatConstraints.left || floatConstraints.right);
if (floatConstraints.left && floatConstraints.right) {
// In case of left and right constraints, we need to pick the one that's closer to the current line.
Expand All @@ -74,7 +77,8 @@ InlineLayoutUnit InlineFormattingGeometry::logicalTopForNextLine(const LineBuild
if (floatConstraints.right)
return floatConstraints.right->y;
ASSERT_NOT_REACHED();
return lineBottomWithNoInlineContent;
// Do not get stuck on the same vertical position.
return lineLogicalRect.bottom() + 1.0f;
}

ContentWidthAndMargin InlineFormattingGeometry::inlineBlockContentWidthAndMargin(const Box& formattingContextRoot, const HorizontalConstraints& horizontalConstraints, const OverriddenHorizontalValues& overriddenHorizontalValues) const
Expand Down
Expand Up @@ -39,7 +39,7 @@ class InlineFormattingGeometry : public FormattingGeometry {
public:
InlineFormattingGeometry(const InlineFormattingContext&);

InlineLayoutUnit logicalTopForNextLine(const LineBuilder::LineContent&, const InlineRect& lineInitialRect, const InlineRect& lineLogicalRect, const FloatingContext&) const;
InlineLayoutUnit logicalTopForNextLine(const LineBuilder::LineContent&, const InlineRect& lineLogicalRect, const FloatingContext&) const;

ContentHeightAndMargin inlineBlockContentHeightAndMargin(const Box&, const HorizontalConstraints&, const OverriddenVerticalValues&) const;
ContentWidthAndMargin inlineBlockContentWidthAndMargin(const Box&, const HorizontalConstraints&, const OverriddenHorizontalValues&) const;
Expand Down

0 comments on commit 05aed3a

Please sign in to comment.