Bug 228605

Summary: HTMLElement.innerText setter should convert new lines to <br>
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: HTML EditingAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, apinheiro, cfleizach, changseok, darin, dmazzoni, esprehn+autocc, ews-watchlist, ggaren, gyuyoung.kim, jcraig, jdiggs, samuel_white, sam, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute:dom-innertext-3
Attachments:
Description Flags
WIP Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Chris Dumez
Reported 2021-07-29 13:52:36 PDT
Attachments
WIP Patch (3.77 KB, patch)
2021-07-29 13:53 PDT, Chris Dumez
no flags
Patch (50.16 KB, patch)
2021-07-29 15:18 PDT, Chris Dumez
no flags
Patch (73.79 KB, patch)
2021-07-29 16:18 PDT, Chris Dumez
no flags
Patch (94.84 KB, patch)
2021-07-30 08:50 PDT, Chris Dumez
no flags
Patch (10.53 KB, patch)
2021-07-30 16:20 PDT, Chris Dumez
no flags
Patch (12.56 KB, patch)
2021-07-30 17:07 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2021-07-29 13:53:08 PDT
Created attachment 434568 [details] WIP Patch
Chris Dumez
Comment 2 2021-07-29 15:18:26 PDT
Chris Dumez
Comment 3 2021-07-29 16:18:28 PDT
Chris Dumez
Comment 4 2021-07-30 08:50:35 PDT
EWS
Comment 5 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].
Radar WebKit Bug Importer
Comment 6 2021-07-30 10:47:24 PDT
Darin Adler
Comment 7 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.
Chris Dumez
Comment 8 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.
Chris Dumez
Comment 9 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.
Darin Adler
Comment 10 2021-07-30 16:03:57 PDT
Well, does setting "innerText" have the same behavior as pasting?
Chris Dumez
Comment 11 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.
Chris Dumez
Comment 12 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>
Darin Adler
Comment 13 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.
Darin Adler
Comment 14 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.
Chris Dumez
Comment 15 2021-07-30 16:20:51 PDT
Darin Adler
Comment 16 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.
Chris Dumez
Comment 17 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.
Chris Dumez
Comment 18 2021-07-30 17:07:01 PDT
EWS
Comment 19 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].
Note You need to log in before you can comment on or make changes to this bug.