Bug 228605 - HTMLElement.innerText setter should convert new lines to <br>
Summary: HTMLElement.innerText setter should convert new lines to <br>
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://html.spec.whatwg.org/multipag...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-29 13:52 PDT by Chris Dumez
Modified: 2021-08-02 12:56 PDT (History)
16 users (show)

See Also:


Attachments
WIP Patch (3.77 KB, patch)
2021-07-29 13:53 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (50.16 KB, patch)
2021-07-29 15:18 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (73.79 KB, patch)
2021-07-29 16:18 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (94.84 KB, patch)
2021-07-30 08:50 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (10.53 KB, patch)
2021-07-30 16:20 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.56 KB, patch)
2021-07-30 17:07 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-07-29 13:52:36 PDT
HTMLElement.innerText setter should convert new lines to <br>:
- https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute:dom-innertext-3

This is causing some failures on http://wpt.live/html/dom/elements/the-innertext-and-outertext-properties/innertext-setter.html, in Webkit only.
Comment 1 Chris Dumez 2021-07-29 13:53:08 PDT
Created attachment 434568 [details]
WIP Patch
Comment 2 Chris Dumez 2021-07-29 15:18:26 PDT
Created attachment 434577 [details]
Patch
Comment 3 Chris Dumez 2021-07-29 16:18:28 PDT
Created attachment 434585 [details]
Patch
Comment 4 Chris Dumez 2021-07-30 08:50:35 PDT
Created attachment 434635 [details]
Patch
Comment 5 EWS 2021-07-30 10:46:38 PDT
Committed r280482 (240117@main): <https://commits.webkit.org/240117@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434635 [details].
Comment 6 Radar WebKit Bug Importer 2021-07-30 10:47:24 PDT
<rdar://problem/81333038>
Comment 7 Darin Adler 2021-07-30 14:29:18 PDT
Comment on attachment 434635 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434635&action=review

> Source/WebCore/html/HTMLElement.cpp:-573
> -    if ((r && r->style().preserveNewline()) || (isConnected() && isTextControlInnerTextElement())) {

Do we have test cases that cover text controls? Just wanted to make sure we didn’t lose any valuable behavior that happened to not be covered by web platform tests.
Comment 8 Chris Dumez 2021-07-30 14:57:59 PDT
Comment on attachment 434635 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434635&action=review

>> Source/WebCore/html/HTMLElement.cpp:-573
>> -    if ((r && r->style().preserveNewline()) || (isConnected() && isTextControlInnerTextElement())) {
> 
> Do we have test cases that cover text controls? Just wanted to make sure we didn’t lose any valuable behavior that happened to not be covered by web platform tests.

I suspect that the "Newlines convert to <br> in <textarea>" WPT test covers this but I'll double check.
Comment 9 Chris Dumez 2021-07-30 16:00:46 PDT
Comment on attachment 434635 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434635&action=review

> LayoutTests/platform/mac-catalina/fast/parser/open-comment-in-textarea-expected.txt:13
> +      RenderBR {BR} at (21,0) size 1x13

Oh, the `isConnected() && isTextControlInnerTextElement()` logic doesn't actually trigger in those WPT tests because the logic only triggers when calling setInnerText() on browser-shadow-element inside a text control. Therefore, I think this is probably not Web-Observable. This is what's causing the output change in this test though where we have a blank text run replaced with a RenderBR. I looked at those test's visual output with and without my change and they do look the same. For safety, I could keep the old behavior in the browser-shadow-dom case since it should not be a compatibility-risk AFAICT. However, there may be assumption in WebKit code about the formatting in those browser-shadow-dom-elements.
Comment 10 Darin Adler 2021-07-30 16:03:57 PDT
Well, does setting "innerText" have the same behavior as pasting?
Comment 11 Chris Dumez 2021-07-30 16:07:25 PDT
(In reply to Darin Adler from comment #10)
> Well, does setting "innerText" have the same behavior as pasting?

I cannot call innerText from JS on a browser-shadow-dom element AFAIK and the virtual output looks just the same before and after my change. I am not sure I understand the question.
Comment 12 Chris Dumez 2021-07-30 16:08:28 PDT
Reverted r280482 for reason:

Will take a more conservative approach

Committed r280502 (240134@main): <https://commits.webkit.org/240134@main>
Comment 13 Darin Adler 2021-07-30 16:14:37 PDT
(In reply to Chris Dumez from comment #12)
> Will take a more conservative approach

I hope that’s not just because of my questions.
Comment 14 Darin Adler 2021-07-30 16:15:32 PDT
(In reply to Chris Dumez from comment #11)
> (In reply to Darin Adler from comment #10)
> > Well, does setting "innerText" have the same behavior as pasting?
> 
> I cannot call innerText from JS on a browser-shadow-dom element AFAIK and
> the virtual output looks just the same before and after my change. I am not
> sure I understand the question.

My question was: When we handle a paste, can we end up with newline characters inside the shadow DOM rather than <br> elements? If so, that might be OK.
Comment 15 Chris Dumez 2021-07-30 16:20:51 PDT
Created attachment 434671 [details]
Patch
Comment 16 Darin Adler 2021-07-30 16:21:57 PDT
Comment on attachment 434671 [details]
Patch

Does seem smart to do the part that is visible; we can clean up by removing the other part at our leisure once we are sure it’s not needed.
Comment 17 Chris Dumez 2021-07-30 16:25:46 PDT
(In reply to Darin Adler from comment #16)
> Comment on attachment 434671 [details]
> Patch
> 
> Does seem smart to do the part that is visible; we can clean up by removing
> the other part at our leisure once we are sure it’s not needed.

Yes, I don't want to take any chances, especially at this time of the year. My initial patch was definitely more heavy-handed than I realized because I thought it was about text controls, not browser-shadow-elements inside those controls.
Comment 18 Chris Dumez 2021-07-30 17:07:01 PDT
Created attachment 434677 [details]
Patch
Comment 19 EWS 2021-08-02 10:29:05 PDT
Committed r280541 (240168@main): <https://commits.webkit.org/240168@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434677 [details].