Title: [177555] branches/safari-600.3-branch/Source

Diff

Modified: branches/safari-600.3-branch/Source/WebCore/ChangeLog (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebCore/ChangeLog	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebCore/ChangeLog	2014-12-19 02:56:54 UTC (rev 177555)
@@ -1,3 +1,19 @@
+2014-12-18  Matthew Hanson  <[email protected]>
+
+        Merge r177522. rdar://problem/19288547
+
+    2014-12-18  Timothy Horton  <[email protected]>
+
+            Change page preview loading order, and add a TextIndicator
+            https://bugs.webkit.org/show_bug.cgi?id=139793
+            <rdar://problem/19288547>
+
+            Reviewed by Beth Dakin.
+
+            * WebCore.exp.in:
+            * platform/spi/mac/NSPopoverSPI.h:
+            Add an export and some SPI.
+
 2014-12-17  Matthew Hanson  <[email protected]>
 
         Merge r177427. rdar://problem/19237945

Modified: branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in	2014-12-19 02:56:54 UTC (rev 177555)
@@ -679,6 +679,7 @@
 __ZN7WebCore15mimeTypeFromURLERKNS_3URLE
 __ZN7WebCore15originalURLDataEP5NSURL
 __ZN7WebCore15pathGetFileNameERKN3WTF6StringE
+__ZN7WebCore15rangeOfContentsERNS_4NodeE
 __ZN7WebCore15reportExceptionEPN3JSC9ExecStateENS0_7JSValueEPNS_12CachedScriptE
 __ZN7WebCore15setDOMExceptionEPN3JSC9ExecStateEi
 __ZN7WebCore15toDOMStringListEPN3JSC9ExecStateENS0_7JSValueE

Modified: branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/NSPopoverSPI.h (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/NSPopoverSPI.h	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/NSPopoverSPI.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -38,4 +38,13 @@
 @property NSRect positioningRect;
 @end
 
+typedef NS_OPTIONS(NSUInteger, NSPopoverPositioningOptions) {
+    NSPopoverPositioningOptionNone              = 0,
+    NSPopoverPositioningOptionKeepTopStable     = (1 << 0)
+};
+
+@interface NSPopover (WKDetails)
+@property NSPopoverPositioningOptions positioningOptions;
+@end
+
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000

Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog	2014-12-19 02:56:54 UTC (rev 177555)
@@ -1,3 +1,104 @@
+2014-12-18  Matthew Hanson  <[email protected]>
+
+        Merge r177522. rdar://problem/19288547
+
+    2014-12-18  Timothy Horton  <[email protected]>
+
+            Change page preview loading order, and add a TextIndicator
+            https://bugs.webkit.org/show_bug.cgi?id=139793
+            <rdar://problem/19288547>
+
+            Reviewed by Beth Dakin.
+
+            * Shared/mac/ActionMenuHitTestResult.h:
+            * Shared/mac/ActionMenuHitTestResult.mm:
+            (WebKit::ActionMenuHitTestResult::encode):
+            (WebKit::ActionMenuHitTestResult::decode):
+            * WebProcess/WebPage/mac/WebPageMac.mm:
+            (WebKit::WebPage::performActionMenuHitTestAtLocation):
+            Build a TextIndicator for links.
+
+            * UIProcess/API/Cocoa/WKViewPrivate.h:
+            * UIProcess/API/mac/WKView.mm:
+            (-[WKView _dismissContentRelativeChildWindows]):
+            (-[WKView _setPreviewTitle:]):
+            (-[WKView _setPreviewLoading:]):
+            Remove unneeded WK_API_ENABLED #ifs.
+
+            (-[WKView _setPreviewOverrideImage:]):
+            Add; forward to WKImmediateActionController.
+
+            * UIProcess/mac/WKImmediateActionController.h:
+            * UIProcess/mac/WKImmediateActionController.mm:
+            (-[WKImmediateActionController willDestroyView:]):
+            Shut down the WKPreviewPopoverAnimationController.
+
+            (-[WKImmediateActionController _clearImmediateActionState]):
+            (-[WKImmediateActionController immediateActionRecognizerWillPrepare:]):
+            Don't build an immediate action item here; we'll always build it in
+            willBeginAnimation, and the one we build here is likely to be wrong.
+
+            (-[WKImmediateActionController _defaultAnimationController]):
+            (-[WKImmediateActionController hidePreview]):
+            (-[WKImmediateActionController setPreviewTitle:]):
+            (-[WKImmediateActionController setPreviewLoading:]):
+            (-[WKImmediateActionController setPreviewOverrideImage:]):
+            (-[WKImmediateActionController _animationControllerForCustomPreview]):
+            (-[WKImmediateActionController _createPreviewPopoverIfNeededForURL:]): Deleted.
+            (-[WKImmediateActionController popoverWillClose:]): Deleted.
+            (targetSizeFitsInAvailableSpace): Deleted.
+            (-[WKImmediateActionController largestPopoverSize]): Deleted.
+            (-[WKImmediateActionController _preferredPopoverSizeWithPreviewPadding:]): Deleted.
+            (-[WKImmediateActionController pagePreviewViewController:viewForPreviewingURL:initialFrameSize:]): Deleted.
+            (-[WKImmediateActionController pagePreviewViewController:titleForPreviewOfURL:]): Deleted.
+            (-[WKImmediateActionController pagePreviewViewControllerWasClicked:]): Deleted.
+            Move preview popover code to WKPreviewPopoverAnimationController.
+            Install and uninstall the link text indicator when necessary.
+
+            * UIProcess/mac/WKPagePreviewViewController.h:
+            * UIProcess/mac/WKPagePreviewViewController.mm:
+            (-[WKPagePreviewViewController setLoading:]):
+            (-[WKPagePreviewViewController loadView]):
+            (-[WKPagePreviewViewController replacePreviewWithImage:atSize:]):
+            Allow overriding the preview with a full-view NSImage.
+            Hide the preview view until the loading spinner goes away.
+
+            * UIProcess/mac/WKPreviewPopoverAnimationController.h: Copied from Source/WebKit2/UIProcess/mac/WKImmediateActionController.h.
+            * UIProcess/mac/WKPreviewPopoverAnimationController.mm: Added.
+            (+[WKPreviewPopoverAnimationController _shouldImmediatelyShowPreview]):
+            (-[WKPreviewPopoverAnimationController initWithURL:view:page:originRect:eventLocationInView:]):
+            (-[WKPreviewPopoverAnimationController close]):
+            (-[WKPreviewPopoverAnimationController setPreviewLoading:]):
+            (-[WKPreviewPopoverAnimationController setPreviewOverrideImage:]):
+            If we have shown the popover, choose a size strictly smaller than
+            its current size.
+
+            (-[WKPreviewPopoverAnimationController _hidePreview]):
+            (-[WKPreviewPopoverAnimationController setPreviewTitle:]):
+            (-[WKPreviewPopoverAnimationController _createPreviewPopover]):
+            (-[WKPreviewPopoverAnimationController _showPreview]):
+            (targetSizeFitsInAvailableSpace):
+            (-[WKPreviewPopoverAnimationController largestPopoverSize]):
+            (-[WKPreviewPopoverAnimationController _targetSizeForPagePreview]):
+            (-[WKPreviewPopoverAnimationController _preferredPopoverSizeWithPreviewPadding:forTargetSize:]):
+            (-[WKPreviewPopoverAnimationController _previewWatchdogTimerFired:]):
+            (-[WKPreviewPopoverAnimationController recognizerWillBeginAnimation:]):
+            (-[WKPreviewPopoverAnimationController recognizerDidUpdateAnimation:]):
+            (-[WKPreviewPopoverAnimationController recognizerDidCancelAnimation:]):
+            (-[WKPreviewPopoverAnimationController recognizerDidCompleteAnimation:]):
+            (-[WKPreviewPopoverAnimationController recognizerDidDismissAnimation:]):
+            (-[WKPreviewPopoverAnimationController pagePreviewViewController:viewForPreviewingURL:initialFrameSize:]):
+            (-[WKPreviewPopoverAnimationController pagePreviewViewController:titleForPreviewOfURL:]):
+            (-[WKPreviewPopoverAnimationController pagePreviewViewControllerWasClicked:]):
+            (-[WKPreviewPopoverAnimationController popoverWillClose:]):
+            Move code in from WKImmediateActionController.
+            Forward NSImmediateActionAnimationControllerDelegate methods
+            to the popover's animation controller if we've popped it.
+            Pop the popover if we've loaded or 1 second has passed, whichever
+            comes first.
+
+            * WebKit2.xcodeproj/project.pbxproj:
+
 2014-12-17  Matthew Hanson  <[email protected]>
 
         Merge r177473. rdar://problem/19286550

Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -62,6 +62,8 @@
     WebCore::PageOverlay::PageOverlayID detectedDataOriginatingPageOverlay;
 
     DictionaryPopupInfo dictionaryPopupInfo;
+
+    RefPtr<WebCore::TextIndicator> linkTextIndicator;
 };
 
 } // namespace WebKit

Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -63,13 +63,18 @@
         encoder << detectedDataBoundingBox;
         encoder << detectedDataOriginatingPageOverlay;
 
