Copy and Lookup menu items should be disabled when something is not copyable
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2014 01:29:56 +0000 (01:29 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2014 01:29:56 +0000 (01:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139423

Reviewed by Tim Horton.

Source/WebCore:

New function allowCopy() indicates whether the HitTestResult would allow itself to
be copied onto the pasteboard.
* WebCore.exp.in:
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::allowsCopy):
* rendering/HitTestResult.h:

Source/WebKit/mac:

Disable both lookup and copy when a HitTestResult does not allow copy.
* WebView/WebActionMenuController.mm:

Set autoenablesItems to NO. It’s messing with our ability to control the enable/
disable state otherwise.
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):

Source/WebKit2:

Add allowsCopy to the WebHitTestResult.
* Shared/WebHitTestResult.cpp:
(WebKit::WebHitTestResult::Data::Data):
(WebKit::WebHitTestResult::Data::encode):
(WebKit::WebHitTestResult::Data::decode):
* Shared/WebHitTestResult.h:
(WebKit::WebHitTestResult::allowsCopy):

Set autoenablesItems to NO. It’s messing with our ability to control the enable/
disable state otherwise.
* UIProcess/API/mac/WKView.mm:
(-[WKView initWithFrame:context:configuration:webView:]):

Disable both lookup and copy when a WebHitTestResult does not allow copy.
* UIProcess/mac/WKActionMenuController.mm:

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/rendering/HitTestResult.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebHitTestResult.cpp
Source/WebKit2/Shared/WebHitTestResult.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm

index 2a0e602..e6be1e0 100644 (file)
@@ -1,3 +1,17 @@
+2014-12-08  Beth Dakin  <bdakin@apple.com>
+
+        Copy and Lookup menu items should be disabled when something is not copyable
+        https://bugs.webkit.org/show_bug.cgi?id=139423
+
+        Reviewed by Tim Horton.
+
+        New function allowCopy() indicates whether the HitTestResult would allow itself to 
+        be copied onto the pasteboard.
+        * WebCore.exp.in:
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::allowsCopy):
+        * rendering/HitTestResult.h:
+
 2014-12-08  Chris Dumez  <cdumez@apple.com>
 
         Move 'text-shadow' check from RenderStyle::changeRequiresLayout() to changeAffectsVisualOverflow()
index fdbc5c5..8ba1cad 100644 (file)
@@ -1678,6 +1678,7 @@ __ZNK7WebCore13GraphicsLayer18getDebugBorderInfoERNS_5ColorERf
 __ZNK7WebCore13GraphicsLayer26backingStoreMemoryEstimateEv
 __ZNK7WebCore13HTTPHeaderMap3getENS_14HTTPHeaderNameE
 __ZNK7WebCore13HTTPHeaderMap3getERKN3WTF6StringE
+__ZNK7WebCore13HitTestResult10allowsCopyEv
 __ZNK7WebCore13HitTestResult10isLiveLinkEv
 __ZNK7WebCore13HitTestResult10isSelectedEv
 __ZNK7WebCore13HitTestResult11targetFrameEv
index d390ed3..45cdb33 100644 (file)
@@ -544,6 +544,21 @@ bool HitTestResult::isOverTextInsideFormControlElement() const
     return !wordRange->text().isEmpty();
 }
 
+bool HitTestResult::allowsCopy() const
+{
+    Node* node = innerNode();
+    if (!node)
+        return false;
+
+    RenderObject* renderer = node->renderer();
+    if (!renderer)
+        return false;
+
+    bool isUserSelectNone = renderer->style().userSelect() == SELECT_NONE;
+    bool isPasswordField = is<HTMLInputElement>(node) && downcast<HTMLInputElement>(*node).isPasswordField();
+    return !isPasswordField && !isUserSelectNone;
+}
+
 URL HitTestResult::absoluteLinkURL() const
 {
     if (m_innerURLElement)
index 8b0d5fe..5d09da3 100644 (file)
@@ -126,6 +126,7 @@ public:
     void toggleMediaMuteState() const;
     bool isDownloadableMedia() const;
     bool isOverTextInsideFormControlElement() const;
+    bool allowsCopy() const;
 
     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
     // enclosed by the boundaries of a node.
index f1e92be..8a849fb 100644 (file)
@@ -1,3 +1,18 @@
+2014-12-08  Beth Dakin  <bdakin@apple.com>
+
+        Copy and Lookup menu items should be disabled when something is not copyable
+        https://bugs.webkit.org/show_bug.cgi?id=139423
+
+        Reviewed by Tim Horton.
+
+        Disable both lookup and copy when a HitTestResult does not allow copy.
+        * WebView/WebActionMenuController.mm:
+
+        Set autoenablesItems to NO. It’s messing with our ability to control the enable/
+        disable state otherwise.
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+
 2014-12-08  Anders Carlsson  <andersca@apple.com>
 
         Adding user content to a group should force that group to be created
index 88da074..ade30c1 100644 (file)
@@ -763,13 +763,14 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
         selector = @selector(_copySelection:);
         title = WEB_UI_STRING_KEY("Copy", "Copy (text action menu item)", "text action menu item");
         image = [NSImage imageNamed:@"NSActionMenuCopy"];
+        enabled = _hitTestResult.allowsCopy();
         break;
 
     case WebActionMenuItemTagLookupText:
         selector = @selector(_lookupText:);
         title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
         image = [NSImage imageNamed:@"NSActionMenuLookup"];
-        enabled = getLULookupDefinitionModuleClass();
+        enabled = getLULookupDefinitionModuleClass() && _hitTestResult.allowsCopy();
         break;
 
     case WebActionMenuItemTagPaste:
index e68a77d..d17e221 100644 (file)
@@ -886,6 +886,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
         RetainPtr<NSMenu> actionMenu = adoptNS([[NSMenu alloc] init]);
         self.actionMenu = actionMenu.get();
         _private->actionMenuController = [[WebActionMenuController alloc] initWithWebView:self];
+        self.actionMenu.autoenablesItems = NO;
     }
 #endif
 
