| 1 | /* |
| 2 | * Copyright (C) 2011, 2014 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #include <wtf/Deque.h> |
| 30 | #include <wtf/HashMap.h> |
| 31 | #include <wtf/HashSet.h> |
| 32 | #include <wtf/RetainPtr.h> |
| 33 | #include <wtf/Vector.h> |
| 34 | |
| 35 | #if PLATFORM(GTK) |
| 36 | #include <WebCore/GUniquePtrGtk.h> |
| 37 | #include <gdk/gdk.h> |
| 38 | #endif |
| 39 | |
| 40 | #if PLATFORM(WPE) |
| 41 | #include <wpe/wpe.h> |
| 42 | #endif |
| 43 | |
| 44 | #if PLATFORM(COCOA) |
| 45 | OBJC_CLASS NSEvent; |
| 46 | #endif |
| 47 | |
| 48 | namespace WTR { |
| 49 | |
| 50 | class TestController; |
| 51 | |
| 52 | #if PLATFORM(GTK) |
| 53 | struct WTREventQueueItem; |
| 54 | #endif |
| 55 | |
| 56 | class EventSenderProxy { |
| 57 | public: |
| 58 | explicit EventSenderProxy(TestController*); |
| 59 | ~EventSenderProxy(); |
| 60 | |
| 61 | WKPoint position() const { return m_position; } |
| 62 | |
| 63 | void mouseDown(unsigned button, WKEventModifiers); |
| 64 | void mouseUp(unsigned button, WKEventModifiers); |
| 65 | void mouseForceDown(); |
| 66 | void mouseForceUp(); |
| 67 | void mouseForceChanged(float); |
| 68 | void mouseForceClick(); |
| 69 | void startAndCancelMouseForceClick(); |
| 70 | void mouseMoveTo(double x, double y); |
| 71 | void mouseScrollBy(int x, int y); |
| 72 | void mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum); |
| 73 | void continuousMouseScrollBy(int x, int y, bool paged); |
| 74 | |
| 75 | void leapForward(int milliseconds); |
| 76 | |
| 77 | void keyDown(WKStringRef key, WKEventModifiers, unsigned location); |
| 78 | |
| 79 | #if ENABLE(TOUCH_EVENTS) |
| 80 | // Touch events. |
| 81 | void addTouchPoint(int x, int y); |
| 82 | void updateTouchPoint(int index, int x, int y); |
| 83 | void setTouchModifier(WKEventModifiers, bool enable); |
| 84 | void setTouchPointRadius(int radiusX, int radiusY); |
| 85 | void touchStart(); |
| 86 | void touchMove(); |
| 87 | void touchEnd(); |
| 88 | void touchCancel(); |
| 89 | void clearTouchPoints(); |
| 90 | void releaseTouchPoint(int index); |
| 91 | void cancelTouchPoint(int index); |
| 92 | #endif |
| 93 | |
| 94 | private: |
| 95 | TestController* m_testController; |
| 96 | |
| 97 | double currentEventTime() { return m_time; } |
| 98 | void updateClickCountForButton(int button); |
| 99 | |
| 100 | #if PLATFORM(GTK) |
| 101 | void replaySavedEvents(); |
| 102 | #endif |
| 103 | |
| 104 | void sendMouseDownToStartPressureEvents(); |
| 105 | #if PLATFORM(COCOA) |
| 106 | enum class PressureChangeDirection { Increasing, Decreasing }; |
| 107 | RetainPtr<NSEvent> beginPressureEvent(int stage); |
| 108 | RetainPtr<NSEvent> pressureChangeEvent(int stage, PressureChangeDirection); |
| 109 | RetainPtr<NSEvent> pressureChangeEvent(int stage, float pressure, PressureChangeDirection); |
| 110 | #endif |
| 111 | |
| 112 | #if PLATFORM(GTK) |
| 113 | void sendOrQueueEvent(GdkEvent*); |
| 114 | void dispatchEvent(GdkEvent*); |
| 115 | GdkEvent* createMouseButtonEvent(GdkEventType, unsigned button, WKEventModifiers); |
| 116 | GUniquePtr<GdkEvent> createTouchEvent(GdkEventType, int id); |
| 117 | void sendUpdatedTouchEvents(); |
| 118 | #endif |
| 119 | |
| 120 | #if PLATFORM(WPE) |
| 121 | Vector<struct wpe_input_touch_event_raw> getUpdatedTouchEvents(); |
| 122 | void removeUpdatedTouchEvents(); |
| 123 | void prepareAndDispatchTouchEvent(enum wpe_input_touch_event_type); |
| 124 | #endif |
| 125 | |
| 126 | #if PLATFORM(WIN) |
| 127 | LRESULT dispatchMessage(UINT message, WPARAM, LPARAM); |
| 128 | POINT positionInPoint() const { return { static_cast<LONG>(m_position.x), static_cast<LONG>(m_position.y) }; } |
| 129 | #endif |
| 130 | |
| 131 | double m_time; |
| 132 | WKPoint m_position; |
| 133 | bool m_leftMouseButtonDown; |
| 134 | int m_clickCount; |
| 135 | double m_clickTime; |
| 136 | WKPoint m_clickPosition; |
| 137 | WKEventMouseButton m_clickButton; |
| 138 | #if PLATFORM(COCOA) |
| 139 | int eventNumber; |
| 140 | #elif PLATFORM(GTK) |
| 141 | Deque<WTREventQueueItem> m_eventQueue; |
| 142 | unsigned m_mouseButtonsCurrentlyDown { 0 }; |
| 143 | Vector<GUniquePtr<GdkEvent>> m_touchEvents; |
| 144 | HashSet<int> m_updatedTouchEvents; |
| 145 | #elif PLATFORM(WPE) |
| 146 | uint32_t m_buttonState; |
| 147 | uint32_t m_mouseButtonsCurrentlyDown { 0 }; |
| 148 | Vector<struct wpe_input_touch_event_raw> m_touchEvents; |
| 149 | HashSet<unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> m_updatedTouchEvents; |
| 150 | #endif |
| 151 | }; |
| 152 | |
| 153 | } // namespace WTR |
| 154 | |