Changeset 82852 in webkit
- Timestamp:
- Apr 4, 2011 12:19:01 PM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r82848 r82852 1 2011-03-30 Jer Noble <jer.noble@apple.com> 2 3 Reviewed by Dan Bernstein. 4 5 WebKit2: No "open in preview" contextual menu item for PDFs 6 https://bugs.webkit.org/show_bug.cgi?id=57527 7 8 Add support for opening a PDF in the associated application from the 9 context menu. 10 11 * UIProcess/API/mac/PDFViewController.mm: 12 (_applicationInfoForMIMEType): Added, copied from WebKit/WebPDFView.mm 13 (-[WKPDFView _openWithFinder:]): Added. 14 (-[WKPDFView hitTest:]): Added, copied from WebKit/WebPDFView.mm. 15 (-[WKPDFView menuForEvent:]): Added, adapted from WebKit/WebPDFVie.mm. 16 (-[WKPDFView validateUserInterfaceItem:]): Added. 17 1 18 2011-04-04 Chang Shu <cshu@webkit.org> 2 19 -
trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm
r82733 r82852 53 53 54 54 extern "C" NSString *_NSPathForSystemFramework(NSString *framework); 55 55 56 // MARK: C UTILITY FUNCTIONS 57 58 static void _applicationInfoForMIMEType(NSString *type, NSString **name, NSImage **image) 59 { 60 ASSERT(name); 61 ASSERT(image); 62 63 CFURLRef appURL = 0; 64 65 OSStatus error = LSCopyApplicationForMIMEType((CFStringRef)type, kLSRolesAll, &appURL); 66 if (error != noErr) 67 return; 68 69 NSString *appPath = [(NSURL *)appURL path]; 70 if (appURL) 71 CFRelease(appURL); 72 73 *image = [[NSWorkspace sharedWorkspace] iconForFile:appPath]; 74 [*image setSize:NSMakeSize(16, 16)]; 75 76 *name = [[NSFileManager defaultManager] displayNameAtPath:appPath]; 77 } 78 56 79 @interface WKPDFView : NSView 57 80 { … … 161 184 } 162 185 186 - (void)_openWithFinder:(id)sender 187 { 188 _pdfViewController->openPDFInFinder(); 189 } 190 191 // MARK: NSView overrides 192 163 193 - (void)viewDidMoveToWindow 164 194 { … … 183 213 } 184 214 185 // PDFView delegate methods 215 - (NSView *)hitTest:(NSPoint)point 216 { 217 // Override hitTest so we can override menuForEvent. 218 NSEvent *event = [NSApp currentEvent]; 219 NSEventType type = [event type]; 220 if (type == NSRightMouseDown || (type == NSLeftMouseDown && ([event modifierFlags] & NSControlKeyMask))) 221 return self; 222 223 return [super hitTest:point]; 224 } 225 226 - (NSMenu *)menuForEvent:(NSEvent *)theEvent 227 { 228 NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; 229 230 NSEnumerator *menuItemEnumerator = [[[_pdfView menuForEvent:theEvent] itemArray] objectEnumerator]; 231 while (NSMenuItem *item = [menuItemEnumerator nextObject]) { 232 NSMenuItem *itemCopy = [item copy]; 233 [menu addItem:itemCopy]; 234 [itemCopy release]; 235 236 if ([item action] != @selector(copy:)) 237 continue; 238 239 // Add in an "Open with <default PDF viewer>" item 240 NSString *appName = nil; 241 NSImage *appIcon = nil; 242 243 _applicationInfoForMIMEType(@"application/pdf", &appName, &appIcon); 244 if (!appName) { 245 // FIXME: Localize this. 246 appName = @"Finder"; 247 } 248 249 // To match the PDFKit style, we'll add Open with Preview even when there's no document yet to view, and 250 // disable it using validateUserInterfaceItem. 251 // FIXME: Localize this. 252 NSString *title = [NSString stringWithFormat:@"Open with %@", appName]; 253 item = [[NSMenuItem alloc] initWithTitle:title action:@selector(_openWithFinder:) keyEquivalent:@""]; 254 if (appIcon) 255 [item setImage:appIcon]; 256 [menu addItem:[NSMenuItem separatorItem]]; 257 [menu addItem:item]; 258 [item release]; 259 } 260 261 return [menu autorelease]; 262 } 263 264 // MARK: NSUserInterfaceValidations PROTOCOL IMPLEMENTATION 265 266 - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item 267 { 268 SEL action = [item action]; 269 if (action == @selector(_openWithFinder:)) 270 return [_pdfView document] != nil; 271 return YES; 272 } 273 274 // MARK: PDFView delegate methods 186 275 187 276 - (void)PDFViewWillClickOnLink:(PDFView *)sender withURL:(NSURL *)URL
Note: See TracChangeset
for help on using the changeset viewer.