-        bool hasTextIndicator = detectedDataTextIndicator;
-        encoder << hasTextIndicator;
-        if (hasTextIndicator)
+        bool hasDetectedDataTextIndicator = detectedDataTextIndicator;
+        encoder << hasDetectedDataTextIndicator;
+        if (hasDetectedDataTextIndicator)
             encoder << detectedDataTextIndicator->data();
     }
 
     encoder << dictionaryPopupInfo;
+
+    bool hasLinkTextIndicator = linkTextIndicator;
+    encoder << hasLinkTextIndicator;
+    if (hasLinkTextIndicator)
+        encoder << linkTextIndicator->data();
 }
 
 bool ActionMenuHitTestResult::decode(IPC::ArgumentDecoder& decoder, ActionMenuHitTestResult& actionMenuHitTestResult)
@@ -119,11 +124,11 @@
         if (!decoder.decode(actionMenuHitTestResult.detectedDataOriginatingPageOverlay))
             return false;
 
-        bool hasTextIndicator;
-        if (!decoder.decode(hasTextIndicator))
+        bool hasDetectedDataTextIndicator;
+        if (!decoder.decode(hasDetectedDataTextIndicator))
             return false;
 
-        if (hasTextIndicator) {
+        if (hasDetectedDataTextIndicator) {
             WebCore::TextIndicatorData indicatorData;
             if (!decoder.decode(indicatorData))
                 return false;
@@ -135,6 +140,18 @@
     if (!decoder.decode(actionMenuHitTestResult.dictionaryPopupInfo))
         return false;
 
+    bool hasLinkTextIndicator;
+    if (!decoder.decode(hasLinkTextIndicator))
+        return false;
+
+    if (hasLinkTextIndicator) {
+        WebCore::TextIndicatorData indicatorData;
+        if (!decoder.decode(indicatorData))
+            return false;
+
+        actionMenuHitTestResult.linkTextIndicator = WebCore::TextIndicator::create(indicatorData);
+    }
+
     return true;
 }
     

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -132,6 +132,7 @@
 - (NSString *)_titleForPreviewOfURL:(NSURL *)url;
 - (void)_setPreviewTitle:(NSString *)previewTitle;
 - (void)_setPreviewLoading:(BOOL)loading;
+- (void)_setPreviewOverrideImage:(NSImage *)image;
 - (void)_finishPreviewingURL:(NSURL *)url withPreviewView:(NSView *)previewView;
 - (void)_handleClickInPreviewView:(NSView *)previewView URL:(NSURL *)url;
 - (BOOL)_shouldUseStandardQuickLookPreview;

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -4324,7 +4324,7 @@
     if ([actionsManager respondsToSelector:@selector(requestBubbleClosureUnanchorOnFailure:)])
         [actionsManager requestBubbleClosureUnanchorOnFailure:YES];
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     [_data->_immediateActionController hidePreview];
 #endif
 
@@ -4345,18 +4345,23 @@
 
 - (void)_setPreviewTitle:(NSString *)previewTitle
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     [_data->_immediateActionController setPreviewTitle:previewTitle];
 #endif
 }
 
 - (void)_setPreviewLoading:(BOOL)loading
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     [_data->_immediateActionController setPreviewLoading:loading];
 #endif
 }
 
