Title: [176684] trunk/Source
Revision
176684
Author
[email protected]
Date
2014-12-02 12:36:08 -0800 (Tue, 02 Dec 2014)

Log Message

Should use standardQuickLookMenuItem for apps that don't implement customizations
https://bugs.webkit.org/show_bug.cgi?id=139193
-and corresponding-
rdar://problem/18944696

Reviewed by Anders Carlsson.

Source/WebCore:

New SPI headers.
* WebCore.xcodeproj/project.pbxproj:
* platform/spi/mac/NSMenuSPI.h: Added.
* platform/spi/mac/QuickLookMacSPI.h: Added.

Source/WebKit/mac:

Use [NSMenuItem standardQuickLookMenuItem].
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):

Delegate methods to set up the standardQuickLookMenuItem.
(-[WebActionMenuController menuItem:viewAtScreenPoint:]):
(-[WebActionMenuController menuItem:previewItemAtPoint:]):
(-[WebActionMenuController menuItem:preferredEdgeForPoint:]):

Remove all of the old QLPreviewBubble code.
(-[WebActionMenuController _createActionMenuItemForTag:]):
(-[WebActionMenuController _quickLookURLFromActionMenu:]): Deleted.

Source/WebKit2:

New SPI will allow clients to opt-out of the standardQuickLookMenuItem. By 
default, opt in.
* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _shouldUseStandardQuickLookPreview]):
* UIProcess/mac/WKActionMenuController.mm:

Use [NSMenuItem standardQuickLookMenuItem] unless the client has requested 
otherwise.
(-[WKActionMenuController _defaultMenuItemsForLink]):

Delegate methods to set up the standardQuickLookMenuItem.
(-[WKActionMenuController menuItem:viewAtScreenPoint:]):
(-[WKActionMenuController menuItem:previewItemAtPoint:]):
(-[WKActionMenuController menuItem:preferredEdgeForPoint:]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176683 => 176684)


--- trunk/Source/WebCore/ChangeLog	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebCore/ChangeLog	2014-12-02 20:36:08 UTC (rev 176684)
@@ -1,3 +1,17 @@
+2014-12-02  Beth Dakin  <[email protected]>
+
+        Should use standardQuickLookMenuItem for apps that don't implement customizations
+        https://bugs.webkit.org/show_bug.cgi?id=139193
+        -and corresponding-
+        rdar://problem/18944696
+
+        Reviewed by Anders Carlsson.
+
+        New SPI headers.
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/spi/mac/NSMenuSPI.h: Added.
+        * platform/spi/mac/QuickLookMacSPI.h: Added.
+
 2014-12-02  Gavin Barraclough  <[email protected]>
 
         Generalize PageActivityAssertionToken

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (176683 => 176684)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-12-02 20:36:08 UTC (rev 176684)
@@ -3265,6 +3265,8 @@
 		9362640B0DE1137D009D5A00 /* CSSReflectionDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9362640A0DE1137D009D5A00 /* CSSReflectionDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9370918D1416D86B00477333 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 9370918C1416D86B00477333 /* [email protected] */; };
 		9377ABA015DEFEEF0031FD04 /* Pagination.h in Headers */ = {isa = PBXBuildFile; fileRef = 9377AB9F15DEFEEF0031FD04 /* Pagination.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		937F4CCC1A2D48C100BB39F5 /* QuickLookMacSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 937F4CCB1A2D48C100BB39F5 /* QuickLookMacSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		937F4CCE1A2D4B0100BB39F5 /* NSMenuSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 937F4CCD1A2D4B0100BB39F5 /* NSMenuSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		937FF3D71A10131B008EBA31 /* DictionaryLookup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */; };
 		9380F47309A11AB4001FDB34 /* Widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47109A11AB4001FDB34 /* Widget.cpp */; };
@@ -10435,6 +10437,8 @@
 		936DD03A09CEAC270056AE8C /* Range.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Range.idl; sourceTree = "<group>"; };
 		9370918C1416D86B00477333 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
 		9377AB9F15DEFEEF0031FD04 /* Pagination.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pagination.h; sourceTree = "<group>"; };
+		937F4CCB1A2D48C100BB39F5 /* QuickLookMacSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookMacSPI.h; sourceTree = "<group>"; };
+		937F4CCD1A2D4B0100BB39F5 /* NSMenuSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSMenuSPI.h; sourceTree = "<group>"; };
 		937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryLookup.h; sourceTree = "<group>"; };
 		937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DictionaryLookup.mm; sourceTree = "<group>"; };
 		9380F47109A11AB4001FDB34 /* Widget.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Widget.cpp; sourceTree = "<group>"; };
@@ -17610,9 +17614,11 @@
 				2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */,
 				2D413F601A187A3F0041A521 /* LookupSPI.h */,
 				1C6466271A12C3F90094603C /* NSFontSPI.h */,
