Bug 239423

Summary: [macOS] Image controls are editable and prevent drops in editable web views
Product: WebKit Reporter: Wenson Hsieh <wenson_hsieh>
Component: HTML EditingAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: akeerthi, cdumez, changseok, darin, esprehn+autocc, ews-watchlist, gyuyoung.kim, hi, kangil.han, katherine_cheney, megan_gardner, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
For EWS
none
For landing none

Description Wenson Hsieh 2022-04-16 13:40:09 PDT
rdar://81027082
Comment 1 Wenson Hsieh 2022-04-16 14:05:03 PDT
Created attachment 457755 [details]
For EWS
Comment 2 Darin Adler 2022-04-16 15:14:31 PDT
Comment on attachment 457755 [details]
For EWS

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

> Source/WebCore/dom/mac/ImageControlsMac.cpp:93
> +    controlLayer->setContentEditable("false"_s);

Mildly sad that we allocate and then deallocate the String containing "false" here. There is, however, a clean way to fix that. We can change HTMLElement::setContentEditable to take a StringView. Will still work with the String&& that the JavaScript bindings will pass to it. Probably will have to edit DOMHTMLElement.mm to keep it compiling since an NSString * knows how to turn itself into a String but not a StringView. Not really necessary to do *any* of this as part of this patch, just something I am noticing in passing.
Comment 3 Chris Dumez 2022-04-16 15:42:33 PDT
Comment on attachment 457755 [details]
For EWS

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

>> Source/WebCore/dom/mac/ImageControlsMac.cpp:93
>> +    controlLayer->setContentEditable("false"_s);
> 
> Mildly sad that we allocate and then deallocate the String containing "false" here. There is, however, a clean way to fix that. We can change HTMLElement::setContentEditable to take a StringView. Will still work with the String&& that the JavaScript bindings will pass to it. Probably will have to edit DOMHTMLElement.mm to keep it compiling since an NSString * knows how to turn itself into a String but not a StringView. Not really necessary to do *any* of this as part of this patch, just something I am noticing in passing.

I totally agree that setContentEditable() should take a StringView. I also think that the most efficient code may be:
controlLayer->setAttributeWithoutSynchronization(contenteditableAttr, "false"_s);
or even
controlLayer->setAttributeWithoutSynchronization(contenteditableAttr, HTMLElement::falseName());
if we expose falseName() in the HTMLElement header (it is currently in the cpp only).

To avoid the string comparisons inside setContentEditable().
Comment 4 Wenson Hsieh 2022-04-16 15:47:38 PDT
Thanks for the reviews, Chris and Darin!

(In reply to Chris Dumez from comment #3)
> Comment on attachment 457755 [details]
> For EWS
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457755&action=review
> 
> >> Source/WebCore/dom/mac/ImageControlsMac.cpp:93
> >> +    controlLayer->setContentEditable("false"_s);
> > 
> > Mildly sad that we allocate and then deallocate the String containing "false" here. There is, however, a clean way to fix that. We can change HTMLElement::setContentEditable to take a StringView. Will still work with the String&& that the JavaScript bindings will pass to it. Probably will have to edit DOMHTMLElement.mm to keep it compiling since an NSString * knows how to turn itself into a String but not a StringView. Not really necessary to do *any* of this as part of this patch, just something I am noticing in passing.
> 
> I totally agree that setContentEditable() should take a StringView. I also
> think that the most efficient code may be:
> controlLayer->setAttributeWithoutSynchronization(contenteditableAttr,
> "false"_s);
> or even
> controlLayer->setAttributeWithoutSynchronization(contenteditableAttr,
> HTMLElement::falseName());
> if we expose falseName() in the HTMLElement header (it is currently in the
> cpp only).
> 
> To avoid the string comparisons inside setContentEditable().

That's a great point — I filed <https://webkit.org/b/239424> to track refactoring setContentEditable to take a StringView; I'll also tweak this patch so that it does:

```
controlLayer->setAttributeWithoutSynchronization(contenteditableAttr, "false"_s);
```

...instead of using `setContentEditable()`.
Comment 5 Wenson Hsieh 2022-04-16 16:05:17 PDT
Created attachment 457758 [details]
For landing
Comment 6 EWS 2022-04-16 20:14:11 PDT
Committed r292944 (249709@main): <https://commits.webkit.org/249709@main>

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