+- (void)_setPreviewOverrideImage:(NSImage *)image
+{
+    [_data->_immediateActionController setPreviewOverrideImage:image];
+}
+
 - (void)_finishPreviewingURL:(NSURL *)url withPreviewView:(NSView *)previewView
 {
 }

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.h (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.h	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -46,6 +46,7 @@
 
 @class DDActionContext;
 @class WKPagePreviewViewController;
+@class WKPreviewPopoverAnimationController;
 @class WKView;
 
 @interface WKImmediateActionController : NSObject <NSImmediateActionGestureRecognizerDelegate> {
@@ -64,12 +65,7 @@
     BOOL _hasActivatedActionContext;
     RetainPtr<DDActionContext> _currentActionContext;
 
-#if WK_API_ENABLED
-    RetainPtr<NSPopover> _previewPopover;
-    String _previewPopoverOriginalURL;
-    NSRect _popoverOriginRect;
-    RetainPtr<WKPagePreviewViewController> _previewViewController;
-#endif
+    RetainPtr<WKPreviewPopoverAnimationController> _previewAnimationController;
 }
 
 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(WKView *)wkView recognizer:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer;
@@ -77,11 +73,10 @@
 - (void)didPerformActionMenuHitTest:(const WebKit::ActionMenuHitTestResult&)hitTestResult userData:(API::Object*)userData;
 - (void)wkView:(WKView *)wkView willHandleMouseDown:(NSEvent *)event;
 
-#if WK_API_ENABLED
 - (void)hidePreview;
 - (void)setPreviewTitle:(NSString *)previewTitle;
 - (void)setPreviewLoading:(BOOL)loading;
-#endif // WK_API_ENABLED
+- (void)setPreviewOverrideImage:(NSImage *)image;
 
 @end
 

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -30,13 +30,13 @@
 
 #import "WKNSURLExtras.h"
 #import "WKPagePreviewViewController.h"
+#import "WKPreviewPopoverAnimationController.h"
 #import "WKViewInternal.h"
 #import "WebPageMessages.h"
 #import "WebPageProxy.h"
 #import "WebPageProxyMessages.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DataDetectorsSPI.h>
-#import <WebCore/GeometryUtilities.h>
 #import <WebCore/LookupSPI.h>
 #import <WebCore/NSMenuSPI.h>
 #import <WebCore/NSPopoverSPI.h>
@@ -51,14 +51,9 @@
 using namespace WebCore;
 using namespace WebKit;
 
-@interface WKImmediateActionController () <NSPopoverDelegate, QLPreviewMenuItemDelegate>
+@interface WKImmediateActionController () <QLPreviewMenuItemDelegate>
 @end
 
-#if WK_API_ENABLED
-@interface WKImmediateActionController () <WKPagePreviewViewControllerDelegate>
-@end
-#endif
-
 @implementation WKImmediateActionController
 
 - (instancetype)initWithPage:(WebPageProxy&)page view:(WKView *)wkView recognizer:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
@@ -78,6 +73,8 @@
 
 - (void)willDestroyView:(WKView *)view
 {
+    [_previewAnimationController close];
+
     _page = nullptr;
     _wkView = nil;
     _hitTestResult = ActionMenuHitTestResult();
@@ -101,9 +98,7 @@
 
 - (void)_clearImmediateActionState
 {
-#if WK_API_ENABLED
     [self hidePreview];
-#endif
 
     _page->clearTextIndicator();
 
@@ -144,7 +139,7 @@
     _page->performActionMenuHitTestAtLocation(_eventLocationInView, true);
 
     _state = ImmediateActionState::Pending;
-    [self _updateImmediateActionItem];
+    immediateActionRecognizer.animationController = nil;
 }
 
 - (void)immediateActionRecognizerWillBeginAnimation:(NSImmediateActionGestureRecognizer *)immediateActionRecognizer
@@ -243,14 +238,10 @@
             return (id<NSImmediateActionAnimationController>)qlPreviewLinkItem.get();
         }
 
-#if WK_API_ENABLED
-        [self _createPreviewPopoverIfNeededForURL:absoluteLinkURL];
         if (id<NSImmediateActionAnimationController> previewController = [self _animationControllerForCustomPreview])
             return previewController;
-        return (id<NSImmediateActionAnimationController>)_previewPopover.get();
-#else
         return nil;
-#endif // WK_API_ENABLED
+
     }
 
     if (hitTestResult->isTextNode() || hitTestResult->isOverTextInsideFormControlElement()) {
@@ -288,189 +279,39 @@
 
 #pragma mark Link Preview action
 
-#if WK_API_ENABLED
-
-- (void)_createPreviewPopoverIfNeededForURL:(String)absoluteLinkURL
-{
-    if (_previewPopoverOriginalURL == absoluteLinkURL)
-        return;
-
-    _previewPopoverOriginalURL = absoluteLinkURL;
-
-    NSURL *url = "" _web_URLWithWTFString:absoluteLinkURL];
-    RefPtr<WebHitTestResult> hitTestResult = [self _webHitTestResult];
-    _popoverOriginRect = hitTestResult->elementBoundingBox();
-
-    NSSize previewPadding = [WKPagePreviewViewController previewPadding];
-    NSSize popoverSize = [self _preferredPopoverSizeWithPreviewPadding:previewPadding];
-    CGFloat actualPopoverToViewScale = popoverSize.width / NSWidth(_wkView.bounds);
-    popoverSize.width += previewPadding.width;
-    popoverSize.height += previewPadding.height;
-
-    _previewViewController = adoptNS([[WKPagePreviewViewController alloc] initWithPageURL:url mainViewSize:_wkView.bounds.size popoverToViewScale:actualPopoverToViewScale]);
-    _previewViewController->_delegate = self;
-    [_previewViewController setLoading:YES];
-    [_previewViewController loadView];
-
-    _previewPopover = adoptNS([[NSPopover alloc] init]);
-    [_previewPopover setBehavior:NSPopoverBehaviorTransient];
-    [_previewPopover setContentSize:popoverSize];
-    [_previewPopover setContentViewController:_previewViewController.get()];
-    [_previewPopover setDelegate:self];
-}
-
 - (void)hidePreview
 {
-    if (_previewViewController) {
-        _previewViewController->_delegate = nil;
-        [_wkView _finishPreviewingURL:_previewViewController->_url.get() withPreviewView:_previewViewController->_previewView.get()];
-        _previewViewController = nil;
-    }
-
-    [_previewPopover close];
-    [_previewPopover setDelegate:nil];
-    _previewPopover = nil;
-    _previewPopoverOriginalURL = String();
+    [_previewAnimationController close];
 }
 
 - (void)setPreviewTitle:(NSString *)previewTitle
 {
-    [_previewViewController setPreviewTitle:previewTitle];
+    [_previewAnimationController setPreviewTitle:previewTitle];
 }
 
 - (void)setPreviewLoading:(BOOL)loading
 {
-    [_previewViewController setLoading:loading];
+    [_previewAnimationController setPreviewLoading:loading];
 }
 
-- (void)popoverWillClose:(NSNotification *)notification
+- (void)setPreviewOverrideImage:(NSImage *)image
 {
-    [self hidePreview];
+    [_previewAnimationController setPreviewOverrideImage:image];
 }
 
-static bool targetSizeFitsInAvailableSpace(NSSize targetSize, NSSize availableSpace)
-{
-    return targetSize.width <= availableSpace.width && targetSize.height <= availableSpace.height;
-}
-
-- (NSSize)largestPopoverSize
-{
-    NSSize screenSize = _wkView.window.screen.frame.size;
-
-    if (screenSize.width == 1280 && screenSize.height == 800)
-        return NSMakeSize(1240, 674);
-
-    if (screenSize.width == 1366 && screenSize.height == 768)
-        return NSMakeSize(1264, 642);
-
-    if (screenSize.width == 1440 && screenSize.height == 900)
-        return NSMakeSize(1264, 760);
-
-    if (screenSize.width == 1680 && screenSize.height == 1050)
-        return NSMakeSize(1324, 910);
-
-    return NSMakeSize(1324, 940);
-}
-
-- (NSSize)_preferredPopoverSizeWithPreviewPadding:(NSSize)previewPadding
-{
-    static const CGFloat preferredPopoverToViewScale = 0.75;
-    static const NSSize screenPadding = {40, 40};
-    static const NSSize smallestPopoverSize = NSMakeSize(500, 500);
-
-    const NSSize effectivePadding = NSMakeSize(screenPadding.width + previewPadding.width, screenPadding.height + previewPadding.height);
-
-    NSWindow *window = _wkView.window;
-    NSRect originScreenRect = [window convertRectToScreen:[_wkView convertRect:_popoverOriginRect toView:nil]];
-    NSRect screenFrame = window.screen.visibleFrame;
-
-    NSRect wkViewBounds = _wkView.bounds;
-    NSSize targetSize = NSMakeSize(NSWidth(wkViewBounds) * preferredPopoverToViewScale, NSHeight(wkViewBounds) * preferredPopoverToViewScale);
-    NSSize largestPopoverSize = [self largestPopoverSize];
-
-    CGFloat availableSpaceAbove = NSMaxY(screenFrame) - NSMaxY(originScreenRect);
-    CGFloat availableSpaceBelow = NSMinY(originScreenRect) - NSMinY(screenFrame);
-    CGFloat maxAvailableVerticalSpace = fmax(availableSpaceAbove, availableSpaceBelow) - effectivePadding.height;
-    NSSize maxSpaceAvailableOnYEdge = NSMakeSize(screenFrame.size.width - effectivePadding.height, maxAvailableVerticalSpace);
-    if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnYEdge) && targetSizeFitsInAvailableSpace(targetSize, largestPopoverSize))
-        return targetSize;
-
-    CGFloat availableSpaceAtLeft = NSMinX(originScreenRect) - NSMinX(screenFrame);
-    CGFloat availableSpaceAtRight = NSMaxX(screenFrame) - NSMaxX(originScreenRect);
-    CGFloat maxAvailableHorizontalSpace = fmax(availableSpaceAtLeft, availableSpaceAtRight) - effectivePadding.width;
-    NSSize maxSpaceAvailableOnXEdge = NSMakeSize(maxAvailableHorizontalSpace, screenFrame.size.height - effectivePadding.width);
-    if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnXEdge) && targetSizeFitsInAvailableSpace(targetSize, largestPopoverSize))
-        return targetSize;
-
-    // Adjust the maximum space available if it is larger than the largest popover size.
-    if (maxSpaceAvailableOnYEdge.width > largestPopoverSize.width && maxSpaceAvailableOnYEdge.height > largestPopoverSize.height)
-        maxSpaceAvailableOnYEdge = largestPopoverSize;
-    if (maxSpaceAvailableOnXEdge.width > largestPopoverSize.width && maxSpaceAvailableOnXEdge.height > largestPopoverSize.height)
-        maxSpaceAvailableOnXEdge = largestPopoverSize;
-
-    // If the target size doesn't fit anywhere, we'll find the largest rect that does fit that also maintains the original view's aspect ratio.
-    CGFloat aspectRatio = wkViewBounds.size.width / wkViewBounds.size.height;
-    FloatRect maxVerticalTargetSizePreservingAspectRatioRect = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(0, 0, maxSpaceAvailableOnYEdge.width, maxSpaceAvailableOnYEdge.height));
-    FloatRect maxHorizontalTargetSizePreservingAspectRatioRect = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(0, 0, maxSpaceAvailableOnXEdge.width, maxSpaceAvailableOnXEdge.height));
-
-    NSSize maxVerticalTargetSizePreservingAspectRatio = NSMakeSize(maxVerticalTargetSizePreservingAspectRatioRect.width(), maxVerticalTargetSizePreservingAspectRatioRect.height());
-    NSSize maxHortizontalTargetSizePreservingAspectRatio = NSMakeSize(maxHorizontalTargetSizePreservingAspectRatioRect.width(), maxHorizontalTargetSizePreservingAspectRatioRect.height());
-
-    NSSize computedTargetSize;
-    if ((maxVerticalTargetSizePreservingAspectRatio.width * maxVerticalTargetSizePreservingAspectRatio.height) > (maxHortizontalTargetSizePreservingAspectRatio.width * maxHortizontalTargetSizePreservingAspectRatio.height))
-        computedTargetSize = maxVerticalTargetSizePreservingAspectRatio;
-    else
-        computedTargetSize = maxHortizontalTargetSizePreservingAspectRatio;
-
-    // Now make sure what we've computed isn't too small.
-    if (computedTargetSize.width < smallestPopoverSize.width && computedTargetSize.height < smallestPopoverSize.height) {
-        float limitWidth = smallestPopoverSize.width > computedTargetSize.width ? smallestPopoverSize.width : computedTargetSize.width;
-        float limitHeight = smallestPopoverSize.height > computedTargetSize.height ? smallestPopoverSize.height : computedTargetSize.height;
-        FloatRect targetRectLargerThanMinSize = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(0, 0, limitWidth, limitHeight));
-        computedTargetSize = NSMakeSize(targetRectLargerThanMinSize.size().width(), targetRectLargerThanMinSize.size().height());
-
-        // If our orignal computedTargetSize was so small that we had to get here and make a new computedTargetSize that is
-        // larger than the minimum, then the elementBoundingBox of the _hitTestResult is probably huge. So we should use
-        // the event origin as the popover origin in this case and not worry about obscuring the _hitTestResult.
-        _popoverOriginRect.origin = _eventLocationInView;
-        _popoverOriginRect.size = NSMakeSize(1, 1);
-    }
-    
-    return computedTargetSize;
-}
-
 - (id<NSImmediateActionAnimationController>)_animationControllerForCustomPreview
 {
-    Class nsPopoverAnimationControllerClass = NSClassFromString(@"NSPopoverAnimationController");
-    if (!nsPopoverAnimationControllerClass)
-        return nil;
-    NSPopoverAnimationController *popoverController = [nsPopoverAnimationControllerClass popoverAnimationControllerWithPopover:_previewPopover.get()];
-    popoverController.preferredEdge = NSMaxYEdge;
-    popoverController.anchorView = _wkView;
-    popoverController.positioningRect = _popoverOriginRect;
-    return popoverController;
-}
+    RefPtr<WebHitTestResult> hitTestResult = [self _webHitTestResult];
+    RetainPtr<NSURL> url = "" _web_URLWithWTFString:hitTestResult->absoluteLinkURL()];
 