+				937F4CCD1A2D4B0100BB39F5 /* NSMenuSPI.h */,
 				2DCB837719F99BBA00A7FBE4 /* NSSharingServicePickerSPI.h */,
 				2DCB837819F99BBA00A7FBE4 /* NSSharingServiceSPI.h */,
 				9348428119F1A9190009D5AE /* NSViewSPI.h */,
+				937F4CCB1A2D48C100BB39F5 /* QuickLookMacSPI.h */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -23428,6 +23434,7 @@
 				93309DD7099E64920056E581 /* AppendNodeCommand.h in Headers */,
 				1A8F6BBD0DB55CDC001DB794 /* ApplicationCache.h in Headers */,
 				1A8F6BBF0DB55CDC001DB794 /* ApplicationCacheGroup.h in Headers */,
+				937F4CCC1A2D48C100BB39F5 /* QuickLookMacSPI.h in Headers */,
 				24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */,
 				1A8F6BC10DB55CDC001DB794 /* ApplicationCacheResource.h in Headers */,
 				1A2AAC590DC2A3B100A20D9A /* ApplicationCacheStorage.h in Headers */,
@@ -26075,6 +26082,7 @@
 				E4E9B1191810916F003ACCDF /* SimpleLineLayoutResolver.h in Headers */,
 				C5A1EA7D152BCF08004D00B6 /* SimplifyMarkupCommand.h in Headers */,
 				31741AAD16636609008A5B7E /* SimulatedClickOptions.h in Headers */,
+				937F4CCE1A2D4B0100BB39F5 /* NSMenuSPI.h in Headers */,
 				FD00D7A514A3F61900734011 /* SincResampler.h in Headers */,
 				51327D6011A33A2B004F9D65 /* SinkDocument.h in Headers */,
 				49E911CD0EF86D47009D0CAF /* SkewTransformOperation.h in Headers */,

Added: trunk/Source/WebCore/platform/spi/mac/NSMenuSPI.h (0 => 176684)


--- trunk/Source/WebCore/platform/spi/mac/NSMenuSPI.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/spi/mac/NSMenuSPI.h	2014-12-02 20:36:08 UTC (rev 176684)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2014 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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 "QuickLookMacSPI.h"
+
+#if USE(APPLE_INTERNAL_SDK) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101002
+
+#import <AppKit/NSMenu_Private.h>
+
+#else
+
+#import <AppKit/NSMenu.h>
+
+@interface NSMenuItem (Private)
++ (QLPreviewMenuItem *)standardQuickLookMenuItem;
+@end
+
+#endif

Added: trunk/Source/WebCore/platform/spi/mac/QuickLookMacSPI.h (0 => 176684)


--- trunk/Source/WebCore/platform/spi/mac/QuickLookMacSPI.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/spi/mac/QuickLookMacSPI.h	2014-12-02 20:36:08 UTC (rev 176684)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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.
+ */
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <QuickLookUI/QLPreviewItem.h>
+#import <QuickLookUI/QLPreviewMenuItem.h>
+
+#else
+
+@protocol QLPreviewItem <NSObject>
+@end
+
+@protocol QLPreviewMenuItemDelegate <NSObject>
+@optional
+
+- (NSView *)menuItem:(NSMenuItem *)menuItem viewAtScreenPoint:(NSPoint)screenPoint;
+- (id<QLPreviewItem>)menuItem:(NSMenuItem *)menuItem previewItemAtPoint:(NSPoint)point;
+- (NSRectEdge)menuItem:(NSMenuItem *)menuItem preferredEdgeForPoint:(NSPoint)point;
+
+@end
+
+@interface QLPreviewMenuItem : NSObject
+@end
+
+@interface QLPreviewMenuItem (Details)
+typedef NS_ENUM(NSInteger, QLPreviewStyle) {
+    QLPreviewStyleStandaloneWindow,
+    QLPreviewStylePopover
+};
+
+@property (assign) id<QLPreviewMenuItemDelegate> delegate;
+@property QLPreviewStyle previewStyle;
+@end
+
+#endif

Modified: trunk/Source/WebKit/mac/ChangeLog (176683 => 176684)


