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 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 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 "PlatformEvent.h"
31#include "PointerID.h"
32#include <wtf/WindowsExtras.h>
33
34#if PLATFORM(GTK)
35typedef struct _GdkEventButton GdkEventButton;
36typedef struct _GdkEventMotion GdkEventMotion;
37#endif
38
39namespace WebCore {
40
41const double ForceAtClick = 1;
42const double ForceAtForceClick = 2;
43
44 // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified.
45 // We use -2 for NoButton because -1 is a valid value in the DOM API for Pointer Events for pointermove events that
46 // indicate that the pressed mouse button hasn't changed since the last event.
47 enum MouseButton : int8_t { LeftButton = 0, MiddleButton, RightButton, NoButton = -2 };
48 enum SyntheticClickType : int8_t { NoTap, OneFingerTap, TwoFingerTap };
49
50 class PlatformMouseEvent : public PlatformEvent {
51 public:
52 PlatformMouseEvent()
53 : PlatformEvent(PlatformEvent::MouseMoved)
54 , m_button(NoButton)
55 , m_clickCount(0)
56 , m_modifierFlags(0)
57#if PLATFORM(MAC)
58 , m_eventNumber(0)
59 , m_menuTypeForEvent(0)
60#elif PLATFORM(WIN)
61 , m_didActivateWebView(false)
62#endif
63 {
64 }
65
66 PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type,
67 int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, WallTime timestamp, double force, SyntheticClickType syntheticClickType, PointerID pointerId = mousePointerID)
68 : PlatformEvent(type, shiftKey, ctrlKey, altKey, metaKey, timestamp)
69 , m_position(position)
70 , m_globalPosition(globalPosition)
71 , m_button(button)
72 , m_clickCount(clickCount)
73 , m_modifierFlags(0)
74 , m_force(force)
75 , m_syntheticClickType(syntheticClickType)
76 , m_pointerId(pointerId)
77#if PLATFORM(MAC)
78 , m_eventNumber(0)
79 , m_menuTypeForEvent(0)
80#elif PLATFORM(WIN)
81 , m_didActivateWebView(false)
82#endif
83 {
84 }
85
86 const IntPoint& position() const { return m_position; }
87 const IntPoint& globalPosition() const { return m_globalPosition; }
88#if ENABLE(POINTER_LOCK)
89 const IntPoint& movementDelta() const { return m_movementDelta; }
90#endif
91
92 MouseButton button() const { return m_button; }
93 unsigned short buttons() const { return m_buttons; }
94 int clickCount() const { return m_clickCount; }
95 unsigned modifierFlags() const { return m_modifierFlags; }
96 double force() const { return m_force; }
97 SyntheticClickType syntheticClickType() const { return m_syntheticClickType; }
98 PointerID pointerId() const { return m_pointerId; }
99
100#if PLATFORM(GTK)
101 explicit PlatformMouseEvent(GdkEventButton*);
102 explicit PlatformMouseEvent(GdkEventMotion*);
103 void setClickCount(int count) { m_clickCount = count; }
104#endif
105
106#if PLATFORM(MAC)
107 int eventNumber() const { return m_eventNumber; }
108 int menuTypeForEvent() const { return m_menuTypeForEvent; }
109#endif
110
111#if PLATFORM(WIN)
112 PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool didActivateWebView = false);
113 void setClickCount(int count) { m_clickCount = count; }
114 bool didActivateWebView() const { return m_didActivateWebView; }
115#endif
116
117 protected:
118 IntPoint m_position;
119 IntPoint m_globalPosition;
120#if ENABLE(POINTER_LOCK)
121 IntPoint m_movementDelta;
122#endif
123 MouseButton m_button;
124 unsigned short m_buttons { 0 };
125 int m_clickCount;
126 unsigned m_modifierFlags;
127 double m_force { 0 };
128 SyntheticClickType m_syntheticClickType { NoTap };
129 PointerID m_pointerId { mousePointerID };
130
131#if PLATFORM(MAC)
132 int m_eventNumber;
133 int m_menuTypeForEvent;
134#elif PLATFORM(WIN)
135 bool m_didActivateWebView;
136#endif
137 };
138
139#if COMPILER(MSVC)
140 // These functions are necessary to work around the fact that MSVC will not find a most-specific
141 // operator== to use after implicitly converting MouseButton to a short.
142 inline bool operator==(short a, MouseButton b)
143 {
144 return a == static_cast<short>(b);
145 }
146
147 inline bool operator!=(short a, MouseButton b)
148 {
149 return a != static_cast<short>(b);
150 }
151#endif
152
153} // namespace WebCore
154
155#endif // PlatformMouseEvent_h
156