-#pragma mark WKPagePreviewViewControllerDelegate
+    if (_hitTestResult.linkTextIndicator)
+        _page->setTextIndicator(_hitTestResult.linkTextIndicator->data(), false);
 
-- (NSView *)pagePreviewViewController:(WKPagePreviewViewController *)pagePreviewViewController viewForPreviewingURL:(NSURL *)url initialFrameSize:(NSSize)initialFrameSize
-{
-    return [_wkView _viewForPreviewingURL:url initialFrameSize:initialFrameSize];
-}
+    _previewAnimationController = adoptNS([[WKPreviewPopoverAnimationController alloc] initWithURL:url.get() view:_wkView page:*_page originRect:hitTestResult->elementBoundingBox() eventLocationInView:_eventLocationInView]);
 
-- (NSString *)pagePreviewViewController:(WKPagePreviewViewController *)pagePreviewViewController titleForPreviewOfURL:(NSURL *)url
-{
-    return [_wkView _titleForPreviewOfURL:url];
+    return _previewAnimationController.get();
 }
 
-- (void)pagePreviewViewControllerWasClicked:(WKPagePreviewViewController *)pagePreviewViewController
-{
-    if (NSURL *url = ""
-        [_wkView _handleClickInPreviewView:pagePreviewViewController->_previewView.get() URL:url];
-}
-
-#endif // WK_API_ENABLED
-
 #pragma mark QLPreviewMenuItemDelegate implementation
 
 - (NSView *)menuItem:(NSMenuItem *)menuItem viewAtScreenPoint:(NSPoint)screenPoint

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.h (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.h	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -59,6 +59,7 @@
 @property (nonatomic, getter=isLoading) BOOL loading;
 
 - (instancetype)initWithPageURL:(NSURL *)URL mainViewSize:(NSSize)size popoverToViewScale:(CGFloat)scale;
+- (void)replacePreviewWithImage:(NSImage *)image atSize:(NSSize)size;
 
 + (NSSize)previewPadding;
 

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.mm (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.mm	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -26,10 +26,8 @@
 #import "config.h"
 #import "WKPagePreviewViewController.h"
 
-#import "WKWebViewInternal.h"
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
-
 static const CGFloat previewViewInset = 3;
 static const CGFloat previewViewTitleHeight = 34;
 
@@ -74,6 +72,8 @@
 
     _loading = loading;
 
+    [_previewView setHidden:loading];
+
     if (_loading)
         [_spinner startAnimation:nil];
     else
@@ -89,15 +89,7 @@
 {
     NSRect defaultFrame = NSMakeRect(0, 0, _mainViewSize.width, _mainViewSize.height);
     _previewView = [_delegate pagePreviewViewController:self viewForPreviewingURL:_url.get() initialFrameSize:defaultFrame.size];
-    if (!_previewView) {
-        RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:defaultFrame]);
-        [webView _setIgnoresNonWheelEvents:YES];
-        if (_url) {
-            NSURLRequest *request = [NSURLRequest requestWithURL:_url.get()];
-            [webView loadRequest:request];
-        }
-        _previewView = webView;
-    }
+    ASSERT(_previewView);
 
     RetainPtr<NSClickGestureRecognizer> clickRecognizer = adoptNS([[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(_clickRecognized:)]);
     [_previewView addGestureRecognizer:clickRecognizer.get()];
@@ -114,6 +106,7 @@
     [containerView addSubview:_previewView.get()];
     [_previewView setFrame:previewFrame];
     [_previewView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+    [_previewView setHidden:YES];
 
     _titleTextField = adoptNS([[NSTextField alloc] init]);
     [_titleTextField setWantsLayer:YES];
@@ -166,6 +159,15 @@
     self.view = containerView.get();
 }
 
+- (void)replacePreviewWithImage:(NSImage *)image atSize:(NSSize)size
+{
+    RetainPtr<NSClickGestureRecognizer> clickRecognizer = adoptNS([[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(_clickRecognized:)]);
+    RetainPtr<NSImageView> imageView = adoptNS([[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, size.width, size.height)]);
+    [imageView setImage:image];
+    [imageView addGestureRecognizer:clickRecognizer.get()];
+    self.view = imageView.get();
+}
+
 - (void)_clickRecognized:(NSGestureRecognizer *)gestureRecognizer
 {
     if (gestureRecognizer.state == NSGestureRecognizerStateBegan)
@@ -174,4 +176,4 @@
 
 @end
 
-#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
+#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000

Copied: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.h (from rev 177554, branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKImmediateActionController.h) (0 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.h	                        (rev 0)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.h	2014-12-19 02:56:54 UTC (rev 177555)
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+#ifndef WKPreviewPopoverAnimationController_h
+#define WKPreviewPopoverAnimationController_h
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+#import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
+#import <wtf/Forward.h>
+#import <wtf/RetainPtr.h>
+
+namespace WebKit {
+class WebPageProxy;
+};
+
+@class NSImmediateActionGestureRecognizer;
+@class NSPopoverAnimationController;
+@class NSString;
+@class NSURL;
+@class WKPagePreviewViewController;
+@class WKView;
+
+@interface WKPreviewPopoverAnimationController : NSObject <NSImmediateActionAnimationController> {
+    bool _shouldShowPreviewWhenLoaded;
+    bool _hasFinishedLoading;
+
+    WKView *_wkView;
+    RetainPtr<NSURL> _url;
+    WebKit::WebPageProxy* _page;
+
+    RetainPtr<NSPopover> _previewPopover;
+    NSRect _popoverOriginRect;
+    RetainPtr<WKPagePreviewViewController> _previewViewController;
+    NSPoint _eventLocationInView;
+
+    RetainPtr<NSPopoverAnimationController> _popoverAnimationController;
+
+    NSImmediateActionGestureRecognizer *_recognizer;
+    bool _didCompleteAnimation;
+    RetainPtr<NSTimer> _previewWatchdogTimer;
+}
+
+- (instancetype)initWithURL:(NSURL *)url view:(WKView *)wkView page:(WebKit::WebPageProxy&)page originRect:(NSRect)originRect eventLocationInView:(NSPoint)eventLocationInView;
+- (void)close;
+
+- (void)setPreviewTitle:(NSString *)previewTitle;
+- (void)setPreviewLoading:(BOOL)loading;
+- (void)setPreviewOverrideImage:(NSImage *)image;
+
+@end
+
+
+#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+#endif // WKPreviewPopoverAnimationController_h

Added: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.mm (0 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.mm	                        (rev 0)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKPreviewPopoverAnimationController.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -0,0 +1,339 @@
+/*
+ * 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 "config.h"
+#import "WKPreviewPopoverAnimationController.h"
+
+#import "WKPagePreviewViewController.h"
+#import "WKViewInternal.h"
+#import "WebPageProxy.h"
+#import <WebCore/FloatRect.h>
+#import <WebCore/GeometryUtilities.h>
+#import <WebCore/NSPopoverSPI.h>
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+using namespace WebCore;
+using namespace WebKit;
+
+@interface WKPreviewPopoverAnimationController () <WKPagePreviewViewControllerDelegate, NSPopoverDelegate>
+@end
+
+@implementation WKPreviewPopoverAnimationController
+
++ (bool)_shouldImmediatelyShowPreview
+{
+    static bool shouldImmediatelyShowPreview;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        shouldImmediatelyShowPreview = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitShouldImmediatelyShowPreview"];
+    });
+    return shouldImmediatelyShowPreview;
+}
+
+- (instancetype)initWithURL:(NSURL *)url view:(WKView *)wkView page:(WebPageProxy&)page originRect:(NSRect)originRect eventLocationInView:(NSPoint)eventLocationInView
+{
+    self = [super init];
+
+    if (!self)
+        return nil;
+
+    _url = url;
+    _wkView = wkView;
+    _page = &page;
+    _popoverOriginRect = originRect;
+
+    // FIXME: We should be able to get this from the recognizer.
+    _eventLocationInView = eventLocationInView;
+
+    return self;
+}
+
+- (void)close
+{
+    [self _hidePreview];
+
+    _wkView = nil;
+    _page = nullptr;
+}
+
+- (void)setPreviewLoading:(BOOL)loading
+{
+    [_previewViewController setLoading:loading];
+    _hasFinishedLoading = !loading;
+    if (!loading && _shouldShowPreviewWhenLoaded)
+        [self _showPreview];
+}
+
+- (void)setPreviewOverrideImage:(NSImage *)image
+{
+    NSSize imageSize = image.size;
+    NSSize scaledImageSize;
+    if ([_previewPopover isShown]) {
+        NSSize currentPopoverContentSize = [_previewPopover contentSize];
+        float scale = std::min(std::min(currentPopoverContentSize.width / imageSize.width, 1.0), std::min(currentPopoverContentSize.height / imageSize.height, 1.0));
+        scaledImageSize = NSMakeSize(imageSize.width * scale, imageSize.height * scale);
+    } else
+        scaledImageSize = [self _preferredPopoverSizeWithPreviewPadding:[WKPagePreviewViewController previewPadding] forTargetSize:imageSize];
+
+    [_previewPopover setContentSize:scaledImageSize];
+    [_previewViewController replacePreviewWithImage:image atSize:scaledImageSize];
+}
+
+- (void)_hidePreview
+{
+    if (_page)
+        _page->clearTextIndicator();
+
+    if (_previewViewController) {
+        _previewViewController->_delegate = nil;
+        [_wkView _finishPreviewingURL:_previewViewController->_url.get() withPreviewView:_previewViewController->_previewView.get()];
+        _previewViewController = nil;
+    }
+
+    [_previewPopover close];
+    [_previewPopover setDelegate:nil];
+    _previewPopover = nil;
+}
+
+- (void)setPreviewTitle:(NSString *)previewTitle
+{
+    [_previewViewController setPreviewTitle:previewTitle];
+}
+
+- (void)_createPreviewPopover
+{
+    NSSize previewPadding = [WKPagePreviewViewController previewPadding];
+    NSSize popoverSize = [self _preferredPopoverSizeWithPreviewPadding:previewPadding forTargetSize:[self _targetSizeForPagePreview]];
+    CGFloat actualPopoverToViewScale = popoverSize.width / NSWidth(_wkView.bounds);
+    popoverSize.width += previewPadding.width;
+    popoverSize.height += previewPadding.height;
+
+    _previewViewController = adoptNS([[WKPagePreviewViewController alloc] initWithPageURL:_url.get() mainViewSize:_wkView.bounds.size popoverToViewScale:actualPopoverToViewScale]);
+    _previewViewController->_delegate = self;
+    [_previewViewController setLoading:YES];
+    [_previewViewController loadView];
+
+    _previewPopover = adoptNS([[NSPopover alloc] init]);
+    [_previewPopover setBehavior:NSPopoverBehaviorTransient];
+    [_previewPopover setContentSize:popoverSize];
+    [_previewPopover setContentViewController:_previewViewController.get()];
+    [_previewPopover setDelegate:self];
+    [_previewPopover setPositioningOptions:NSPopoverPositioningOptionKeepTopStable];
+}
+
+- (void)_showPreview
+{
+    _shouldShowPreviewWhenLoaded = false;
+    [_previewWatchdogTimer invalidate];
+    _previewWatchdogTimer = nil;
+
+    Class nsPopoverAnimationControllerClass = NSClassFromString(@"NSPopoverAnimationController");
+    if (nsPopoverAnimationControllerClass) {
+        _popoverAnimationController = [nsPopoverAnimationControllerClass popoverAnimationControllerWithPopover:_previewPopover.get()];
+        [_popoverAnimationController setPreferredEdge:NSMaxYEdge];
+        [_popoverAnimationController setAnchorView:_wkView];
+        [_popoverAnimationController setPositioningRect:_popoverOriginRect];
+
+        [_popoverAnimationController recognizerWillBeginAnimation:_recognizer];
+
+        if (_didCompleteAnimation)
+            [_popoverAnimationController recognizerDidCompleteAnimation:_recognizer];
+        else
+            [_popoverAnimationController recognizerDidUpdateAnimation:_recognizer];
+    }
+}
+
+static bool targetSizeFitsInAvailableSpace(NSSize targetSize, NSSize availableSpace)
+{
+    return targetSize.width <= availableSpace.width && targetSize.height <= availableSpace.height;
+}
+
+- (NSSize)largestPopoverSize
+{
+    NSSize screenSize = _wkView.window.screen.frame.size;
+
+    if (screenSize.width == 1280 && screenSize.height == 800)
+        return NSMakeSize(1240, 674);
+
+    if (screenSize.width == 1366 && screenSize.height == 768)
+        return NSMakeSize(1264, 642);
+
+    if (screenSize.width == 1440 && screenSize.height == 900)
+        return NSMakeSize(1264, 760);
+
+    if (screenSize.width == 1680 && screenSize.height == 1050)
+        return NSMakeSize(1324, 910);
+
+    return NSMakeSize(1324, 940);
+}
+
+- (NSSize)_targetSizeForPagePreview
+{
+    static const CGFloat preferredPopoverToViewScale = 0.75;
+    NSRect wkViewBounds = _wkView.bounds;
+    return NSMakeSize(NSWidth(wkViewBounds) * preferredPopoverToViewScale, NSHeight(wkViewBounds) * preferredPopoverToViewScale);
+}
+
+- (NSSize)_preferredPopoverSizeWithPreviewPadding:(NSSize)previewPadding forTargetSize:(NSSize)targetSize
+{
+    static const NSSize screenPadding = NSMakeSize(40, 40);
+    static const NSSize smallestPopoverSize = NSMakeSize(500, 500);
+
+    const NSSize effectivePadding = NSMakeSize(screenPadding.width + previewPadding.width, screenPadding.height + previewPadding.height);
+
+    NSWindow *window = _wkView.window;
+    NSRect originScreenRect = [window convertRectToScreen:[_wkView convertRect:_popoverOriginRect toView:nil]];
+    NSRect screenFrame = window.screen.visibleFrame;
+
+    NSSize largestPopoverSize = [self largestPopoverSize];
+
+    CGFloat availableSpaceAbove = NSMaxY(screenFrame) - NSMaxY(originScreenRect);
+    CGFloat availableSpaceBelow = NSMinY(originScreenRect) - NSMinY(screenFrame);
+    CGFloat maxAvailableVerticalSpace = fmax(availableSpaceAbove, availableSpaceBelow) - effectivePadding.height;
+    NSSize maxSpaceAvailableOnYEdge = NSMakeSize(screenFrame.size.width - effectivePadding.height, maxAvailableVerticalSpace);
+    if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnYEdge) && targetSizeFitsInAvailableSpace(targetSize, largestPopoverSize))
+        return targetSize;
+
+    CGFloat availableSpaceAtLeft = NSMinX(originScreenRect) - NSMinX(screenFrame);
+    CGFloat availableSpaceAtRight = NSMaxX(screenFrame) - NSMaxX(originScreenRect);
+    CGFloat maxAvailableHorizontalSpace = fmax(availableSpaceAtLeft, availableSpaceAtRight) - effectivePadding.width;
+    NSSize maxSpaceAvailableOnXEdge = NSMakeSize(maxAvailableHorizontalSpace, screenFrame.size.height - effectivePadding.width);
+    if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnXEdge) && targetSizeFitsInAvailableSpace(targetSize, largestPopoverSize))
+        return targetSize;
+
+    // Adjust the maximum space available if it is larger than the largest popover size.
+    if (maxSpaceAvailableOnYEdge.width > largestPopoverSize.width && maxSpaceAvailableOnYEdge.height > largestPopoverSize.height)
+        maxSpaceAvailableOnYEdge = largestPopoverSize;
+    if (maxSpaceAvailableOnXEdge.width > largestPopoverSize.width && maxSpaceAvailableOnXEdge.height > largestPopoverSize.height)
+        maxSpaceAvailableOnXEdge = largestPopoverSize;
+
+    // If the target size doesn't fit anywhere, we'll find the largest rect that does fit that also maintains the original view's aspect ratio.
+    CGFloat aspectRatio = targetSize.width / targetSize.height;
+    FloatRect maxVerticalTargetSizePreservingAspectRatioRect = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(FloatPoint(), FloatSize(maxSpaceAvailableOnYEdge)));
+    FloatRect maxHorizontalTargetSizePreservingAspectRatioRect = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(FloatPoint(), FloatSize(maxSpaceAvailableOnXEdge)));
+
+    NSSize maxVerticalTargetSizePreservingAspectRatio = NSMakeSize(maxVerticalTargetSizePreservingAspectRatioRect.width(), maxVerticalTargetSizePreservingAspectRatioRect.height());
+    NSSize maxHortizontalTargetSizePreservingAspectRatio = NSMakeSize(maxHorizontalTargetSizePreservingAspectRatioRect.width(), maxHorizontalTargetSizePreservingAspectRatioRect.height());
+
+    NSSize computedTargetSize;
+    if ((maxVerticalTargetSizePreservingAspectRatio.width * maxVerticalTargetSizePreservingAspectRatio.height) > (maxHortizontalTargetSizePreservingAspectRatio.width * maxHortizontalTargetSizePreservingAspectRatio.height))
+        computedTargetSize = maxVerticalTargetSizePreservingAspectRatio;
+    else
+        computedTargetSize = maxHortizontalTargetSizePreservingAspectRatio;
+
+    // Now make sure what we've computed isn't too small.
+    if (computedTargetSize.width < smallestPopoverSize.width && computedTargetSize.height < smallestPopoverSize.height) {
+        float limitWidth = smallestPopoverSize.width > computedTargetSize.width ? smallestPopoverSize.width : computedTargetSize.width;
+        float limitHeight = smallestPopoverSize.height > computedTargetSize.height ? smallestPopoverSize.height : computedTargetSize.height;
+        FloatRect targetRectLargerThanMinSize = largestRectWithAspectRatioInsideRect(aspectRatio, FloatRect(0, 0, limitWidth, limitHeight));
+        computedTargetSize = NSMakeSize(targetRectLargerThanMinSize.size().width(), targetRectLargerThanMinSize.size().height());
+
+        // If our orignal computedTargetSize was so small that we had to get here and make a new computedTargetSize that is
+        // larger than the minimum, then the elementBoundingBox of the _hitTestResult is probably huge. So we should use
+        // the event origin as the popover origin in this case and not worry about obscuring the _hitTestResult.
+        _popoverOriginRect.origin = _eventLocationInView;
+        _popoverOriginRect.size = NSMakeSize(1, 1);
+    }
+    
+    return computedTargetSize;
+}
+
+- (void)_previewWatchdogTimerFired:(NSTimer *)timer
+{
+    [self _showPreview];
+    _previewWatchdogTimer = nil;
+}
+
+#pragma mark NSImmediateActionAnimationController
+
+- (void)recognizerWillBeginAnimation:(NSImmediateActionGestureRecognizer *)recognizer
+{
+    _recognizer = recognizer;
+    _didCompleteAnimation = false;
+    [self _createPreviewPopover];
+
+    if ([self.class _shouldImmediatelyShowPreview])
+        [self _showPreview];
+    else {
+        _shouldShowPreviewWhenLoaded = true;
+        _previewWatchdogTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(_previewWatchdogTimerFired:) userInfo:nil repeats:NO];
+    }
+}
+
+- (void)recognizerDidUpdateAnimation:(NSImmediateActionGestureRecognizer *)recognizer
+{
+    [_popoverAnimationController recognizerDidUpdateAnimation:recognizer];
+}
+
+- (void)recognizerDidCancelAnimation:(NSImmediateActionGestureRecognizer *)recognizer
+{
+    [self _hidePreview];
+
+    [_popoverAnimationController recognizerDidCancelAnimation:recognizer];
+}
+
+- (void)recognizerDidCompleteAnimation:(NSImmediateActionGestureRecognizer *)recognizer
+{
+    _didCompleteAnimation = true;
+    [_popoverAnimationController recognizerDidCompleteAnimation:recognizer];
+}
+
+- (void)recognizerDidDismissAnimation:(NSImmediateActionGestureRecognizer *)recognizer
+{
+    [self _hidePreview];
+
+    [_popoverAnimationController recognizerDidDismissAnimation:recognizer];
+}
+
+#pragma mark WKPagePreviewViewControllerDelegate
+
+- (NSView *)pagePreviewViewController:(WKPagePreviewViewController *)pagePreviewViewController viewForPreviewingURL:(NSURL *)url initialFrameSize:(NSSize)initialFrameSize
+{
+    return [_wkView _viewForPreviewingURL:url initialFrameSize:initialFrameSize];
+}
+
+- (NSString *)pagePreviewViewController:(WKPagePreviewViewController *)pagePreviewViewController titleForPreviewOfURL:(NSURL *)url
+{
+    return [_wkView _titleForPreviewOfURL:url];
+}
+
+- (void)pagePreviewViewControllerWasClicked:(WKPagePreviewViewController *)pagePreviewViewController
+{
+    if (NSURL *url = ""
+        [_wkView _handleClickInPreviewView:pagePreviewViewController->_previewView.get() URL:url];
+}
+
+#pragma mark NSPopoverDelegate
+
+- (void)popoverWillClose:(NSNotification *)notification
+{
+    [self _hidePreview];
+}
+
+@end
+
+
+#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000

Modified: branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-12-19 02:56:54 UTC (rev 177555)
@@ -560,6 +560,8 @@
 		29D55DF2161BF9F10031A2E3 /* WebPageGroupProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 29D55DF0161BF9F10031A2E3 /* WebPageGroupProxyMessages.h */; };
 		2D0730A219F9C7DA00E9D9C4 /* WKActionMenuController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D0730A019F9C7DA00E9D9C4 /* WKActionMenuController.mm */; };
 		2D0730A319F9C7DA00E9D9C4 /* WKActionMenuController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D0730A119F9C7DA00E9D9C4 /* WKActionMenuController.h */; };
+		2D0B8ACA1A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D0B8AC81A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.h */; };
+		2D0B8ACB1A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D0B8AC91A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.mm */; };
 		2D125C5E1857EA05003BA3CB /* ViewGestureController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D125C5C1857EA05003BA3CB /* ViewGestureController.h */; };
 		2D125C5F1857EA05003BA3CB /* ViewGestureControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D125C5D1857EA05003BA3CB /* ViewGestureControllerMac.mm */; };
 		2D1B5D5D185869C8006C6596 /* ViewGestureControllerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D1B5D5B185869C8006C6596 /* ViewGestureControllerMessageReceiver.cpp */; };
