Reviewed by Kevin Decker
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2007 19:00:43 +0000 (19:00 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2007 19:00:43 +0000 (19:00 +0000)
        - fixed <rdar://problem/4184640> "Look Up in Dictionary" item is always disabled for PDF pages

        * WebView/WebPDFView.mm:
        (-[WebPDFView validateUserInterfaceItem:]):
        enable "Look Up in Dictionary" only if we're using a version of PDFKit that knows how to do so
        (-[WebPDFView _canLookUpInDictionary]):
        use respondsToSelector to test whether the current version of PDFKit supports this non-API feature
        (-[WebPDFView _lookUpInDictionaryFromMenu:]):
        implement this method, which WebKit includes in the context menu when there's selected text
        (-[WebPDFView _menuItemsFromPDFKitForEvent:]):
        updated comment for this change

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

WebKit/ChangeLog
WebKit/WebView/WebPDFView.mm

index b21ec86f76274a3574916606f5b37ff42acb521e..3d3dc067673e926a178e56f3f12bf7d22c5440d0 100644 (file)
@@ -1,3 +1,19 @@
+2007-04-17  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Kevin Decker
+
+        - fixed <rdar://problem/4184640> "Look Up in Dictionary" item is always disabled for PDF pages
+
+        * WebView/WebPDFView.mm:
+        (-[WebPDFView validateUserInterfaceItem:]):
+        enable "Look Up in Dictionary" only if we're using a version of PDFKit that knows how to do so
+        (-[WebPDFView _canLookUpInDictionary]):
+        use respondsToSelector to test whether the current version of PDFKit supports this non-API feature
+        (-[WebPDFView _lookUpInDictionaryFromMenu:]):
+        implement this method, which WebKit includes in the context menu when there's selected text
+        (-[WebPDFView _menuItemsFromPDFKitForEvent:]):
+        updated comment for this change
+
 2007-04-16  Darin Adler  <darin@apple.com>
 
         Rubber stamped by Tim Hatcher.
index 072c0eec35e9aa8524eeddcbec67d578c8b02322..3f8e56bfcd46d667a791ce136cc84514ed33bc53 100644 (file)
@@ -68,6 +68,7 @@ using namespace EventNames;
 + (Class)_PDFViewClass;
 - (BOOL)_anyPDFTagsFoundInMenu:(NSMenu *)menu;
 - (void)_applyPDFDefaults;
+- (BOOL)_canLookUpInDictionary;
 - (NSEvent *)_fakeKeyEventWithFunctionKey:(unichar)functionKey;
 - (NSMutableArray *)_menuItemsFromPDFKitForEvent:(NSEvent *)theEvent;
 - (void)_openWithFinder:(id)sender;
@@ -450,6 +451,9 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
     
     if (action == @selector(_openWithFinder:))
         return [PDFSubview document] != nil;
+    
+    if (action == @selector(_lookUpInDictionaryFromMenu:))
+        return [self _canLookUpInDictionary];
 
     return YES;
 }
@@ -945,6 +949,11 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
     [PDFSubview setDisplayMode:[prefs PDFDisplayMode]];    
 }
 
+- (BOOL)_canLookUpInDictionary
+{
+    return [PDFSubview respondsToSelector:@selector(_searchInDictionary:)];
+}
+
 - (NSEvent *)_fakeKeyEventWithFunctionKey:(unichar)functionKey
 {
     // FIXME 4400480: when PDFView implements the standard scrolling selectors that this
@@ -962,6 +971,15 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
                              keyCode:0];
 }
 
+- (void)_lookUpInDictionaryFromMenu:(id)sender
+{
+    // This method is used by WebKit's context menu item. Here we map to the method that
+    // PDFView uses. Since the PDFView method isn't API, and isn't available on all versions
+    // of PDFKit, we use performSelector after a respondsToSelector check, rather than calling it directly.
+    if ([self _canLookUpInDictionary])
+        [PDFSubview performSelector:@selector(_searchInDictionary:) withObject:sender];
+}
+
 - (NSMutableArray *)_menuItemsFromPDFKitForEvent:(NSEvent *)theEvent
 {
     NSMutableArray *copiedItems = [NSMutableArray array];
@@ -979,9 +997,9 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
         [NSNumber numberWithInt:WebMenuItemPDFPreviousPage], NSStringFromSelector(@selector(goToPreviousPage:)),
         nil];
     
-    // Leave these menu items out, since WebKit inserts equivalent ones.
-    // FIXME 4184640: need to make "Look Up in Dictionary" item work with PDFKit. Either we need to use PDFKit's
-    // menu item instead of ignoring it here, or we need to make WebKit's menu item hook into PDFKit's method.
+    // Leave these menu items out, since WebKit inserts equivalent ones. Note that we leave out PDFKit's "Look Up in Dictionary"
+    // item here because WebKit already includes an item with the same title and purpose. We map WebKit's to PDFKit's 
+    // "Look Up in Dictionary" via the implementation of -[WebPDFView _lookUpInDictionaryFromMenu:].
     NSSet *unwantedActions = [[NSSet alloc] initWithObjects:
                               NSStringFromSelector(@selector(_searchInSpotlight:)),
                               NSStringFromSelector(@selector(_searchInGoogle:)),