Changeset 277772 in webkit


Ignore:
Timestamp:
May 19, 2021 7:26:07 PM (14 months ago)
Author:
Devin Rousso
Message:

Add a way to create "wheel" events from gesture/touch events
https://bugs.webkit.org/show_bug.cgi?id=225788
<rdar://problem/76714308>

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/events/gesture/wheel-from-gesture.html

Other browsers have taken the approach of dispatching "wheel" events with ctrlKey and
deltaY when handling multi-touch pinch-to-zoom gestures. Add helper functions to do this.

  • platform/PlatformWheelEvent.h:
  • platform/PlatformWheelEvent.cpp:

(WebCore::PlatformWheelEvent::createFromGesture): Added.

Tools:

  • WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
  • WebKitTestRunner/InjectedBundle/EventSendingController.h:
  • WebKitTestRunner/InjectedBundle/EventSendingController.cpp:

(WTR::EventSendingController::scaleGestureStart): Added.
(WTR::EventSendingController::scaleGestureChange): Added.
(WTR::EventSendingController::scaleGestureEnd): Added.

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):

  • WebKitTestRunner/EventSenderProxy.h:
  • WebKitTestRunner/mac/EventSenderProxy.mm:

(EventSenderCGGesturePhaseFromNSEventPhase):
(-[EventSenderSyntheticEvent initPressureEventAtLocation:globalLocation:stage:pressure:stageTransition:phase:time:eventNumber:window:]):
(-[EventSenderSyntheticEvent initMagnifyEventAtLocation:globalLocation:magnification:phase:time:eventNumber:window:]): Added.
(-[EventSenderSyntheticEvent magnification]): Added.
(WTR::EventSenderProxy::mouseDown):
(WTR::EventSenderProxy::mouseUp):
(WTR::EventSenderProxy::sendMouseDownToStartPressureEvents):
(WTR::EventSenderProxy::beginPressureEvent):
(WTR::EventSenderProxy::pressureChangeEvent):
(WTR::EventSenderProxy::mouseForceClick):
(WTR::EventSenderProxy::startAndCancelMouseForceClick):
(WTR::EventSenderProxy::mouseMoveTo):
(WTR::EventSenderProxy::scaleGestureStart): Added.
(WTR::EventSenderProxy::scaleGestureChange): Added.
(WTR::EventSenderProxy::scaleGestureEnd): Added.
Allow tests to synthesize scale (a.k.a. magnify) gesture events.

  • WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:

(WTR::EventSenderProxy::EventSenderProxy):
Drive-by: Rename eventNumber to m_eventNumber since it's a member variable.

  • DumpRenderTree/Scripts/generate-derived-sources.sh:
  • DumpRenderTree/DerivedSources.make:
  • WebKitTestRunner/Scripts/generate-derived-sources.sh:
  • WebKitTestRunner/DerivedSources.make:

Make sure to pass all feature flags when generating JS files from IDL files.

LayoutTests:

  • fast/events/gesture/wheel-from-gesture.html: Added.
  • fast/events/gesture/wheel-from-gesture-expected.txt: Added.
