WK1: Text is getting selected even when an action menu fails to invoke
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Nov 2014 22:12:01 +0000 (22:12 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Nov 2014 22:12:01 +0000 (22:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138576
-and corresponding-
rdar://problem/18931330

Reviewed by Tim Horton.

Selection changes should happen in willOpenMenu: instead of prepareForMenu:
* WebView/WebActionMenuController.h:
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController prepareForMenu:withEvent:]):
(-[WebActionMenuController willOpenMenu:withEvent:]):

_selectLookupText no longer needs to return a BOOL indicating success or failure.
(-[WebActionMenuController _selectLookupText]):
(-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):

Pass willOpenMenu: on to the controller.
* WebView/WebView.mm:
(-[WebView willOpenMenu:withEvent:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175831 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebActionMenuController.h
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit/mac/WebView/WebView.mm

index 61011de..03ec907 100644 (file)
@@ -1,5 +1,28 @@
 2014-11-10  Beth Dakin  <bdakin@apple.com>
 
+        WK1: Text is getting selected even when an action menu fails to invoke
+        https://bugs.webkit.org/show_bug.cgi?id=138576
+        -and corresponding-
+        rdar://problem/18931330
+
+        Reviewed by Tim Horton.
+
+        Selection changes should happen in willOpenMenu: instead of prepareForMenu:
+        * WebView/WebActionMenuController.h:
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController prepareForMenu:withEvent:]):
+        (-[WebActionMenuController willOpenMenu:withEvent:]):
+
+        _selectLookupText no longer needs to return a BOOL indicating success or failure.
+        (-[WebActionMenuController _selectLookupText]):
+        (-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):
+
+        Pass willOpenMenu: on to the controller.
+        * WebView/WebView.mm:
+        (-[WebView willOpenMenu:withEvent:]):
+
+2014-11-10  Beth Dakin  <bdakin@apple.com>
+
         Speculative build fix.
 
         * WebView/WebActionMenuController.mm:
index 745c8d0..be0fbc1 100644 (file)
@@ -38,6 +38,7 @@
 - (id)initWithWebView:(WebView *)webView;
 - (void)webViewClosed;
 - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
 - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
 
 @end
index e95cc09..fe6479a 100644 (file)
@@ -118,9 +118,6 @@ struct DictionaryPopupInfo {
     WebElementDictionary *hitTestResult = [self performHitTestAtPoint:[_webView convertPoint:event.locationInWindow fromView:nil]];
     NSArray *menuItems = [self _defaultMenuItemsForHitTestResult:hitTestResult];
 
-    if (_type != WebActionMenuReadOnlyText)
-        [[_webView _selectedOrMainFrame] _clearSelection];
-
     // Allow clients to customize the menu items.
     if ([[_webView UIDelegate] respondsToSelector:@selector(_webView:actionMenuItemsForHitTestResult:withType:defaultActionMenuItems:)])
         menuItems = [[_webView UIDelegate] _webView:_webView actionMenuItemsForHitTestResult:hitTestResult withType:_type defaultActionMenuItems:menuItems];
@@ -129,6 +126,22 @@ struct DictionaryPopupInfo {
         [actionMenu addItem:item];
 }
 
+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    if (menu != _webView.actionMenu)
+        return;
+
+    if (_type != WebActionMenuReadOnlyText) {
+        [[_webView _selectedOrMainFrame] _clearSelection];
+        return;
+    }
+
+    // Action menus for text should highlight the text so that it is clear what the action menu actions
+    // will apply to. If the text is already selected, the menu will use the existing selection.
+    if (!_hitTestResult.isSelected())
+        [self _selectLookupText];
+}
+
 - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
 {
     if (menu != _webView.actionMenu)
@@ -270,19 +283,19 @@ struct DictionaryPopupInfo {
     WKShowWordDefinitionWindow(popupInfo.attributedString.get(), textBaselineOrigin, popupInfo.options.get());
 }
 
-- (BOOL)_selectLookupText
+- (void)_selectLookupText
 {
     NSDictionary *options = nil;
     RefPtr<Range> lookupRange = rangeForDictionaryLookupAtHitTestResult(_hitTestResult, &options);
     if (!lookupRange)
-        return false;
+        return;
 
     Frame* frame = _hitTestResult.innerNode()->document().frame();
     if (!frame)
-        return false;
+        return;
 
     frame->selection().setSelectedRange(lookupRange.get(), DOWNSTREAM, true);
-    return true;
+    return;
 }
 
 static DictionaryPopupInfo performDictionaryLookupForSelection(Frame* frame, const VisibleSelection& selection)
@@ -406,10 +419,6 @@ static NSImage *webKitBundleImageNamed(NSString *name)
 
     Node* node = _hitTestResult.innerNode();
     if (node && node->isTextNode()) {
-        if (![[hitTestResult objectForKey:WebElementIsSelectedKey] boolValue]) {
-            if (![self _selectLookupText])
-                return @[ ];
-        }
         _type = WebActionMenuReadOnlyText;
         return [self _defaultMenuItemsForText:hitTestResult];
     }
index d6961b1..4848711 100644 (file)
@@ -8544,6 +8544,14 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
     [_private->actionMenuController prepareForMenu:menu withEvent:event];
 }
 
+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    if (menu != self.actionMenu)
+        return;
+
+    [_private->actionMenuController willOpenMenu:menu withEvent:event];
+}
+
 - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
 {
     if (menu != self.actionMenu)