--- trunk/Source/WebKit/mac/ChangeLog	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-12-02 20:36:08 UTC (rev 176684)
@@ -1,3 +1,25 @@
+2014-12-02  Beth Dakin  <[email protected]>
+
+        Should use standardQuickLookMenuItem for apps that don't implement customizations
+        https://bugs.webkit.org/show_bug.cgi?id=139193
+        -and corresponding-
+        rdar://problem/18944696
+
+        Reviewed by Anders Carlsson.
+
+        Use [NSMenuItem standardQuickLookMenuItem].
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController _defaultMenuItemsForLink]):
+
+        Delegate methods to set up the standardQuickLookMenuItem.
+        (-[WebActionMenuController menuItem:viewAtScreenPoint:]):
+        (-[WebActionMenuController menuItem:previewItemAtPoint:]):
+        (-[WebActionMenuController menuItem:preferredEdgeForPoint:]):
+
+        Remove all of the old QLPreviewBubble code.
+        (-[WebActionMenuController _createActionMenuItemForTag:]):
+        (-[WebActionMenuController _quickLookURLFromActionMenu:]): Deleted.
+
 2014-12-02  Timothy Horton  <[email protected]>
 
         Fix the build.

Modified: trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm (176683 => 176684)


--- trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm	2014-12-02 20:36:08 UTC (rev 176684)
@@ -54,10 +54,12 @@
 #import <WebCore/FrameView.h>
 #import <WebCore/HTMLConverter.h>
 #import <WebCore/LookupSPI.h>
+#import <WebCore/NSMenuSPI.h>
 #import <WebCore/NSSharingServicePickerSPI.h>
 #import <WebCore/NSSharingServiceSPI.h>
 #import <WebCore/NSViewSPI.h>
 #import <WebCore/Page.h>
+#import <WebCore/QuickLookMacSPI.h>
 #import <WebCore/Range.h>
 #import <WebCore/RenderElement.h>
 #import <WebCore/RenderObject.h>
@@ -70,19 +72,12 @@
 #import <objc/objc.h>
 
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, QuickLookUI)
-SOFT_LINK_CLASS(QuickLookUI, QLPreviewBubble)
+SOFT_LINK_CLASS(QuickLookUI, QLPreviewMenuItem)
 
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, ImageKit)
 SOFT_LINK_CLASS(ImageKit, IKSlideshow)
 
-@class QLPreviewBubble;
-@interface NSObject (WKQLPreviewBubbleDetails)
-@property (copy) NSArray * controls;
-@property NSSize maximumSize;
-@property NSRectEdge preferredEdge;
-@property (retain) IBOutlet NSWindow* parentWindow;
-- (void)showPreviewItem:(id)previewItem itemFrame:(NSRect)frame;
-- (void)setAutomaticallyCloseWithMask:(NSEventMask)autocloseMask filterMask:(NSEventMask)filterMask block:(void (^)(void))block;
+@interface WebActionMenuController () <QLPreviewMenuItemDelegate>
 @end
 
 using namespace WebCore;
@@ -282,39 +277,14 @@
     return view->contentsToWindow(node->pixelSnappedBoundingBox());
 }
 
-- (void)_quickLookURLFromActionMenu:(id)sender
-{
-    if (!_webView)
-        return;
-
-    NSURL *url = ""
-    if (!url)
-        return;
-
-    Node* node = _hitTestResult.innerNode();
-    if (!node)
-        return;
-
-    NSRect itemFrame = elementBoundingBoxInWindowCoordinatesFromNode(node);
-    NSSize maximumPreviewSize = NSMakeSize(_webView.bounds.size.width * 0.75, _webView.bounds.size.height * 0.75);
-
-    RetainPtr<QLPreviewBubble> bubble = adoptNS([[getQLPreviewBubbleClass() alloc] init]);
-    [bubble setParentWindow:_webView.window];
-    [bubble setMaximumSize:maximumPreviewSize];
-    [bubble setPreferredEdge:NSMaxYEdge];
-    [bubble setControls:@[ ]];
-    NSEventMask filterMask = NSAnyEventMask & ~(NSAppKitDefinedMask | NSSystemDefinedMask | NSApplicationDefinedMask | NSMouseEnteredMask | NSMouseExitedMask);
-    NSEventMask autocloseMask = NSLeftMouseDownMask | NSRightMouseDownMask | NSKeyDownMask;
-    [bubble setAutomaticallyCloseWithMask:autocloseMask filterMask:filterMask block:[bubble] {
-        [bubble close];
-    }];
-    [bubble showPreviewItem:url itemFrame:itemFrame];
-}
-
 - (NSArray *)_defaultMenuItemsForLink
 {
     RetainPtr<NSMenuItem> openLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagOpenLinkInDefaultBrowser];
-    RetainPtr<NSMenuItem> previewLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagPreviewLink];
+
+    RetainPtr<QLPreviewMenuItem> previewLinkItem = [NSMenuItem standardQuickLookMenuItem];
+    [previewLinkItem setPreviewStyle:QLPreviewStylePopover];
+    [previewLinkItem setDelegate:self];
+
     RetainPtr<NSMenuItem> readingListItem = [self _createActionMenuItemForTag:WebActionMenuItemTagAddLinkToSafariReadingList];
 
     return @[ openLinkItem.get(), previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
@@ -748,6 +718,26 @@
     return _webView.window;
 }
 
+#pragma mark QLPreviewMenuItemDelegate implementation
+
+- (NSView *)menuItem:(NSMenuItem *)menuItem viewAtScreenPoint:(NSPoint)screenPoint
+{
+    return _webView;
+}
+
+- (id<QLPreviewItem>)menuItem:(NSMenuItem *)menuItem previewItemAtPoint:(NSPoint)point
+{
+    if (!_webView)
+        return nil;
+
+    return _hitTestResult.absoluteLinkURL();
+}
+
+- (NSRectEdge)menuItem:(NSMenuItem *)menuItem preferredEdgeForPoint:(NSPoint)point
+{
+    return NSMaxYEdge;
+}
+
 #pragma mark Menu Items
 
 - (RetainPtr<NSMenuItem>)_createActionMenuItemForTag:(uint32_t)tag
@@ -764,12 +754,6 @@
         image = [NSImage imageNamed:@"NSActionMenuOpenInNewWindow"];
         break;
 
-    case WebActionMenuItemTagPreviewLink:
-        selector = @selector(_quickLookURLFromActionMenu:);
-        title = WEB_UI_STRING_KEY("Preview", "Preview (action menu item)", "action menu item");
-        image = [NSImage imageNamed:@"NSActionMenuQuickLook"];
-        break;
-
     case WebActionMenuItemTagAddLinkToSafariReadingList:
         selector = @selector(_addToReadingListFromActionMenu:);
         title = WEB_UI_STRING_KEY("Add to Reading List", "Add to Reading List (action menu item)", "action menu item");

Modified: trunk/Source/WebKit2/ChangeLog (176683 => 176684)


--- trunk/Source/WebKit2/ChangeLog	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit2/ChangeLog	2014-12-02 20:36:08 UTC (rev 176684)
@@ -1,3 +1,28 @@
+2014-12-02  Beth Dakin  <[email protected]>
+
+        Should use standardQuickLookMenuItem for apps that don't implement customizations
+        https://bugs.webkit.org/show_bug.cgi?id=139193
+        -and corresponding-
+        rdar://problem/18944696
+
+        Reviewed by Anders Carlsson.
+
+        New SPI will allow clients to opt-out of the standardQuickLookMenuItem. By 
+        default, opt in.
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _shouldUseStandardQuickLookPreview]):
+        * UIProcess/mac/WKActionMenuController.mm:
+
+        Use [NSMenuItem standardQuickLookMenuItem] unless the client has requested 
+        otherwise.
+        (-[WKActionMenuController _defaultMenuItemsForLink]):
+
+        Delegate methods to set up the standardQuickLookMenuItem.
+        (-[WKActionMenuController menuItem:viewAtScreenPoint:]):
+        (-[WKActionMenuController menuItem:previewItemAtPoint:]):
+        (-[WKActionMenuController menuItem:preferredEdgeForPoint:]):
+
 2014-12-02  Tim Horton  <[email protected]>
 
         TextIndicator can get stuck (especially if we don't get LUNotificationPopoverWillClose when we should)

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h (176683 => 176684)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h	2014-12-02 20:36:08 UTC (rev 176684)
@@ -127,6 +127,7 @@
 - (void)_setPreviewTitle:(NSString *)previewTitle;
 - (void)_finishPreviewingURL:(NSURL *)url withPreviewView:(NSView *)previewView;
 - (void)_handleClickInPreviewView:(NSView *)previewView URL:(NSURL *)url;
+- (BOOL)_shouldUseStandardQuickLookPreview;
 
 - (void)_dismissActionMenuPopovers;
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (176683 => 176684)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-12-02 20:36:08 UTC (rev 176684)
@@ -4246,6 +4246,11 @@
     [[NSWorkspace sharedWorkspace] openURL:url];
 }
 
