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 COMPUTER, 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 COMPUTER, 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 31 #if PLATFORM(GTK) 32 typedef struct _GdkEventButton GdkEventButton; 33 typedef struct _GdkEventMotion GdkEventMotion; 34 #endif 35 36 #if PLATFORM(EFL) 37 typedef struct _Evas_Event_Mouse_Down Evas_Event_Mouse_Down; 38 typedef struct _Evas_Event_Mouse_Up Evas_Event_Mouse_Up; 39 typedef struct _Evas_Event_Mouse_Move Evas_Event_Mouse_Move; 40 #endif 41 42 #if PLATFORM(QT) 43 QT_BEGIN_NAMESPACE 44 class QInputEvent; 45 class QGraphicsSceneMouseEvent; 46 QT_END_NAMESPACE 47 #endif 48 49 #if PLATFORM(WIN) 50 typedef struct HWND__* HWND; 51 typedef unsigned UINT; 52 typedef unsigned WPARAM; 53 typedef long LPARAM; 54 #endif 55 56 #if PLATFORM(WX) 57 class wxMouseEvent; 58 #endif 59 60 #if PLATFORM(HAIKU) 61 class BMessage; 62 #endif 63 64 #if PLATFORM(BREWMP) 65 typedef unsigned short uint16; 66 typedef unsigned long int uint32; 67 #define AEEEvent uint16 68 #endif 69 70 namespace WebCore { 71 72 // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified. 73 enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton }; 74 enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll }; 75 76 class PlatformMouseEvent { 77 public: 78 PlatformMouseEvent() 79 : m_button(NoButton) 80 , m_eventType(MouseEventMoved) 81 , m_clickCount(0) 82 , m_shiftKey(false) 83 , m_ctrlKey(false) 84 , m_altKey(false) 85 , m_metaKey(false) 86 , m_timestamp(0) 87 , m_modifierFlags(0) 88 #if PLATFORM(MAC) 89 , m_eventNumber(0) 90 #elif PLATFORM(WIN) 91 , m_didActivateWebView(false) 92 #endif 93 { 94 } 95 96 PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, MouseEventType eventType, 97 int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp) 98 : m_position(position) 99 , m_globalPosition(globalPosition) 100 , m_button(button) 101 , m_eventType(eventType) 102 , m_clickCount(clickCount) 103 , m_shiftKey(shift) 104 , m_ctrlKey(ctrl) 105 , m_altKey(alt) 106 , m_metaKey(meta) 107 , m_timestamp(timestamp) 108 , m_modifierFlags(0) 109 #if PLATFORM(MAC) 110 , m_eventNumber(0) 111 #elif PLATFORM(WIN) 112 , m_didActivateWebView(false) 113 #endif 114 { 115 } 116 117 const IntPoint& pos() const { return m_position; } 118 int x() const { return m_position.x(); } 119 int y() const { return m_position.y(); } 120 int globalX() const { return m_globalPosition.x(); } 121 int globalY() const { return m_globalPosition.y(); } 122 MouseButton button() const { return m_button; } 123 MouseEventType eventType() const { return m_eventType; } 124 int clickCount() const { return m_clickCount; } 125 bool shiftKey() const { return m_shiftKey; } 126 bool ctrlKey() const { return m_ctrlKey; } 127 bool altKey() const { return m_altKey; } 128 bool metaKey() const { return m_metaKey; } 129 unsigned modifierFlags() const { return m_modifierFlags; } 130 131 // Time in seconds. 132 double timestamp() const { return m_timestamp; } 133 134 #if PLATFORM(GTK) 135 PlatformMouseEvent(GdkEventButton*); 136 PlatformMouseEvent(GdkEventMotion*); 137 void setClickCount(int count) { m_clickCount = count; } 138 #endif 139 140 #if PLATFORM(EFL) 141 void setClickCount(unsigned int); 142 PlatformMouseEvent(const Evas_Event_Mouse_Down*, IntPoint); 143 PlatformMouseEvent(const Evas_Event_Mouse_Up*, IntPoint); 144 PlatformMouseEvent(const Evas_Event_Mouse_Move*, IntPoint); 145 #endif 146 147 #if PLATFORM(MAC) 148 #if defined(__OBJC__) 149 PlatformMouseEvent(NSEvent *, NSView *windowView); 150 #endif 151 PlatformMouseEvent(int x, int y, int globalX, int globalY, MouseButton button, MouseEventType eventType, 152 int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp, 153 unsigned modifierFlags, int eventNumber); 154 int eventNumber() const { return m_eventNumber; } 155 #endif 156 157 #if PLATFORM(QT) 158 PlatformMouseEvent(QInputEvent*, int clickCount); 159 PlatformMouseEvent(QGraphicsSceneMouseEvent*, int clickCount); 160 #endif 161 162 #if PLATFORM(WIN) 163 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool didActivateWebView = false); 164 void setClickCount(int count) { m_clickCount = count; } 165 bool didActivateWebView() const { return m_didActivateWebView; } 166 #endif 167 168 #if PLATFORM(WX) 169 PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint, int clickCount); 170 #endif 171 172 #if PLATFORM(HAIKU) 173 PlatformMouseEvent(const BMessage*); 174 #endif 175 176 #if PLATFORM(BREWMP) 177 PlatformMouseEvent(AEEEvent, uint16 wParam, uint32 dwParam); 178 #endif 179 180 protected: 181 IntPoint m_position; 182 IntPoint m_globalPosition; 183 MouseButton m_button; 184 MouseEventType m_eventType; 185 int m_clickCount; 186 bool m_shiftKey; 187 bool m_ctrlKey; 188 bool m_altKey; 189 bool m_metaKey; 190 double m_timestamp; // unit: seconds 191 unsigned m_modifierFlags; 192 193 #if PLATFORM(MAC) 194 int m_eventNumber; 195 #elif PLATFORM(WIN) 196 bool m_didActivateWebView; 197 #endif 198 }; 199 200 #if PLATFORM(MAC) && defined(__OBJC__) 201 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *); 202 IntPoint pointForEvent(NSEvent *, NSView *windowView); 203 IntPoint globalPointForEvent(NSEvent *); 204 #endif 205 206 } // namespace WebCore 207 208 #endif // PlatformMouseEvent_h 209