Changeset 194125 in webkit


Ignore:
Timestamp:
Dec 15, 2015 4:55:49 PM (8 years ago)
Author:
timothy_horton@apple.com
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.

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r194122 r194125  
     12015-12-15  Tim Horton  <timothy_horton@apple.com>
     2
     3        [Mac] Gesture Events should not have negative scale
     4        https://bugs.webkit.org/show_bug.cgi?id=151065
     5        <rdar://problem/23474123>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * page/EventHandler.cpp:
     10        (WebCore::EventHandler::clear):
     11        * page/EventHandler.h:
     12        Make it possible to use m_gestureInitialDiameter for Mac gesture events too.
     13
    1142015-12-15  Timothy Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WebCore/page/EventHandler.cpp

    r192354 r194125  
    427427    m_clickNode = nullptr;
    428428#if ENABLE(IOS_GESTURE_EVENTS)
     429    m_gestureInitialRotation = GestureUnknown;
     430#endif
     431#if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
    429432    m_gestureInitialDiameter = GestureUnknown;
    430     m_gestureInitialRotation = GestureUnknown;
    431 #endif
    432 #if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
    433433    m_gestureLastDiameter = GestureUnknown;
    434434    m_gestureLastRotation = GestureUnknown;
  • trunk/Source/WebCore/page/EventHandler.h

    r192354 r194125  
    513513
    514514#if ENABLE(IOS_GESTURE_EVENTS)
     515    float m_gestureInitialRotation { GestureUnknown };
     516#endif
     517#if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
    515518    float m_gestureInitialDiameter { GestureUnknown };
    516     float m_gestureInitialRotation { GestureUnknown };
    517 #endif
    518 #if ENABLE(IOS_GESTURE_EVENTS) || ENABLE(MAC_GESTURE_EVENTS)
    519519    float m_gestureLastDiameter { GestureUnknown };
    520520    float m_gestureLastRotation { GestureUnknown };
  • trunk/Source/WebKit2/ChangeLog

    r194124 r194125  
     12015-12-15  Tim Horton  <timothy_horton@apple.com>
     2
     3        [Mac] Gesture Events should not have negative scale
     4        https://bugs.webkit.org/show_bug.cgi?id=151065
     5        <rdar://problem/23474123>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * Shared/NativeWebGestureEvent.h:
     10        * Shared/mac/NativeWebGestureEventMac.mm:
     11        (WebKit::distanceForTouches):
     12        (WebKit::NativeWebGestureEvent::NativeWebGestureEvent):
     13        Compute the distance between the two oldest touches, and use that as
     14        the scale (really the gesture diameter) on the event, instead of
     15        passing through AppKit's magnification (which is computed differently).
     16        This matches the documented behavior of the existing gesture events on iOS.
     17
     18        * UIProcess/API/Cocoa/WKWebView.mm:
     19        (-[WKWebView touchesBeganWithEvent:]):
     20        (-[WKWebView touchesMovedWithEvent:]):
     21        (-[WKWebView touchesEndedWithEvent:]):
     22        (-[WKWebView touchesCancelledWithEvent:]):
     23        * UIProcess/API/mac/WKView.mm:
     24        (-[WKView touchesBeganWithEvent:]):
     25        (-[WKView touchesMovedWithEvent:]):
     26        (-[WKView touchesEndedWithEvent:]):
     27        (-[WKView touchesCancelledWithEvent:]):
     28        Plumb touch events through to WebViewImpl.
     29
     30        * UIProcess/Cocoa/WebViewImpl.h:
     31        * UIProcess/Cocoa/WebViewImpl.mm:
     32        (WebKit::WebViewImpl::WebViewImpl):
     33        (WebKit::WebViewImpl::magnifyWithEvent):
     34        (WebKit::WebViewImpl::touchesOrderedByAge):
     35        (WebKit::WebViewImpl::touchesBeganWithEvent):
     36        (WebKit::WebViewImpl::touchesMovedWithEvent):
     37        (WebKit::WebViewImpl::touchesEndedWithEvent):
     38        (WebKit::WebViewImpl::touchesCancelledWithEvent):
     39        (WebKit::WebViewImpl::rotateWithEvent):
     40        Keep track of the most recent incoming touches, by identifier, in age order.
     41        Pass them through to NativeWebGestureEvent so it can determine the gesture diameter.
     42
    1432015-12-15  Anders Carlsson  <andersca@apple.com>
    244
  • trunk/Source/WebKit2/Shared/NativeWebGestureEvent.h

    r191299 r194125  
    3333
    3434OBJC_CLASS NSEvent;
     35OBJC_CLASS NSTouch;
    3536
    3637namespace WebKit {
     
    3839class NativeWebGestureEvent final : public WebGestureEvent {
    3940public:
    40     explicit NativeWebGestureEvent(NSEvent *, NSView *);
     41    explicit NativeWebGestureEvent(NSEvent *, NSView *, Vector<NSTouch *> touches);
    4142
    4243    NSEvent *nativeEvent() const { return m_nativeEvent.get(); }
  • trunk/Source/WebKit2/Shared/mac/NativeWebGestureEventMac.mm

    r191299 r194125  
    6060}
    6161
    62 NativeWebGestureEvent::NativeWebGestureEvent(NSEvent *event, NSView *view)
     62static CGFloat distanceForTouches(Vector<NSTouch *> touches)
     63{
     64    if (touches.size() < 2)
     65        return -1;
     66
     67    NSPoint firstTouchPosition = touches[0].normalizedPosition;
     68    NSPoint secondTouchPosition = touches[1].normalizedPosition;
     69
     70    CGFloat dx = secondTouchPosition.x - firstTouchPosition.x;
     71    CGFloat dy = secondTouchPosition.y - firstTouchPosition.y;
     72
     73    return sqrtf(dx * dx + dy * dy);
     74}
     75
     76NativeWebGestureEvent::NativeWebGestureEvent(NSEvent *event, NSView *view, Vector<NSTouch *> touches)
    6377    : WebGestureEvent(
    6478        webEventTypeForNSEvent(event),
     
    6680        event.timestamp,
    6781        WebCore::IntPoint(pointForEvent(event, view)),
    68         event.type == NSEventTypeMagnify ? event.magnification : 0,
     82        distanceForTouches(touches),
    6983        event.type == NSEventTypeRotate ? event.rotation : 0)
    7084    , m_nativeEvent(event)
    7185{
     86
    7287}
    7388
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r193489 r194125  
    27122712}
    27132713
     2714- (void)touchesBeganWithEvent:(NSEvent *)event
     2715{
     2716    _impl->touchesBeganWithEvent(event);
     2717}
     2718
     2719- (void)touchesMovedWithEvent:(NSEvent *)event
     2720{
     2721    _impl->touchesMovedWithEvent(event);
     2722}
     2723
     2724- (void)touchesEndedWithEvent:(NSEvent *)event
     2725{
     2726    _impl->touchesEndedWithEvent(event);
     2727}
     2728
     2729- (void)touchesCancelledWithEvent:(NSEvent *)event
     2730{
     2731    _impl->touchesCancelledWithEvent(event);
     2732}
     2733
    27142734- (NSTextInputContext *)_web_superInputContext
    27152735{
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r192834 r194125  
    843843}
    844844
     845- (void)touchesBeganWithEvent:(NSEvent *)event
     846{
     847    _data->_impl->touchesBeganWithEvent(event);
     848}
     849
     850- (void)touchesMovedWithEvent:(NSEvent *)event
     851{
     852    _data->_impl->touchesMovedWithEvent(event);
     853}
     854
     855- (void)touchesEndedWithEvent:(NSEvent *)event
     856{
     857    _data->_impl->touchesEndedWithEvent(event);
     858}
     859
     860- (void)touchesCancelledWithEvent:(NSEvent *)event
     861{
     862    _data->_impl->touchesCancelledWithEvent(event);
     863}
     864
    845865- (instancetype)initWithFrame:(NSRect)frame processPool:(WebProcessPool&)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView
    846866{
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h

    r192898 r194125  
    409409    void smartMagnifyWithEvent(NSEvent *);
    410410
     411    void touchesBeganWithEvent(NSEvent *);
     412    void touchesMovedWithEvent(NSEvent *);
     413    void touchesEndedWithEvent(NSEvent *);
     414    void touchesCancelledWithEvent(NSEvent *);
     415
    411416    void setLastMouseDownEvent(NSEvent *);
    412417
     
    492497    bool mightBeginScrollWhileInactive();
    493498
     499    Vector<NSTouch *> touchesOrderedByAge();
     500
    494501    NSView <WebViewImplDelegate> *m_view;
    495502    std::unique_ptr<PageClient> m_pageClient;
     
    603610    RetainPtr<NSEvent> m_keyDownEventBeingResent;
    604611    Vector<WebCore::KeypressCommand>* m_collectedKeypressCommands { nullptr };
     612
     613    Vector<RetainPtr<id <NSObject, NSCopying>>> m_activeTouchIdentities;
     614    RetainPtr<NSArray> m_lastTouches;
    605615};
    606616   
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm

    r192898 r194125  
    477477
    478478    m_view.wantsLayer = YES;
     479    m_view.acceptsTouchEvents = YES;
    479480
    480481    // Explicitly set the layer contents placement so AppKit will make sure that our layer has masksToBounds set to YES.
     
    31173118    if (!m_allowsMagnification) {
    31183119#if ENABLE(MAC_GESTURE_EVENTS)
    3119         NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
     3120        NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
    31203121        m_page->handleGestureEvent(webEvent);
    31213122#endif
     
    31343135    }
    31353136
    3136     NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
     3137    NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
    31373138    m_page->handleGestureEvent(webEvent);
    31383139#else
     
    31413142}
    31423143
     3144Vector<NSTouch *> WebViewImpl::touchesOrderedByAge()
     3145{
     3146    Vector<NSTouch *> touches;
     3147
     3148    for (auto& touchIdentity : m_activeTouchIdentities) {
     3149        for (NSTouch *touch in m_lastTouches.get()) {
     3150            if (![touch.identity isEqual:touchIdentity.get()])
     3151                continue;
     3152            touches.append(touch);
     3153            break;
     3154        }
     3155    }
     3156
     3157    return touches;
     3158}
     3159
     3160void WebViewImpl::touchesBeganWithEvent(NSEvent *event)
     3161{
     3162    m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
     3163    for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseBegan inView:m_view])
     3164        m_activeTouchIdentities.append(touch.identity);
     3165}
     3166
     3167void WebViewImpl::touchesMovedWithEvent(NSEvent *event)
     3168{
     3169    m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
     3170}
     3171
     3172void WebViewImpl::touchesEndedWithEvent(NSEvent *event)
     3173{
     3174    m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
     3175    for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseEnded inView:m_view]) {
     3176        size_t identityIndex = m_activeTouchIdentities.find(touch.identity);
     3177        ASSERT(identityIndex != notFound);
     3178        m_activeTouchIdentities.remove(identityIndex);
     3179    }
     3180}
     3181
     3182void WebViewImpl::touchesCancelledWithEvent(NSEvent *event)
     3183{
     3184    m_lastTouches = [event touchesMatchingPhase:NSTouchPhaseAny inView:m_view].allObjects;
     3185    for (NSTouch *touch in [event touchesMatchingPhase:NSTouchPhaseCancelled inView:m_view]) {
     3186        size_t identityIndex = m_activeTouchIdentities.find(touch.identity);
     3187        ASSERT(identityIndex != notFound);
     3188        m_activeTouchIdentities.remove(identityIndex);
     3189    }
     3190}
     3191
    31433192void WebViewImpl::smartMagnifyWithEvent(NSEvent *event)
    31443193{
     
    31663215void WebViewImpl::rotateWithEvent(NSEvent *event)
    31673216{
    3168     NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view);
     3217    NativeWebGestureEvent webEvent = NativeWebGestureEvent(event, m_view, touchesOrderedByAge());
    31693218    m_page->handleGestureEvent(webEvent);
    31703219}
Note: See TracChangeset for help on using the changeset viewer.