WebCore:
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2007 16:12:19 +0000 (16:12 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2007 16:12:19 +0000 (16:12 +0000)
        Reviewed by Anders

        - WebCore part of fix for:
        <rdar://problem/5128697> REGRESSION: At least one PDF context menu item isn't appearing on Leopard

        * platform/ContextMenuItem.h:
        (WebCore::):
        add two PDF-related context menu items to enum to keep it in sync with WebKit

        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::checkOrEnableIfNeeded):
        add the new context menu items to the do-nothing case of a big switch statement

WebKit:

        Reviewed by Anders

        - WebKit part of fix for:
        <rdar://problem/5128697> REGRESSION: At least one PDF context menu item isn't appearing on Leopard

        * Misc/WebNSArrayExtras.h: Added.
        * Misc/WebNSArrayExtras.m: Added.
        (-[NSMutableArray _webkit_removeUselessMenuItemSeparators]):
        New file, includes this method to strip leading, trailing, and duplicate separators from arrays
        of NSMenuItems (copied from Safari)

        * WebView/WebUIDelegatePrivate.h:
        new MenuItemTag enum values for new PDFKit context menu items

        * WebKit.xcodeproj/project.pbxproj:
        updated for new files

        * WebView/WebPDFView.mm:
        (-[WebPDFView _anyPDFTagsFoundInMenu:]):
        check for new PDFKit context menu items
        (-[WebPDFView _menuItemsFromPDFKitForEvent:]):
        associate new PDFKit context menu item selectors with the new tags; skip certain selectors that
        correspond to menu items that WebKit already includes; remove useless menu item separators when
        we're done, since we might have removed arbitrarily-placed menu items

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

WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/platform/ContextMenu.cpp
WebCore/platform/ContextMenuItem.h
WebKit/ChangeLog
WebKit/Misc/WebNSArrayExtras.h [new file with mode: 0644]
WebKit/Misc/WebNSArrayExtras.m [new file with mode: 0644]
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebPDFView.mm
WebKit/WebView/WebUIDelegatePrivate.h

index 5a86117..da833f7 100644 (file)
@@ -1,3 +1,18 @@
+2007-04-12  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Anders
+
+        - WebCore part of fix for:
+        <rdar://problem/5128697> REGRESSION: At least one PDF context menu item isn't appearing on Leopard
+
+        * platform/ContextMenuItem.h:
+        (WebCore::):
+        add two PDF-related context menu items to enum to keep it in sync with WebKit
+
+        * platform/ContextMenu.cpp:
+        (WebCore::ContextMenu::checkOrEnableIfNeeded):
+        add the new context menu items to the do-nothing case of a big switch statement
+
 2007-04-12  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Zack.
index c2cad50..fb312dd 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
+                       shouldCheckCompatibility = 1;
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
index 2f3085b..95386e3 100644 (file)
@@ -506,6 +506,8 @@ void ContextMenu::checkOrEnableIfNeeded(ContextMenuItem& item) const
         case ContextMenuItemTagStartSpeaking:
         case ContextMenuItemTagStopSpeaking:
         case ContextMenuItemTagWritingDirectionMenu:
+        case ContextMenuItemTagPDFSinglePageScrolling:
+        case ContextMenuItemTagPDFFacingPagesScrolling:
         case ContextMenuItemBaseApplicationTag:
             break;
     }
index fc6f20d..d7e05d1 100644 (file)
@@ -117,6 +117,8 @@ namespace WebCore {
         ContextMenuItemTagDefaultDirection,
         ContextMenuItemTagLeftToRight,
         ContextMenuItemTagRightToLeft,
+        ContextMenuItemTagPDFSinglePageScrolling,
+        ContextMenuItemTagPDFFacingPagesScrolling,
         ContextMenuItemBaseApplicationTag = 10000
     };
 
index 06d079a..adff6d1 100644 (file)
@@ -1,3 +1,30 @@
+2007-04-11  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Anders
+
+        - WebKit part of fix for:
+        <rdar://problem/5128697> REGRESSION: At least one PDF context menu item isn't appearing on Leopard
+
+        * Misc/WebNSArrayExtras.h: Added.
+        * Misc/WebNSArrayExtras.m: Added.
+        (-[NSMutableArray _webkit_removeUselessMenuItemSeparators]):
+        New file, includes this method to strip leading, trailing, and duplicate separators from arrays
+        of NSMenuItems (copied from Safari)
+
+        * WebView/WebUIDelegatePrivate.h:
+        new MenuItemTag enum values for new PDFKit context menu items
+
+        * WebKit.xcodeproj/project.pbxproj:
+        updated for new files
+
+        * WebView/WebPDFView.mm:
+        (-[WebPDFView _anyPDFTagsFoundInMenu:]):
+        check for new PDFKit context menu items
+        (-[WebPDFView _menuItemsFromPDFKitForEvent:]):
+        associate new PDFKit context menu item selectors with the new tags; skip certain selectors that
+        correspond to menu items that WebKit already includes; remove useless menu item separators when
+        we're done, since we might have removed arbitrarily-placed menu items
+
 2007-04-11  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Maciej.
@@ -28,7 +55,6 @@
         * WebCoreSupport/WebPasteboardHelper.mm:
         (WebPasteboardHelper::insertablePasteboardTypes):
 
-=======
 2007-04-11  MorganL  <morganl.webkit@yahoo.com>
 
         Reviewed by Maciej.
@@ -45,7 +71,6 @@
         (WebChromeClient::createWindow):
         (WebChromeClient::createModalDialog):
 
->>>>>>> .r20857
 2007-04-10  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Darin
diff --git a/WebKit/Misc/WebNSArrayExtras.h b/WebKit/Misc/WebNSArrayExtras.h
new file mode 100644 (file)
index 0000000..5e3294d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSMutableArray (WebNSArrayExtras)
+
+- (void)_webkit_removeUselessMenuItemSeparators;
+
+@end
diff --git a/WebKit/Misc/WebNSArrayExtras.m b/WebKit/Misc/WebNSArrayExtras.m
new file mode 100644 (file)
index 0000000..efc655e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebNSArrayExtras.h"
+
+#import <JavaScriptCore/Assertions.h>
+
+@implementation NSMutableArray (WebExtras)
+
+- (void)_webkit_removeUselessMenuItemSeparators
+{
+    // Starting with a mutable array of NSMenuItems, removes any separators at the start,
+    // removes any separators at the end, and collapses any other adjacent separators to
+    // a single separator.
+
+    int index;
+    // Start this with YES so very last item will be removed if it's a separator.
+    BOOL removePreviousItemIfSeparator = YES;
+    for (index = [self count] - 1; index >= 0; --index) {
+        NSMenuItem *item = [self objectAtIndex:index];
+        ASSERT([item isKindOfClass:[NSMenuItem class]]);
+        BOOL itemIsSeparator = [item isSeparatorItem];
+        if (itemIsSeparator && (removePreviousItemIfSeparator || index == 0))
+            [self removeObjectAtIndex:index];
+        removePreviousItemIfSeparator = itemIsSeparator;
+    }
+    
+    // This could leave us with one initial separator; kill it off too
+    if ([self count] && [[self objectAtIndex:0] isSeparatorItem])
+        [self removeObjectAtIndex:0];
+}
+
+@end
index f453301..6d8dbdc 100644 (file)
                ED6BE2E8088C32B50044DEDC /* WebNSAttributedStringExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED6BE2E6088C32B50044DEDC /* WebNSAttributedStringExtras.mm */; };
                ED7F6D8B0980683500C235ED /* WebNSDataExtrasPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = ED7F6D8A0980683500C235ED /* WebNSDataExtrasPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                EDD6132C0AED9990000B75CA /* WebViewEditingContextMenuOld.nib in Resources */ = {isa = PBXBuildFile; fileRef = EDD6132A0AED9990000B75CA /* WebViewEditingContextMenuOld.nib */; };
+               EDE983800BCDF5FE00FDAE28 /* WebNSArrayExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE9837E0BCDF5FE00FDAE28 /* WebNSArrayExtras.h */; };
+               EDE983810BCDF5FE00FDAE28 /* WebNSArrayExtras.m in Sources */ = {isa = PBXBuildFile; fileRef = EDE9837F0BCDF5FE00FDAE28 /* WebNSArrayExtras.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXBuildRule section */
                EDD1A5C705C83987008E3150 /* WebNSPrintOperationExtras.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebNSPrintOperationExtras.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                EDD6132B0AED9990000B75CA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/WebViewEditingContextMenuOld.nib; sourceTree = "<group>"; };
                EDE850CD06ECC79E005FAB05 /* WebPreferenceKeysPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPreferenceKeysPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+               EDE9837E0BCDF5FE00FDAE28 /* WebNSArrayExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNSArrayExtras.h; sourceTree = "<group>"; };
+               EDE9837F0BCDF5FE00FDAE28 /* WebNSArrayExtras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebNSArrayExtras.m; sourceTree = "<group>"; };
                F508946902B71D59018A9CD4 /* WebNSViewExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebNSViewExtras.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                F508946A02B71D59018A9CD4 /* WebNSViewExtras.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebNSViewExtras.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                F5143A370221DCCE01A80181 /* WebFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebFrame.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                1C0D40860AC1C8F40009C113 /* WebKitVersionChecks.m */,
                                BEE18F990472B73200CA289C /* WebLocalizableStrings.h */,
                                BEE18F9A0472B73200CA289C /* WebLocalizableStrings.m */,
+                               EDE9837E0BCDF5FE00FDAE28 /* WebNSArrayExtras.h */,
+                               EDE9837F0BCDF5FE00FDAE28 /* WebNSArrayExtras.m */,
                                ED6BE2E5088C32B50044DEDC /* WebNSAttributedStringExtras.h */,
                                ED6BE2E6088C32B50044DEDC /* WebNSAttributedStringExtras.mm */,
                                65EEDE51084FFB920002DB25 /* WebNSCalendarDateExtras.h */,
                                51C714FB0B20F79F00E5E33C /* WebBackForwardListInternal.h in Headers */,
                                A70936AF0B5608DC00CDB48E /* WebDragClient.h in Headers */,
                                A7D3C5BC0B5773C5002CA450 /* WebPasteboardHelper.h in Headers */,
+                               EDE983800BCDF5FE00FDAE28 /* WebNSArrayExtras.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
+                       shouldCheckCompatibility = 1;
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );
                                1CCFFD130B1F81F2002EE926 /* OldWebAssertions.c in Sources */,
                                A70936B00B5608DC00CDB48E /* WebDragClient.mm in Sources */,
                                A7D3C5BD0B5773C5002CA450 /* WebPasteboardHelper.mm in Sources */,
+                               EDE983810BCDF5FE00FDAE28 /* WebNSArrayExtras.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 066d29d..072c0ee 100644 (file)
 #import "WebFrameInternal.h"
 #import "WebFrameView.h"
 #import "WebLocalizableStrings.h"
+#import "WebNSArrayExtras.h"
 #import "WebNSAttributedStringExtras.h"
 #import "WebNSPasteboardExtras.h"
 #import "WebNSViewExtras.h"
 #import "WebPDFRepresentation.h"
 #import "WebPreferencesPrivate.h"
 #import "WebUIDelegate.h"
+#import "WebUIDelegatePrivate.h"
 #import "WebView.h"
 #import "WebViewInternal.h"
 #import <WebCore/EventNames.h>
@@ -917,7 +919,9 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
             case WebMenuItemPDFZoomOut:
             case WebMenuItemPDFAutoSize:
             case WebMenuItemPDFSinglePage:
+            case WebMenuItemPDFSinglePageScrolling:
             case WebMenuItemPDFFacingPages:
+            case WebMenuItemPDFFacingPagesScrolling:
             case WebMenuItemPDFContinuous:
             case WebMenuItemPDFNextPage:
             case WebMenuItemPDFPreviousPage:
@@ -967,30 +971,51 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
         [NSNumber numberWithInt:WebMenuItemPDFZoomOut], NSStringFromSelector(@selector(zoomOut:)),
         [NSNumber numberWithInt:WebMenuItemPDFAutoSize], NSStringFromSelector(@selector(_setAutoSize:)),
         [NSNumber numberWithInt:WebMenuItemPDFSinglePage], NSStringFromSelector(@selector(_setSinglePage:)),
+        [NSNumber numberWithInt:WebMenuItemPDFSinglePageScrolling], NSStringFromSelector(@selector(_setSinglePageScrolling:)),
         [NSNumber numberWithInt:WebMenuItemPDFFacingPages], NSStringFromSelector(@selector(_setDoublePage:)),
+        [NSNumber numberWithInt:WebMenuItemPDFFacingPagesScrolling], NSStringFromSelector(@selector(_setDoublePageScrolling:)),
         [NSNumber numberWithInt:WebMenuItemPDFContinuous], NSStringFromSelector(@selector(_toggleContinuous:)),
         [NSNumber numberWithInt:WebMenuItemPDFNextPage], NSStringFromSelector(@selector(goToNextPage:)),
         [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.
+    NSSet *unwantedActions = [[NSSet alloc] initWithObjects:
+                              NSStringFromSelector(@selector(_searchInSpotlight:)),
+                              NSStringFromSelector(@selector(_searchInGoogle:)),
+                              NSStringFromSelector(@selector(_searchInDictionary:)),
+                              NSStringFromSelector(@selector(copy:)),
+                              nil];
+    
     NSEnumerator *e = [[[PDFSubview menuForEvent:theEvent] itemArray] objectEnumerator];
     NSMenuItem *item;
     while ((item = [e nextObject]) != nil) {
+        
+        NSString *actionString = NSStringFromSelector([item action]);
+        
+        if ([unwantedActions containsObject:actionString])
+            continue;
+        
         // Copy items since a menu item can be in only one menu at a time, and we don't
         // want to modify the original menu supplied by PDFKit.
         NSMenuItem *itemCopy = [item copy];
         [copiedItems addObject:itemCopy];
         
+        // Include all of PDFKit's separators for now. At the end we'll remove any ones that were made
+        // useless by removing PDFKit's menu items.
         if ([itemCopy isSeparatorItem])
             continue;
 
-        NSString *actionString = NSStringFromSelector([itemCopy action]);
         NSNumber *tagNumber = [actionsToTags objectForKey:actionString];
         
         int tag;
         if (tagNumber != nil)
             tag = [tagNumber intValue];
         else {
+            // This should happen only if PDFKit updates behind WebKit's back. It's non-ideal because clients that only include tags
+            // that they recognize (like Safari) won't get these PDFKit additions until WebKit is updated to match.
             tag = WebMenuItemTagOther;
             LOG_ERROR("no WebKit menu item tag found for PDF context menu item action \"%@\", using WebMenuItemTagOther", actionString);
         }
@@ -1007,6 +1032,12 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
     }
     
     [actionsToTags release];
+    [unwantedActions release];
+    
+    // Since we might have removed elements supplied by PDFKit, and we want to minimize our hardwired
+    // knowledge of the order and arrangement of PDFKit's menu items, we need to remove any bogus
+    // separators that were left behind.
+    [copiedItems _webkit_removeUselessMenuItemSeparators];
     
     return copiedItems;
 }
index 9e9f478..2ede934 100644 (file)
@@ -58,6 +58,8 @@ enum {
     WebMenuItemTagDefaultDirection,
     WebMenuItemTagLeftToRight,
     WebMenuItemTagRightToLeft,
+    WebMenuItemPDFSinglePageScrolling,
+    WebMenuItemPDFFacingPagesScrolling,
     WebMenuItemTagBaseApplication = 10000
 };