Title: [104215] branches/safari-534.54-branch/Source/WebKit2

Diff

Modified: branches/safari-534.54-branch/Source/WebKit2/ChangeLog (104214 => 104215)


--- branches/safari-534.54-branch/Source/WebKit2/ChangeLog	2012-01-05 22:00:07 UTC (rev 104214)
+++ branches/safari-534.54-branch/Source/WebKit2/ChangeLog	2012-01-05 22:01:31 UTC (rev 104215)
@@ -1,5 +1,26 @@
 2011-1-5  Lucas Forschler  <[email protected]>
 
+    Merge 98362
+
+    2011-10-25  John Sullivan  <[email protected]>
+
+            "Open with" item missing from PDF context menu in some cases
+            https://bugs.webkit.org/show_bug.cgi?id=70828
+            <rdar://problem/10034302>
+
+            Reviewed by Anders Carlsson.
+
+            * UIProcess/API/mac/PDFViewController.mm:
+            (insertOpenWithDefaultPDFMenuItem):
+            New helper function, extracted from -menuForEvent:. Identical to original code except
+            that it inserts the item at a specified index, rather than always at the end.
+            (-[WKPDFView menuForEvent:]):
+            Now keeps track of whether the Open With item has been inserted while iterating through
+            the PDFKit-supplied menu items looking for a "Copy" item. If a "Copy" item is not found,
+            inserts the Open With item at the top of the context menu.
+
+2011-1-5  Lucas Forschler  <[email protected]>
+
     Merge 98186
 
     2011-10-21  Sam Weinig  <[email protected]>

Modified: branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm (104214 => 104215)


--- branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm	2012-01-05 22:00:07 UTC (rev 104214)
+++ branches/safari-534.54-branch/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm	2012-01-05 22:01:31 UTC (rev 104215)
@@ -296,38 +296,56 @@
     return [super hitTest:point];
 }
 
+static void insertOpenWithDefaultPDFMenuItem(NSMenu *menu, NSUInteger index)
+{
+    // Add in an "Open with <default PDF viewer>" item
+    NSString *appName = nil;
+    NSImage *appIcon = nil;
+    
+    _applicationInfoForMIMEType(@"application/pdf", &appName, &appIcon);
+    if (!appName)
+        appName = WEB_UI_STRING("Finder", "Default application name for Open With context menu");
+    
+    // To match the PDFKit style, we'll add Open with Preview even when there's no document yet to view, and
+    // disable it using validateUserInterfaceItem.
+    NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Open with %@", "context menu item for PDF"), appName];
+    
+    NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:@selector(_openWithFinder:) keyEquivalent:@""];
+    if (appIcon)
+        [item setImage:appIcon];
+    [menu insertItem:item atIndex:index];
+    [item release];
+}
+
 - (NSMenu *)menuForEvent:(NSEvent *)theEvent
 {
     NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
 
+    bool insertedOpenWithItem = false;
+    
     NSEnumerator *menuItemEnumerator = [[[_pdfView menuForEvent:theEvent] itemArray] objectEnumerator];
     while (NSMenuItem *item = [menuItemEnumerator nextObject]) {
         NSMenuItem *itemCopy = [item copy];
         [menu addItem:itemCopy];
         [itemCopy release];
 
+        if (insertedOpenWithItem)
+            continue;
+        
+        // If a "Copy" item is present, place the "Open With" item just after it, with an intervening separator.
         if ([item action] != @selector(copy:))
             continue;
-
-        // Add in an "Open with <default PDF viewer>" item
-        NSString *appName = nil;
-        NSImage *appIcon = nil;
-
-        _applicationInfoForMIMEType(@"application/pdf", &appName, &appIcon);
-        if (!appName)
-            appName = WEB_UI_STRING("Finder", "Default application name for Open With context menu");
-
-        // To match the PDFKit style, we'll add Open with Preview even when there's no document yet to view, and
-        // disable it using validateUserInterfaceItem.
-        NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Open with %@", "context menu item for PDF"), appName];
-
-        item = [[NSMenuItem alloc] initWithTitle:title action:@selector(_openWithFinder:) keyEquivalent:@""];
-        if (appIcon)
-            [item setImage:appIcon];
+        
         [menu addItem:[NSMenuItem separatorItem]];
-        [menu addItem:item];
-        [item release];
+        insertOpenWithDefaultPDFMenuItem(menu, [menu numberOfItems]);
+        insertedOpenWithItem = true;
     }
+    
+    if (!insertedOpenWithItem) {
+        // No "Copy" item was found; place the "Open With" item at the top of the menu, with a trailing separator.
+        insertOpenWithDefaultPDFMenuItem(menu, 0);
+        [menu insertItem:[NSMenuItem separatorItem] atIndex:1];
+    }
 
     return [menu autorelease];
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to