From: sullivan Date: Fri, 1 Jul 2005 21:30:52 +0000 (+0000) Subject: Reviewed by Darin Adler. X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=38e1983e842aebee29ad5301637ff39589211356 Reviewed by Darin Adler. - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=3711: Displayed PDF have limited options in contextual menu This was a problem with using Tiger's version of Safari with tip of tree WebKit. * WebView.subproj/WebPDFView.m: (-[WebPDFView _anyPDFTagsFoundInMenu:]): new method, returns YES if the menu contains any items with any of the new PDF-related tags. (-[WebPDFView menuForEvent:]): If the executable was linked on Tiger or older (but it will never be older, since this code is new to Tiger), force all of the PDF-related items into the menu if none of them were there after processing by the delegate. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9566 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog index 43c2b43..13bc224 100644 --- a/WebKit/ChangeLog +++ b/WebKit/ChangeLog @@ -1,3 +1,19 @@ +2005-07-01 John Sullivan + + Reviewed by Darin Adler. + + - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=3711: Displayed PDF have limited options in contextual menu + + This was a problem with using Tiger's version of Safari with tip of tree WebKit. + + * WebView.subproj/WebPDFView.m: + (-[WebPDFView _anyPDFTagsFoundInMenu:]): + new method, returns YES if the menu contains any items with any of the new PDF-related tags. + (-[WebPDFView menuForEvent:]): + If the executable was linked on Tiger or older (but it will never be older, since this code is + new to Tiger), force all of the PDF-related items into the menu if none of them were there + after processing by the delegate. + 2005-06-30 Darin Adler Reviewed by John Sullivan. diff --git a/WebKit/WebView.subproj/WebPDFView.m b/WebKit/WebView.subproj/WebPDFView.m index 53e5bc4..418025c 100644 --- a/WebKit/WebView.subproj/WebPDFView.m +++ b/WebKit/WebView.subproj/WebPDFView.m @@ -39,6 +39,7 @@ #import #import +#import #import // QuartzPrivate.h doesn't include the PDFKit private headers, so we can't get at PDFViewPriv.h. (3957971) @@ -230,6 +231,28 @@ static void applicationInfoForMIMEType(NSString *type, NSString **name, NSImage return copiedItems; } +- (BOOL)_anyPDFTagsFoundInMenu:(NSMenu *)menu +{ + NSEnumerator *e = [[menu itemArray] objectEnumerator]; + NSMenuItem *item; + while ((item = [e nextObject]) != nil) { + switch ([item tag]) { + case WebMenuItemTagOpenWithDefaultApplication: + case WebMenuItemPDFActualSize: + case WebMenuItemPDFZoomIn: + case WebMenuItemPDFZoomOut: + case WebMenuItemPDFAutoSize: + case WebMenuItemPDFSinglePage: + case WebMenuItemPDFFacingPages: + case WebMenuItemPDFContinuous: + case WebMenuItemPDFNextPage: + case WebMenuItemPDFPreviousPage: + return YES; + } + } + return NO; +} + - (NSMenu *)menuForEvent:(NSEvent *)theEvent { // Start with the menu items supplied by PDFKit, with WebKit tags applied @@ -258,7 +281,30 @@ static void applicationInfoForMIMEType(NSString *type, NSString **name, NSImage ASSERT(webView); // Currently clicks anywhere in the PDF view are treated the same, so we just pass NSZeroPoint; // we implement elementAtPoint: here just to be slightly forward-looking. - return [webView _menuForElement:[self elementAtPoint:NSZeroPoint] defaultItems:items]; + NSMenu *menu = [webView _menuForElement:[self elementAtPoint:NSZeroPoint] defaultItems:items]; + + // The delegate has now had the opportunity to add items to the standard PDF-related items, or to + // remove or modify some of the PDF-related items. In 10.4, the PDF context menu did not go through + // the standard WebKit delegate path, and so the standard PDF-related items always appeared. For + // clients that create their own context menu by hand-picking specific items from the default list, such as + // Safari, none of the PDF-related items will appear until the client is rewritten to explicitly + // include these items. So for backwards compatibility we're going to include the entire set of PDF-related + // items if the executable was linked in 10.4 or earlier and the menu returned from the delegate mechanism + // contains none of the PDF-related items. + if (WKExecutableLinkedInTigerOrEarlier()) { + if (![self _anyPDFTagsFoundInMenu:menu]) { + [menu addItem:[NSMenuItem separatorItem]]; + NSEnumerator *e = [items objectEnumerator]; + NSMenuItem *menuItem; + while ((menuItem = [e nextObject]) != nil) { + // copy menuItem since a given menuItem can be in only one menu at a time, and we don't + // want to mess with the menu returned from PDFKit. + [menu addItem:[menuItem copy]]; + } + } + } + + return menu; } - (void)_updateScalingToReflectTextSize