Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[line-clamp] Fix bug with line-breaking ellipsis inserted in last line #51539

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

With line-clamp, if the line that would have the ellipsis happens to
be the last line in the line-clamp container, then it must not have
the ellipsis. In the spec's terms, there cannot be a region break (or
a clamp point) at the end of the container. The way this was
implemented was by laying out first with the ellipsis, and then doing
a relayout without ellipsizing if we detected that there were no lines
after it.

However, this was implemented when the ellipsis simply hid content
from the line. With the line breaking ellipsis the spec requires,
which we are implementing under the CSSLineClampLineBreakingEllipsis
flag, the presence of the ellipsis can push content to the next line,
which can make a line no longer the last line.

The behavior that is almost certainly expected is that in such cases,
the line would not have the ellipsis. To implement this, we detect
whether an ellipsized line would be the last line of its IFC if it
didn't have the ellipsis. We implement this in
InlineLayoutAlgorithm::DoesRemainderFitInLineWithoutEllipsis, which
tries to compute that based on item metrics, and it returns nullopt
to indicate that this cannot be computed without LineBreaker. Then,
the LayoutResult::WouldBeLastLineIfNotForEllipsis flag is set.

In the block layout algorithm's BlockLineClampData, if we're
clamping by a number of lines, and we've just laid out a line box with
the WouldBeLastLineIfNotForEllipsis, then we set a flag that will
make any further calls to BlockLineClampData::UpdateAfterLayout
ignore any further lines for the purposes of decreasing the number of
lines until clamp. This will mean that any remaining lines in the same
IFC will not be counted when determining whether we should relayout
without ellipsizing.

Bug: 40336192
Change-Id: Ie28f65b02f1adcb5b7f55ac52e55d0103788ea56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6361775
Commit-Queue: Andreu Botella <[email protected]>
Reviewed-by: Koji Ishii <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1436702}

With line-clamp, if the line that would have the ellipsis happens to
be the last line in the line-clamp container, then it must not have
the ellipsis. In the spec's terms, there cannot be a region break (or
a clamp point) at the end of the container. The way this was
implemented was by laying out first with the ellipsis, and then doing
a relayout without ellipsizing if we detected that there were no lines
after it.

However, this was implemented when the ellipsis simply hid content
from the line. With the line breaking ellipsis the spec requires,
which we are implementing under the `CSSLineClampLineBreakingEllipsis`
flag, the presence of the ellipsis can push content to the next line,
which can make a line no longer the last line.

The behavior that is almost certainly expected is that in such cases,
the line would not have the ellipsis. To implement this, we detect
whether an ellipsized line would be the last line of its IFC if it
didn't have the ellipsis. We implement this in
`InlineLayoutAlgorithm::DoesRemainderFitInLineWithoutEllipsis`, which
tries to compute that based on item metrics, and it returns `nullopt`
to indicate that this cannot be computed without `LineBreaker`. Then,
the `LayoutResult::WouldBeLastLineIfNotForEllipsis` flag is set.

In the block layout algorithm's `BlockLineClampData`, if we're
clamping by a number of lines, and we've just laid out a line box with
the `WouldBeLastLineIfNotForEllipsis`, then we set a flag that will
make any further calls to `BlockLineClampData::UpdateAfterLayout`
ignore any further lines for the purposes of decreasing the number of
lines until clamp. This will mean that any remaining lines in the same
IFC will not be counted when determining whether we should relayout
without ellipsizing.

Bug: 40336192
Change-Id: Ie28f65b02f1adcb5b7f55ac52e55d0103788ea56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6361775
Commit-Queue: Andreu Botella <[email protected]>
Reviewed-by: Koji Ishii <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1436702}
Copy link
Collaborator

@wpt-pr-bot wpt-pr-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The review process for this patch is being conducted in the Chromium project.

@chromium-wpt-export-bot chromium-wpt-export-bot merged commit ca57368 into master Mar 24, 2025
21 checks passed
@chromium-wpt-export-bot chromium-wpt-export-bot deleted the chromium-export-213972caa6 branch March 24, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants