Move the preview popover to WebImmediateActionController
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Dec 2014 23:11:41 +0000 (23:11 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Dec 2014 23:11:41 +0000 (23:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139563
<rdar://problem/19208291>

Reviewed by Beth Dakin.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):
(-[WebActionMenuController menuItem:viewAtScreenPoint:]): Deleted.
(-[WebActionMenuController menuItem:previewItemAtPoint:]): Deleted.
(-[WebActionMenuController menuItem:preferredEdgeForPoint:]): Deleted.
* WebView/WebImmediateActionController.h:
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController webViewClosed]):
(-[WebImmediateActionController immediateActionRecognizerWillPrepare:]):
(-[WebImmediateActionController immediateActionRecognizerWillBeginAnimation:]):
(-[WebImmediateActionController immediateActionRecognizerDidCancelAnimation:]):
(-[WebImmediateActionController immediateActionRecognizerDidCompleteAnimation:]):
(-[WebImmediateActionController _updateImmediateActionItem]):
(-[WebImmediateActionController menuItem:viewAtScreenPoint:]):
(-[WebImmediateActionController menuItem:previewItemAtPoint:]):
(-[WebImmediateActionController menuItem:preferredEdgeForPoint:]):
Move page preview popover related code to WebImmediateActionController.

* WebView/WebUIDelegatePrivate.h:
Add a link preview type.

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
Pass the gesture recognizer to the WebImmediateActionController.

* UIProcess/mac/WKImmediateActionController.h:
Remove an unnecessary forward declaration.

* UIProcess/mac/WKImmediateActionController.mm:
(-[WKImmediateActionController willDestroyView:]):
Clear the immediate action recognizer when the view goes away.

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit/mac/WebView/WebImmediateActionController.h
Source/WebKit/mac/WebView/WebImmediateActionController.mm
Source/WebKit/mac/WebView/WebUIDelegatePrivate.h
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/WKImmediateActionController.h
Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm

index 0d5fad8..ccadfe1 100644 (file)
@@ -1,5 +1,38 @@
 2014-12-11  Timothy Horton  <timothy_horton@apple.com>
 
+        Move the preview popover to WebImmediateActionController
+        https://bugs.webkit.org/show_bug.cgi?id=139563
+        <rdar://problem/19208291>
+
+        Reviewed by Beth Dakin.
+
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController _defaultMenuItemsForLink]):
+        (-[WebActionMenuController menuItem:viewAtScreenPoint:]): Deleted.
+        (-[WebActionMenuController menuItem:previewItemAtPoint:]): Deleted.
+        (-[WebActionMenuController menuItem:preferredEdgeForPoint:]): Deleted.
+        * WebView/WebImmediateActionController.h:
+        * WebView/WebImmediateActionController.mm:
+        (-[WebImmediateActionController webViewClosed]):
+        (-[WebImmediateActionController immediateActionRecognizerWillPrepare:]):
+        (-[WebImmediateActionController immediateActionRecognizerWillBeginAnimation:]):
+        (-[WebImmediateActionController immediateActionRecognizerDidCancelAnimation:]):
+        (-[WebImmediateActionController immediateActionRecognizerDidCompleteAnimation:]):
+        (-[WebImmediateActionController _updateImmediateActionItem]):
+        (-[WebImmediateActionController menuItem:viewAtScreenPoint:]):
+        (-[WebImmediateActionController menuItem:previewItemAtPoint:]):
+        (-[WebImmediateActionController menuItem:preferredEdgeForPoint:]):
+        Move page preview popover related code to WebImmediateActionController.
+
+        * WebView/WebUIDelegatePrivate.h:
+        Add a link preview type.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        Pass the gesture recognizer to the WebImmediateActionController.
+
+2014-12-11  Timothy Horton  <timothy_horton@apple.com>
+
         Fix the build.
 
         * WebView/WebImmediateActionController.h:
index 49b33c6..e0bd607 100644 (file)
 #import <objc/objc-class.h>
 #import <objc/objc.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)
 
-@interface WebActionMenuController () <QLPreviewMenuItemDelegate>
-@end
-
 using namespace WebCore;
 
 @implementation WebActionMenuController
