blob: 4a8fa7f0dfba115a6019eedf649215508bb8b292 [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
ggaren1ec99532006-06-10 16:09:27 +000051#if PLATFORM(GDK)
52typedef union _GdkEvent GdkEvent;
53#endif
54
rwlbuisa90ab052006-08-18 11:45:29 +000055#if PLATFORM(QT)
56class QMouseEvent;
57#endif
58
darinb9481ed2006-03-20 02:57:59 +000059namespace WebCore {
olivera485c2f2007-02-01 06:02:09 +000060
aliceli1304a95832006-12-12 03:17:45 +000061 // 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 };
olivera485c2f2007-02-01 06:02:09 +000063 enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll };
64
darinb9481ed2006-03-20 02:57:59 +000065 class PlatformMouseEvent {
66 public:
ap3afac8d2006-07-20 19:20:55 +000067 static const struct CurrentEventTag {} currentEvent;
68
69 PlatformMouseEvent()
olivera485c2f2007-02-01 06:02:09 +000070 : m_button(NoButton)
71 , m_eventType(MouseEventMoved)
ap3afac8d2006-07-20 19:20:55 +000072 , m_clickCount(0)
73 , m_shiftKey(false)
74 , m_ctrlKey(false)
75 , m_altKey(false)
76 , m_metaKey(false)
olivera485c2f2007-02-01 06:02:09 +000077 , m_timestamp(0)
ap3afac8d2006-07-20 19:20:55 +000078 {
79 }
80
81 PlatformMouseEvent(const CurrentEventTag&);
82
olivera485c2f2007-02-01 06:02:09 +000083 PlatformMouseEvent(const IntPoint& pos, const IntPoint& globalPos, MouseButton button, MouseEventType eventType,
84 int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp)
darinb9481ed2006-03-20 02:57:59 +000085 : m_position(pos), m_globalPosition(globalPos), m_button(button)
olivera485c2f2007-02-01 06:02:09 +000086 , m_eventType(eventType)
darinb9481ed2006-03-20 02:57:59 +000087 , m_clickCount(clickCount)
weinig681a5172006-06-19 22:58:36 +000088 , m_shiftKey(shift)
89 , m_ctrlKey(ctrl)
90 , m_altKey(alt)
91 , m_metaKey(meta)
olivera485c2f2007-02-01 06:02:09 +000092 , m_timestamp(timestamp)
weinig681a5172006-06-19 22:58:36 +000093 {
94 }
darinb9481ed2006-03-20 02:57:59 +000095
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; }
olivera485c2f2007-02-01 06:02:09 +0000102 MouseEventType eventType() const { return m_eventType; }
darinb9481ed2006-03-20 02:57:59 +0000103 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; }
olivera485c2f2007-02-01 06:02:09 +0000108
109 //time in seconds
110 double timestamp() const { return m_timestamp; }
darinb9481ed2006-03-20 02:57:59 +0000111
darine4d34c62006-10-29 06:48:02 +0000112#if PLATFORM(MAC)
darinb9481ed2006-03-20 02:57:59 +0000113 PlatformMouseEvent(NSEvent*);
olivera485c2f2007-02-01 06:02:09 +0000114 int eventNumber() const { return m_eventNumber; }
darinb9481ed2006-03-20 02:57:59 +0000115#endif
weinigf18aae32006-08-03 21:55:57 +0000116#if PLATFORM(WIN)
aliceli171592372006-12-04 23:30:19 +0000117 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false);
hyatt5d338752006-09-29 08:40:25 +0000118 void setClickCount(int count) { m_clickCount = count; }
aliceli171592372006-12-04 23:30:19 +0000119 bool activatedWebView() const { return m_activatedWebView; }
darinb9481ed2006-03-20 02:57:59 +0000120#endif
ggaren1ec99532006-06-10 16:09:27 +0000121#if PLATFORM(GDK)
122 PlatformMouseEvent(GdkEvent*);
123#endif
rwlbuisa90ab052006-08-18 11:45:29 +0000124#if PLATFORM(QT)
125 PlatformMouseEvent(QMouseEvent*, int clickCount);
126#endif
darinb9481ed2006-03-20 02:57:59 +0000127
128 private:
129 IntPoint m_position;
130 IntPoint m_globalPosition;
131 MouseButton m_button;
olivera485c2f2007-02-01 06:02:09 +0000132 MouseEventType m_eventType;
darinb9481ed2006-03-20 02:57:59 +0000133 int m_clickCount;
134 bool m_shiftKey;
135 bool m_ctrlKey;
136 bool m_altKey;
137 bool m_metaKey;
aliceli171592372006-12-04 23:30:19 +0000138 double m_timestamp; // unit: seconds
olivera485c2f2007-02-01 06:02:09 +0000139#if PLATFORM(MAC)
140 int m_eventNumber;
141#endif
142#if PLATFORM(WIN)
aliceli171592372006-12-04 23:30:19 +0000143 bool m_activatedWebView;
aliceli171592372006-12-04 23:30:19 +0000144#endif
darinb9481ed2006-03-20 02:57:59 +0000145 };
146
ggaren52fd1072006-11-06 23:56:59 +0000147#if PLATFORM(MAC)
148 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window);
149 IntPoint pointForEvent(NSEvent *event);
150 IntPoint globalPointForEvent(NSEvent *event);
151#endif
152
weinig681a5172006-06-19 22:58:36 +0000153} // namespace WebCore
darinb9481ed2006-03-20 02:57:59 +0000154
weinig681a5172006-06-19 22:58:36 +0000155#endif // PlatformMouseEvent_h