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 | |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 51 | #if PLATFORM(GDK) |
| 52 | typedef union _GdkEvent GdkEvent; |
| 53 | #endif |
| 54 | |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 55 | #if PLATFORM(QT) |
| 56 | class QMouseEvent; |
| 57 | #endif |
| 58 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 59 | namespace WebCore { |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 60 | |
aliceli1 | 304a9583 | 2006-12-12 03:17:45 +0000 | [diff] [blame] | 61 | // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified. |
| 62 | enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton }; |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 63 | enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll }; |
| 64 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 65 | class PlatformMouseEvent { |
| 66 | public: |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 67 | static const struct CurrentEventTag {} currentEvent; |
| 68 | |
| 69 | PlatformMouseEvent() |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 70 | : m_button(NoButton) |
| 71 | , m_eventType(MouseEventMoved) |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 72 | , m_clickCount(0) |
| 73 | , m_shiftKey(false) |
| 74 | , m_ctrlKey(false) |
| 75 | , m_altKey(false) |
| 76 | , m_metaKey(false) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 77 | , m_timestamp(0) |
ap | 3afac8d | 2006-07-20 19:20:55 +0000 | [diff] [blame] | 78 | { |
| 79 | } |
| 80 | |
| 81 | PlatformMouseEvent(const CurrentEventTag&); |
| 82 | |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 83 | PlatformMouseEvent(const IntPoint& pos, const IntPoint& globalPos, MouseButton button, MouseEventType eventType, |
| 84 | int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 85 | : m_position(pos), m_globalPosition(globalPos), m_button(button) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 86 | , m_eventType(eventType) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 87 | , m_clickCount(clickCount) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 88 | , m_shiftKey(shift) |
| 89 | , m_ctrlKey(ctrl) |
| 90 | , m_altKey(alt) |
| 91 | , m_metaKey(meta) |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 92 | , m_timestamp(timestamp) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 93 | { |
| 94 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 95 | |
| 96 | const IntPoint& pos() const { return m_position; } |
| 97 | int x() const { return m_position.x(); } |
| 98 | int y() const { return m_position.y(); } |
| 99 | int globalX() const { return m_globalPosition.x(); } |
| 100 | int globalY() const { return m_globalPosition.y(); } |
| 101 | MouseButton button() const { return m_button; } |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 102 | MouseEventType eventType() const { return m_eventType; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 103 | int clickCount() const { return m_clickCount; } |
| 104 | bool shiftKey() const { return m_shiftKey; } |
| 105 | bool ctrlKey() const { return m_ctrlKey; } |
| 106 | bool altKey() const { return m_altKey; } |
| 107 | bool metaKey() const { return m_metaKey; } |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 108 | |
| 109 | //time in seconds |
| 110 | double timestamp() const { return m_timestamp; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 111 | |
darin | e4d34c6 | 2006-10-29 06:48:02 +0000 | [diff] [blame] | 112 | #if PLATFORM(MAC) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 113 | PlatformMouseEvent(NSEvent*); |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 114 | int eventNumber() const { return m_eventNumber; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 115 | #endif |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 116 | #if PLATFORM(WIN) |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 117 | PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false); |
hyatt | 5d33875 | 2006-09-29 08:40:25 +0000 | [diff] [blame] | 118 | void setClickCount(int count) { m_clickCount = count; } |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 119 | bool activatedWebView() const { return m_activatedWebView; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 120 | #endif |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 121 | #if PLATFORM(GDK) |
| 122 | PlatformMouseEvent(GdkEvent*); |
| 123 | #endif |
rwlbuis | a90ab05 | 2006-08-18 11:45:29 +0000 | [diff] [blame] | 124 | #if PLATFORM(QT) |
| 125 | PlatformMouseEvent(QMouseEvent*, int clickCount); |
| 126 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 127 | |
| 128 | private: |
| 129 | IntPoint m_position; |
| 130 | IntPoint m_globalPosition; |
| 131 | MouseButton m_button; |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 132 | MouseEventType m_eventType; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 133 | int m_clickCount; |
| 134 | bool m_shiftKey; |
| 135 | bool m_ctrlKey; |
| 136 | bool m_altKey; |
| 137 | bool m_metaKey; |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 138 | double m_timestamp; // unit: seconds |
oliver | a485c2f | 2007-02-01 06:02:09 +0000 | [diff] [blame^] | 139 | #if PLATFORM(MAC) |
| 140 | int m_eventNumber; |
| 141 | #endif |
| 142 | #if PLATFORM(WIN) |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 143 | bool m_activatedWebView; |
aliceli1 | 7159237 | 2006-12-04 23:30:19 +0000 | [diff] [blame] | 144 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 147 | #if PLATFORM(MAC) |
| 148 | IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window); |
| 149 | IntPoint pointForEvent(NSEvent *event); |
| 150 | IntPoint globalPointForEvent(NSEvent *event); |
| 151 | #endif |
| 152 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 153 | } // namespace WebCore |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 154 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 155 | #endif // PlatformMouseEvent_h |