Location:
trunk
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r277767 r277772  
     12021-05-19  Devin Rousso  <drousso@apple.com>
     2
     3        Add a way to create `"wheel"` events from gesture/touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=225788
     5        <rdar://problem/76714308>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * fast/events/gesture/wheel-from-gesture.html: Added.
     10        * fast/events/gesture/wheel-from-gesture-expected.txt: Added.
     11
     12        * TestExpectations:
     13
    1142021-05-19  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/LayoutTests/TestExpectations

    r277767 r277772  
    5454http/tests/device-orientation [ Skip ]
    5555fast/events/cursors [ Skip ]
     56fast/events/gesture [ Skip ]
    5657fast/events/ios [ Skip ]
    5758fast/events/watchos [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r277768 r277772  
     12021-05-19  Devin Rousso  <drousso@apple.com>
     2
     3        Add a way to create `"wheel"` events from gesture/touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=225788
     5        <rdar://problem/76714308>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Test: fast/events/gesture/wheel-from-gesture.html
     10
     11        Other browsers have taken the approach of dispatching `"wheel"` events with `ctrlKey` and
     12        `deltaY` when handling multi-touch pinch-to-zoom gestures. Add helper functions to do this.
     13
     14        * platform/PlatformWheelEvent.h:
     15        * platform/PlatformWheelEvent.cpp:
     16        (WebCore::PlatformWheelEvent::createFromGesture): Added.
     17
    1182021-05-19  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebCore/platform/PlatformWheelEvent.cpp

    r270312 r277772  
    2727#include "PlatformWheelEvent.h"
    2828
     29#include "Scrollbar.h"
    2930#include <wtf/text/TextStream.h>
    3031
     32#if ENABLE(MAC_GESTURE_EVENTS)
     33#include "PlatformGestureEventMac.h"
     34#endif
     35
    3136namespace WebCore {
     37
     38#if ENABLE(MAC_GESTURE_EVENTS)
     39
     40PlatformWheelEvent PlatformWheelEvent::createFromGesture(const PlatformGestureEvent& platformGestureEvent, double deltaY)
     41{
     42    // This tries to match as much of the behavior of `WebKit::WebEventFactory::createWebWheelEvent` as
     43    // possible assuming `-[NSEvent hasPreciseScrollingDeltas]` and no `-[NSEvent _scrollCount]`.
     44
     45    double deltaX = 0;
     46    double wheelTicksX = 0;
     47    double wheelTicksY = deltaY / static_cast<float>(Scrollbar::pixelsPerLineStep());
     48    bool shiftKey = platformGestureEvent.modifiers().contains(PlatformEvent::Modifier::ShiftKey);
     49    bool ctrlKey = true;
     50    bool altKey = platformGestureEvent.modifiers().contains(PlatformEvent::Modifier::AltKey);
     51    bool metaKey = platformGestureEvent.modifiers().contains(PlatformEvent::Modifier::MetaKey);
     52    PlatformWheelEvent platformWheelEvent(platformGestureEvent.pos(), platformGestureEvent.globalPosition(), deltaX, deltaY, wheelTicksX, wheelTicksY, ScrollByPixelWheelEvent, shiftKey, ctrlKey, altKey, metaKey);
     53
     54    // PlatformEvent
     55    platformWheelEvent.m_timestamp = platformGestureEvent.timestamp();
     56
     57    // PlatformWheelEvent
     58    platformWheelEvent.m_hasPreciseScrollingDeltas = true;
     59
     60#if ENABLE(KINETIC_SCROLLING)
     61    switch (platformGestureEvent.type()) {
     62    case PlatformEvent::GestureStart:
     63        platformWheelEvent.m_phase = PlatformWheelEventPhase::Began;
     64        break;
     65    case PlatformEvent::GestureChange:
     66        platformWheelEvent.m_phase = PlatformWheelEventPhase::Changed;
     67        break;
     68    case PlatformEvent::GestureEnd:
     69        platformWheelEvent.m_phase = PlatformWheelEventPhase::Ended;
     70        break;
     71    default:
     72        ASSERT_NOT_REACHED();
     73        break;
     74    }
     75#endif // ENABLE(KINETIC_SCROLLING)
     76
     77#if PLATFORM(COCOA)
     78    platformWheelEvent.m_unacceleratedScrollingDeltaY = deltaY;
     79#endif // PLATFORM(COCOA)
     80
     81    return platformWheelEvent;
     82}
     83
     84#endif // ENABLE(MAC_GESTURE_EVENTS)
    3285
    3386#if ENABLE(KINETIC_SCROLLING)
  • trunk/Source/WebCore/platform/PlatformWheelEvent.h

    r270425 r277772  
    3737namespace WebCore {
    3838
     39class PlatformGestureEvent;
     40
    3941enum class WheelEventProcessingSteps : uint8_t {
    4042    ScrollingThread                             = 1 << 0,
     
    107109    }
    108110
     111#if ENABLE(MAC_GESTURE_EVENTS)
     112    static PlatformWheelEvent createFromGesture(const PlatformGestureEvent&, double deltaY);
     113#endif
     114
    109115    PlatformWheelEvent copySwappingDirection() const
    110116    {
  • trunk/Tools/ChangeLog

    r277769 r277772  
     12021-05-19  Devin Rousso  <drousso@apple.com>
     2
     3        Add a way to create `"wheel"` events from gesture/touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=225788
     5        <rdar://problem/76714308>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
     10        * WebKitTestRunner/InjectedBundle/EventSendingController.h:
     11        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
     12        (WTR::EventSendingController::scaleGestureStart): Added.
     13        (WTR::EventSendingController::scaleGestureChange): Added.
     14        (WTR::EventSendingController::scaleGestureEnd): Added.
     15        * WebKitTestRunner/TestController.cpp:
     16        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
     17        * WebKitTestRunner/EventSenderProxy.h:
     18        * WebKitTestRunner/mac/EventSenderProxy.mm:
     19        (EventSenderCGGesturePhaseFromNSEventPhase):
     20        (-[EventSenderSyntheticEvent initPressureEventAtLocation:globalLocation:stage:pressure:stageTransition:phase:time:eventNumber:window:]):
     21        (-[EventSenderSyntheticEvent initMagnifyEventAtLocation:globalLocation:magnification:phase:time:eventNumber:window:]): Added.
     22        (-[EventSenderSyntheticEvent magnification]): Added.
     23        (WTR::EventSenderProxy::mouseDown):
     24        (WTR::EventSenderProxy::mouseUp):
     25        (WTR::EventSenderProxy::sendMouseDownToStartPressureEvents):
     26        (WTR::EventSenderProxy::beginPressureEvent):
     27        (WTR::EventSenderProxy::pressureChangeEvent):
     28        (WTR::EventSenderProxy::mouseForceClick):
     29        (WTR::EventSenderProxy::startAndCancelMouseForceClick):
     30        (WTR::EventSenderProxy::mouseMoveTo):
     31        (WTR::EventSenderProxy::scaleGestureStart): Added.
     32        (WTR::EventSenderProxy::scaleGestureChange): Added.
     33        (WTR::EventSenderProxy::scaleGestureEnd): Added.
     34        Allow tests to synthesize scale (a.k.a. magnify) gesture events.
     35
     36        * WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:
     37        (WTR::EventSenderProxy::EventSenderProxy):
     38        Drive-by: Rename `eventNumber` to `m_eventNumber` since it's a member variable.
     39
     40        * DumpRenderTree/Scripts/generate-derived-sources.sh:
     41        * DumpRenderTree/DerivedSources.make:
     42        * WebKitTestRunner/Scripts/generate-derived-sources.sh:
     43        * WebKitTestRunner/DerivedSources.make:
     44        Make sure to pass all feature flags when generating JS files from IDL files.
     45
    1462021-05-19  Wenson Hsieh  <wenson_hsieh@apple.com>
    247
  • trunk/Tools/DumpRenderTree/DerivedSources.make

    r269105 r277772  
    2222# THE POSSIBILITY OF SUCH DAMAGE.
    2323
     24PERL = perl
    2425RUBY = ruby
     26
     27ifneq ($(SDKROOT),)
     28    SDK_FLAGS = -isysroot $(SDKROOT)
     29endif
     30
     31ifeq ($(USE_LLVM_TARGET_TRIPLES_FOR_CLANG),YES)
     32    WK_CURRENT_ARCH = $(word 1, $(ARCHS))
     33    TARGET_TRIPLE_FLAGS = -target $(WK_CURRENT_ARCH)-$(LLVM_TARGET_TRIPLE_VENDOR)-$(LLVM_TARGET_TRIPLE_OS_VERSION)$(LLVM_TARGET_TRIPLE_SUFFIX)
     34endif
     35
     36FRAMEWORK_FLAGS := $(shell echo $(BUILT_PRODUCTS_DIR) $(FRAMEWORK_SEARCH_PATHS) $(SYSTEM_FRAMEWORK_SEARCH_PATHS) | $(PERL) -e 'print "-F " . join(" -F ", split(" ", <>));')
     37HEADER_FLAGS := $(shell echo $(BUILT_PRODUCTS_DIR) $(HEADER_SEARCH_PATHS) $(SYSTEM_HEADER_SEARCH_PATHS) | $(PERL) -e 'print "-I" . join(" -I", split(" ", <>));')
     38FEATURE_AND_PLATFORM_DEFINES := $(shell $(CC) -std=gnu++1z -x c++ -E -P -dM $(SDK_FLAGS) $(TARGET_TRIPLE_FLAGS) $(FRAMEWORK_FLAGS) $(HEADER_FLAGS) -include "wtf/Platform.h" /dev/null | $(PERL) -ne "print if s/\#define ((HAVE_|USE_|ENABLE_|WTF_PLATFORM_)\w+) 1/\1/")
     39
     40# FIXME: This should list Platform.h and all the things it includes. Could do that by using the -MD flag in the CC line above.
     41FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = $(DumpRenderTree)/DerivedSources.make
    2542
    2643UISCRIPTCONTEXT_DIR = $(DumpRenderTree)/../TestRunnerShared/UIScriptContext/Bindings
     
    4764.PHONY : all
    4865
    49 JS%.h JS%.cpp : %.idl $(SCRIPTS) $(IDL_ATTRIBUTES_FILE)
     66JS%.h JS%.cpp : %.idl $(SCRIPTS) $(IDL_ATTRIBUTES_FILE) $(FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES)
    5067        @echo Generating bindings for $*...
    51         @perl -I $(WebCoreScripts) -I $(UISCRIPTCONTEXT_DIR) -I $(DumpRenderTree)/Bindings $(WebCoreScripts)/generate-bindings.pl --defines "" --include $(UISCRIPTCONTEXT_DIR) --outputDir . --generator DumpRenderTree --idlAttributesFile $(IDL_ATTRIBUTES_FILE) $<
     68        $(PERL) -I $(WebCoreScripts) -I $(UISCRIPTCONTEXT_DIR) -I $(DumpRenderTree)/Bindings $(WebCoreScripts)/generate-bindings.pl --defines "$(FEATURE_AND_PLATFORM_DEFINES)" --include $(UISCRIPTCONTEXT_DIR) --outputDir . --generator DumpRenderTree --idlAttributesFile $(IDL_ATTRIBUTES_FILE) $<
    5269
    5370all : \
  • trunk/Tools/DumpRenderTree/Scripts/generate-derived-sources.sh

    r238639 r277772  
    1616
    1717if [ "${ACTION}" = "build" -o "${ACTION}" = "install" -o "${ACTION}" = "installhdrs" ]; then
    18     make -f "${DumpRenderTree}/DerivedSources.make" -j `/usr/sbin/sysctl -n hw.activecpu` "${ARGS[@]}"
     18    make -f "${DumpRenderTree}/DerivedSources.make" -j `/usr/sbin/sysctl -n hw.activecpu` SDKROOT="${SDKROOT}" "${ARGS[@]}"
    1919fi
  • trunk/Tools/WebKitTestRunner/DerivedSources-input.xcfilelist

    r268604 r277772  
    66$(BUILT_PRODUCTS_DIR)/usr/local/include/wtf/Scripts/Preferences/WebPreferencesInternal.yaml
    77$(PROJECT_DIR)/../TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
     8$(PROJECT_DIR)/DerivedSources.make
    89$(PROJECT_DIR)/InjectedBundle/Bindings/AccessibilityController.idl
    910$(PROJECT_DIR)/InjectedBundle/Bindings/AccessibilityTextMarker.idl
  • trunk/Tools/WebKitTestRunner/DerivedSources.make

    r268604 r277772  
    2727#
    2828
     29PERL = perl
    2930RUBY = ruby
     31
     32ifneq ($(SDKROOT),)
     33    SDK_FLAGS = -isysroot $(SDKROOT)
     34endif
     35
     36ifeq ($(USE_LLVM_TARGET_TRIPLES_FOR_CLANG),YES)
     37    WK_CURRENT_ARCH = $(word 1, $(ARCHS))
     38    TARGET_TRIPLE_FLAGS = -target $(WK_CURRENT_ARCH)-$(LLVM_TARGET_TRIPLE_VENDOR)-$(LLVM_TARGET_TRIPLE_OS_VERSION)$(LLVM_TARGET_TRIPLE_SUFFIX)
     39endif
     40
     41FRAMEWORK_FLAGS := $(shell echo $(BUILT_PRODUCTS_DIR) $(FRAMEWORK_SEARCH_PATHS) $(SYSTEM_FRAMEWORK_SEARCH_PATHS) | $(PERL) -e 'print "-F " . join(" -F ", split(" ", <>));')
     42HEADER_FLAGS := $(shell echo $(BUILT_PRODUCTS_DIR) $(HEADER_SEARCH_PATHS) $(SYSTEM_HEADER_SEARCH_PATHS) | $(PERL) -e 'print "-I" . join(" -I", split(" ", <>));')
     43FEATURE_AND_PLATFORM_DEFINES := $(shell $(CC) -std=gnu++1z -x c++ -E -P -dM $(SDK_FLAGS) $(TARGET_TRIPLE_FLAGS) $(FRAMEWORK_FLAGS) $(HEADER_FLAGS) -include "wtf/Platform.h" /dev/null | $(PERL) -ne "print if s/\#define ((HAVE_|USE_|ENABLE_|WTF_PLATFORM_)\w+) 1/\1/")
     44
     45# FIXME: This should list Platform.h and all the things it includes. Could do that by using the -MD flag in the CC line above.
     46FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = $(WebKitTestRunner)/DerivedSources.make
    3047
    3148WEB_PREFERENCES = \
     
    7491.PHONY : all
    7592
    76 JS%.h JS%.cpp : %.idl $(SCRIPTS) $(IDL_ATTRIBUTES_FILE)
     93JS%.h JS%.cpp : %.idl $(SCRIPTS) $(IDL_ATTRIBUTES_FILE) $(FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES)
    7794        @echo Generating bindings for $*...
    78         @perl -I $(WebCoreScripts) -I $(WebKitTestRunner)/InjectedBundle/Bindings -I $(WebKitTestRunner)/UIScriptContext/Bindings $(WebCoreScripts)/generate-bindings.pl --defines "" --include InjectedBundle/Bindings --include UIScriptContext/Bindings --outputDir . --generator TestRunner --idlAttributesFile $(IDL_ATTRIBUTES_FILE) $<
     95        $(PERL) -I $(WebCoreScripts) -I $(WebKitTestRunner)/InjectedBundle/Bindings -I $(WebKitTestRunner)/UIScriptContext/Bindings $(WebCoreScripts)/generate-bindings.pl --defines "$(FEATURE_AND_PLATFORM_DEFINES)" --include InjectedBundle/Bindings --include UIScriptContext/Bindings --outputDir . --generator TestRunner --idlAttributesFile $(IDL_ATTRIBUTES_FILE) $<
    7996
    8097all : \
  • trunk/Tools/WebKitTestRunner/EventSenderProxy.h

    r270582 r277772  
    8888#endif
    8989
     90#if ENABLE(MAC_GESTURE_EVENTS)
     91    // Gesture events.
     92    void scaleGestureStart(double scale);
     93    void scaleGestureChange(double scale);
     94    void scaleGestureEnd(double scale);
     95#endif
     96
    9097private:
    9198    TestController* m_testController;
     
    122129    unsigned m_mouseButtonsCurrentlyDown { 0 };
    123130#if PLATFORM(COCOA)
    124     int eventNumber { 0 };
     131    int m_eventNumber { 0 };
    125132#endif
    126133#if PLATFORM(WPE)
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl

    r270582 r277772  
    7272    undefined cancelTouchPoint(long index);
    7373#endif
     74
     75#if defined(ENABLE_MAC_GESTURE_EVENTS) && ENABLE_MAC_GESTURE_EVENTS
     76    // Gesture events.
     77    undefined scaleGestureStart(double scale);
     78    undefined scaleGestureChange(double scale);
     79    undefined scaleGestureEnd(double scale);
     80#endif
    7481};
    7582
  • trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp

    r271459 r277772  
    619619#endif
    620620
     621#if ENABLE(MAC_GESTURE_EVENTS)
     622
     623void EventSendingController::scaleGestureStart(double scale)
     624{
     625    auto body = adoptWK(WKMutableDictionaryCreate());
     626    setValue(body, "SubMessage", "ScaleGestureStart");
     627    setValue(body, "Scale", scale);
     628    postSynchronousPageMessage("EventSender", body);
     629}
     630
     631void EventSendingController::scaleGestureChange(double scale)
     632{
     633    auto body = adoptWK(WKMutableDictionaryCreate());
     634    setValue(body, "SubMessage", "ScaleGestureChange");
     635    setValue(body, "Scale", scale);
     636    postSynchronousPageMessage("EventSender", body);
     637}
     638
     639void EventSendingController::scaleGestureEnd(double scale)
     640{
     641    auto body = adoptWK(WKMutableDictionaryCreate());
     642    setValue(body, "SubMessage", "ScaleGestureEnd");
     643    setValue(body, "Scale", scale);
     644    postSynchronousPageMessage("EventSender", body);
     645}
     646
     647#endif // ENABLE(MAC_GESTURE_EVENTS)
     648
    621649// Object Creation
    622650
  • trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h

    r270582 r277772  
    9090#endif
    9191
     92#if ENABLE(MAC_GESTURE_EVENTS)
     93    void scaleGestureStart(double scale);
     94    void scaleGestureChange(double scale);
     95    void scaleGestureEnd(double scale);
     96#endif
     97
    9298private:
    9399    EventSendingController() = default;
  • trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm

    r270582 r277772  
    4040    UNUSED_PARAM(m_testController);
    4141    UNUSED_PARAM(m_leftMouseButtonDown);
    42     UNUSED_PARAM(eventNumber);
     42    UNUSED_PARAM(m_eventNumber);
    4343}
    4444
  • trunk/Tools/WebKitTestRunner/Scripts/generate-derived-sources.sh

    r238639 r277772  
    1616
    1717if [ "${ACTION}" = "build" -o "${ACTION}" = "install" -o "${ACTION}" = "installhdrs" ]; then
    18     make -f "${WebKitTestRunner}/DerivedSources.make" -j `/usr/sbin/sysctl -n hw.activecpu` "${ARGS[@]}"
     18    make -f "${WebKitTestRunner}/DerivedSources.make" -j `/usr/sbin/sysctl -n hw.activecpu` SDKROOT="${SDKROOT}" "${ARGS[@]}"
    1919fi
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r277564 r277772  
    17781778        }
    17791779#endif
     1780
     1781#if ENABLE(MAC_GESTURE_EVENTS)
     1782        if (WKStringIsEqualToUTF8CString(subMessageName, "ScaleGestureStart")) {
     1783            auto scale = doubleValue(dictionary, "Scale");
     1784            m_eventSenderProxy->scaleGestureStart(scale);
     1785            return completionHandler(nullptr);
     1786        }
     1787
     1788        if (WKStringIsEqualToUTF8CString(subMessageName, "ScaleGestureChange")) {
     1789            auto scale = doubleValue(dictionary, "Scale");
     1790            m_eventSenderProxy->scaleGestureChange(scale);
     1791            return completionHandler(nullptr);
     1792        }
     1793
     1794        if (WKStringIsEqualToUTF8CString(subMessageName, "ScaleGestureEnd")) {
     1795            auto scale = doubleValue(dictionary, "Scale");
     1796            m_eventSenderProxy->scaleGestureEnd(scale);
     1797            return completionHandler(nullptr);
     1798        }
     1799#endif // ENABLE(MAC_GESTURE_EVENTS)
     1800
    17801801        ASSERT_NOT_REACHED();
    17811802    }
  • trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm

    r273966 r277772  
    3838#import <WebKit/WKPagePrivate.h>
    3939#import <WebKit/WKWebView.h>
     40#import <pal/spi/cocoa/IOKitSPI.h>
    4041#import <wtf/RetainPtr.h>
    4142
     
    5556    NSInteger _eventSender_stage;
    5657    float _eventSender_pressure;
     58    CGFloat _eventSender_magnification;
    5759    CGFloat _eventSender_stageTransition;
    5860    NSEventPhase _eventSender_phase;
     
    6668
    6769- (id)initPressureEventAtLocation:(NSPoint)location globalLocation:(NSPoint)globalLocation stage:(NSInteger)stage pressure:(float)pressure stageTransition:(float)stageTransition phase:(NSEventPhase)phase time:(NSTimeInterval)time eventNumber:(NSInteger)eventNumber window:(NSWindow *)window;
     70- (id)initMagnifyEventAtLocation:(NSPoint)location globalLocation:(NSPoint)globalLocation magnification:(CGFloat)magnification phase:(NSEventPhase)phase time:(NSTimeInterval)time eventNumber:(NSInteger)eventNumber window:(NSWindow *)window;
    6871- (NSTimeInterval)timestamp;
    6972@end
    7073
    71 @implementation EventSenderSyntheticEvent
    72 
    73 - (instancetype)initPressureEventAtLocation:(NSPoint)location globalLocation:(NSPoint)globalLocation stage:(NSInteger)stage pressure:(float)pressure stageTransition:(float)stageTransition phase:(NSEventPhase)phase time:(NSTimeInterval)time eventNumber:(NSInteger)eventNumber window:(NSWindow *)window
    74 {
    75     CGSGesturePhase gesturePhase;
     74static CGSGesturePhase EventSenderCGGesturePhaseFromNSEventPhase(NSEventPhase phase)
     75{
    7676    switch (phase) {
    7777    case NSEventPhaseMayBegin:
    78         gesturePhase = kCGSGesturePhaseMayBegin;
    79         break;
     78        return kCGSGesturePhaseMayBegin;
     79
    8080    case NSEventPhaseBegan:
    81         gesturePhase = kCGSGesturePhaseBegan;
    82         break;
     81        return kCGSGesturePhaseBegan;
     82
    8383    case NSEventPhaseChanged:
    84         gesturePhase = kCGSGesturePhaseChanged;
    85         break;
     84        return kCGSGesturePhaseChanged;
     85
    8686    case NSEventPhaseCancelled:
    87         gesturePhase = kCGSGesturePhaseCancelled;
    88         break;
     87        return kCGSGesturePhaseCancelled;
     88
    8989    case NSEventPhaseEnded:
    90         gesturePhase = kCGSGesturePhaseEnded;
    91         break;
     90        return kCGSGesturePhaseEnded;
     91
    9292    case NSEventPhaseNone:
    9393    default:
    94         gesturePhase = kCGSGesturePhaseNone;
    95         break;
    96     }
    97 
     94        return kCGSGesturePhaseNone;
     95    }
     96}
     97
     98@implementation EventSenderSyntheticEvent
     99
     100- (instancetype)initPressureEventAtLocation:(NSPoint)location globalLocation:(NSPoint)globalLocation stage:(NSInteger)stage pressure:(float)pressure stageTransition:(float)stageTransition phase:(NSEventPhase)phase time:(NSTimeInterval)time eventNumber:(NSInteger)eventNumber window:(NSWindow *)window
     101{
    98102    auto cgEvent = adoptCF(CGEventCreate(nullptr));
    99103    CGEventSetType(cgEvent.get(), (CGEventType)kCGSEventGesture);
    100     CGEventSetIntegerValueField(cgEvent.get(), kCGEventGestureHIDType, 32);
    101     CGEventSetIntegerValueField(cgEvent.get(), kCGEventGesturePhase, gesturePhase);
     104    CGEventSetIntegerValueField(cgEvent.get(), kCGEventGestureHIDType, kIOHIDEventTypeForce);
     105    CGEventSetIntegerValueField(cgEvent.get(), kCGEventGesturePhase, EventSenderCGGesturePhaseFromNSEventPhase(phase));
    102106    CGEventSetDoubleValueField(cgEvent.get(), kCGEventStagePressure, pressure);
    103107    CGEventSetDoubleValueField(cgEvent.get(), kCGEventTransitionProgress, pressure);
     
    124128}
    125129
     130- (id)initMagnifyEventAtLocation:(NSPoint)location globalLocation:(NSPoint)globalLocation magnification:(CGFloat)magnification phase:(NSEventPhase)phase time:(NSTimeInterval)time eventNumber:(NSInteger)eventNumber window:(NSWindow *)window
     131{
     132    auto cgEvent = adoptCF(CGEventCreate(nullptr));
     133    CGEventSetType(cgEvent.get(), (CGEventType)kCGSEventGesture);
     134    CGEventSetIntegerValueField(cgEvent.get(), kCGEventGestureHIDType, kIOHIDEventTypeZoom);
     135    CGEventSetIntegerValueField(cgEvent.get(), kCGEventGesturePhase, EventSenderCGGesturePhaseFromNSEventPhase(phase));
     136    CGEventSetDoubleValueField(cgEvent.get(), kCGEventGestureZoomValue, magnification);
     137
     138    if (!(self = [super _initWithCGEvent:cgEvent.get() eventRef:nullptr]))
     139        return nil;
     140
     141    _eventSender_location = location;
     142    _eventSender_locationInWindow = globalLocation;
     143    _eventSender_magnification = magnification;
     144    _eventSender_phase = phase;
     145    _eventSender_timestamp = time;
     146    _eventSender_eventNumber = eventNumber;
     147    _eventSender_window = window;
     148    _eventSender_type = NSEventTypeMagnify;
     149
     150    return self;
     151}
     152
    126153- (CGFloat)stageTransition
    127154{
     
    162189{
    163190    return _eventSender_pressure;
     191}
     192
     193- (CGFloat)magnification
     194{
     195    return _eventSender_magnification;
    164196}
    165197
     
    309341                                    windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
    310342                                         context:[NSGraphicsContext currentContext]
    311                                      eventNumber:++eventNumber
     343                                     eventNumber:++m_eventNumber
    312344                                      clickCount:m_clickCount
    313345                                        pressure:0.0];
     
    335367                                    windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
    336368                                         context:[NSGraphicsContext currentContext]
    337                                      eventNumber:++eventNumber
     369                                     eventNumber:++m_eventNumber
    338370                                      clickCount:m_clickCount
    339371                                        pressure:0.0];
     
    367399        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
    368400        context:[NSGraphicsContext currentContext]
    369         eventNumber:++eventNumber
     401        eventNumber:++m_eventNumber
    370402        clickCount:m_clickCount
    371403        pressure:0.0];
     
    391423        phase:NSEventPhaseBegan
    392424        time:absoluteTimeForEventTime(currentEventTime())
    393         eventNumber:++eventNumber
     425        eventNumber:++m_eventNumber
    394426        window:[m_testController->mainWebView()->platformView() window]]);
    395427
     
    406438        phase:NSEventPhaseChanged
    407439        time:absoluteTimeForEventTime(currentEventTime())
    408         eventNumber:++eventNumber
     440        eventNumber:++m_eventNumber
    409441        window:[m_testController->mainWebView()->platformView() window]]);
    410442
     
    431463        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
    432464        context:[NSGraphicsContext currentContext]
    433         eventNumber:++eventNumber
     465        eventNumber:++m_eventNumber
    434466        clickCount:m_clickCount
    435467        pressure:0.0];
     
    467499        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
    468500        context:[NSGraphicsContext currentContext]
    469         eventNumber:++eventNumber
     501        eventNumber:++m_eventNumber
    470502        clickCount:m_clickCount
    471503        pressure:0.0];
     
    568600                                    windowNumber:view.window.windowNumber
    569601                                         context:[NSGraphicsContext currentContext]
    570                                      eventNumber:++eventNumber
     602                                     eventNumber:++m_eventNumber
    571603                                      clickCount:(m_leftMouseButtonDown ? m_clickCount : 0)
    572604                                        pressure:0];
     
    873905}
    874906
     907#if ENABLE(MAC_GESTURE_EVENTS)
     908
     909void EventSenderProxy::scaleGestureStart(double scale)
     910{
     911    auto* mainWebView = m_testController->mainWebView();
     912    NSView *platformView = mainWebView->platformView();
     913
     914    auto event = adoptNS([[EventSenderSyntheticEvent alloc] initMagnifyEventAtLocation:NSMakePoint(m_position.x, m_position.y)
     915        globalLocation:([mainWebView->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin)
     916        magnification:scale
     917        phase:NSEventPhaseBegan
     918        time:absoluteTimeForEventTime(currentEventTime())
     919        eventNumber:++m_eventNumber
     920        window:platformView.window]);
     921
     922    if (NSView *targetView = [platformView hitTest:[event locationInWindow]]) {
     923        [NSApp _setCurrentEvent:event.get()];
     924        [targetView magnifyWithEvent:event.get()];
     925        [NSApp _setCurrentEvent:nil];
     926    } else {
     927        NSPoint windowLocation = [event locationInWindow];
     928        WTFLogAlways("gestureStart failed to find the target view at %f,%f\n", windowLocation.x, windowLocation.y);
     929    }
     930}
     931
     932void EventSenderProxy::scaleGestureChange(double scale)
     933{
     934    auto* mainWebView = m_testController->mainWebView();
     935    NSView *platformView = mainWebView->platformView();
     936
     937    auto event = adoptNS([[EventSenderSyntheticEvent alloc] initMagnifyEventAtLocation:NSMakePoint(m_position.x, m_position.y)
     938        globalLocation:([mainWebView->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin)
     939        magnification:scale
     940        phase:NSEventPhaseChanged
     941        time:absoluteTimeForEventTime(currentEventTime())
     942        eventNumber:++m_eventNumber
     943        window:platformView.window]);
     944
     945    if (NSView *targetView = [platformView hitTest:[event locationInWindow]]) {
     946        [NSApp _setCurrentEvent:event.get()];
     947        [targetView magnifyWithEvent:event.get()];
     948        [NSApp _setCurrentEvent:nil];
     949    } else {
     950        NSPoint windowLocation = [event locationInWindow];
     951        WTFLogAlways("gestureStart failed to find the target view at %f,%f\n", windowLocation.x, windowLocation.y);
     952    }
     953}
     954
     955void EventSenderProxy::scaleGestureEnd(double scale)
     956{
     957    auto* mainWebView = m_testController->mainWebView();
     958    NSView *platformView = mainWebView->platformView();
     959
     960    auto event = adoptNS([[EventSenderSyntheticEvent alloc] initMagnifyEventAtLocation:NSMakePoint(m_position.x, m_position.y)
     961        globalLocation:([mainWebView->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin)
     962        magnification:scale
     963        phase:NSEventPhaseEnded
     964        time:absoluteTimeForEventTime(currentEventTime())
     965        eventNumber:++m_eventNumber
     966        window:platformView.window]);
     967
     968    if (NSView *targetView = [platformView hitTest:[event locationInWindow]]) {
     969        [NSApp _setCurrentEvent:event.get()];
     970        [targetView magnifyWithEvent:event.get()];
     971        [NSApp _setCurrentEvent:nil];
     972    } else {
     973        NSPoint windowLocation = [event locationInWindow];
     974        WTFLogAlways("gestureStart failed to find the target view at %f,%f\n", windowLocation.x, windowLocation.y);
     975    }
     976}
     977
     978#endif // ENABLE(MAC_GESTURE_EVENTS)
     979
    875980} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.