@@ -268,20 +262,9 @@ static IntRect elementBoundingBoxInWindowCoordinatesFromNode(Node* node)
 - (NSArray *)_defaultMenuItemsForLink
 {
     RetainPtr<NSMenuItem> openLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagOpenLinkInDefaultBrowser];
-
-    BOOL shouldUseStandardQuickLookPreview = [NSMenuItem respondsToSelector:@selector(standardQuickLookMenuItem)];
-    RetainPtr<NSMenuItem> previewLinkItem;
-    RetainPtr<QLPreviewMenuItem> qlPreviewLinkItem;
-    if (shouldUseStandardQuickLookPreview) {
-        qlPreviewLinkItem = [NSMenuItem standardQuickLookMenuItem];
-        [qlPreviewLinkItem setPreviewStyle:QLPreviewStylePopover];
-        [qlPreviewLinkItem setDelegate:self];
-    } else
-        previewLinkItem = [NSMenuItem separatorItem];
-
     RetainPtr<NSMenuItem> readingListItem = [self _createActionMenuItemForTag:WebActionMenuItemTagAddLinkToSafariReadingList];
 
-    return @[ openLinkItem.get(), shouldUseStandardQuickLookPreview ? qlPreviewLinkItem.get() : previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
+    return @[ openLinkItem.get(), [NSMenuItem separatorItem], [NSMenuItem separatorItem], readingListItem.get() ];
 }
 
 #pragma mark mailto: and tel: Link actions
@@ -721,26 +704,6 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
     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
index 80bc96d..57e2939 100644 (file)
     WebView *_webView;
     WebImmediateActionType _type;
     WebCore::HitTestResult _hitTestResult;
+    NSImmediateActionGestureRecognizer *_immediateActionRecognizer;
 }
 
-- (instancetype)initWithWebView:(WebView *)webView;
+- (instancetype)initWithWebView:(WebView *)webView recognizer:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer;
 - (void)webViewClosed;
 
 @end
index 936edf4..888fb9a 100644 (file)
 #import "WebViewInternal.h"
 #import <WebCore/EventHandler.h>
 #import <WebCore/Frame.h>
+#import <WebCore/NSMenuSPI.h>
+#import <WebCore/SoftLinking.h>
 #import <objc/objc-class.h>
 #import <objc/objc.h>
 
+SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, QuickLookUI)
+SOFT_LINK_CLASS(QuickLookUI, QLPreviewMenuItem)
+
+@interface WebImmediateActionController () <QLPreviewMenuItemDelegate>
+@end
+
 using namespace WebCore;
 
 @implementation WebImmediateActionController
 
-- (instancetype)initWithWebView:(WebView *)webView
+- (instancetype)initWithWebView:(WebView *)webView recognizer:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
 {
     if (!(self = [super init]))
         return nil;
 
     _webView = webView;
     _type = WebImmediateActionNone;
+    _immediateActionRecognizer = immediateActionRecognizer;
 
     return self;
 }
@@ -55,6 +64,7 @@ using namespace WebCore;
 - (void)webViewClosed
 {
     _webView = nil;
+    _immediateActionRecognizer = nil;
 }
 
 - (void)_clearImmediateActionState
@@ -77,17 +87,18 @@ using namespace WebCore;
     if (!_webView)
         return;
 
-    if (immediateActionRecognizer.view != _webView)
+    if (immediateActionRecognizer != _immediateActionRecognizer)
         return;
 
     WebHTMLView *documentView = [[[_webView _selectedOrMainFrame] frameView] documentView];
     NSPoint locationInDocumentView = [immediateActionRecognizer locationInView:documentView];
     [self performHitTestAtPoint:locationInDocumentView];