index 2b8bb27..51781dd 100644 (file)
@@ -1,3 +1,26 @@
+2014-12-08  Beth Dakin  <bdakin@apple.com>
+
+        Copy and Lookup menu items should be disabled when something is not copyable
+        https://bugs.webkit.org/show_bug.cgi?id=139423
+
+        Reviewed by Tim Horton.
+
+        Add allowsCopy to the WebHitTestResult.
+        * Shared/WebHitTestResult.cpp:
+        (WebKit::WebHitTestResult::Data::Data):
+        (WebKit::WebHitTestResult::Data::encode):
+        (WebKit::WebHitTestResult::Data::decode):
+        * Shared/WebHitTestResult.h:
+        (WebKit::WebHitTestResult::allowsCopy):
+
+        Set autoenablesItems to NO. It’s messing with our ability to control the enable/
+        disable state otherwise.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView initWithFrame:context:configuration:webView:]):
+
+        Disable both lookup and copy when a WebHitTestResult does not allow copy.
+        * UIProcess/mac/WKActionMenuController.mm:
+
 2014-12-08  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/18905383> [iOS] Crash due to null m_webPageProxyForBackForwardListForCurrentSwipe in ViewGestureController::endSwipeGesture
index c313f04..965c299 100644 (file)
@@ -55,6 +55,7 @@ WebHitTestResult::Data::Data(const HitTestResult& hitTestResult)
     , isSelected(hitTestResult.isSelected())
     , isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
     , isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
+    , allowsCopy(hitTestResult.allowsCopy())
     , isDownloadableMedia(hitTestResult.isDownloadableMedia())
 {
 }
@@ -77,6 +78,7 @@ void WebHitTestResult::Data::encode(IPC::ArgumentEncoder& encoder) const
     encoder << isSelected;
     encoder << isTextNode;
     encoder << isOverTextInsideFormControlElement;
+    encoder << allowsCopy;
     encoder << isDownloadableMedia;
 }
 
@@ -94,6 +96,7 @@ bool WebHitTestResult::Data::decode(IPC::ArgumentDecoder& decoder, WebHitTestRes
         || !decoder.decode(hitTestResultData.isSelected)
         || !decoder.decode(hitTestResultData.isTextNode)
         || !decoder.decode(hitTestResultData.isOverTextInsideFormControlElement)
+        || !decoder.decode(hitTestResultData.allowsCopy)
         || !decoder.decode(hitTestResultData.isDownloadableMedia))
         return false;
 
index dbcd25b..863ed94 100644 (file)
@@ -55,6 +55,7 @@ public:
         bool isSelected;
         bool isTextNode;
         bool isOverTextInsideFormControlElement;
+        bool allowsCopy;
         bool isDownloadableMedia;
 
         Data();
@@ -89,6 +90,8 @@ public:
 
     bool isOverTextInsideFormControlElement() const { return m_data.isOverTextInsideFormControlElement; }
 
+    bool allowsCopy() const { return m_data.allowsCopy; }
+
     bool isDownloadableMedia() const { return m_data.isDownloadableMedia; }
 
 private:
index fe92d59..fb1a0e3 100644 (file)
@@ -3600,6 +3600,7 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
         self.actionMenu = menu.get();
         _data->_actionMenuController = adoptNS([[WKActionMenuController alloc] initWithPage:*_data->_page view:self]);
         self.actionMenu.delegate = _data->_actionMenuController.get();
+        self.actionMenu.autoenablesItems = NO;
     }
 #endif
 
index 8a92829..7504f12 100644 (file)
@@ -981,6 +981,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     NSString *title = nil;
     NSImage *image = nil;
     bool enabled = true;
+    RefPtr<WebHitTestResult> hitTestResult = [self _webHitTestResult];
 
     switch (tag) {
     case kWKContextActionItemTagOpenLinkInDefaultBrowser:
@@ -1030,13 +1031,14 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
         selector = @selector(_copySelection:);
         title = WEB_UI_STRING_KEY("Copy", "Copy (text action menu item)", "text action menu item");
         image = [NSImage imageNamed:@"NSActionMenuCopy"];
+        enabled = hitTestResult->allowsCopy();
         break;
 
     case kWKContextActionItemTagLookupText:
         selector = @selector(_lookupText:);
         title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
         image = [NSImage imageNamed:@"NSActionMenuLookup"];
-        enabled = getLULookupDefinitionModuleClass();
+        enabled = getLULookupDefinitionModuleClass() && hitTestResult->allowsCopy();
         break;
 
     case kWKContextActionItemTagPaste: