Bug 239423 - [macOS] Image controls are editable and prevent drops in editable web views
Summary: [macOS] Image controls are editable and prevent drops in editable web views
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: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-16 13:40 PDT by Wenson Hsieh
Modified: 2022-04-16 20:14 PDT (History)
14 users (show)

See Also:


Attachments
For EWS (6.29 KB, patch)
2022-04-16 14:05 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
For landing (6.33 KB, patch)
2022-04-16 16:05 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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].