• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(QT)
37 QT_BEGIN_NAMESPACE
38 class QInputEvent;
39 QT_END_NAMESPACE
40 #endif
41 
42 #if PLATFORM(WIN)
43 typedef struct HWND__* HWND;
44 typedef unsigned UINT;
45 typedef unsigned WPARAM;
46 typedef long LPARAM;
47 #endif
48 
49 #if PLATFORM(WX)
50 class wxMouseEvent;
51 #endif
52 
53 namespace WebCore {
54 
55     // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified.
56     enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton };
57     enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll };
58 
59     class PlatformMouseEvent {
60     public:
PlatformMouseEvent()61         PlatformMouseEvent()
62             : m_button(NoButton)
63             , m_eventType(MouseEventMoved)
64             , m_clickCount(0)
65             , m_shiftKey(false)
66             , m_ctrlKey(false)
67             , m_altKey(false)
68             , m_metaKey(false)
69             , m_timestamp(0)
70             , m_modifierFlags(0)
71         {
72         }
73 
PlatformMouseEvent(const IntPoint & position,const IntPoint & globalPosition,MouseButton button,MouseEventType eventType,int clickCount,bool shift,bool ctrl,bool alt,bool meta,double timestamp)74         PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, MouseEventType eventType,
75                            int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp)
76             : m_position(position)
77             , m_globalPosition(globalPosition)
78             , m_button(button)
79             , m_eventType(eventType)
80             , m_clickCount(clickCount)
81             , m_shiftKey(shift)
82             , m_ctrlKey(ctrl)
83             , m_altKey(alt)
84             , m_metaKey(meta)
85             , m_timestamp(timestamp)
86             , m_modifierFlags(0)
87         {
88         }
89 
pos()90         const IntPoint& pos() const { return m_position; }
x()91         int x() const { return m_position.x(); }
y()92         int y() const { return m_position.y(); }
globalX()93         int globalX() const { return m_globalPosition.x(); }
globalY()94         int globalY() const { return m_globalPosition.y(); }
button()95         MouseButton button() const { return m_button; }
eventType()96         MouseEventType eventType() const { return m_eventType; }
clickCount()97         int clickCount() const { return m_clickCount; }
shiftKey()98         bool shiftKey() const { return m_shiftKey; }
ctrlKey()99         bool ctrlKey() const { return m_ctrlKey; }
altKey()100         bool altKey() const { return m_altKey; }
metaKey()101         bool metaKey() const { return m_metaKey; }
modifierFlags()102         unsigned modifierFlags() const { return m_modifierFlags; }
103 
104         // Time in seconds.
timestamp()105         double timestamp() const { return m_timestamp; }
106 
107 #if PLATFORM(GTK)
108         PlatformMouseEvent(GdkEventButton*);
109         PlatformMouseEvent(GdkEventMotion*);
110 #endif
111 
112 #if PLATFORM(MAC) && defined(__OBJC__)
113         PlatformMouseEvent(NSEvent *, NSView *windowView);
eventNumber()114         int eventNumber() const { return m_eventNumber; }
115 #endif
116 
117 #if PLATFORM(QT)
118         PlatformMouseEvent(QInputEvent*, int clickCount);
119 #endif
120 
121 #if PLATFORM(WIN)
122         PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false);
setClickCount(int count)123         void setClickCount(int count) { m_clickCount = count; }
activatedWebView()124         bool activatedWebView() const { return m_activatedWebView; }
125 #endif
126 
127 #if PLATFORM(WX)
128         PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint, int clickCount);
129 #endif
130 
131     protected:
132         IntPoint m_position;
133         IntPoint m_globalPosition;
134         MouseButton m_button;
135         MouseEventType m_eventType;
136         int m_clickCount;
137         bool m_shiftKey;
138         bool m_ctrlKey;
139         bool m_altKey;
140         bool m_metaKey;
141         double m_timestamp; // unit: seconds
142         unsigned m_modifierFlags;
143 
144 #if PLATFORM(MAC)
145         int m_eventNumber;
146 #endif
147 
148 #if PLATFORM(WIN)
149         bool m_activatedWebView;
150 #endif
151     };
152 
153 #if PLATFORM(MAC) && defined(__OBJC__)
154     IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *);
155     IntPoint pointForEvent(NSEvent *, NSView *windowView);
156     IntPoint globalPointForEvent(NSEvent *);
157 #endif
158 
159 } // namespace WebCore
160 
161 #endif // PlatformMouseEvent_h
162