Modified: branches/safari-600.3-branch/Source/WebCore/ChangeLog (175711 => 175712)
--- branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-11-06 21:35:11 UTC (rev 175711)
+++ branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-11-06 22:01:10 UTC (rev 175712)
@@ -1,3 +1,17 @@
+2014-11-06 Dana Burkart <dburk...@apple.com>
+
+ Merge r175710. <rdar://problem/18898712>
+
+ 2014-11-06 Beth Dakin <bda...@apple.com>
+
+ Preview views often misplaced inside popover
+ https://bugs.webkit.org/show_bug.cgi?id=138472
+
+ Reviewed by Tim Horton.
+
+ * WebCore.exp.in:
+
+
2014-11-05 Dana Burkart <dburk...@apple.com>
Merge r175609. <rdar://problem/18869345>
Modified: branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in (175711 => 175712)
--- branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in 2014-11-06 21:35:11 UTC (rev 175711)
+++ branches/safari-600.3-branch/Source/WebCore/WebCore.exp.in 2014-11-06 22:01:10 UTC (rev 175712)
@@ -1080,6 +1080,7 @@
__ZN7WebCore31CrossOriginPreflightResultCache6sharedEv
__ZN7WebCore33deleteAllCookiesModifiedAfterDateERKNS_21NetworkStorageSessionEd
__ZN7WebCore33stripLeadingAndTrailingHTMLSpacesERKN3WTF6StringE
+__ZN7WebCore36largestRectWithAspectRatioInsideRectEfRKNS_9FloatRectE
__ZN7WebCore36standardUserAgentWithApplicationNameERKN3WTF6StringES3_
__ZN7WebCore37WidgetHierarchyUpdatesSuspensionScope11moveWidgetsEv
__ZN7WebCore37WidgetHierarchyUpdatesSuspensionScope35s_widgetHierarchyUpdateSuspendCountE
Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (175711 => 175712)
--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-06 21:35:11 UTC (rev 175711)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-06 22:01:10 UTC (rev 175712)
@@ -1,3 +1,26 @@
+2014-11-06 Dana Burkart <dburk...@apple.com>
+
+ Merge r175710. <rdar://problem/18898712>
+
+ 2014-11-06 Beth Dakin <bda...@apple.com>
+
+ Preview views often misplaced inside popover
+ https://bugs.webkit.org/show_bug.cgi?id=138472
+
+ Reviewed by Tim Horton.
+
+ This patch makes the popover maintain aspect ratio, and it uses the final scale of
+ that popover to scale the preview view as well.
+
+ * UIProcess/mac/WKActionMenuController.mm:
+ (-[WKPagePreviewViewController initWithPageURL:mainViewSize:popoverToViewScale:]):
+ (-[WKPagePreviewViewController loadView]):
+ (-[WKActionMenuController _createPreviewPopoverForURL:originRect:]):
+ (-[WKActionMenuController _targetSize:fitsInAvailableSpace:]):
+ (-[WKActionMenuController _preferredSizeForPopoverPresentedFromOriginRect:]):
+ (-[WKPagePreviewViewController initWithPageURL:]): Deleted.
+
+
2014-11-05 Dana Burkart <dburk...@apple.com>
Merge r175649. <rdar://problem/18887140>
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (175711 => 175712)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-06 21:35:11 UTC (rev 175711)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-06 22:01:10 UTC (rev 175712)
@@ -43,6 +43,7 @@
#import <ImageIO/ImageIO.h>
#import <ImageKit/ImageKit.h>
#import <WebCore/DataDetectorsSPI.h>
+#import <WebCore/GeometryUtilities.h>
#import <WebCore/NSSharingServiceSPI.h>
#import <WebCore/NSSharingServicePickerSPI.h>
#import <WebCore/NSViewSPI.h>
@@ -73,8 +74,6 @@
#if WK_API_ENABLED
-static const CGFloat popoverToViewScale = 0.75;
-
@class WKPagePreviewViewController;
@protocol WKPagePreviewViewControllerDelegate <NSObject>
@@ -86,21 +85,23 @@
NSSize _mainViewSize;
RetainPtr<NSURL> _url;
id <WKPagePreviewViewControllerDelegate> _delegate;
+ CGFloat _popoverToViewScale;
}
-- (instancetype)initWithPageURL:(NSURL *)URL;
+- (instancetype)initWithPageURL:(NSURL *)URL mainViewSize:(NSSize)size popoverToViewScale:(CGFloat)scale;
@end
@implementation WKPagePreviewViewController
-- (instancetype)initWithPageURL:(NSURL *)URL
+- (instancetype)initWithPageURL:(NSURL *)URL mainViewSize:(NSSize)size popoverToViewScale:(CGFloat)scale
{
if (!(self = [super init]))
return nil;
_url = URL;
- _mainViewSize = NSMakeSize(320, 568);
+ _mainViewSize = size;
+ _popoverToViewScale = scale;
return self;
}
@@ -115,7 +116,7 @@
}
// Setting the webView bounds will scale it to 75% of the _mainViewSize.
- [webView setBounds:NSMakeRect(0, 0, _mainViewSize.width / popoverToViewScale, _mainViewSize.height / popoverToViewScale)];
+ [webView setBounds:NSMakeRect(0, 0, _mainViewSize.width / _popoverToViewScale, _mainViewSize.height / _popoverToViewScale)];
RetainPtr<NSClickGestureRecognizer> clickRecognizer = adoptNS([[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(_clickRecognized:)]);
[webView addGestureRecognizer:clickRecognizer.get()];
@@ -309,38 +310,60 @@
- (void)_createPreviewPopoverForURL:(NSURL *)url originRect:(NSRect)originRect
{
- RetainPtr<WKPagePreviewViewController> previewViewController = adoptNS([[WKPagePreviewViewController alloc] initWithPageURL:url]);
- previewViewController->_mainViewSize = _wkView.bounds.size;
+ NSSize popoverSize = [self _preferredSizeForPopoverPresentedFromOriginRect:originRect];
+ CGFloat actualPopoverToViewScale = popoverSize.width / NSWidth(_wkView.bounds);
+ RetainPtr<WKPagePreviewViewController> previewViewController = adoptNS([[WKPagePreviewViewController alloc] initWithPageURL:url mainViewSize:_wkView.bounds.size popoverToViewScale:actualPopoverToViewScale]);
previewViewController->_delegate = self;
_previewPopover = adoptNS([[NSPopover alloc] init]);
[_previewPopover setBehavior:NSPopoverBehaviorTransient];
- [_previewPopover setContentSize:[self _preferredSizeForPopoverPresentedFromOriginRect:originRect]];
+ [_previewPopover setContentSize:popoverSize];
[_previewPopover setContentViewController:previewViewController.get()];
[_previewPopover setDelegate:self];
}
+static bool targetSizeFitsInAvailableSpace(NSSize targetSize, NSSize availableSpace)
+{
+ return targetSize.width <= availableSpace.width && targetSize.height <= availableSpace.height;
+}
+
- (NSSize)_preferredSizeForPopoverPresentedFromOriginRect:(NSRect)originRect
{
+ static const CGFloat preferredPopoverToViewScale = 0.75;
static const CGFloat screenPadding = 40;
NSWindow *window = _wkView.window;
NSRect originScreenRect = [window convertRectToScreen:[_wkView convertRect:originRect toView:nil]];
NSRect screenFrame = window.screen.visibleFrame;
+ NSRect wkViewBounds = _wkView.bounds;
+ NSSize targetSize = NSMakeSize(NSWidth(wkViewBounds) * preferredPopoverToViewScale, NSHeight(wkViewBounds) * preferredPopoverToViewScale);
+
CGFloat availableSpaceAbove = NSMaxY(screenFrame) - NSMaxY(originScreenRect);
CGFloat availableSpaceBelow = NSMinY(originScreenRect) - NSMinY(screenFrame);
CGFloat maxAvailableVerticalSpace = fmax(availableSpaceAbove, availableSpaceBelow) - screenPadding;
+ NSSize maxSpaceAvailableOnYEdge = NSMakeSize(screenFrame.size.width - screenPadding, maxAvailableVerticalSpace);
+ if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnYEdge))
+ return targetSize;
CGFloat availableSpaceAtLeft = NSMinX(originScreenRect) - NSMinX(screenFrame);
CGFloat availableSpaceAtRight = NSMaxX(screenFrame) - NSMaxX(originScreenRect);
CGFloat maxAvailableHorizontalSpace = fmax(availableSpaceAtLeft, availableSpaceAtRight) - screenPadding;
+ NSSize maxSpaceAvailableOnXEdge = NSMakeSize(maxAvailableHorizontalSpace, screenFrame.size.height - screenPadding);
+ if (targetSizeFitsInAvailableSpace(targetSize, maxSpaceAvailableOnXEdge))
+ return targetSize;
- NSRect wkViewBounds = _wkView.bounds;
- NSSize preferredSize = NSMakeSize(NSWidth(wkViewBounds) * popoverToViewScale, NSHeight(wkViewBounds) * popoverToViewScale);
- preferredSize.width = fmin(preferredSize.width, maxAvailableHorizontalSpace);
- preferredSize.height = fmin(preferredSize.height, maxAvailableVerticalSpace);
- return preferredSize;
+ // 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());
+
+ if ((maxVerticalTargetSizePreservingAspectRatio.width * maxVerticalTargetSizePreservingAspectRatio.height) > (maxHortizontalTargetSizePreservingAspectRatio.width * maxHortizontalTargetSizePreservingAspectRatio.height))
+ return maxVerticalTargetSizePreservingAspectRatio;
+ return maxHortizontalTargetSizePreservingAspectRatio;
}
#endif // WK_API_ENABLED