Skip to content

[css-overflow] [css-text] Interaction between whitespace collapsing and line-clamp #12008

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

Open
andreubotella opened this issue Mar 26, 2025 · 5 comments

Comments

@andreubotella
Copy link
Member

andreubotella commented Mar 26, 2025

The current spec text for block-ellipsis (which is one of the longhands for line-clamp) says that when an ellipsis is inserted on the last line before clamp, it must be placed after the last soft wrap opportunity that would make the line with the ellipsis not overflow, considering that the content after the ellipsis gets pushed to the next line box or fragment.

However, according to the Unicode line breaking algorithm, ASCII spaces don't have a break opportunity before them, but only after them. Which means any soft wrap opportunity caused by a space would show the ellipsis after the space, not at the end of the word. Or at least that would be the case if the ellipsis inline is added at the end of the line box during line breaking and before phase II of whitespace processing.

There's also the fact that the block-ellipsis spec text allows inserting the ellipsis in the middle of text-wrap: nowrap text, since it only talks about finding the last soft wrap opportunity, and nowrap does not remove wrap opportunities, it just prevents wrapping. Given that, the question comes up of how trailing whitespace would work before the ellipsis inside white-space: pre text. If we just say to collapse as usual according to phase II, and then add the ellipsis, we would still have spaces between the end of the word and the ellipsis in white-space: pre text. Do we want that?

@andreubotella
Copy link
Member Author

andreubotella commented Mar 26, 2025

cc @emilio @kojiishi @frivoal

aarongable pushed a commit to chromium/chromium that referenced this issue Apr 3, 2025
With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Apr 3, 2025
With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Apr 3, 2025
With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}
ChunMinChang pushed a commit to ChunMinChang/gecko-dev that referenced this issue Apr 7, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Apr 8, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Apr 8, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818

UltraBlame original commit: d32bb7c166f17371fbfd77e7d819ba101ec65f62
globau pushed a commit to globau/firefox-test that referenced this issue Apr 8, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Apr 8, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818

UltraBlame original commit: d32bb7c166f17371fbfd77e7d819ba101ec65f62
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Apr 8, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818

UltraBlame original commit: d32bb7c166f17371fbfd77e7d819ba101ec65f62
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Apr 9, 2025
…s inside nowrap text, a=testonly

Automatic update from web-platform-tests
[line-clamp] Allow inserting the ellipsis inside nowrap text

With the `CSSLineClampLineBreakingEllipsis` runtime feature on, the
ellipsis width computation happens as part of line breaking, so that
the ellipsis gets inserted at the last possible break opportunity.
However, this currently does not work with `text-wrap: nowrap` text,
because regular line breaking would not wrap inside that text, but
there are still break opportunities in it that must be used when
clamping.

This patch replaces any calls to the `ComputedStyle` methods
`ShouldWrapLine` and `ShouldBreakOnlyAfterWhiteSpace` with equivalent
methods in `ComputedStyle` that also check whether the line is being
ellipsized for line-clamp; and replaces any such calls inside
`LineBreaker` to use them. This is enough to cover the spec's
requirements, which explicitly ignore break opportunities created by
`overflow-wrap`.

This patch also fixes the removal of trailing spaces so that when an
ellipsis is inserted inside `white-space: pre` text, there are no
preserved spaces between the end of the word and the ellipsis (see
w3c/csswg-drafts#12008).

Bug: 40336192
Change-Id: I22822d5f1d6a44e5b5c5b99a9fb698df10ffcf9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394977
Commit-Queue: Andreu Botella 
Reviewed-by: Koji Ishii 
Cr-Commit-Position: refs/heads/main@{#1441973}

--

wpt-commits: 00037969dc735353f69f8675504126ae4041faa3
wpt-pr: 51818
@frivoal
Copy link
Collaborator

frivoal commented Jun 6, 2025

Interesting. I think there's several parts in there.

For « nowrap does not remove wrap opportunities, it just prevents wrapping » I suspect that can be changed, and have the definition of text-wrap-mode: nowrap say that it suppresses opportunities. In that case, yes, if the whole line (or the whole block) is set to nowrap, then that means you cannot insert the ellipsis in the middle of the line, and you either have to tack it at the very end—including after preserved spaces if any—if there's room, or have to remove the whole line to make room if there isn't, but that seems appropriate: if the content is indivisible, it is indivisible.

In terms of wrap opportunities being after, not before, spaces. I agree that we don't want the ellipsis being after a space that would otherwise be removed by phase two, so we need to do ellipsis insertion after phase two.

I think the case where I'm least comfortable is when the line ends with preserved white-space (which is thus not discarded) which hang (as can happen with white-space: pre-wrap). This is different from the nowrap case: here, we can wrap, but we did ask for preserving. In that case, what would fall out of the above is that the ellipsis would be inserted after the space, even though the line is wrapable. This may also be the desirable behavior (the author did ask for spaces to be preserved after all), but I'm less sure.

@andreubotella
Copy link
Member Author

andreubotella commented Jun 6, 2025

For « nowrap does not remove wrap opportunities, it just prevents wrapping » I suspect that can be changed, and have the definition of text-wrap-mode: nowrap say that it suppresses opportunities. In that case, yes, if the whole line (or the whole block) is set to nowrap, then that means you cannot insert the ellipsis in the middle of the line, and you either have to tack it at the very end—including after preserved spaces if any—if there's room, or have to remove the whole line to make room if there isn't, but that seems appropriate: if the content is indivisible, it is indivisible.

We can probably say "soft wrap opportunities were breaking would be allowed (i.e. not text-wrap: nowrap)" without needing to change css-text.

I think the case where I'm least comfortable is when the line ends with preserved white-space (which is thus not discarded) which hang (as can happen with white-space: pre-wrap). This is different from the nowrap case: here, we can wrap, but we did ask for preserving. In that case, what would fall out of the above is that the ellipsis would be inserted after the space, even though the line is wrapable. This may also be the desirable behavior (the author did ask for spaces to be preserved after all), but I'm less sure.

Although I believe the goal is for browsers to implement hanging punctuation eventually, I'm not sure how possible this currently is in Chromium. Maybe it would be doable for line-clamp ellipsis, due to the special way in which we're implementing them, but wouldn't be for other punctuation. But I would need to look into it.

@andreubotella
Copy link
Member Author

For « nowrap does not remove wrap opportunities, it just prevents wrapping » I suspect that can be changed, and have the definition of text-wrap-mode: nowrap say that it suppresses opportunities. In that case, yes, if the whole line (or the whole block) is set to nowrap, then that means you cannot insert the ellipsis in the middle of the line, and you either have to tack it at the very end—including after preserved spaces if any—if there's room, or have to remove the whole line to make room if there isn't, but that seems appropriate: if the content is indivisible, it is indivisible.

IIUC, if there's a forced line break inside text-wrap-mode: nowrap text and there's remaining space to put the ellipsis without overflowing, then the ellipsis gets inserted at the end; otherwise, the line gets displaced by the ellipsis, right?

@frivoal
Copy link
Collaborator

frivoal commented Jun 8, 2025

IIUC, if there's a forced line break inside text-wrap-mode: nowrap text and there's remaining space to put the ellipsis without overflowing, then the ellipsis gets inserted at the end; otherwise, the line gets displaced by the ellipsis, right?

If text-wrap-mode: nowrap is set on the whole line (or more), yes, that's understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants