Diff
Modified: trunk/Source/WebCore/ChangeLog (191633 => 191634)
--- trunk/Source/WebCore/ChangeLog 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebCore/ChangeLog 2015-10-27 20:09:29 UTC (rev 191634)
@@ -1,3 +1,12 @@
+2015-10-27 Tim Horton <timothy_hor...@apple.com>
+
+ WKView being inside WKWebView leads to weird API issues
+ https://bugs.webkit.org/show_bug.cgi?id=150174
+
+ Reviewed by Anders Carlsson.
+
+ * platform/spi/cg/CoreGraphicsSPI.h:
+
2015-10-27 Zhuo Li <zac...@apple.com>
Add WebKit API to clear data type Search Field Recent Searches.
Modified: trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h (191633 => 191634)
--- trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h 2015-10-27 20:09:29 UTC (rev 191634)
@@ -182,6 +182,7 @@
CFArrayRef CGSHWCaptureWindowList(CGSConnectionID cid, CGSWindowIDList windowList, CGSWindowCount windowCount, CGSWindowCaptureOptions options);
CGError CGSSetConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef value);
CGError CGSCopyConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef *value);
+CGError CGSGetScreenRectForWindow(CGSConnectionID, CGSWindowID, CGRect *);
#endif
WTF_EXTERN_C_END
Modified: trunk/Source/WebKit2/ChangeLog (191633 => 191634)
--- trunk/Source/WebKit2/ChangeLog 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/ChangeLog 2015-10-27 20:09:29 UTC (rev 191634)
@@ -1,3 +1,76 @@
+2015-10-27 Tim Horton <timothy_hor...@apple.com>
+
+ WKView being inside WKWebView leads to weird API issues
+ https://bugs.webkit.org/show_bug.cgi?id=150174
+
+ Reviewed by Anders Carlsson.
+
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView scrollWheel:]):
+ (-[WKView swipeWithEvent:]):
+ (-[WKView _superSwipeWithEvent:]):
+ (-[WKView _superMagnifyWithEvent:]):
+ (-[WKView _superSmartMagnifyWithEvent:]):
+ (-[WKView _processDidExit]):
+ (-[WKView setAllowsBackForwardNavigationGestures:]):
+ (-[WKView allowsBackForwardNavigationGestures]):
+ (-[WKView setAllowsMagnification:]):
+ (-[WKView allowsMagnification]):
+ (-[WKView magnifyWithEvent:]):
+ (-[WKView rotateWithEvent:]):
+ (-[WKView _gestureEventWasNotHandledByWebCore:]):
+ (-[WKView smartMagnifyWithEvent:]):
+ (-[WKView setMagnification:centeredAtPoint:]):
+ (-[WKView setMagnification:]):
+ (-[WKView magnification]):
+ (-[WKView _setCustomSwipeViews:]):
+ (-[WKView _setCustomSwipeViewsTopContentInset:]):
+ (-[WKView _tryToSwipeWithEvent:ignoringPinnedState:]):
+ (-[WKView _setDidMoveSwipeSnapshotCallback:]):
+ (-[WKView _ensureGestureController]): Deleted.
+ (takeWindowSnapshot): Deleted.
+ (-[WKView _takeViewSnapshot]): Deleted.
+ (-[WKView _wheelEventWasNotHandledByWebCore:]): Deleted.
+ (-[WKView _didFirstVisuallyNonEmptyLayoutForMainFrame]): Deleted.
+ (-[WKView _didFinishLoadForMainFrame]): Deleted.
+ (-[WKView _didFailLoadForMainFrame]): Deleted.
+ (-[WKView _didSameDocumentNavigationForMainFrame:]): Deleted.
+ (-[WKView _removeNavigationGestureSnapshot]): Deleted.
+ * UIProcess/API/mac/WKViewInternal.h:
+ * UIProcess/Cocoa/WebViewImpl.h:
+ (WebKit::WebViewImpl::gestureController):
+ (WebKit::WebViewImpl::allowsBackForwardNavigationGestures):
+ (WebKit::WebViewImpl::allowsMagnification):
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::takeWindowSnapshot):
+ (WebKit::WebViewImpl::takeViewSnapshot):
+ (WebKit::WebViewImpl::ensureGestureController):
+ (WebKit::WebViewImpl::resetGestureController):
+ (WebKit::WebViewImpl::setAllowsBackForwardNavigationGestures):
+ (WebKit::WebViewImpl::setAllowsMagnification):
+ (WebKit::WebViewImpl::setMagnification):
+ (WebKit::WebViewImpl::magnification):
+ (WebKit::WebViewImpl::setCustomSwipeViews):
+ (WebKit::WebViewImpl::setCustomSwipeViewsTopContentInset):
+ (WebKit::WebViewImpl::tryToSwipeWithEvent):
+ (WebKit::WebViewImpl::setDidMoveSwipeSnapshotCallback):
+ (WebKit::WebViewImpl::scrollWheel):
+ (WebKit::WebViewImpl::swipeWithEvent):
+ (WebKit::WebViewImpl::magnifyWithEvent):
+ (WebKit::WebViewImpl::smartMagnifyWithEvent):
+ (WebKit::WebViewImpl::rotateWithEvent):
+ (WebKit::WebViewImpl::gestureEventWasNotHandledByWebCore):
+ (WebKit::WebViewImpl::gestureEventWasNotHandledByWebCoreFromViewOnly):
+ * UIProcess/mac/PageClientImpl.mm:
+ (WebKit::PageClientImpl::takeViewSnapshot):
+ (WebKit::PageClientImpl::wheelEventWasNotHandledByWebCore):
+ (WebKit::PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame):
+ (WebKit::PageClientImpl::didFinishLoadForMainFrame):
+ (WebKit::PageClientImpl::didFailLoadForMainFrame):
+ (WebKit::PageClientImpl::didSameDocumentNavigationForMainFrame):
+ (WebKit::PageClientImpl::removeNavigationGestureSnapshot):
+ Move swipe, zoom, rotate, and snapshotting code.
+
2015-10-27 Zhuo Li <zac...@apple.com>
Add WebKit API to clear data type Search Field Recent Searches.
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191633 => 191634)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-10-27 20:09:29 UTC (rev 191634)
@@ -41,7 +41,6 @@
#import "EditorState.h"
#import "LayerTreeContext.h"
#import "Logging.h"
-#import "NativeWebGestureEvent.h"
#import "NativeWebKeyboardEvent.h"
#import "NativeWebMouseEvent.h"
#import "NativeWebWheelEvent.h"
@@ -54,8 +53,6 @@
#import "TextChecker.h"
#import "TextCheckerState.h"
#import "TiledCoreAnimationDrawingAreaProxy.h"
-#import "ViewGestureController.h"
-#import "ViewSnapshotStore.h"
#import "WKAPICast.h"
#import "WKFullScreenWindowController.h"
#import "WKLayoutMode.h"
@@ -83,6 +80,7 @@
#import <QuartzCore/QuartzCore.h>
#import <WebCore/AXObjectCache.h>
#import <WebCore/ColorMac.h>
+#import <WebCore/CoreGraphicsSPI.h>
#import <WebCore/DataDetectorsSPI.h>
#import <WebCore/DictionaryLookup.h>
#import <WebCore/DragController.h>
@@ -131,17 +129,6 @@
@end
#endif
-#if defined(__has_include) && __has_include(<CoreGraphics/CoreGraphicsPrivate.h>)
-#import <CoreGraphics/CoreGraphicsPrivate.h>
-#endif
-
-extern "C" {
-typedef uint32_t CGSConnectionID;
-typedef uint32_t CGSWindowID;
-CGSConnectionID CGSMainConnectionID(void);
-CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGSWindowID wid, CGRect *rect);
-};
-
using namespace WebKit;
using namespace WebCore;
@@ -204,10 +191,6 @@
BOOL _windowOcclusionDetectionEnabled;
- std::unique_ptr<ViewGestureController> _gestureController;
- BOOL _allowsMagnification;
- BOOL _allowsBackForwardNavigationGestures;
-
CGFloat _totalHeightOfBanners;
}
@@ -1010,48 +993,14 @@
#undef NATIVE_MOUSE_EVENT_HANDLER
-- (void)_ensureGestureController
-{
- if (_data->_gestureController)
- return;
-
- _data->_gestureController = std::make_unique<ViewGestureController>(*_data->_page);
-}
-
- (void)scrollWheel:(NSEvent *)event
{
- if (_data->_impl->ignoresAllEvents())
- return;
-
- if (event.phase == NSEventPhaseBegan)
- [self _dismissContentRelativeChildWindowsWithAnimation:NO];
-
- if (_data->_allowsBackForwardNavigationGestures) {
- [self _ensureGestureController];
- if (_data->_gestureController->handleScrollWheelEvent(event))
- return;
- }
-
- NativeWebWheelEvent webEvent = NativeWebWheelEvent(event, self);
- _data->_page->handleWheelEvent(webEvent);
+ _data->_impl->scrollWheel(event);
}
- (void)swipeWithEvent:(NSEvent *)event
{
- if (_data->_impl->ignoresNonWheelEvents())
- return;
-
- if (!_data->_allowsBackForwardNavigationGestures) {
- [super swipeWithEvent:event];
- return;
- }
-
- if (event.deltaX > 0.0)
- _data->_page->goBack();
- else if (event.deltaX < 0.0)
- _data->_page->goForward();
- else
- [super swipeWithEvent:event];
+ _data->_impl->swipeWithEvent(event);
}
- (void)mouseMoved:(NSEvent *)event
@@ -2078,6 +2027,21 @@
[super quickLookWithEvent:event];
}
+- (void)_superSwipeWithEvent:(NSEvent *)event
+{
+ [super swipeWithEvent:event];
+}
+
+- (void)_superMagnifyWithEvent:(NSEvent *)event
+{
+ [super magnifyWithEvent:event];
+}
+
+- (void)_superSmartMagnifyWithEvent:(NSEvent *)event
+{
+ [super smartMagnifyWithEvent:event];
+}
+
- (void)_superRemoveTrackingRect:(NSTrackingRectTag)tag
{
[super removeTrackingRect:tag];
@@ -2316,7 +2280,7 @@
[self _updateRemoteAccessibilityRegistration:NO];
- _data->_gestureController = nullptr;
+ _data->_impl->resetGestureController();
}
- (void)_pageClosed
@@ -2419,81 +2383,6 @@
_data->_impl->toolTipChanged(oldToolTip, newToolTip);
}
-static RetainPtr<CGImageRef> takeWindowSnapshot(CGSWindowID windowID, bool captureAtNominalResolution)
-{
- CGSWindowCaptureOptions options = kCGSCaptureIgnoreGlobalClipShape;
- if (captureAtNominalResolution)
- options |= kCGSWindowCaptureNominalResolution;
- RetainPtr<CFArrayRef> windowSnapshotImages = adoptCF(CGSHWCaptureWindowList(CGSMainConnectionID(), &windowID, 1, options));
-
- if (windowSnapshotImages && CFArrayGetCount(windowSnapshotImages.get()))
- return (CGImageRef)CFArrayGetValueAtIndex(windowSnapshotImages.get(), 0);
-
- // Fall back to the non-hardware capture path if we didn't get a snapshot
- // (which usually happens if the window is fully off-screen).
- CGWindowImageOption imageOptions = kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque;
- if (captureAtNominalResolution)
- imageOptions |= kCGWindowImageNominalResolution;
- return adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, windowID, imageOptions));
-}
-
-- (PassRefPtr<ViewSnapshot>)_takeViewSnapshot
-{
- NSWindow *window = self.window;
-
- CGSWindowID windowID = (CGSWindowID)[window windowNumber];
- if (!windowID || ![window isVisible])
- return nullptr;
-
- RetainPtr<CGImageRef> windowSnapshotImage = takeWindowSnapshot(windowID, false);
- if (!windowSnapshotImage)
- return nullptr;
-
- // Work around <rdar://problem/17084993>; re-request the snapshot at kCGWindowImageNominalResolution if it was captured at the wrong scale.
- CGFloat desiredSnapshotWidth = window.frame.size.width * window.screen.backingScaleFactor;
- if (CGImageGetWidth(windowSnapshotImage.get()) != desiredSnapshotWidth)
- windowSnapshotImage = takeWindowSnapshot(windowID, true);
-
- if (!windowSnapshotImage)
- return nullptr;
-
- [self _ensureGestureController];
-
- NSRect windowCaptureRect;
- FloatRect boundsForCustomSwipeViews = _data->_gestureController->windowRelativeBoundsForCustomSwipeViews();
- if (!boundsForCustomSwipeViews.isEmpty())
- windowCaptureRect = boundsForCustomSwipeViews;
- else {
- NSRect unobscuredBounds = self.bounds;
- float topContentInset = _data->_page->topContentInset();
- unobscuredBounds.origin.y += topContentInset;
- unobscuredBounds.size.height -= topContentInset;
- windowCaptureRect = [self convertRect:unobscuredBounds toView:nil];
- }
-
- NSRect windowCaptureScreenRect = [window convertRectToScreen:windowCaptureRect];
- CGRect windowScreenRect;
- CGSGetScreenRectForWindow(CGSMainConnectionID(), (CGSWindowID)[window windowNumber], &windowScreenRect);
-
- NSRect croppedImageRect = windowCaptureRect;
- croppedImageRect.origin.y = windowScreenRect.size.height - windowCaptureScreenRect.size.height - NSMinY(windowCaptureRect);
-
- auto croppedSnapshotImage = adoptCF(CGImageCreateWithImageInRect(windowSnapshotImage.get(), NSRectToCGRect([window convertRectToBacking:croppedImageRect])));
-
- auto surface = IOSurface::createFromImage(croppedSnapshotImage.get());
- if (!surface)
- return nullptr;
- surface->setIsVolatile(true);
-
- return ViewSnapshot::create(WTF::move(surface));
-}
-
-- (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event
-{
- if (_data->_gestureController)
- _data->_gestureController->wheelEventWasNotHandledByWebCore(event);
-}
-
- (void)_setAccessibilityWebProcessToken:(NSData *)data
{
_data->_remoteAccessibilityChild = WKAXRemoteElementForToken(data);
@@ -2784,12 +2673,6 @@
}
#endif // WK_API_ENABLED
-- (void)_didFirstVisuallyNonEmptyLayoutForMainFrame
-{
- if (_data->_gestureController)
- _data->_gestureController->didFirstVisuallyNonEmptyLayoutForMainFrame();
-}
-
#if WK_API_ENABLED
- (_WKRemoteObjectRegistry *)_remoteObjectRegistry
{
@@ -2802,30 +2685,6 @@
}
#endif
-- (void)_didFinishLoadForMainFrame
-{
- if (_data->_gestureController)
- _data->_gestureController->didFinishLoadForMainFrame();
-}
-
-- (void)_didFailLoadForMainFrame
-{
- if (_data->_gestureController)
- _data->_gestureController->didFailLoadForMainFrame();
-}
-
-- (void)_didSameDocumentNavigationForMainFrame:(SameDocumentNavigationType)type
-{
- if (_data->_gestureController)
- _data->_gestureController->didSameDocumentNavigationForMainFrame(type);
-}
-
-- (void)_removeNavigationGestureSnapshot
-{
- if (_data->_gestureController)
- _data->_gestureController->removeSwipeSnapshot();
-}
-
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
- (void)_startWindowDrag
{
@@ -3064,14 +2923,12 @@
- (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures
{
- _data->_allowsBackForwardNavigationGestures = allowsBackForwardNavigationGestures;
- _data->_page->setShouldRecordNavigationSnapshots(allowsBackForwardNavigationGestures);
- _data->_page->setShouldUseImplicitRubberBandControl(allowsBackForwardNavigationGestures);
+ _data->_impl->setAllowsBackForwardNavigationGestures(allowsBackForwardNavigationGestures);
}
- (BOOL)allowsBackForwardNavigationGestures
{
- return _data->_allowsBackForwardNavigationGestures;
+ return _data->_impl->allowsBackForwardNavigationGestures();
}
- (BOOL)allowsLinkPreview
@@ -3271,145 +3128,69 @@
- (void)setAllowsMagnification:(BOOL)allowsMagnification
{
- _data->_allowsMagnification = allowsMagnification;
+ _data->_impl->setAllowsMagnification(allowsMagnification);
}
- (BOOL)allowsMagnification
{
- return _data->_allowsMagnification;
+ return _data->_impl->allowsMagnification();
}
- (void)magnifyWithEvent:(NSEvent *)event
{
- if (!_data->_allowsMagnification) {
-#if ENABLE(MAC_GESTURE_EVENTS)
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, self);
- _data->_page->handleGestureEvent(webEvent);
-#endif
- [super magnifyWithEvent:event];
- return;
- }
-
- [self _dismissContentRelativeChildWindowsWithAnimation:NO];
-
- [self _ensureGestureController];
-
-#if ENABLE(MAC_GESTURE_EVENTS)
- if (_data->_gestureController->hasActiveMagnificationGesture()) {
- _data->_gestureController->handleMagnificationGestureEvent(event, [self convertPoint:event.locationInWindow fromView:nil]);
- return;
- }
-
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, self);
- _data->_page->handleGestureEvent(webEvent);
-#else
- _data->_gestureController->handleMagnificationGestureEvent(event, [self convertPoint:event.locationInWindow fromView:nil]);
-#endif
+ _data->_impl->magnifyWithEvent(event);
}
#if ENABLE(MAC_GESTURE_EVENTS)
- (void)rotateWithEvent:(NSEvent *)event
{
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, self);
- _data->_page->handleGestureEvent(webEvent);
+ _data->_impl->rotateWithEvent(event);
}
#endif
- (void)_gestureEventWasNotHandledByWebCore:(NSEvent *)event
{
-#if ENABLE(MAC_GESTURE_EVENTS)
- if (_data->_gestureController)
- _data->_gestureController->gestureEventWasNotHandledByWebCore(event, [self convertPoint:event.locationInWindow fromView:nil]);
-#endif
+ _data->_impl->gestureEventWasNotHandledByWebCoreFromViewOnly(event);
}
- (void)smartMagnifyWithEvent:(NSEvent *)event
{
- if (!_data->_allowsMagnification) {
- [super smartMagnifyWithEvent:event];
- return;
- }
-
- [self _dismissContentRelativeChildWindowsWithAnimation:NO];
-
- [self _ensureGestureController];
-
- _data->_gestureController->handleSmartMagnificationGesture([self convertPoint:event.locationInWindow fromView:nil]);
+ _data->_impl->smartMagnifyWithEvent(event);
}
- (void)setMagnification:(double)magnification centeredAtPoint:(NSPoint)point
{
- if (magnification <= 0 || isnan(magnification) || isinf(magnification))
- [NSException raise:NSInvalidArgumentException format:@"Magnification should be a positive number"];
-
- [self _dismissContentRelativeChildWindowsWithAnimation:NO];
-
- _data->_page->scalePageInViewCoordinates(magnification, roundedIntPoint(point));
+ _data->_impl->setMagnification(magnification, NSPointToCGPoint(point));
}
- (void)setMagnification:(double)magnification
{
- if (magnification <= 0 || isnan(magnification) || isinf(magnification))
- [NSException raise:NSInvalidArgumentException format:@"Magnification should be a positive number"];
-
- [self _dismissContentRelativeChildWindowsWithAnimation:NO];
-
- FloatPoint viewCenter(NSMidX([self bounds]), NSMidY([self bounds]));
- _data->_page->scalePageInViewCoordinates(magnification, roundedIntPoint(viewCenter));
+ _data->_impl->setMagnification(magnification);
}
- (double)magnification
{
- if (_data->_gestureController)
- return _data->_gestureController->magnification();
-
- return _data->_page->pageScaleFactor();
+ return _data->_impl->magnification();
}
- (void)_setCustomSwipeViews:(NSArray *)customSwipeViews
{
- if (!customSwipeViews.count && !_data->_gestureController)
- return;
-
- [self _ensureGestureController];
-
- Vector<RetainPtr<NSView>> views;
- for (NSView *view in customSwipeViews)
- views.append(view);
-
- _data->_gestureController->setCustomSwipeViews(views);
+ _data->_impl->setCustomSwipeViews(customSwipeViews);
}
- (void)_setCustomSwipeViewsTopContentInset:(float)topContentInset
{
- [self _ensureGestureController];
- _data->_gestureController->setCustomSwipeViewsTopContentInset(topContentInset);
+ _data->_impl->setCustomSwipeViewsTopContentInset(topContentInset);
}
- (BOOL)_tryToSwipeWithEvent:(NSEvent *)event ignoringPinnedState:(BOOL)ignoringPinnedState
{
- if (!_data->_allowsBackForwardNavigationGestures)
- return NO;
-
- [self _ensureGestureController];
-
- BOOL wasIgnoringPinnedState = _data->_gestureController->shouldIgnorePinnedState();
- _data->_gestureController->setShouldIgnorePinnedState(ignoringPinnedState);
-
- BOOL handledEvent = _data->_gestureController->handleScrollWheelEvent(event);
-
- _data->_gestureController->setShouldIgnorePinnedState(wasIgnoringPinnedState);
-
- return handledEvent;
+ return _data->_impl->tryToSwipeWithEvent(event, ignoringPinnedState);
}
- (void)_setDidMoveSwipeSnapshotCallback:(void(^)(CGRect))callback
{
- if (!_data->_allowsBackForwardNavigationGestures)
- return;
-
- [self _ensureGestureController];
- _data->_gestureController->setDidMoveSwipeSnapshotCallback(callback);
+ _data->_impl->setDidMoveSwipeSnapshotCallback(callback);
}
- (id)_immediateActionAnimationControllerForHitTestResult:(WKHitTestResultRef)hitTestResult withType:(uint32_t)type userData:(WKTypeRef)userData
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (191633 => 191634)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2015-10-27 20:09:29 UTC (rev 191634)
@@ -87,9 +87,6 @@
- (NSRect)_convertToDeviceSpace:(NSRect)rect;
- (NSRect)_convertToUserSpace:(NSRect)rect;
-- (PassRefPtr<WebKit::ViewSnapshot>)_takeViewSnapshot;
-- (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event;
-
- (void)_setAccessibilityWebProcessToken:(NSData *)data;
- (void)_dragImageForView:(NSView *)view withImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag;
@@ -106,12 +103,6 @@
- (void)_setSuppressVisibilityUpdates:(BOOL)suppressVisibilityUpdates;
- (BOOL)_suppressVisibilityUpdates;
-- (void)_didFirstVisuallyNonEmptyLayoutForMainFrame;
-- (void)_didFinishLoadForMainFrame;
-- (void)_didFailLoadForMainFrame;
-- (void)_didSameDocumentNavigationForMainFrame:(WebKit::SameDocumentNavigationType)type;
-- (void)_removeNavigationGestureSnapshot;
-
#if WK_API_ENABLED
@property (nonatomic, setter=_setThumbnailView:) _WKThumbnailView *_thumbnailView;
#endif
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191633 => 191634)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-10-27 20:09:29 UTC (rev 191634)
@@ -52,6 +52,9 @@
- (NSTextInputContext *)_superInputContext;
- (void)_superQuickLookWithEvent:(NSEvent *)event;
- (void)_superRemoveTrackingRect:(NSTrackingRectTag)tag;
+- (void)_superSwipeWithEvent:(NSEvent *)event;
+- (void)_superMagnifyWithEvent:(NSEvent *)event;
+- (void)_superSmartMagnifyWithEvent:(NSEvent *)event;
// This is a hack; these things live can live on a category (e.g. WKView (Private)) but WKView itself conforms to this protocol.
// They're not actually optional.
@@ -63,11 +66,13 @@
- (void)_completeImmediateActionAnimation;
- (void)_dismissContentRelativeChildWindows;
- (void)_dismissContentRelativeChildWindowsWithAnimation:(BOOL)animate;
+- (void)_gestureEventWasNotHandledByWebCore:(NSEvent *)event;
@end
namespace WebKit {
+class ViewGestureController;
class WebEditCommandProxy;
class WebPageProxy;
struct ColorSpaceData;
@@ -250,6 +255,33 @@
void registerDraggedTypes();
#endif
+ RefPtr<ViewSnapshot> takeViewSnapshot();
+
+ ViewGestureController* gestureController() { return m_gestureController.get(); }
+ ViewGestureController& ensureGestureController();
+ void resetGestureController();
+ void setAllowsBackForwardNavigationGestures(bool);
+ bool allowsBackForwardNavigationGestures() const { return m_allowsBackForwardNavigationGestures; }
+ void setAllowsMagnification(bool);
+ bool allowsMagnification() const { return m_allowsMagnification; }
+
+ void setMagnification(double, CGPoint centerPoint);
+ void setMagnification(double);
+ double magnification() const;
+ void setCustomSwipeViews(NSArray *);
+ void setCustomSwipeViewsTopContentInset(float);
+ bool tryToSwipeWithEvent(NSEvent *, bool ignoringPinnedState);
+ void setDidMoveSwipeSnapshotCallback(void(^)(CGRect));
+
+ void scrollWheel(NSEvent *);
+ void swipeWithEvent(NSEvent *);
+ void magnifyWithEvent(NSEvent *);
+ void rotateWithEvent(NSEvent *);
+ void smartMagnifyWithEvent(NSEvent *);
+
+ void gestureEventWasNotHandledByWebCore(NSEvent *);
+ void gestureEventWasNotHandledByWebCoreFromViewOnly(NSEvent *);
+
private:
WeakPtr<WebViewImpl> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
@@ -346,6 +378,10 @@
#if WK_API_ENABLED
_WKThumbnailView *m_thumbnailView { nullptr };
#endif
+
+ std::unique_ptr<ViewGestureController> m_gestureController;
+ bool m_allowsBackForwardNavigationGestures { false };
+ bool m_allowsMagnification { false };
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191633 => 191634)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-10-27 20:09:29 UTC (rev 191634)
@@ -31,11 +31,14 @@
#import "ColorSpaceData.h"
#import "GenericCallback.h"
#import "Logging.h"
+#import "NativeWebGestureEvent.h"
#import "NativeWebKeyboardEvent.h"
#import "NativeWebMouseEvent.h"
+#import "NativeWebWheelEvent.h"
#import "PageClient.h"
#import "PasteboardTypes.h"
#import "StringUtilities.h"
+#import "ViewGestureController.h"
#import "WKFullScreenWindowController.h"
#import "WKImmediateActionController.h"
#import "WKTextInputWindowController.h"
@@ -47,6 +50,7 @@
#import "_WKThumbnailViewInternal.h"
#import <HIToolbox/CarbonEventsCore.h>
#import <WebCore/AXObjectCache.h>
+#import <WebCore/CoreGraphicsSPI.h>
#import <WebCore/DataDetectorsSPI.h>
#import <WebCore/DictionaryLookup.h>
#import <WebCore/DragData.h>
@@ -1809,6 +1813,264 @@
}
#endif // ENABLE(DRAG_SUPPORT)
+static RetainPtr<CGImageRef> takeWindowSnapshot(CGSWindowID windowID, bool captureAtNominalResolution)
+{
+ CGSWindowCaptureOptions options = kCGSCaptureIgnoreGlobalClipShape;
+ if (captureAtNominalResolution)
+ options |= kCGSWindowCaptureNominalResolution;
+ RetainPtr<CFArrayRef> windowSnapshotImages = adoptCF(CGSHWCaptureWindowList(CGSMainConnectionID(), &windowID, 1, options));
+
+ if (windowSnapshotImages && CFArrayGetCount(windowSnapshotImages.get()))
+ return (CGImageRef)CFArrayGetValueAtIndex(windowSnapshotImages.get(), 0);
+
+ // Fall back to the non-hardware capture path if we didn't get a snapshot
+ // (which usually happens if the window is fully off-screen).
+ CGWindowImageOption imageOptions = kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque;
+ if (captureAtNominalResolution)
+ imageOptions |= kCGWindowImageNominalResolution;
+ return adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, windowID, imageOptions));
+}
+
+RefPtr<ViewSnapshot> WebViewImpl::takeViewSnapshot()
+{
+ NSWindow *window = m_view.window;
+
+ CGSWindowID windowID = (CGSWindowID)window.windowNumber;
+ if (!windowID || !window.isVisible)
+ return nullptr;
+
+ RetainPtr<CGImageRef> windowSnapshotImage = takeWindowSnapshot(windowID, false);
+ if (!windowSnapshotImage)
+ return nullptr;
+
+ // Work around <rdar://problem/17084993>; re-request the snapshot at kCGWindowImageNominalResolution if it was captured at the wrong scale.
+ CGFloat desiredSnapshotWidth = window.frame.size.width * window.screen.backingScaleFactor;
+ if (CGImageGetWidth(windowSnapshotImage.get()) != desiredSnapshotWidth)
+ windowSnapshotImage = takeWindowSnapshot(windowID, true);
+
+ if (!windowSnapshotImage)
+ return nullptr;
+
+ ViewGestureController& gestureController = ensureGestureController();
+
+ NSRect windowCaptureRect;
+ WebCore::FloatRect boundsForCustomSwipeViews = gestureController.windowRelativeBoundsForCustomSwipeViews();
+ if (!boundsForCustomSwipeViews.isEmpty())
+ windowCaptureRect = boundsForCustomSwipeViews;
+ else {
+ NSRect unobscuredBounds = m_view.bounds;
+ float topContentInset = m_page.topContentInset();
+ unobscuredBounds.origin.y += topContentInset;
+ unobscuredBounds.size.height -= topContentInset;
+ windowCaptureRect = [m_view convertRect:unobscuredBounds toView:nil];
+ }
+
+ NSRect windowCaptureScreenRect = [window convertRectToScreen:windowCaptureRect];
+ CGRect windowScreenRect;
+ CGSGetScreenRectForWindow(CGSMainConnectionID(), (CGSWindowID)[window windowNumber], &windowScreenRect);
+
+ NSRect croppedImageRect = windowCaptureRect;
+ croppedImageRect.origin.y = windowScreenRect.size.height - windowCaptureScreenRect.size.height - NSMinY(windowCaptureRect);
+
+ auto croppedSnapshotImage = adoptCF(CGImageCreateWithImageInRect(windowSnapshotImage.get(), NSRectToCGRect([window convertRectToBacking:croppedImageRect])));
+
+ auto surface = WebCore::IOSurface::createFromImage(croppedSnapshotImage.get());
+ if (!surface)
+ return nullptr;
+ surface->setIsVolatile(true);
+
+ return ViewSnapshot::create(WTF::move(surface));
+}
+
+ViewGestureController& WebViewImpl::ensureGestureController()
+{
+ if (!m_gestureController)
+ m_gestureController = std::make_unique<ViewGestureController>(m_page);
+ return *m_gestureController;
+}
+
+void WebViewImpl::resetGestureController()
+{
+ m_gestureController = nullptr;
+}
+
+void WebViewImpl::setAllowsBackForwardNavigationGestures(bool allowsBackForwardNavigationGestures)
+{
+ m_allowsBackForwardNavigationGestures = allowsBackForwardNavigationGestures;
+ m_page.setShouldRecordNavigationSnapshots(allowsBackForwardNavigationGestures);
+ m_page.setShouldUseImplicitRubberBandControl(allowsBackForwardNavigationGestures);
+}
+
+void WebViewImpl::setAllowsMagnification(bool allowsMagnification)
+{
+ m_allowsMagnification = allowsMagnification;
+}
+
+void WebViewImpl::setMagnification(double magnification, CGPoint centerPoint)
+{
+ if (magnification <= 0 || isnan(magnification) || isinf(magnification))
+ [NSException raise:NSInvalidArgumentException format:@"Magnification should be a positive number"];
+
+ dismissContentRelativeChildWindowsWithAnimation(false);
+
+ m_page.scalePageInViewCoordinates(magnification, WebCore::roundedIntPoint(centerPoint));
+}
+
+void WebViewImpl::setMagnification(double magnification)
+{
+ if (magnification <= 0 || isnan(magnification) || isinf(magnification))
+ [NSException raise:NSInvalidArgumentException format:@"Magnification should be a positive number"];
+
+ dismissContentRelativeChildWindowsWithAnimation(false);
+
+ WebCore::FloatPoint viewCenter(NSMidX([m_view bounds]), NSMidY([m_view bounds]));
+ m_page.scalePageInViewCoordinates(magnification, roundedIntPoint(viewCenter));
+}
+
+double WebViewImpl::magnification() const
+{
+ if (m_gestureController)
+ return m_gestureController->magnification();
+ return m_page.pageScaleFactor();
+}
+
+void WebViewImpl::setCustomSwipeViews(NSArray *customSwipeViews)
+{
+ if (!customSwipeViews.count && !m_gestureController)
+ return;
+
+ Vector<RetainPtr<NSView>> views;
+ views.reserveInitialCapacity(customSwipeViews.count);
+ for (NSView *view in customSwipeViews)
+ views.uncheckedAppend(view);
+
+ ensureGestureController().setCustomSwipeViews(views);
+}
+
+void WebViewImpl::setCustomSwipeViewsTopContentInset(float topContentInset)
+{
+ ensureGestureController().setCustomSwipeViewsTopContentInset(topContentInset);
+}
+
+bool WebViewImpl::tryToSwipeWithEvent(NSEvent *event, bool ignoringPinnedState)
+{
+ if (!m_allowsBackForwardNavigationGestures)
+ return false;
+
+ auto& gestureController = ensureGestureController();
+
+ bool wasIgnoringPinnedState = gestureController.shouldIgnorePinnedState();
+ gestureController.setShouldIgnorePinnedState(ignoringPinnedState);
+
+ bool handledEvent = gestureController.handleScrollWheelEvent(event);
+
+ gestureController.setShouldIgnorePinnedState(wasIgnoringPinnedState);
+
+ return handledEvent;
+}
+
+void WebViewImpl::setDidMoveSwipeSnapshotCallback(void(^callback)(CGRect))
+{
+ if (!m_allowsBackForwardNavigationGestures)
+ return;
+
+ ensureGestureController().setDidMoveSwipeSnapshotCallback(callback);
+}
+
+void WebViewImpl::scrollWheel(NSEvent *event)
+{
+ if (m_ignoresAllEvents)
+ return;
+
+ if (event.phase == NSEventPhaseBegan)
+ dismissContentRelativeChildWindowsWithAnimation(false);
+
+ if (m_allowsBackForwardNavigationGestures && ensureGestureController().handleScrollWheelEvent(event))
+ return;
+
+ NativeWebWheelEvent webEvent = NativeWebWheelEvent(event, m_view);
+ m_page.handleWheelEvent(webEvent);
+}
+
+void WebViewImpl::swipeWithEvent(NSEvent *event)
+{
+ if (m_ignoresNonWheelEvents)
+ return;
+
+ if (!m_allowsBackForwardNavigationGestures) {
+ [m_view _superSwipeWithEvent:event];
+ return;
+ }
+
+ if (event.deltaX > 0.0)
+ m_page.goBack();
+ else if (event.deltaX < 0.0)
+ m_page.goForward();
+ else
+ [m_view _superSwipeWithEvent:event];
+}
+
+void WebViewImpl::magnifyWithEvent(NSEvent *event)
+{
+ if (!m_allowsMagnification) {
+#if ENABLE(MAC_GESTURE_EVENTS)
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ m_page.handleGestureEvent(webEvent);
+#endif
+ [m_view _superMagnifyWithEvent:event];
+ return;
+ }
+
+ dismissContentRelativeChildWindowsWithAnimation(false);
+
+ auto& gestureController = ensureGestureController();
+
+#if ENABLE(MAC_GESTURE_EVENTS)
+ if (gestureController.hasActiveMagnificationGesture()) {
+ gestureController.handleMagnificationGestureEvent(event, [m_view convertPoint:event.locationInWindow fromView:nil]);
+ return;
+ }
+
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ m_page.handleGestureEvent(webEvent);
+#else
+ gestureController.handleMagnificationGestureEvent(event, [m_view convertPoint:event.locationInWindow fromView:nil]);
+#endif
+}
+
+void WebViewImpl::smartMagnifyWithEvent(NSEvent *event)
+{
+ if (!m_allowsMagnification) {
+ [m_view _superSmartMagnifyWithEvent:event];
+ return;
+ }
+
+ dismissContentRelativeChildWindowsWithAnimation(false);
+
+ ensureGestureController().handleSmartMagnificationGesture([m_view convertPoint:event.locationInWindow fromView:nil]);
+}
+
+#if ENABLE(MAC_GESTURE_EVENTS)
+void WebViewImpl::rotateWithEvent(NSEvent *event)
+{
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ m_page.handleGestureEvent(webEvent);
+}
+#endif
+
+void WebViewImpl::gestureEventWasNotHandledByWebCore(NSEvent *event)
+{
+ [m_view _gestureEventWasNotHandledByWebCore:event];
+}
+
+void WebViewImpl::gestureEventWasNotHandledByWebCoreFromViewOnly(NSEvent *event)
+{
+#if ENABLE(MAC_GESTURE_EVENTS)
+ if (m_gestureController)
+ m_gestureController->gestureEventWasNotHandledByWebCore(event, [m_view convertPoint:event.locationInWindow fromView:nil]);
+#endif
+}
+
} // namespace WebKit
#endif // PLATFORM(MAC)
Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (191633 => 191634)
--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2015-10-27 20:01:08 UTC (rev 191633)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2015-10-27 20:09:29 UTC (rev 191634)
@@ -37,6 +37,7 @@
#import "NativeWebWheelEvent.h"
#import "NavigationState.h"
#import "StringUtilities.h"
+#import "ViewGestureController.h"
#import "ViewSnapshotStore.h"
#import "WKAPICast.h"
#import "WKFullScreenWindowController.h"
@@ -514,7 +515,7 @@
PassRefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot()
{
- return [m_wkView _takeViewSnapshot];
+ return m_impl->takeViewSnapshot();
}
void PageClientImpl::selectionDidChange()
@@ -524,7 +525,8 @@
void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
{
- [m_wkView _wheelEventWasNotHandledByWebCore:event.nativeEvent()];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->wheelEventWasNotHandledByWebCore(event.nativeEvent());
}
#if ENABLE(MAC_GESTURE_EVENTS)
@@ -747,27 +749,32 @@
void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
{
- [m_wkView _didFirstVisuallyNonEmptyLayoutForMainFrame];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->didFirstVisuallyNonEmptyLayoutForMainFrame();
}
void PageClientImpl::didFinishLoadForMainFrame()
{
- [m_wkView _didFinishLoadForMainFrame];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->didFinishLoadForMainFrame();
}
void PageClientImpl::didFailLoadForMainFrame()
{
- [m_wkView _didFailLoadForMainFrame];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->didFailLoadForMainFrame();
}
void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
{
- [m_wkView _didSameDocumentNavigationForMainFrame:type];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->didSameDocumentNavigationForMainFrame(type);
}
void PageClientImpl::removeNavigationGestureSnapshot()
{
- [m_wkView _removeNavigationGestureSnapshot];
+ if (auto gestureController = m_impl->gestureController())
+ gestureController->removeSwipeSnapshot();
}
void PageClientImpl::didChangeBackgroundColor()