darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 26 | #ifndef PlatformMouseEvent_h |
| 27 | #define PlatformMouseEvent_h |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | |
| 29 | #include "IntPoint.h" |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 30 | #include <wtf/Platform.h> |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 31 | |
darin | e4d34c6 | 2006-10-29 06:48:02 +0000 | [diff] [blame] | 32 | #if PLATFORM(MAC) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 33 | #ifdef __OBJC__ |
| 34 | @class NSEvent; |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 35 | @class NSScreen; |
| 36 | @class NSWindow; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 37 | #else |
| 38 | class NSEvent; |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 39 | class NSScreen; |
| 40 | class NSWindow; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 41 | #endif |
| 42 | #endif |
| 43 | |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 44 | #if PLATFORM(WIN) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 45 | typedef struct HWND__* HWND; |
aroben | 30630fc | 2006-10-03 04:26:59 +0000 | [diff] [blame] | 46 | typedef unsigned UINT; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 47 | typedef unsigned WPARAM; |
| 48 | typedef long LPARAM; |
| 49 | #endif |
| 50 | |
zecke | 2752405 | 2007-09-23 09:50:35 +0000 | [diff] [blame] | 51 | #if PLATFORM(GTK) |
zecke | 258b9a8 | 2007-08-07 22:04:09 +0000 | [diff] [blame] | 52 | typedef struct _GdkEventButton GdkEventButton; |
| 53 | typedef struct _GdkEventMotion GdkEventMotion; |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 56 | #if PLATFORM(QT) |
hausmann | 7fb66c4 | 2007-11-07 14:29:03 +0000 | [diff] [blame] | 57 | class QInputEvent; |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
kevino | b9b68c9 | 2007-10-28 19:18:04 +0000 | [diff] [blame] | 60 | #if PLATFORM(WX) |
| 61 | class wxMouseEvent; |
| 62 | #endif |
| 63 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 64 | namespace WebCore { |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 65 | |
aliceli1 | 304a9583 | 2006-12-12 03:17:45 +0000 | [diff] [blame] | 66 | // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified. |
| 67 | enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton }; |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 68 | enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll }; |
| 69 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 70 | class PlatformMouseEvent { |
| 71 | public: |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 72 | PlatformMouseEvent() |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 73 | : m_button(NoButton) |
| 74 | , m_eventType(MouseEventMoved) |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 75 | , m_clickCount(0) |
| 76 | , m_shiftKey(false) |
| 77 | , m_ctrlKey(false) |
| 78 | , m_altKey(false) |
| 79 | , m_metaKey(false) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 80 | , m_timestamp(0) |
aroben | 3f2ff8c | 2007-07-05 03:00:03 +0000 | [diff] [blame] | 81 | , m_modifierFlags(0) |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 85 | PlatformMouseEvent(const IntPoint& pos, const IntPoint& globalPos, MouseButton button, MouseEventType eventType, |
| 86 | int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 87 | : m_position(pos), m_globalPosition(globalPos), m_button(button) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 88 | , m_eventType(eventType) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 89 | , m_clickCount(clickCount) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 90 | , m_shiftKey(shift) |
| 91 | , m_ctrlKey(ctrl) |
| 92 | , m_altKey(alt) |
| 93 | , m_metaKey(meta) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 94 | , m_timestamp(timestamp) |
aroben | 3f2ff8c | 2007-07-05 03:00:03 +0000 | [diff] [blame] | 95 | , m_modifierFlags(0) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 96 | { |
| 97 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 98 | |
| 99 | const IntPoint& pos() const { return m_position; } |
| 100 | int x() const { return m_position.x(); } |
| 101 | int y() const { return m_position.y(); } |
| 102 | int globalX() const { return m_globalPosition.x(); } |
| 103 | int globalY() const { return m_globalPosition.y(); } |
| 104 | MouseButton button() const { return m_button; } |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 105 | MouseEventType eventType() const { return m_eventType; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 106 | int clickCount() const { return m_clickCount; } |
| 107 | bool shiftKey() const { return m_shiftKey; } |
| 108 | bool ctrlKey() const { return m_ctrlKey; } |
| 109 | bool altKey() const { return m_altKey; } |
| 110 | bool metaKey() const { return m_metaKey; } |
aroben | 3f2ff8c | 2007-07-05 03:00:03 +0000 | [diff] [blame] | 111 | unsigned modifierFlags() const { return m_modifierFlags; } |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 112 | |
| 113 | //time in seconds |
| 114 | double timestamp() const { return m_timestamp; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 115 | |
darin | e4d34c6 | 2006-10-29 06:48:02 +0000 | [diff] [blame] | 116 | #if PLATFORM(MAC) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 117 | PlatformMouseEvent(NSEvent*); |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 118 | int eventNumber() const { return m_eventNumber; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 119 | #endif |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 120 | #if PLATFORM(WIN) |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 121 | PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false); |
hyatt | 5d33875 | 2006-09-29 08:40:25 +0000 | [diff] [blame] | 122 | void setClickCount(int count) { m_clickCount = count; } |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 123 | bool activatedWebView() const { return m_activatedWebView; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 124 | #endif |
zecke | 2752405 | 2007-09-23 09:50:35 +0000 | [diff] [blame] | 125 | #if PLATFORM(GTK) |
zecke | 258b9a8 | 2007-08-07 22:04:09 +0000 | [diff] [blame] | 126 | PlatformMouseEvent(GdkEventButton*); |
| 127 | PlatformMouseEvent(GdkEventMotion*); |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 128 | #endif |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 129 | #if PLATFORM(QT) |
hausmann | 7fb66c4 | 2007-11-07 14:29:03 +0000 | [diff] [blame] | 130 | PlatformMouseEvent(QInputEvent*, int clickCount); |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 131 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 132 | |
kevino | b9b68c9 | 2007-10-28 19:18:04 +0000 | [diff] [blame] | 133 | #if PLATFORM(WX) |
| 134 | PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint); |
| 135 | #endif |
| 136 | |
| 137 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 138 | private: |
| 139 | IntPoint m_position; |
| 140 | IntPoint m_globalPosition; |
| 141 | MouseButton m_button; |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 142 | MouseEventType m_eventType; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 143 | int m_clickCount; |
| 144 | bool m_shiftKey; |
| 145 | bool m_ctrlKey; |
| 146 | bool m_altKey; |
| 147 | bool m_metaKey; |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 148 | double m_timestamp; // unit: seconds |
aroben | 3f2ff8c | 2007-07-05 03:00:03 +0000 | [diff] [blame] | 149 | unsigned m_modifierFlags; |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame] | 150 | #if PLATFORM(MAC) |
| 151 | int m_eventNumber; |
| 152 | #endif |
| 153 | #if PLATFORM(WIN) |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 154 | bool m_activatedWebView; |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 155 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 158 | #if PLATFORM(MAC) |
| 159 | IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window); |
| 160 | IntPoint pointForEvent(NSEvent *event); |
| 161 | IntPoint globalPointForEvent(NSEvent *event); |
| 162 | #endif |
| 163 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 164 | } // namespace WebCore |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 165 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 166 | #endif // PlatformMouseEvent_h |