@@ -2563,6 +2565,8 @@
 		29D55DF0161BF9F10031A2E3 /* WebPageGroupProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageGroupProxyMessages.h; sourceTree = "<group>"; };
 		2D0730A019F9C7DA00E9D9C4 /* WKActionMenuController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKActionMenuController.mm; sourceTree = "<group>"; };
 		2D0730A119F9C7DA00E9D9C4 /* WKActionMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKActionMenuController.h; sourceTree = "<group>"; };
+		2D0B8AC81A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPreviewPopoverAnimationController.h; sourceTree = "<group>"; };
+		2D0B8AC91A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPreviewPopoverAnimationController.mm; sourceTree = "<group>"; };
 		2D125C5C1857EA05003BA3CB /* ViewGestureController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewGestureController.h; sourceTree = "<group>"; };
 		2D125C5D1857EA05003BA3CB /* ViewGestureControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewGestureControllerMac.mm; sourceTree = "<group>"; };
 		2D1B5D5A18586599006C6596 /* ViewGestureController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = ViewGestureController.messages.in; sourceTree = "<group>"; };
@@ -6653,6 +6657,8 @@
 				9321D5871A38EE74008052BE /* WKImmediateActionController.mm */,
 				2DEB346F1A3987AB0030E2BA /* WKPagePreviewViewController.h */,
 				2DEB34701A3987AB0030E2BA /* WKPagePreviewViewController.mm */,
+				2D0B8AC81A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.h */,
+				2D0B8AC91A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.mm */,
 				0FCB4E5C18BBE3D9000FCFC9 /* WKPrintingView.h */,
 				0FCB4E5D18BBE3D9000FCFC9 /* WKPrintingView.mm */,
 				0FCB4E5E18BBE3D9000FCFC9 /* WKTextInputWindowController.h */,
@@ -7187,6 +7193,7 @@
 				1A7C6CDB1378950800B9C04D /* EnvironmentVariables.h in Headers */,
 				1AA575FB1496B52600A4EE06 /* EventDispatcher.h in Headers */,
 				1A90C1F41264FD71003E44D4 /* FindController.h in Headers */,
+				2D0B8ACA1A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.h in Headers */,
 				515E7728183DD6F60007203F /* AsyncRequest.h in Headers */,
 				BCE81D8D1319F7EF00241910 /* FontInfo.h in Headers */,
 				1ABC3DFC1899F51C004F0626 /* WKNavigationDelegate.h in Headers */,
@@ -9122,6 +9129,7 @@
 				BC72B9FA11E6476B001EB4EA /* WebBackForwardListProxy.cpp in Sources */,
 				BC111A5A112F4FBB00337BAB /* WebChromeClient.cpp in Sources */,
 				2D0730A219F9C7DA00E9D9C4 /* WKActionMenuController.mm in Sources */,
