| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef PlatformMouseEvent_h |
| 27 | #define PlatformMouseEvent_h |
| 28 | |
| 29 | #include "IntPoint.h" |
| 30 | #include "PlatformEvent.h" |
| 31 | #include <wtf/WindowsExtras.h> |
| 32 | |
| 33 | #if PLATFORM(GTK) |
| 34 | typedef struct _GdkEventButton GdkEventButton; |
| 35 | typedef struct _GdkEventMotion GdkEventMotion; |
| 36 | #endif |
| 37 | |
| 38 | namespace WebCore { |
| 39 | |
| 40 | const double ForceAtClick = 1; |
| 41 | const double ForceAtForceClick = 2; |
| 42 | |
| 43 | // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified. |
| 44 | enum MouseButton : int8_t { NoButton = -1, LeftButton, MiddleButton, RightButton }; |
| 45 | enum SyntheticClickType : int8_t { NoTap, OneFingerTap, TwoFingerTap }; |
| 46 | |
| 47 | class PlatformMouseEvent : public PlatformEvent { |
| 48 | public: |
| 49 | PlatformMouseEvent() |
| 50 | : PlatformEvent(PlatformEvent::MouseMoved) |
| 51 | , m_button(NoButton) |
| 52 | , m_clickCount(0) |
| 53 | , m_modifierFlags(0) |
| 54 | #if PLATFORM(MAC) |
| 55 | , m_eventNumber(0) |
| 56 | , m_menuTypeForEvent(0) |
| 57 | #elif PLATFORM(WIN) |
| 58 | , m_didActivateWebView(false) |
| 59 | #endif |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type, |
| 64 | int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, WallTime timestamp, double force, SyntheticClickType syntheticClickType) |
| 65 | : PlatformEvent(type, shiftKey, ctrlKey, altKey, metaKey, timestamp) |
| 66 | , m_position(position) |
| 67 | , m_globalPosition(globalPosition) |
| 68 | , m_button(button) |
| 69 | , m_clickCount(clickCount) |
| 70 | , m_modifierFlags(0) |
| 71 | , m_force(force) |
| 72 | , m_syntheticClickType(syntheticClickType) |
| 73 | #if PLATFORM(MAC) |
| 74 | , m_eventNumber(0) |
| 75 | , m_menuTypeForEvent(0) |
| 76 | #elif PLATFORM(WIN) |
| 77 | , m_didActivateWebView(false) |
| 78 | #endif |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | const IntPoint& position() const { return m_position; } |
| 83 | const IntPoint& globalPosition() const { return m_globalPosition; } |
| 84 | #if ENABLE(POINTER_LOCK) |
| 85 | const IntPoint& movementDelta() const { return m_movementDelta; } |
| 86 | #endif |
| 87 | |
| 88 | MouseButton button() const { return m_button; } |
| 89 | unsigned short buttons() const { return m_buttons; } |
| 90 | int clickCount() const { return m_clickCount; } |
| 91 | unsigned modifierFlags() const { return m_modifierFlags; } |
| 92 | double force() const { return m_force; } |
| 93 | SyntheticClickType syntheticClickType() const { return m_syntheticClickType; } |
| 94 | |
| 95 | #if PLATFORM(GTK) |
| 96 | explicit PlatformMouseEvent(GdkEventButton*); |
| 97 | explicit PlatformMouseEvent(GdkEventMotion*); |
| 98 | void setClickCount(int count) { m_clickCount = count; } |
| 99 | #endif |
| 100 | |
| 101 | #if PLATFORM(MAC) |
| 102 | int eventNumber() const { return m_eventNumber; } |
| 103 | int menuTypeForEvent() const { return m_menuTypeForEvent; } |
| 104 | #endif |
| 105 | |
| 106 | #if PLATFORM(WIN) |
| 107 | PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool didActivateWebView = false); |
| 108 | void setClickCount(int count) { m_clickCount = count; } |
| 109 | bool didActivateWebView() const { return m_didActivateWebView; } |
| 110 | #endif |
| 111 | |
| 112 | protected: |
| 113 | IntPoint m_position; |
| 114 | IntPoint m_globalPosition; |
| 115 | #if ENABLE(POINTER_LOCK) |
| 116 | IntPoint m_movementDelta; |
| 117 | #endif |
| 118 | MouseButton m_button; |
| 119 | unsigned short m_buttons { 0 }; |
| 120 | int m_clickCount; |
| 121 | unsigned m_modifierFlags; |
| 122 | double m_force { 0 }; |
| 123 | SyntheticClickType m_syntheticClickType { NoTap }; |
| 124 | |
| 125 | #if PLATFORM(MAC) |
| 126 | int m_eventNumber; |
| 127 | int m_menuTypeForEvent; |
| 128 | #elif PLATFORM(WIN) |
| 129 | bool m_didActivateWebView; |
| 130 | #endif |
| 131 | }; |
| 132 | |
| 133 | #if COMPILER(MSVC) |
| 134 | // These functions are necessary to work around the fact that MSVC will not find a most-specific |
| 135 | // operator== to use after implicitly converting MouseButton to an unsigned short. |
| 136 | inline bool operator==(unsigned short a, MouseButton b) |
| 137 | { |
| 138 | return a == static_cast<unsigned short>(b); |
| 139 | } |
| 140 | |
| 141 | inline bool operator!=(unsigned short a, MouseButton b) |
| 142 | { |
| 143 | return a != static_cast<unsigned short>(b); |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | } // namespace WebCore |
| 148 | |
| 149 | #endif // PlatformMouseEvent_h |
| 150 | |