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 26 #ifndef PlatformMouseEvent_h 27 #define PlatformMouseEvent_h 28 29 #include "IntPoint.h" 30 #include <wtf/Platform.h> 31 32 #if PLATFORM(MAC) 33 #ifdef __OBJC__ 34 @class NSEvent; 35 @class NSScreen; 36 @class NSWindow; 37 #else 38 class NSEvent; 39 class NSScreen; 40 class NSWindow; 41 #endif 42 #endif 43 44 #if PLATFORM(WIN) 45 typedef struct HWND__* HWND; 46 typedef unsigned UINT; 47 typedef unsigned WPARAM; 48 typedef long LPARAM; 49 #endif 50 51 #if PLATFORM(GTK) 52 typedef struct _GdkEventButton GdkEventButton; 53 typedef struct _GdkEventMotion GdkEventMotion; 54 #endif 55 56 #if PLATFORM(QT) 57 QT_BEGIN_NAMESPACE 58 class QInputEvent; 59 QT_END_NAMESPACE 60 #endif 61 62 #if PLATFORM(WX) 63 class wxMouseEvent; 64 #endif 65 66 namespace WebCore { 67 68 // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified. 69 enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton }; 70 enum MouseEventType { MouseEventMoved, MouseEventPressed, MouseEventReleased, MouseEventScroll }; 71 72 class PlatformMouseEvent { 73 public: PlatformMouseEvent()74 PlatformMouseEvent() 75 : m_button(NoButton) 76 , m_eventType(MouseEventMoved) 77 , m_clickCount(0) 78 , m_shiftKey(false) 79 , m_ctrlKey(false) 80 , m_altKey(false) 81 , m_metaKey(false) 82 , m_timestamp(0) 83 , m_modifierFlags(0) 84 { 85 } 86 PlatformMouseEvent(const IntPoint & pos,const IntPoint & globalPos,MouseButton button,MouseEventType eventType,int clickCount,bool shift,bool ctrl,bool alt,bool meta,double timestamp)87 PlatformMouseEvent(const IntPoint& pos, const IntPoint& globalPos, MouseButton button, MouseEventType eventType, 88 int clickCount, bool shift, bool ctrl, bool alt, bool meta, double timestamp) 89 : m_position(pos), m_globalPosition(globalPos), 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(MAC) 119 PlatformMouseEvent(NSEvent*); eventNumber()120 int eventNumber() const { return m_eventNumber; } 121 #endif 122 #if PLATFORM(WIN) 123 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool activatedWebView = false); setClickCount(int count)124 void setClickCount(int count) { m_clickCount = count; } activatedWebView()125 bool activatedWebView() const { return m_activatedWebView; } 126 #endif 127 #if PLATFORM(GTK) 128 PlatformMouseEvent(GdkEventButton*); 129 PlatformMouseEvent(GdkEventMotion*); 130 #endif 131 #if PLATFORM(QT) 132 PlatformMouseEvent(QInputEvent*, int clickCount); 133 #endif 134 #if PLATFORM(WX) 135 PlatformMouseEvent(const wxMouseEvent&, const wxPoint& globalPoint); 136 #endif 137 138 139 protected: 140 IntPoint m_position; 141 IntPoint m_globalPosition; 142 MouseButton m_button; 143 MouseEventType m_eventType; 144 int m_clickCount; 145 bool m_shiftKey; 146 bool m_ctrlKey; 147 bool m_altKey; 148 bool m_metaKey; 149 double m_timestamp; // unit: seconds 150 unsigned m_modifierFlags; 151 #if PLATFORM(MAC) 152 int m_eventNumber; 153 #endif 154 #if PLATFORM(WIN) 155 bool m_activatedWebView; 156 #endif 157 }; 158 159 #if PLATFORM(MAC) 160 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window); 161 IntPoint pointForEvent(NSEvent *event); 162 IntPoint globalPointForEvent(NSEvent *event); 163 #endif 164 165 } // namespace WebCore 166 167 #endif // PlatformMouseEvent_h 168