Skip to content
Permalink
Browse files
Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

* wtf/cocoa/RuntimeApplicationChecksCocoa.h:
Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

If the page is editable, don't select if the element is an image.

* page/EventHandler.cpp:
(WebCore::EventHandler::sendContextMenuEvent):
Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

API test coverage.

* TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
(TestWebKitAPI::rightClick):
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/250494@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294113 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
kcheney1 committed May 12, 2022
1 parent 56f3d02 commit 5f3a40a5dfb656ad90ded3f6dcf431740769b083
@@ -1,3 +1,13 @@
2022-05-11 Kate Cheney <katherine_cheney@apple.com>

Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

* wtf/cocoa/RuntimeApplicationChecksCocoa.h:

2022-05-10 Brent Fulgham <bfulgham@apple.com>

Remove abandoned CSSDeferredParser implementation and feature flag
@@ -72,6 +72,7 @@ enum class SDKAlignedBehavior {
NullOriginForNonSpecialSchemedURLs,
ObservesClassProperty,
PictureInPictureMediaPlayback,
PreventImageSelectionOnContextualMenuClickInEditablePage,
ProcessSwapOnCrossSiteNavigation,
RequiresUserGestureToLoadVideo,
RestrictsBaseURLSchemes,
@@ -1,3 +1,16 @@
2022-05-11 Kate Cheney <katherine_cheney@apple.com>

Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

If the page is editable, don't select if the element is an image.

* page/EventHandler.cpp:
(WebCore::EventHandler::sendContextMenuEvent):

2022-05-12 Eric Carlson <eric.carlson@apple.com>

[macOS] Remove support for deprecated ScreenCaptureKit API
@@ -127,6 +127,10 @@
#include <wtf/SetForScope.h>
#include <wtf/StdLibExtras.h>

#if PLATFORM(COCOA)
#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
#endif

#if ENABLE(IOS_TOUCH_EVENTS)
#include "PlatformTouchEventIOS.h"
#endif
@@ -3277,8 +3281,17 @@ bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
if (mouseEvent.scrollbar() || view->scrollbarAtPoint(event.position()))
return false;

bool allowSelection = true;
#if PLATFORM(COCOA)
if (linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::PreventImageSelectionOnContextualMenuClickInEditablePage)) {
auto* page = m_frame.page();
allowSelection = page && (!page->isEditable() || !is<HTMLImageElement>(mouseEvent.hitTestResult().targetElement()));
}
#endif

if (m_frame.editor().behavior().shouldSelectOnContextualMenuClick()
&& !m_frame.selection().contains(viewportPos)) {
&& !m_frame.selection().contains(viewportPos)
&& allowSelection) {
m_mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
selectClosestContextualWordOrLinkFromHitTestResult(mouseEvent.hitTestResult(), shouldAppendTrailingWhitespace(mouseEvent, m_frame));
}
@@ -1,3 +1,17 @@
2022-05-11 Kate Cheney <katherine_cheney@apple.com>

Mail compose: right clicking an image attachment selects it
https://bugs.webkit.org/show_bug.cgi?id=240315
rdar://45454933

Reviewed by Wenson Hsieh.

API test coverage.

* TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
(TestWebKitAPI::rightClick):
(TestWebKitAPI::TEST):

2022-05-11 Wenson Hsieh <wenson_hsieh@apple.com>

ImageAnalysisQueue should extract and analyze images inside of subframes
@@ -33,6 +33,7 @@
#import "Utilities.h"
#import <WebKit/WKMenuItemIdentifiersPrivate.h>
#import <WebKit/WKUIDelegatePrivate.h>
#import <WebKit/WKWebViewConfigurationPrivate.h>

@interface NSMenu (ContextMenuTests)
- (NSMenuItem *)itemWithIdentifier:(NSString *)identifier;
@@ -83,6 +84,45 @@ - (NSMenuItem *)itemWithIdentifier:(NSString *)identifier
EXPECT_NOT_NULL([spellingSubmenu itemWithIdentifier:_WKMenuItemIdentifierCheckGrammarWithSpelling]);
}

NSString *imageWithContextMenuHandler = @""
"<script>"
" addEventListener('contextmenu', () => contextmenuSeen = true);"
"</script>"
"<img src='large-red-square.png'>";

static void rightClick(RetainPtr<TestWKWebView> webView)
{
[webView mouseDownAtPoint:NSMakePoint(100, 100) simulatePressure:NO withFlags:0 eventType:NSEventTypeRightMouseDown];
[webView mouseUpAtPoint:NSMakePoint(100, 100) withFlags:0 eventType:NSEventTypeRightMouseUp];
}

TEST(ContextMenuTests, ContextMenuForEditableWebViewDoesNotSelectImage)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
[configuration _setAttachmentElementEnabled:YES];
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
[webView _setEditable:YES];

[webView synchronouslyLoadHTMLString:imageWithContextMenuHandler];

auto uiDelegate = adoptNS([[TestUIDelegate alloc] init]);
[webView setUIDelegate:uiDelegate.get()];

__block bool done = false;
[uiDelegate setGetContextMenuFromProposedMenu:^(NSMenu *menu, _WKContextMenuElementInfo *, id<NSSecureCoding>, void (^completion)(NSMenu *)) {
completion(nil);
done = true;
}];

rightClick(webView);
Util::run(&done);

rightClick(webView);
EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"window.contextmenuSeen"] boolValue]);
NSNumber *result = [webView objectByEvaluatingJavaScript:@"window.getSelection().isCollapsed"];
EXPECT_TRUE([result boolValue]);
}

} // namespace TestWebKitAPI

#endif // PLATFORM(MAC)

0 comments on commit 5f3a40a

Please sign in to comment.