From fd637abec43903daad7b1f87e845cbca84e5410f Mon Sep 17 00:00:00 2001 From: Alan Baradlay Date: Mon, 27 Mar 2023 12:56:36 -0700 Subject: [PATCH] [IFC] Incorrect out-of-flow box placement when text-indent is present (display: inline) https://bugs.webkit.org/show_bug.cgi?id=254492 Reviewed by Antti Koivisto. Take text-ident (mainly each-line) into account when computing the static position for a "display: inline" out-of-flow box on "overflowing line" after the last line with inline content. * LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line-expected.html: Added. * LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line.html: Added. * Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp: (WebCore::Layout::InlineFormattingGeometry::lineBoxOffsetAfterLastLine const): (WebCore::Layout::InlineFormattingGeometry::staticPositionForOutOfFlowInlineLevelBox const): * Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h: Canonical link: https://commits.webkit.org/262170@main --- ...ith-text-indent-on-last-line-expected.html | 24 +++++++++++++++++++ ...-inline-with-text-indent-on-last-line.html | 24 +++++++++++++++++++ .../inline/InlineFormattingGeometry.cpp | 13 ++++++---- .../inline/InlineFormattingGeometry.h | 2 ++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line-expected.html create mode 100644 LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line.html diff --git a/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line-expected.html b/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line-expected.html new file mode 100644 index 000000000000..9c55a7ad419a --- /dev/null +++ b/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line-expected.html @@ -0,0 +1,24 @@ + +
some text
+
some text
+
some text
+
some text
+
some text
+
some text
+
diff --git a/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line.html b/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line.html new file mode 100644 index 000000000000..2d9b62821382 --- /dev/null +++ b/LayoutTests/fast/inline/out-of-flow-inline-with-text-indent-on-last-line.html @@ -0,0 +1,24 @@ + +
some text
+
some text
+
some text
+
some text
+
some text
+
some text
+
some text
diff --git a/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp b/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp index 607a9e72cb6a..c352ed04d8e5 100644 --- a/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp +++ b/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.cpp @@ -261,6 +261,13 @@ static std::optional nextDisplayBoxIndex(const Box& outOfFlowBox, const return { }; } +InlineLayoutUnit InlineFormattingGeometry::lineBoxOffsetAfterLastLine(const ConstraintsForInFlowContent& constraints) const +{ + auto alignmentOffset = horizontalAlignmentOffset(constraints.horizontal().logicalWidth, IsLastLineOrAfterLineBreak::Yes); + auto textIndent = computedTextIndent(IsIntrinsicWidthMode::No, true, constraints.horizontal().logicalWidth); + return alignmentOffset + constraints.horizontal().logicalLeft + textIndent; +} + LayoutPoint InlineFormattingGeometry::staticPositionForOutOfFlowInlineLevelBox(const Box& outOfFlowBox, const ConstraintsForInFlowContent& constraints, const InlineDisplay::Content& displayContent) const { ASSERT(outOfFlowBox.style().isOriginalDisplayInlineType()); @@ -269,8 +276,7 @@ LayoutPoint InlineFormattingGeometry::staticPositionForOutOfFlowInlineLevelBox(c if (lines.isEmpty()) { ASSERT(boxes.isEmpty()); - auto alignmentOffset = horizontalAlignmentOffset(constraints.horizontal().logicalWidth, IsLastLineOrAfterLineBreak::Yes); - return { constraints.horizontal().logicalLeft + alignmentOffset, constraints.logicalTop() }; + return { lineBoxOffsetAfterLastLine(constraints), constraints.logicalTop() }; } auto isHorizontalWritingMode = formattingContext().root().style().isHorizontalWritingMode(); @@ -313,8 +319,7 @@ LayoutPoint InlineFormattingGeometry::staticPositionForOutOfFlowInlineLevelBox(c auto nextDisplayBoxIndexAfterOutOfFlow = nextDisplayBoxIndex(outOfFlowBox, boxes); if (!nextDisplayBoxIndexAfterOutOfFlow) { // This is the last content on the block and it does not fit the last line. - auto alignmentOffset = horizontalAlignmentOffset(constraints.horizontal().logicalWidth, IsLastLineOrAfterLineBreak::Yes); - return { constraints.horizontal().logicalLeft + alignmentOffset, isHorizontalWritingMode ? currentLine.bottom() : currentLine.right() }; + return { lineBoxOffsetAfterLastLine(constraints), isHorizontalWritingMode ? currentLine.bottom() : currentLine.right() }; } auto& nextDisplayBox = boxes[*nextDisplayBoxIndexAfterOutOfFlow]; return leftSideToLogicalTopLeft(nextDisplayBox, lines[nextDisplayBox.lineIndex()]); diff --git a/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h b/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h index 160d68e4ac03..79c5554288fd 100644 --- a/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h +++ b/Source/WebCore/layout/formattingContexts/inline/InlineFormattingGeometry.h @@ -65,6 +65,8 @@ class InlineFormattingGeometry : public FormattingGeometry { InlineLayoutUnit horizontalAlignmentOffset(InlineLayoutUnit horizontalAvailableSpace, IsLastLineOrAfterLineBreak, std::optional inlineBaseDirectionOverride = std::nullopt) const; private: + InlineLayoutUnit lineBoxOffsetAfterLastLine(const ConstraintsForInFlowContent&) const; + const InlineFormattingContext& formattingContext() const { return downcast(FormattingGeometry::formattingContext()); } };