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 class QGraphicsSceneMouseEvent; 40 QT_END_NAMESPACE 41 #endif 42 43 #if PLATFORM(WIN) 44 typedef struct HWND__* HWND; 45 typedef unsigned UINT; 46 typedef unsigned WPARAM; 47 typedef long LPARAM; 48 #endif 49 50 #if PLATFORM(WX) 51 class wxMouseEvent; 52 #endif 53 54 #if PLATFORM(HAIKU) 55 class BMessage; 56 #endif 57 58 #if PLATFORM(BREWMP) 59 typedef unsigned short uint16; 60 typedef unsigned long int uint32; 61 #define AEEEvent uint16 62 #endif 63 64 namespace WebCore { 65 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 }; 68 enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll }; 69 70 class PlatformMouseEvent { 71 public: PlatformMouseEvent()72 PlatformMouseEvent() 73 : m_button(NoButton) 74 , m_eventType(MouseEventMoved) 75 , m_clickCount(0) 76 , m_shiftKey(false) 77 , m_ctrlKey(false) 78 , m_altKey(false) 79 , m_metaKey(false) 80 , m_timestamp(0) 81 , m_modifierFlags(0) 82 { 83 } 84 PlatformMouseEvent(const IntPoint & position,const IntPoint & globalPosition,MouseButton button,MouseEventType eventType,int clickCount,bool shift,bool ctrl,bool alt,bool meta,double timestamp)85 PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, MouseEventType eventType, 86 int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp) 87 : m_position(position) 88 , m_globalPosition(globalPosition) 89 , m_button(button) 90 , m_eventType(eventType) 91 , m_clickCount(clickCount) 92 , m_shiftKey(shift) 93 , m_ctrlKey(ctrl) 94 , m_altKey(alt) 95 , m_metaKey(meta) 96 , m_timestamp(timestamp) 97 , m_modifierFlags(0) 98 { 99 } 100 pos()101 const IntPoint& pos() const { return m_position; } x()102 int x() const { return m_position.x(); } y()103 int y() const { return m_position.y(); } globalX()104 int globalX() const { return m_globalPosition.x(); } globalY()105 int globalY() const { return m_globalPosition.y(); } button()106 MouseButton button() const { return m_button; } eventType()107 MouseEventType eventType() const { return m_eventType; } clickCount()108 int clickCount() const { return m_clickCount; } shiftKey()109 bool shiftKey() const { return m_shiftKey; } ctrlKey()110 bool ctrlKey() const { return m_ctrlKey; } altKey()111 bool altKey() const { return m_altKey; } metaKey()112 bool metaKey() const { return m_metaKey; } modifierFlags()113 unsigned modifierFlags() const { return m_modifierFlags; } 114 115 // Time in seconds. timestamp()116 double timestamp() const { return m_timestamp; } 117 118 #if PLATFORM(GTK) 119 PlatformMouseEvent(GdkEventButton*); 120 PlatformMouseEvent(GdkEventMotion*); 121 #endif 122 123 #if PLATFORM(MAC) 124 #if defined(__OBJC__) 125 PlatformMouseEvent(NSEvent *, NSView *windowView); 126 #endif 127 PlatformMouseEvent(int x, int y, int globalX, int globalY, MouseButton button, MouseEventType eventType, 128 int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp, 129 unsigned modifierFlags, int eventNumber); eventNumber()130 int eventNumber() const { return m_eventNumber; } 131 #endif 132 133 #if PLATFORM(QT) 134 PlatformMouseEvent(QInputEvent*, int clickCount); 135 PlatformMouseEvent(QGraphicsSceneMouseEvent*, int clickCount); 136 #endif 137 138 #if PLATFORM(WIN) 139 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false); setClickCount(int count)140 void setClickCount(int count) { m_clickCount = count; } activatedWebView()141 bool activatedWebView() const { return m_activatedWebView; } 142 #endif 143 144 #if PLATFORM(WX) 145 PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint, int clickCount); 146 #endif 147 148 #if PLATFORM(HAIKU) 149 PlatformMouseEvent(const BMessage*); 150 #endif 151 152 #if PLATFORM(BREWMP) 153 PlatformMouseEvent(AEEEvent, uint16 wParam, uint32 dwParam); 154 #endif 155 156 protected: 157 IntPoint m_position; 158 IntPoint m_globalPosition; 159 MouseButton m_button; 160 MouseEventType m_eventType; 161 int m_clickCount; 162 bool m_shiftKey; 163 bool m_ctrlKey; 164 bool m_altKey; 165 bool m_metaKey; 166 double m_timestamp; // unit: seconds 167 unsigned m_modifierFlags; 168 169 #if PLATFORM(MAC) 170 int m_eventNumber; 171 #endif 172 173 #if PLATFORM(WIN) 174 bool m_activatedWebView; 175 #endif 176 }; 177 178 #if PLATFORM(MAC) && defined(__OBJC__) 179 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *); 180 IntPoint pointForEvent(NSEvent *, NSView *windowView); 181 IntPoint globalPointForEvent(NSEvent *); 182 #endif 183 184 } // namespace WebCore 185 186 #endif // PlatformMouseEvent_h 187