Skip to content

Commit

Permalink
(REGRESSION: 267587@main) Text indent is incorrect when paragraph is …
Browse files Browse the repository at this point in the history
…affected by a floating element

https://bugs.webkit.org/show_bug.cgi?id=265216
<rdar://problem/118701491>

Reviewed by Antti Koivisto.

Before 267587@main (which merged all the float constraints codepaths), we ignored the text-indent during the _initial_ constraint computation
and adjusted the line rect later.
At 267587@main, we started adding the text-indent value twice to the line rect; first while computing the initial constraint and
the second time when we would normally add it.

* LayoutTests/fast/text/text-indent-with-intrusive-float-expected.html: Added.
* LayoutTests/fast/text/text-indent-with-intrusive-float.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::initialConstraintsForLine const): Let's go back to "before 267587@main" state.
(WebCore::Layout::LineBuilder::floatConstrainedRect const): Add some comment and change variable names to reflect what they mean.

Canonical link: https://commits.webkit.org/271080@main
  • Loading branch information
alanbaradlay committed Nov 23, 2023
1 parent 4d59b02 commit b741d4c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
.inline-block {
display: inline-block;
margin-right: 100px;
}

div {
width: 100px;
height: 100px;
background-color: green;
}
</style>
<div class=inline-block></div><div class=inline-block></div>
<div></div>
18 changes: 18 additions & 0 deletions LayoutTests/fast/text/text-indent-with-intrusive-float.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<style>
.inline-block {
display: inline-block;
width: 100px;
height: 100px;
background-color: green;
}

.float-box {
width: 100px;
height: 100px;
float: left;
background-color: green;
}
</style>
<!-- PASS if text-indent puts a 100px gap between the float and the inline content -->
<div><div class="float-box"></div><div style="text-indent: 100px"><div class=inline-block></div></div></div>
<div><div class="float-box"></div><div style="text-indent: -100px"><div class=inline-block></div></div></div>
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ LineContent LineBuilder::placeInlineAndFloatContent(const InlineItemRange& needs
LineBuilder::UsedConstraints LineBuilder::initialConstraintsForLine(const InlineRect& initialLineLogicalRect, std::optional<bool> previousLineEndsWithLineBreak) const
{
auto isIntrinsicWidthMode = isInIntrinsicWidthMode() ? InlineFormattingUtils::IsIntrinsicWidthMode::Yes : InlineFormattingUtils::IsIntrinsicWidthMode::No;
auto textIndent = formattingContext().formattingUtils().computedTextIndent(isIntrinsicWidthMode, previousLineEndsWithLineBreak, initialLineLogicalRect.width());

return floatConstrainedRect(initialLineLogicalRect, textIndent);
auto constraints = floatConstrainedRect(initialLineLogicalRect, { });
constraints.marginStart = formattingContext().formattingUtils().computedTextIndent(isIntrinsicWidthMode, previousLineEndsWithLineBreak, initialLineLogicalRect.width());
return constraints;
}

InlineLayoutUnit LineBuilder::leadingPunctuationWidthForLineCandiate(size_t firstInlineTextItemIndex, size_t candidateContentStartIndex) const
Expand Down Expand Up @@ -756,20 +756,20 @@ LineBuilder::UsedConstraints LineBuilder::floatConstrainedRect(const InlineRect&
return { logicalRect, marginStart, { } };

auto isConstrainedByFloat = OptionSet<UsedFloat> { };
auto adjustedLogicalRect = logicalRect;
adjustedLogicalRect.shiftLeftBy(-marginStart);
// text-indent acts as (start)margin on the line. When looking for intrusive floats we need to check against the line's _margin_ box.
auto marginBoxRect = InlineRect { logicalRect.top(), logicalRect.left() - marginStart, logicalRect.width() + marginStart, logicalRect.height() };

if (constraints.left && constraints.left->x > adjustedLogicalRect.left()) {
adjustedLogicalRect.shiftLeftTo(constraints.left->x);
if (constraints.left && constraints.left->x > marginBoxRect.left()) {
marginBoxRect.shiftLeftTo(constraints.left->x);
isConstrainedByFloat.add(UsedFloat::Left);
}
if (constraints.right && constraints.right->x < adjustedLogicalRect.right()) {
adjustedLogicalRect.setRight(std::max<InlineLayoutUnit>(adjustedLogicalRect.left(), constraints.right->x));
if (constraints.right && constraints.right->x < marginBoxRect.right()) {
marginBoxRect.setRight(std::max<InlineLayoutUnit>(marginBoxRect.left(), constraints.right->x));
isConstrainedByFloat.add(UsedFloat::Right);
}

adjustedLogicalRect.shiftLeftBy(marginStart);
return { adjustedLogicalRect, marginStart, isConstrainedByFloat };
auto lineLogicalRect = InlineRect { marginBoxRect.top(), marginBoxRect.left() + marginStart, marginBoxRect.width() - marginStart, marginBoxRect.height() };
return { lineLogicalRect, marginStart, isConstrainedByFloat };
}();

if (auto adjustedRect = formattingContext().quirks().adjustedRectForLineGridLineAlign(constraints.logicalRect))
Expand Down

0 comments on commit b741d4c

Please sign in to comment.