WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 239712
[macOS] Only show a context menu action to "Copy Cropped Image" when appropriate
https://bugs.webkit.org/show_bug.cgi?id=239712
Summary
[macOS] Only show a context menu action to "Copy Cropped Image" when appropriate
Wenson Hsieh
Reported
2022-04-24 14:56:16 PDT
rdar://92239384
Attachments
Patch
(11.50 KB, patch)
2022-04-25 08:25 PDT
,
Wenson Hsieh
darin
: review+
Details
Formatted Diff
Diff
Patch
(11.38 KB, patch)
2022-04-25 09:53 PDT
,
Wenson Hsieh
no flags
Details
Formatted Diff
Diff
Patch
(11.37 KB, patch)
2022-04-25 10:00 PDT
,
Wenson Hsieh
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Wenson Hsieh
Comment 1
2022-04-25 08:25:22 PDT
Created
attachment 458271
[details]
Patch
Darin Adler
Comment 2
2022-04-25 09:08:44 PDT
Comment on
attachment 458271
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=458271&action=review
> Source/WebKit/UIProcess/WebPageProxy.cpp:1194 > #if ENABLE(CONTEXT_MENUS) > m_activeContextMenu = nullptr; > -#endif > +#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > + m_croppedImageForContextMenu = nullptr; > +#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > +#endif // ENABLE(CONTEXT_MENUS)
I find && works much better than nesting for #if since we don’t indent. Even when it’s right next to another block. Also, #endif comments are so heavy for short sequences. So I would have written: #if ENABLE(CONTEXT_MENUS) m_activeContextMenu = nullptr; #endif #if ENABLE(CONTEXT_MENUS) && ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) m_croppedImageForContextMenu = nullptr #endif Even if, below, we use nesting instead of &&. Not sure about the order, I noticed elsewhere you used the reverse order.
> Source/WebKit/UIProcess/WebPageProxy.h:2800 > #if ENABLE(CONTEXT_MENUS) > RefPtr<WebContextMenuProxy> m_activeContextMenu; > ContextMenuContextData m_activeContextMenuContextData; > -#endif > +#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > + RetainPtr<CGImageRef> m_croppedImageForContextMenu; > +#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > +#endif // ENABLE(CONTEXT_MENUS)
Same here as above: #if ENABLE(CONTEXT_MENUS) RefPtr<WebContextMenuProxy> m_activeContextMenu; ContextMenuContextData m_activeContextMenuContextData; #endif #if ENABLE(CONTEXT_MENUS) && ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) RetainPtr<CGImageRef> m_croppedImageForContextMenu; #endif
> Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:609 > + auto action = item.action();
Maybe a switch here instead of two if statements? I like how that eliminates the local variable.
Wenson Hsieh
Comment 3
2022-04-25 09:29:11 PDT
Comment on
attachment 458271
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=458271&action=review
Thanks for the review!
>> Source/WebKit/UIProcess/WebPageProxy.cpp:1194 >> +#endif // ENABLE(CONTEXT_MENUS) > > I find && works much better than nesting for #if since we don’t indent. Even when it’s right next to another block. Also, #endif comments are so heavy for short sequences. So I would have written: > > #if ENABLE(CONTEXT_MENUS) > m_activeContextMenu = nullptr; > #endif > > #if ENABLE(CONTEXT_MENUS) && ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > m_croppedImageForContextMenu = nullptr > #endif > > Even if, below, we use nesting instead of &&. Not sure about the order, I noticed elsewhere you used the reverse order.
Sounds good! Changed to use `ENABLE(CONTEXT_MENUS) && ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)` here.
>> Source/WebKit/UIProcess/WebPageProxy.h:2800 >> +#endif // ENABLE(CONTEXT_MENUS) > > Same here as above: > > #if ENABLE(CONTEXT_MENUS) > RefPtr<WebContextMenuProxy> m_activeContextMenu; > ContextMenuContextData m_activeContextMenuContextData; > #endif > > #if ENABLE(CONTEXT_MENUS) && ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > RetainPtr<CGImageRef> m_croppedImageForContextMenu; > #endif
👍🏻
>> Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:609 >> + auto action = item.action(); > > Maybe a switch here instead of two if statements? I like how that eliminates the local variable.
Makes sense — changed to use a switch case here.
Wenson Hsieh
Comment 4
2022-04-25 09:53:24 PDT
Created
attachment 458280
[details]
Patch
Wenson Hsieh
Comment 5
2022-04-25 10:00:43 PDT
Created
attachment 458281
[details]
Patch
EWS
Comment 6
2022-04-25 13:01:32 PDT
Committed
r293340
(
249961@main
): <
https://commits.webkit.org/249961@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 458281
[details]
.
Nikolas Zimmermann
Comment 7
2022-04-25 15:01:25 PDT
Oops, this broke the macOS Montery builds for me: /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:661:27: error: no member named 'setCroppedImageForContextMenu' in 'WebKit::WebPageProxy' page->setCroppedImageForContextMenu(nullptr); ~~~~~~^ /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:670:31: error: no member named 'setCroppedImageForContextMenu' in 'WebKit::WebPageProxy' page->setCroppedImageForContextMenu(result); ~~~~~~^ /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:662:21: error: use of undeclared identifier 'requestImageAnalysisMarkup' requestImageAnalysisMarkup(image.get(), [weakPage, protectedThis, copyCroppedImageItem = WTFMove(*copyCroppedImageItem)](auto result, auto) { ^ 3 errors generated. ... Th relevant code section is only guarded by "#if ENABLE(IMAGE_ANALYSIS)" - I guess you meant to test 'IMAGE_ANALYSIS_ENHANCEMENTS' instead? #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) void WebPageProxy::setCroppedImageForContextMenu(CGImageRef image) { ...
Wenson Hsieh
Comment 8
2022-04-25 15:02:25 PDT
(In reply to Nikolas Zimmermann from
comment #7
)
> Oops, this broke the macOS Montery builds for me: > > /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/ > UIProcess/mac/WebContextMenuProxyMac.mm:661:27: error: no member named > 'setCroppedImageForContextMenu' in > 'WebKit::WebPageProxy' > page->setCroppedImageForContextMenu(nullptr); > ~~~~~~^ > /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/ > UIProcess/mac/WebContextMenuProxyMac.mm:670:31: error: no member named > 'setCroppedImageForContextMenu' in > 'WebKit::WebPageProxy' > page->setCroppedImageForContextMenu(result); > ~~~~~~^ > /Users/nzimmermann/Software/GitRepositories/WebKitVanilla/Source/WebKit/ > UIProcess/mac/WebContextMenuProxyMac.mm:662:21: error: use of undeclared > identifier > 'requestImageAnalysisMarkup' > requestImageAnalysisMarkup(image.get(), [weakPage, > protectedThis, copyCroppedImageItem = WTFMove(*copyCroppedImageItem)](auto > result, auto) { > ^ > 3 errors generated. > ... > > Th relevant code section is only guarded by "#if ENABLE(IMAGE_ANALYSIS)" - I > guess you meant to test 'IMAGE_ANALYSIS_ENHANCEMENTS' instead? > > #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) > void WebPageProxy::setCroppedImageForContextMenu(CGImageRef image) > { > ...
Sorry about that — I'm landing a fix for that momentarily!
Nikolas Zimmermann
Comment 9
2022-04-25 15:11:23 PDT
Comment on
attachment 458281
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=458281&action=review
> Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:659 > + if (copyCroppedImageItem) {
The whole if body needs to be guarded by #if ENABLE(IMAGE_ANALYSIS_ENHANCMENTS) -- not sure why EWS is not affected - I'm using 'vanilla' build options macOS Monterey debug / release builds. Otherwise setCroppedImageForContextMenu() is undefined.
Nikolas Zimmermann
Comment 10
2022-04-25 15:11:56 PDT
(In reply to Wenson Hsieh from
comment #8
)
> Sorry about that — I'm landing a fix for that momentarily!
No worries, thanks for the prompt fix.
Wenson Hsieh
Comment 11
2022-04-25 15:13:23 PDT
(In reply to Nikolas Zimmermann from
comment #9
)
> Comment on
attachment 458281
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=458281&action=review
> > > Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:659 > > + if (copyCroppedImageItem) { > > The whole if body needs to be guarded by #if > ENABLE(IMAGE_ANALYSIS_ENHANCMENTS) -- not sure why EWS is not affected - I'm > using 'vanilla' build options macOS Monterey debug / release builds. > Otherwise setCroppedImageForContextMenu() is undefined.
Indeed — I'm changing it to this: ``` #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) if (copyCroppedImageItem) { … } #else UNUSED_PARAM(copyCroppedImageItem); #endif ``` EWS didn't catch this, because the EWS bots are only on Big Sur.
Wenson Hsieh
Comment 12
2022-04-25 15:25:32 PDT
Committed
r293363
: <
https://commits.webkit.org/r293363
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug