- Revision
- 194125
- Author
- [email protected]
- Date
- 2015-12-15 16:55:49 -0800 (Tue, 15 Dec 2015)
Log Message
[Mac] Gesture Events should not have negative scale
https://bugs.webkit.org/show_bug.cgi?id=151065
<rdar://problem/23474123>
Reviewed by Anders Carlsson.
* Shared/NativeWebGestureEvent.h:
* Shared/mac/NativeWebGestureEventMac.mm:
(WebKit::distanceForTouches):
(WebKit::NativeWebGestureEvent::NativeWebGestureEvent):
Compute the distance between the two oldest touches, and use that as
the scale (really the gesture diameter) on the event, instead of
passing through AppKit's magnification (which is computed differently).
This matches the documented behavior of the existing gesture events on iOS.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView touchesBeganWithEvent:]):
(-[WKWebView touchesMovedWithEvent:]):
(-[WKWebView touchesEndedWithEvent:]):
(-[WKWebView touchesCancelledWithEvent:]):
* UIProcess/API/mac/WKView.mm:
(-[WKView touchesBeganWithEvent:]):
(-[WKView touchesMovedWithEvent:]):
(-[WKView touchesEndedWithEvent:]):
(-[WKView touchesCancelledWithEvent:]):
Plumb touch events through to WebViewImpl.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::WebViewImpl):
(WebKit::WebViewImpl::magnifyWithEvent):
(WebKit::WebViewImpl::touchesOrderedByAge):
(WebKit::WebViewImpl::touchesBeganWithEvent):
(WebKit::WebViewImpl::touchesMovedWithEvent):
(WebKit::WebViewImpl::touchesEndedWithEvent):
(WebKit::WebViewImpl::touchesCancelledWithEvent):
(WebKit::WebViewImpl::rotateWithEvent):
Keep track of the most recent incoming touches, by identifier, in age order.
Pass them through to NativeWebGestureEvent so it can determine the gesture diameter.
* page/EventHandler.cpp:
(WebCore::EventHandler::clear):
* page/EventHandler.h:
Make it possible to use m_gestureInitialDiameter for Mac gesture events too.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (194124 => 194125)
--- trunk/Source/WebCore/ChangeLog 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebCore/ChangeLog 2015-12-16 00:55:49 UTC (rev 194125)
@@ -1,3 +1,16 @@
+2015-12-15 Tim Horton <[email protected]>
+
+ [Mac] Gesture Events should not have negative scale
+ https://bugs.webkit.org/show_bug.cgi?id=151065
+ <rdar://problem/23474123>
+
+ Reviewed by Anders Carlsson.
+
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::clear):
+ * page/EventHandler.h:
+ Make it possible to use m_gestureInitialDiameter for Mac gesture events too.
+
2015-12-15 Timothy Horton <[email protected]>
Try to fix the CMake build
Modified: trunk/Source/WebCore/page/EventHandler.cpp (194124 => 194125)
--- trunk/Source/WebCore/page/EventHandler.cpp 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2015-12-16 00:55:49 UTC (rev 194125)
@@ -426,10 +426,10 @@
m_clickCount = 0;
m_clickNode = nullptr;
#if ENABLE(IOS_GESTURE_EVENTS)
- m_gestureInitialDiameter = GestureUnknown;
m_gestureInitialRotation = GestureUnknown;
#endif
#if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
+ m_gestureInitialDiameter = GestureUnknown;
m_gestureLastDiameter = GestureUnknown;
m_gestureLastRotation = GestureUnknown;
m_gestureTargets.clear();
Modified: trunk/Source/WebCore/page/EventHandler.h (194124 => 194125)
--- trunk/Source/WebCore/page/EventHandler.h 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebCore/page/EventHandler.h 2015-12-16 00:55:49 UTC (rev 194125)
@@ -512,10 +512,10 @@
RefPtr<Node> m_clickNode;
#if ENABLE(IOS_GESTURE_EVENTS)
- float m_gestureInitialDiameter { GestureUnknown };
float m_gestureInitialRotation { GestureUnknown };
#endif
#if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
+ float m_gestureInitialDiameter { GestureUnknown };
float m_gestureLastDiameter { GestureUnknown };
float m_gestureLastRotation { GestureUnknown };
EventTargetSet m_gestureTargets;
Modified: trunk/Source/WebKit2/ChangeLog (194124 => 194125)
--- trunk/Source/WebKit2/ChangeLog 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/ChangeLog 2015-12-16 00:55:49 UTC (rev 194125)
@@ -1,3 +1,45 @@
+2015-12-15 Tim Horton <[email protected]>
+
+ [Mac] Gesture Events should not have negative scale
+ https://bugs.webkit.org/show_bug.cgi?id=151065
+ <rdar://problem/23474123>
+
+ Reviewed by Anders Carlsson.
+
+ * Shared/NativeWebGestureEvent.h:
+ * Shared/mac/NativeWebGestureEventMac.mm:
+ (WebKit::distanceForTouches):
+ (WebKit::NativeWebGestureEvent::NativeWebGestureEvent):
+ Compute the distance between the two oldest touches, and use that as
+ the scale (really the gesture diameter) on the event, instead of
+ passing through AppKit's magnification (which is computed differently).
+ This matches the documented behavior of the existing gesture events on iOS.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView touchesBeganWithEvent:]):
+ (-[WKWebView touchesMovedWithEvent:]):
+ (-[WKWebView touchesEndedWithEvent:]):
+ (-[WKWebView touchesCancelledWithEvent:]):
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView touchesBeganWithEvent:]):
+ (-[WKView touchesMovedWithEvent:]):
+ (-[WKView touchesEndedWithEvent:]):
+ (-[WKView touchesCancelledWithEvent:]):
+ Plumb touch events through to WebViewImpl.
+
+ * UIProcess/Cocoa/WebViewImpl.h:
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::WebViewImpl):
+ (WebKit::WebViewImpl::magnifyWithEvent):
+ (WebKit::WebViewImpl::touchesOrderedByAge):
+ (WebKit::WebViewImpl::touchesBeganWithEvent):
+ (WebKit::WebViewImpl::touchesMovedWithEvent):
+ (WebKit::WebViewImpl::touchesEndedWithEvent):
+ (WebKit::WebViewImpl::touchesCancelledWithEvent):
+ (WebKit::WebViewImpl::rotateWithEvent):
+ Keep track of the most recent incoming touches, by identifier, in age order.
+ Pass them through to NativeWebGestureEvent so it can determine the gesture diameter.
+
2015-12-15 Anders Carlsson <[email protected]>
Call DatabaseManager directly from WKBundle.cpp
Modified: trunk/Source/WebKit2/Shared/NativeWebGestureEvent.h (194124 => 194125)
--- trunk/Source/WebKit2/Shared/NativeWebGestureEvent.h 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/Shared/NativeWebGestureEvent.h 2015-12-16 00:55:49 UTC (rev 194125)
@@ -32,12 +32,13 @@
#include "WebGestureEvent.h"
OBJC_CLASS NSEvent;
+OBJC_CLASS NSTouch;
namespace WebKit {
class NativeWebGestureEvent final : public WebGestureEvent {
public:
- explicit NativeWebGestureEvent(NSEvent *, NSView *);
+ explicit NativeWebGestureEvent(NSEvent *, NSView *, Vector<NSTouch *> touches);
NSEvent *nativeEvent() const { return m_nativeEvent.get(); }
Modified: trunk/Source/WebKit2/Shared/mac/NativeWebGestureEventMac.mm (194124 => 194125)
--- trunk/Source/WebKit2/Shared/mac/NativeWebGestureEventMac.mm 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/Shared/mac/NativeWebGestureEventMac.mm 2015-12-16 00:55:49 UTC (rev 194125)
@@ -59,16 +59,31 @@
return location;
}
-NativeWebGestureEvent::NativeWebGestureEvent(NSEvent *event, NSView *view)
+static CGFloat distanceForTouches(Vector<NSTouch *> touches)
+{
+ if (touches.size() < 2)
+ return -1;
+
+ NSPoint firstTouchPosition = touches[0].normalizedPosition;
+ NSPoint secondTouchPosition = touches[1].normalizedPosition;
+
+ CGFloat dx = secondTouchPosition.x - firstTouchPosition.x;
+ CGFloat dy = secondTouchPosition.y - firstTouchPosition.y;
+
+ return sqrtf(dx * dx + dy * dy);
+}
+
+NativeWebGestureEvent::NativeWebGestureEvent(NSEvent *event, NSView *view, Vector<NSTouch *> touches)
: WebGestureEvent(
webEventTypeForNSEvent(event),
static_cast<Modifiers>(0),
event.timestamp,
WebCore::IntPoint(pointForEvent(event, view)),
- event.type == NSEventTypeMagnify ? event.magnification : 0,
+ distanceForTouches(touches),
event.type == NSEventTypeRotate ? event.rotation : 0)
, m_nativeEvent(event)
{
+
}
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (194124 => 194125)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-12-16 00:55:49 UTC (rev 194125)
@@ -2711,6 +2711,26 @@
[[self _ensureTextFinderClient] selectFindMatch:findMatch completionHandler:completionHandler];
}
+- (void)touchesBeganWithEvent:(NSEvent *)event
+{
+ _impl->touchesBeganWithEvent(event);
+}
+
+- (void)touchesMovedWithEvent:(NSEvent *)event
+{
+ _impl->touchesMovedWithEvent(event);
+}
+
+- (void)touchesEndedWithEvent:(NSEvent *)event
+{
+ _impl->touchesEndedWithEvent(event);
+}
+
+- (void)touchesCancelledWithEvent:(NSEvent *)event
+{
+ _impl->touchesCancelledWithEvent(event);
+}
+
- (NSTextInputContext *)_web_superInputContext
{
return [super inputContext];
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (194124 => 194125)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-12-16 00:55:49 UTC (rev 194125)
@@ -842,6 +842,26 @@
return _data->_impl->namesOfPromisedFilesDroppedAtDestination(dropDestination);
}
+- (void)touchesBeganWithEvent:(NSEvent *)event
+{
+ _data->_impl->touchesBeganWithEvent(event);
+}
+
+- (void)touchesMovedWithEvent:(NSEvent *)event
+{
+ _data->_impl->touchesMovedWithEvent(event);
+}
+
+- (void)touchesEndedWithEvent:(NSEvent *)event
+{
+ _data->_impl->touchesEndedWithEvent(event);
+}
+
+- (void)touchesCancelledWithEvent:(NSEvent *)event
+{
+ _data->_impl->touchesCancelledWithEvent(event);
+}
+
- (instancetype)initWithFrame:(NSRect)frame processPool:(WebProcessPool&)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView
{
self = [super initWithFrame:frame];
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (194124 => 194125)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-12-16 00:55:49 UTC (rev 194125)
@@ -408,6 +408,11 @@
void rotateWithEvent(NSEvent *);
void smartMagnifyWithEvent(NSEvent *);
+ void touchesBeganWithEvent(NSEvent *);
+ void touchesMovedWithEvent(NSEvent *);
+ void touchesEndedWithEvent(NSEvent *);
+ void touchesCancelledWithEvent(NSEvent *);
+
void setLastMouseDownEvent(NSEvent *);
void gestureEventWasNotHandledByWebCore(NSEvent *);
@@ -491,6 +496,8 @@
bool mightBeginDragWhileInactive();
bool mightBeginScrollWhileInactive();
+ Vector<NSTouch *> touchesOrderedByAge();
+
NSView <WebViewImplDelegate> *m_view;
std::unique_ptr<PageClient> m_pageClient;
Ref<WebPageProxy> m_page;
@@ -602,6 +609,9 @@
// that has been already sent to WebCore.
RetainPtr<NSEvent> m_keyDownEventBeingResent;
Vector<WebCore::KeypressCommand>* m_collectedKeypressCommands { nullptr };
+
+ Vector<RetainPtr<id <NSObject, NSCopying>>> m_activeTouchIdentities;
+ RetainPtr<NSArray> m_lastTouches;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (194124 => 194125)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-12-16 00:52:55 UTC (rev 194124)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-12-16 00:55:49 UTC (rev 194125)
@@ -476,6 +476,7 @@
registerDraggedTypes();
m_view.wantsLayer = YES;
+ m_view.acceptsTouchEvents = YES;
// Explicitly set the layer contents placement so AppKit will make sure that our layer has masksToBounds set to YES.
m_view.layerContentsPlacement = NSViewLayerContentsPlacementTopLeft;
@@ -3116,7 +3117,7 @@
{
if (!m_allowsMagnification) {
#if ENABLE(MAC_GESTURE_EVENTS)
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
m_page->handleGestureEvent(webEvent);
#endif
[m_view _web_superMagnifyWithEvent:event];
@@ -3133,13 +3134,61 @@
return;
}
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
m_page->handleGestureEvent(webEvent);
#else
gestureController.handleMagnificationGestureEvent(event, [m_view convertPoint:event.locationInWindow fromView:nil]);
#endif
}
+Vector<NSTouch *> WebViewImpl::touchesOrderedByAge()
+{
+ Vector<NSTouch *> touches;
+
+ for (auto& touchIdentity : m_activeTouchIdentities) {
+ for (NSTouch *touch in m_lastTouches.get()) {
+ if (![touch.identity isEqual:touchIdentity.get()])
+ continue;
+ touches.append(touch);
+ break;
+ }
+ }
+
+ return touches;
+}
+
+void WebViewImpl::touchesBeganWithEvent(NSEvent *event)
+{
+ m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
+ for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseBegan inView:m_view])
+ m_activeTouchIdentities.append(touch.identity);
+}
+
+void WebViewImpl::touchesMovedWithEvent(NSEvent *event)
+{
+ m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
+}
+
+void WebViewImpl::touchesEndedWithEvent(NSEvent *event)
+{
+ m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
+ for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseEnded inView:m_view]) {
+ size_t identityIndex = m_activeTouchIdentities.find(touch.identity);
+ ASSERT(identityIndex != notFound);
+ m_activeTouchIdentities.remove(identityIndex);
+ }
+}
+
+void WebViewImpl::touchesCancelledWithEvent(NSEvent *event)
+{
+ m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
+ for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseCancelled inView:m_view]) {
+ size_t identityIndex = m_activeTouchIdentities.find(touch.identity);
+ ASSERT(identityIndex != notFound);
+ m_activeTouchIdentities.remove(identityIndex);
+ }
+}
+
void WebViewImpl::smartMagnifyWithEvent(NSEvent *event)
{
if (!m_allowsMagnification) {
@@ -3165,7 +3214,7 @@
#if ENABLE(MAC_GESTURE_EVENTS)
void WebViewImpl::rotateWithEvent(NSEvent *event)
{
- NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
+ NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
m_page->handleGestureEvent(webEvent);
}
#endif