[line-clamp] Fix bug with line-breaking ellipsis inserted in last line #51539
+73
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
, whichtries 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'reclamping by a number of lines, and we've just laid out a line box with
the
WouldBeLastLineIfNotForEllipsis
, then we set a flag that willmake 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}