+				2D0B8ACB1A42A39C006D7FC8 /* WKPreviewPopoverAnimationController.mm in Sources */,
 				868160D0187645570021E79D /* WindowServerConnection.mm in Sources */,
 				3F87B9BD158940120090FF62 /* WebColorChooser.cpp in Sources */,
 				A58B6F0918FCA733008CBA53 /* WKFileUploadPanel.mm in Sources */,

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (177554 => 177555)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-12-19 02:56:17 UTC (rev 177554)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-12-19 02:56:54 UTC (rev 177555)
@@ -999,6 +999,13 @@
 
     RefPtr<Range> selectionRange = corePage()->focusController().focusedOrMainFrame().selection().selection().firstRange();
 
+    URL absoluteLinkURL = hitTestResult.absoluteLinkURL();
+    Node *innerNode = hitTestResult.innerNode();
+    if (!absoluteLinkURL.isEmpty() && innerNode) {
+        RefPtr<Range> linkRange = rangeOfContents(*innerNode);
+        actionMenuResult.linkTextIndicator = TextIndicator::createWithRange(*linkRange, textIndicatorTransitionForActionMenu(selectionRange.get(), *linkRange, forImmediateAction, false));
+    }
+
     NSDictionary *options = nil;
     RefPtr<Range> lookupRange = lookupTextAtLocation(locationInViewCooordinates, &options);
     actionMenuResult.lookupText = lookupRange ? lookupRange->text() : String();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to