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

[css-text-3] Disambiguation about soft wrap opportunities around replaced elements #9964

Closed
frivoal opened this issue Feb 14, 2024 · 2 comments
Assignees
Labels
Closed Accepted by CSSWG Resolution css-text-3 Current Work Tested Memory aid - issue has WPT tests

Comments

@frivoal
Copy link
Collaborator

frivoal commented Feb 14, 2024

Should there be a soft wrap opporunity in the middle of the following divs?

<style>
div {
  width: 0px;
  white-space: normal;
}
span {
  white-space: nowrap;
}
img {  width: 30px;  height: 30px; }

</style>
<div><span><img></span><span><img></span></div>

<div><span></span><span><img></span></div>

<div><span><img></span><span></span></div>

Currently, we don't have interop, with Chrome and Safari allowing a break, and Firefox not.

I believe that the spec is not clear. The parts that seem relevant but don't actually spell it out clearly would be the following two points from https://drafts.csswg.org/css-text-4/#line-break-details:

  • For Web-compatibility there is a soft wrap opportunity before and after each replaced element or other atomic inline, even when adjacent to a character that would normally suppress them, including U+00A0 NO-BREAK SPACE. However, with the exception of U+00A0 NO-BREAK SPACE, there must be no soft wrap opportunity between atomic inlines and adjacent characters belonging to the Unicode GL, WJ, or ZWJ line breaking classes. [UAX14]
    Tests
  • For soft wrap opportunities created by characters that disappear at the line break (e.g. U+0020 SPACE), properties on the box directly containing that character control the line breaking at that opportunity. For soft wrap opportunities defined by the boundary between two characters, the white-space property on the nearest common ancestor of the two characters controls breaking; which elements’ line-break, word-break, and overflow-wrap properties control the determination of soft wrap opportunities at such boundaries is undefined in this level.

The goal of the first rule quoted above is to make replaced elements / atomic inlines break more than other things. The Firefox implementation makes then break less than ideographs, which goes against that expectation.

But I think a literal interpretation of the spec falls short of saying what to do, because:

  1. the second rule talks about the boundary between two characters, and replaced elements or other atomic inlines are not characters
  2. the first rule says that there's a wrap opportunity before and after, which is similar but not identical to making it defined by the boundary between two things.

So I think we should clarify that the Chrome/Webkit behavior is the intended one, and do so with the following two additions:

For soft wrap opportunities defined by the boundary between two characters, replaced element, or other atomic inlines, […]

there is a soft wrap opportunity at the boundary before and after each replaced element or other atomic inline

@frivoal
Copy link
Collaborator Author

frivoal commented Feb 14, 2024

Another place that almost but not quite defines this (in the same direction) may be this:

For soft wrap opportunities before the first or after the last character of a box, the break occurs immediately before/after the box (at its margin edge) rather than breaking the box between its content edge and the content.

Here, the soft wrap opportunity before and after each replaced element is the first or last thing in a box, but not the first/last character in a box.

So we could also fix this with the following addition:

For soft wrap opportunities before the first or after the last character, replaced element, or atomic inline of a box […]

@Loirooriol Loirooriol added the css-text-3 Current Work label Feb 17, 2024
@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-text-3] Disambiguation about soft wrap opportunities around replaced elements, and agreed to the following:

  • RESOLVED: Clarify spec about soft-wrap oppos before/after characters to also reference atomic inlines.