+- (BOOL)_shouldUseStandardQuickLookPreview
+{
+    return YES;
+}
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 
 - (void)_setAutomaticallyAdjustsContentInsets:(BOOL)automaticallyAdjustsContentInsets

Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (176683 => 176684)


--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-12-02 20:30:17 UTC (rev 176683)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-12-02 20:36:08 UTC (rev 176684)
@@ -45,20 +45,25 @@
 #import <WebCore/GeometryUtilities.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/LookupSPI.h>
+#import <WebCore/NSMenuSPI.h>
 #import <WebCore/NSSharingServiceSPI.h>
 #import <WebCore/NSSharingServicePickerSPI.h>
 #import <WebCore/NSViewSPI.h>
+#import <WebCore/QuickLookMacSPI.h>
 #import <WebCore/SoftLinking.h>
 #import <WebCore/TextIndicator.h>
 #import <WebCore/URL.h>
 
+SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, QuickLookUI)
+SOFT_LINK_CLASS(QuickLookUI, QLPreviewMenuItem)
+
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, ImageKit)
 SOFT_LINK_CLASS(ImageKit, IKSlideshow)
 
 using namespace WebCore;
 using namespace WebKit;
 
-@interface WKActionMenuController () <NSSharingServiceDelegate, NSSharingServicePickerDelegate, NSPopoverDelegate>
+@interface WKActionMenuController () <NSSharingServiceDelegate, NSSharingServicePickerDelegate, NSPopoverDelegate, QLPreviewMenuItemDelegate>
 - (void)_updateActionMenuItems;
 - (BOOL)_canAddMediaToPhotos;
 - (void)_showTextIndicator;
@@ -388,14 +393,25 @@
 - (NSArray *)_defaultMenuItemsForLink
 {
     RetainPtr<NSMenuItem> openLinkItem = [self _createActionMenuItemForTag:kWKContextActionItemTagOpenLinkInDefaultBrowser];
+
+    BOOL shouldUseStandardQuickLookPreview = [_wkView _shouldUseStandardQuickLookPreview];
+    RetainPtr<NSMenuItem> previewLinkItem;
+    RetainPtr<QLPreviewMenuItem> qlPreviewLinkItem;
+    if (shouldUseStandardQuickLookPreview) {
+        qlPreviewLinkItem = [NSMenuItem standardQuickLookMenuItem];
+        [qlPreviewLinkItem setPreviewStyle:QLPreviewStylePopover];
+        [qlPreviewLinkItem setDelegate:self];
+    } else {
 #if WK_API_ENABLED
-    RetainPtr<NSMenuItem> previewLinkItem = [self _createActionMenuItemForTag:kWKContextActionItemTagPreviewLink];
+        previewLinkItem = [self _createActionMenuItemForTag:kWKContextActionItemTagPreviewLink];
 #else
-    RetainPtr<NSMenuItem> previewLinkItem = [NSMenuItem separatorItem];
+        previewLinkItem = [NSMenuItem separatorItem];
 #endif
+    }
+
     RetainPtr<NSMenuItem> readingListItem = [self _createActionMenuItemForTag:kWKContextActionItemTagAddLinkToSafariReadingList];
 
-    return @[ openLinkItem.get(), previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
+    return @[ openLinkItem.get(), shouldUseStandardQuickLookPreview ? qlPreviewLinkItem.get() : previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
 }
 
 - (void)_openURLFromActionMenu:(id)sender
@@ -931,6 +947,27 @@
     [self _clearPreviewPopover];
 }
 
+#pragma mark QLPreviewMenuItemDelegate implementation
+
+- (NSView *)menuItem:(NSMenuItem *)menuItem viewAtScreenPoint:(NSPoint)screenPoint
+{
+    return _wkView;
+}
+
+- (id<QLPreviewItem>)menuItem:(NSMenuItem *)menuItem previewItemAtPoint:(NSPoint)point
+{
+    if (!_wkView)
+        return nil;
+
+    RefPtr<WebHitTestResult> hitTestResult = [self _webHitTestResult];
+    return [NSURL _web_URLWithWTFString:hitTestResult->absoluteLinkURL()];
+}
+
+- (NSRectEdge)menuItem:(NSMenuItem *)menuItem preferredEdgeForPoint:(NSPoint)point
+{
+    return NSMaxYEdge;
+}
+
 #pragma mark Menu Items
 
 - (RetainPtr<NSMenuItem>)_createActionMenuItemForTag:(uint32_t)tag
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to