blob: 983a5d11683fd716a98051dbdcf930318be295a5 [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
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
weinig681a5172006-06-19 22:58:36 +000026#ifndef PlatformMouseEvent_h
27#define PlatformMouseEvent_h
darinb9481ed2006-03-20 02:57:59 +000028
29#include "IntPoint.h"
weinigf18aae32006-08-03 21:55:57 +000030#include <wtf/Platform.h>
darinb9481ed2006-03-20 02:57:59 +000031
darine4d34c62006-10-29 06:48:02 +000032#if PLATFORM(MAC)
darinb9481ed2006-03-20 02:57:59 +000033#ifdef __OBJC__
34@class NSEvent;
ggaren52fd1072006-11-06 23:56:59 +000035@class NSScreen;
36@class NSWindow;
darinb9481ed2006-03-20 02:57:59 +000037#else
38class NSEvent;
ggaren52fd1072006-11-06 23:56:59 +000039class NSScreen;
40class NSWindow;
darinb9481ed2006-03-20 02:57:59 +000041#endif
42#endif
43
weinigf18aae32006-08-03 21:55:57 +000044#if PLATFORM(WIN)
darinb9481ed2006-03-20 02:57:59 +000045typedef struct HWND__* HWND;
aroben30630fc2006-10-03 04:26:59 +000046typedef unsigned UINT;
darinb9481ed2006-03-20 02:57:59 +000047typedef unsigned WPARAM;
48typedef long LPARAM;
49#endif
50
zecke27524052007-09-23 09:50:35 +000051#if PLATFORM(GTK)
zecke258b9a82007-08-07 22:04:09 +000052typedef struct _GdkEventButton GdkEventButton;
53typedef struct _GdkEventMotion GdkEventMotion;
ggaren1ec99532006-06-10 16:09:27 +000054#endif
55
rwlbuisa90ab052006-08-18 11:45:29 +000056#if PLATFORM(QT)
hausmann7fb66c42007-11-07 14:29:03 +000057class QInputEvent;
rwlbuisa90ab052006-08-18 11:45:29 +000058#endif
59
kevinob9b68c92007-10-28 19:18:04 +000060#if PLATFORM(WX)
61class wxMouseEvent;
62#endif
63
darinb9481ed2006-03-20 02:57:59 +000064namespace WebCore {
olivera485c2f2007-02-01 06:02:09 +000065
aliceli1304a95832006-12-12 03:17:45 +000066 // 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 };
olivera485c2f2007-02-01 06:02:09 +000068 enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll };
69
darinb9481ed2006-03-20 02:57:59 +000070 class PlatformMouseEvent {
71 public:
ap3afac8d2006-07-20 19:20:55 +000072 PlatformMouseEvent()
olivera485c2f2007-02-01 06:02:09 +000073 : m_button(NoButton)
74 , m_eventType(MouseEventMoved)
ap3afac8d2006-07-20 19:20:55 +000075 , m_clickCount(0)
76 , m_shiftKey(false)
77 , m_ctrlKey(false)
78 , m_altKey(false)
79 , m_metaKey(false)
olivera485c2f2007-02-01 06:02:09 +000080 , m_timestamp(0)
aroben3f2ff8c2007-07-05 03:00:03 +000081 , m_modifierFlags(0)
ap3afac8d2006-07-20 19:20:55 +000082 {
83 }
84
olivera485c2f2007-02-01 06:02:09 +000085 PlatformMouseEvent(const IntPoint& pos, const IntPoint& globalPos, MouseButton button, MouseEventType eventType,
86 int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp)
darinb9481ed2006-03-20 02:57:59 +000087 : m_position(pos), m_globalPosition(globalPos), m_button(button)
olivera485c2f2007-02-01 06:02:09 +000088 , m_eventType(eventType)
darinb9481ed2006-03-20 02:57:59 +000089 , m_clickCount(clickCount)
weinig681a5172006-06-19 22:58:36 +000090 , m_shiftKey(shift)
91 , m_ctrlKey(ctrl)
92 , m_altKey(alt)
93 , m_metaKey(meta)
olivera485c2f2007-02-01 06:02:09 +000094 , m_timestamp(timestamp)
aroben3f2ff8c2007-07-05 03:00:03 +000095 , m_modifierFlags(0)
weinig681a5172006-06-19 22:58:36 +000096 {
97 }
darinb9481ed2006-03-20 02:57:59 +000098
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; }
olivera485c2f2007-02-01 06:02:09 +0000105 MouseEventType eventType() const { return m_eventType; }
darinb9481ed2006-03-20 02:57:59 +0000106 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; }
aroben3f2ff8c2007-07-05 03:00:03 +0000111 unsigned modifierFlags() const { return m_modifierFlags; }
olivera485c2f2007-02-01 06:02:09 +0000112
113 //time in seconds
114 double timestamp() const { return m_timestamp; }
darinb9481ed2006-03-20 02:57:59 +0000115
darine4d34c62006-10-29 06:48:02 +0000116#if PLATFORM(MAC)
darinb9481ed2006-03-20 02:57:59 +0000117 PlatformMouseEvent(NSEvent*);
olivera485c2f2007-02-01 06:02:09 +0000118 int eventNumber() const { return m_eventNumber; }
darinb9481ed2006-03-20 02:57:59 +0000119#endif
weinigf18aae32006-08-03 21:55:57 +0000120#if PLATFORM(WIN)
aliceli171592372006-12-04 23:30:19 +0000121 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false);
hyatt5d338752006-09-29 08:40:25 +0000122 void setClickCount(int count) { m_clickCount = count; }
aliceli171592372006-12-04 23:30:19 +0000123 bool activatedWebView() const { return m_activatedWebView; }
darinb9481ed2006-03-20 02:57:59 +0000124#endif
zecke27524052007-09-23 09:50:35 +0000125#if PLATFORM(GTK)
zecke258b9a82007-08-07 22:04:09 +0000126 PlatformMouseEvent(GdkEventButton*);
127 PlatformMouseEvent(GdkEventMotion*);
ggaren1ec99532006-06-10 16:09:27 +0000128#endif
rwlbuisa90ab052006-08-18 11:45:29 +0000129#if PLATFORM(QT)
hausmann7fb66c42007-11-07 14:29:03 +0000130 PlatformMouseEvent(QInputEvent*, int clickCount);
rwlbuisa90ab052006-08-18 11:45:29 +0000131#endif
darinb9481ed2006-03-20 02:57:59 +0000132
kevinob9b68c92007-10-28 19:18:04 +0000133#if PLATFORM(WX)
134 PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint);
135#endif
136
137
darinb9481ed2006-03-20 02:57:59 +0000138 private:
139 IntPoint m_position;
140 IntPoint m_globalPosition;
141 MouseButton m_button;
olivera485c2f2007-02-01 06:02:09 +0000142 MouseEventType m_eventType;
darinb9481ed2006-03-20 02:57:59 +0000143 int m_clickCount;
144 bool m_shiftKey;
145 bool m_ctrlKey;
146 bool m_altKey;
147 bool m_metaKey;
aliceli171592372006-12-04 23:30:19 +0000148 double m_timestamp; // unit: seconds
aroben3f2ff8c2007-07-05 03:00:03 +0000149 unsigned m_modifierFlags;
olivera485c2f2007-02-01 06:02:09 +0000150#if PLATFORM(MAC)
151 int m_eventNumber;
152#endif
153#if PLATFORM(WIN)
aliceli171592372006-12-04 23:30:19 +0000154 bool m_activatedWebView;
aliceli171592372006-12-04 23:30:19 +0000155#endif
darinb9481ed2006-03-20 02:57:59 +0000156 };
157
ggaren52fd1072006-11-06 23:56:59 +0000158#if PLATFORM(MAC)
159 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window);
160 IntPoint pointForEvent(NSEvent *event);
161 IntPoint globalPointForEvent(NSEvent *event);
162#endif
163
weinig681a5172006-06-19 22:58:36 +0000164} // namespace WebCore
darinb9481ed2006-03-20 02:57:59 +0000165
weinig681a5172006-06-19 22:58:36 +0000166#endif // PlatformMouseEvent_h