+    [self _updateImmediateActionItem];
 }
 
 - (void)immediateActionRecognizerWillBeginAnimation:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
 {
-    if (immediateActionRecognizer.view != _webView)
+    if (immediateActionRecognizer != _immediateActionRecognizer)
         return;
 
     // FIXME: Add support for the types of functionality provided in Action menu's menuNeedsUpdate.
@@ -95,7 +106,7 @@ using namespace WebCore;
 
 - (void)immediateActionRecognizerDidCancelAnimation:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
 {
-    if (immediateActionRecognizer.view != _webView)
+    if (immediateActionRecognizer != _immediateActionRecognizer)
         return;
 
     [self _clearImmediateActionState];
@@ -103,7 +114,7 @@ using namespace WebCore;
 
 - (void)immediateActionRecognizerDidCompleteAnimation:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
 {
-    if (immediateActionRecognizer.view != _webView)
+    if (immediateActionRecognizer != _immediateActionRecognizer)
         return;
 
     // FIXME: Add support for the types of functionality provided in Action menu's willOpenMenu.
@@ -113,7 +124,40 @@ using namespace WebCore;
 
 - (void)_updateImmediateActionItem
 {
-    // FIXME: Implement. Inspect _hitTestResult to determine if there is an immediate action to take.
+    _type = WebImmediateActionNone;
+    _immediateActionRecognizer.animationController = nil;
+
+    NSURL *url = _hitTestResult.absoluteLinkURL();
+    NSString *absoluteURLString = [url absoluteString];
+    if (url && WebCore::protocolIsInHTTPFamily(absoluteURLString)) {
+        _type = WebImmediateActionLinkPreview;
+
+        RetainPtr<QLPreviewMenuItem> qlPreviewLinkItem = [NSMenuItem standardQuickLookMenuItem];
+        [qlPreviewLinkItem setPreviewStyle:QLPreviewStylePopover];
+        [qlPreviewLinkItem setDelegate:self];
+        _immediateActionRecognizer.animationController = (id<NSImmediateActionAnimationController>)qlPreviewLinkItem.get();
+        return;
+    }
+}
+
+#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;
 }
 
 @end
index 875109f..95e3d28 100644 (file)
@@ -146,6 +146,7 @@ typedef enum {
 
 typedef enum {
     WebImmediateActionNone = 0,
+    WebImmediateActionLinkPreview
 } WebImmediateActionType;
 
 // Message Sources.
index 409df49..0b1c6ad 100644 (file)
@@ -895,7 +895,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 
     if (Class gestureClass = NSClassFromString(@"NSImmediateActionGestureRecognizer")) {
         RetainPtr<NSImmediateActionGestureRecognizer> recognizer = adoptNS([(NSImmediateActionGestureRecognizer *)[gestureClass alloc] initWithTarget:nil action:NULL]);
-        _private->immediateActionController = [[WebImmediateActionController alloc] initWithWebView:self];
+        _private->immediateActionController = [[WebImmediateActionController alloc] initWithWebView:self recognizer:recognizer.get()];
         [recognizer setDelegate:_private->immediateActionController];
         [self addGestureRecognizer:recognizer.get()];
     }
index 7f8fb95..16c5055 100644 (file)
@@ -1,5 +1,20 @@
 2014-12-11  Timothy Horton  <timothy_horton@apple.com>
 
+        Move the preview popover to WebImmediateActionController
+        https://bugs.webkit.org/show_bug.cgi?id=139563
+        <rdar://problem/19208291>
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/mac/WKImmediateActionController.h:
+        Remove an unnecessary forward declaration.
+
+        * UIProcess/mac/WKImmediateActionController.mm:
+        (-[WKImmediateActionController willDestroyView:]):
+        Clear the immediate action recognizer when the view goes away.
+
+2014-12-11  Timothy Horton  <timothy_horton@apple.com>
+
         Fix the build.
 
         * UIProcess/mac/WKImmediateActionController.h:
index 61d188e..c8b41ab 100644 (file)
@@ -44,7 +44,6 @@ enum class ImmediateActionState {
 };
 }
 
-@class NSImmediateActionGestureRecognizer;
 @class WKPagePreviewViewController;
 @class WKView;
 
index 0a6cb70..9e54fc5 100644 (file)
@@ -77,6 +77,7 @@ using namespace WebKit;
     _page = nullptr;
     _wkView = nil;
     _hitTestResult = ActionMenuHitTestResult();
+    _immediateActionRecognizer = nil;
 }
 
 - (void)_clearImmediateActionState