The full IRC log of that discussion <TabAtkins> fantasai: There's an ambiguity in the spec
<TabAtkins> fantasai: we talk about how line-breaking properties affect breaking between characters
<TabAtkins> fantasai: and we talk about how line-breaking occurs before/after rpelaced elements
<TabAtkins> fantasai: But we don't connect to the idea of line-breaking controlling breaks between replaced elements, or between replaced and characters
<TabAtkins> fantasai: So proposal is to repalce references to "between or aroudn characters" with "between or around characters or atomic inlines"
<TabAtkins> fantasai: This aligns with Chrome/WebKit behavior, and we think is more expected behavior than what Firefox is doing.
<kizu> q+
<Rossen__> ack kizu
<TabAtkins> kizu: I encountered this recently. I remember wanting to not allow breaks, aligning with firefox, because otherwise i don't think there's a way for an author to disallow the wrapping
<TabAtkins> kizu: So if you have this combination of elements, white-space:no-wrap prevents wrapping; if you want wrapping you can remove it
<TabAtkins> kizu: If you want it to work differently, it would be nice to add another way to avoid introducing soft-wrap opportunities between replaced or replaced and text
<emilio> https://bugzilla.mozilla.org/show_bug.cgi?id=225382 suggests this might be quirks-mode dependent too?
<TabAtkins> fantasai: This is specifically cases where there's a span around an image, and another span around an image, and they're adjoining. Between those two spans, the white-space property allows wrapping.
<TabAtkins> fantasai: If we had two characters in those spans, wrapping woudl be allowed. But two images, it is ambiguous in the spec.
<TabAtkins> fantasai: So I don't think white-space *in* the element should affect wrapping *outside* the element
<TabAtkins> fantasai: Controlling the wrapping of images would probably be useful, there's been suggestions for properties controlling that
<TabAtkins> fantasai: Web-compat behavior, which allows more breaks, or like an Enlgihs letter, or like a Japanese character. Those are the common ways you'd want it to behave.
<TabAtkins> fantasai: but that's a seaprate issue. This is just about behavior at element boundaries.
<TabAtkins> fantasai: There is one thing I"m not sure is implemented yet, we tweaked the spec, and it might help your use-case
<TabAtkins> fantasai: for webcompat we require there's a softwrap before and after each repalced, even if the next char is a nbsp
<TabAtkins> fantasai: But we previously said it doesn't matter what it's next to - it just *always* gets a soft-wrap
<TabAtkins> fantasai: But there are some other gluey characters in Unicode that are less commonly used, so we recently updated the spec to not break between an image and *those* characters.
<TabAtkins> fantasai: we probably don't ahve interop on that yet, it's a recent change. But that would allow you more control over breaking if you use those characters.
<TabAtkins> fantasai: (In addition to any future property that controls breaking beahvior)
<kizu> Sounds good.
<TabAtkins> Rossen__: Any feedback? Otherwise we'll resolve
<TabAtkins> RESOLVED: Clarify spec about soft-wrap oppos before/after characters to also reference atomic inlines.
<dbaron> One off-topic thought is that a property for controlling the breaking behavior of an image could take a string that means "have the breaking behavior of this text", e.g., replaced-break-as: "A" or replaced-break-as: "正"

@frivoal frivoal added Tested Memory aid - issue has WPT tests and removed Needs Testcase (WPT) labels May 27, 2024
@frivoal frivoal self-assigned this May 27, 2024
frivoal added a commit to web-platform-tests/wpt that referenced this issue May 27, 2024
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 3, 2024
…nes at element boundary, a=testonly

Automatic update from web-platform-tests
Tests for line breaking around atomic lines at element boundary

See w3c/csswg-drafts#9964

--

wpt-commits: 609801f34c3d7098c1799dd131355c3b065322ab
wpt-pr: 46489
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this issue Jun 5, 2024
…nes at element boundary, a=testonly

Automatic update from web-platform-tests
Tests for line breaking around atomic lines at element boundary

See w3c/csswg-drafts#9964

--

wpt-commits: 609801f34c3d7098c1799dd131355c3b065322ab
wpt-pr: 46489
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Jun 14, 2024
…nes at element boundary, a=testonly

Automatic update from web-platform-tests
Tests for line breaking around atomic lines at element boundary

See w3c/csswg-drafts#9964

--

wpt-commits: 609801f34c3d7098c1799dd131355c3b065322ab
wpt-pr: 46489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by CSSWG Resolution css-text-3 Current Work Tested Memory aid - issue has WPT tests
Projects
None yet
Development

No branches or pull requests

4 participants