forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMouseEvents.h
426 lines (360 loc) · 12.8 KB
/
MouseEvents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_MouseEvents_h__
#define mozilla_MouseEvents_h__
#include <stdint.h>
#include "mozilla/BasicEvents.h"
#include "mozilla/MathAlgorithms.h"
#include "nsCOMPtr.h"
#include "nsIDOMDataTransfer.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMWheelEvent.h"
/******************************************************************************
* nsDragDropEventStatus
******************************************************************************/
enum nsDragDropEventStatus
{
// The event is a enter
nsDragDropEventStatus_eDragEntered,
// The event is exit
nsDragDropEventStatus_eDragExited,
// The event is drop
nsDragDropEventStatus_eDrop
};
namespace mozilla {
namespace dom {
class PBrowserParent;
class PBrowserChild;
} // namespace dom
/******************************************************************************
* mozilla::WidgetMouseEventBase
******************************************************************************/
class WidgetMouseEventBase : public WidgetInputEvent
{
private:
friend class dom::PBrowserParent;
friend class dom::PBrowserChild;
public:
WidgetMouseEventBase()
{
}
WidgetMouseEventBase(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
nsEventStructType aStructType) :
WidgetInputEvent(aIsTrusted, aMessage, aWidget, aStructType),
button(0), buttons(0), pressure(0),
inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
{
}
/// The possible related target
nsCOMPtr<nsISupports> relatedTarget;
enum buttonType
{
eLeftButton = 0,
eMiddleButton = 1,
eRightButton = 2
};
// Pressed button ID of mousedown or mouseup event.
// This is set only when pressing a button causes the event.
int16_t button;
enum buttonsFlag {
eLeftButtonFlag = 0x01,
eRightButtonFlag = 0x02,
eMiddleButtonFlag = 0x04,
// typicall, "back" button being left side of 5-button
// mice, see "buttons" attribute document of DOM3 Events.
e4thButtonFlag = 0x08,
// typicall, "forward" button being right side of 5-button
// mice, see "buttons" attribute document of DOM3 Events.
e5thButtonFlag = 0x10
};
// Flags of all pressed buttons at the event fired.
// This is set at any mouse event, don't be confused with |button|.
int16_t buttons;
// Finger or touch pressure of event. It ranges between 0.0 and 1.0.
float pressure;
// Possible values at nsIDOMMouseEvent
uint16_t inputSource;
void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
bool aCopyTargets)
{
AssignInputEventData(aEvent, aCopyTargets);
relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
button = aEvent.button;
buttons = aEvent.buttons;
pressure = aEvent.pressure;
inputSource = aEvent.inputSource;
}
};
/******************************************************************************
* mozilla::WidgetMouseEvent
******************************************************************************/
class WidgetMouseEvent : public WidgetMouseEventBase
{
private:
friend class mozilla::dom::PBrowserParent;
friend class mozilla::dom::PBrowserChild;
public:
enum reasonType
{
eReal,
eSynthesized
};
enum contextType
{
eNormal,
eContextMenuKey
};
enum exitType
{
eChild,
eTopLevel
};
WidgetMouseEvent()
{
}
protected:
WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
nsEventStructType aStructType, reasonType aReason) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aStructType),
acceptActivation(false), ignoreRootScrollFrame(false),
reason(aReason), context(eNormal), exit(eChild), clickCount(0)
{
switch (aMessage) {
case NS_MOUSE_MOVE:
mFlags.mCancelable = false;
break;
case NS_MOUSEENTER:
case NS_MOUSELEAVE:
mFlags.mBubbles = false;
mFlags.mCancelable = false;
break;
default:
break;
}
}
public:
WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
reasonType aReason, contextType aContext = eNormal) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_EVENT),
acceptActivation(false), ignoreRootScrollFrame(false),
reason(aReason), context(aContext), exit(eChild), clickCount(0)
{
switch (aMessage) {
case NS_MOUSE_MOVE:
mFlags.mCancelable = false;
break;
case NS_MOUSEENTER:
case NS_MOUSELEAVE:
mFlags.mBubbles = false;
mFlags.mCancelable = false;
break;
case NS_CONTEXTMENU:
button = (context == eNormal) ? eRightButton : eLeftButton;
break;
default:
break;
}
}
#ifdef DEBUG
~WidgetMouseEvent() {
NS_WARN_IF_FALSE(message != NS_CONTEXTMENU ||
button ==
((context == eNormal) ? eRightButton : eLeftButton),
"Wrong button set to NS_CONTEXTMENU event?");
}
#endif
// Special return code for MOUSE_ACTIVATE to signal.
// If the target accepts activation (1), or denies it (0).
bool acceptActivation;
// Whether the event should ignore scroll frame bounds during dispatch.
bool ignoreRootScrollFrame;
reasonType reason : 4;
contextType context : 4;
exitType exit;
/// The number of mouse clicks.
uint32_t clickCount;
void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets)
{
AssignMouseEventBaseData(aEvent, aCopyTargets);
acceptActivation = aEvent.acceptActivation;
ignoreRootScrollFrame = aEvent.ignoreRootScrollFrame;
clickCount = aEvent.clickCount;
}
};
/******************************************************************************
* mozilla::WidgetDragEvent
******************************************************************************/
class WidgetDragEvent : public WidgetMouseEvent
{
public:
WidgetDragEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetMouseEvent(aIsTrusted, aMessage, aWidget, NS_DRAG_EVENT, eReal),
userCancelled(false)
{
mFlags.mCancelable =
(aMessage != NS_DRAGDROP_EXIT_SYNTH &&
aMessage != NS_DRAGDROP_LEAVE_SYNTH &&
aMessage != NS_DRAGDROP_END);
}
// The dragging data.
nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
// If this is true, user has cancelled the drag operation.
bool userCancelled;
// XXX Not tested by test_assign_event_data.html
void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets)
{
AssignMouseEventData(aEvent, aCopyTargets);
dataTransfer = aEvent.dataTransfer;
// XXX userCancelled isn't copied, is this instentionally?
userCancelled = false;
}
};
/******************************************************************************
* mozilla::WidgetMouseScrollEvent
*
* This is used for legacy DOM mouse scroll events, i.e.,
* DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
* by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
******************************************************************************/
class WidgetMouseScrollEvent : public WidgetMouseEventBase
{
private:
WidgetMouseScrollEvent()
{
}
public:
WidgetMouseScrollEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_SCROLL_EVENT),
delta(0), isHorizontal(false)
{
}
// The delta value of mouse scroll event.
// If the event message is NS_MOUSE_SCROLL, the value indicates scroll amount
// in lines. However, if the value is nsIDOMUIEvent::SCROLL_PAGE_UP or
// nsIDOMUIEvent::SCROLL_PAGE_DOWN, the value inducates one page scroll.
// If the event message is NS_MOUSE_PIXEL_SCROLL, the value indicates scroll
// amount in pixels.
int32_t delta;
// If this is true, it may cause to scroll horizontally.
// Otherwise, vertically.
bool isHorizontal;
void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
bool aCopyTargets)
{
AssignMouseEventBaseData(aEvent, aCopyTargets);
delta = aEvent.delta;
isHorizontal = aEvent.isHorizontal;
}
};
/******************************************************************************
* mozilla::WidgetWheelEvent
******************************************************************************/
class WidgetWheelEvent : public WidgetMouseEventBase
{
private:
friend class mozilla::dom::PBrowserParent;
friend class mozilla::dom::PBrowserChild;
WidgetWheelEvent()
{
}
public:
WidgetWheelEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_WHEEL_EVENT),
deltaX(0.0), deltaY(0.0), deltaZ(0.0),
deltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL),
customizedByUserPrefs(false), isMomentum(false), isPixelOnlyDevice(false),
lineOrPageDeltaX(0), lineOrPageDeltaY(0), scrollType(SCROLL_DEFAULT),
overflowDeltaX(0.0), overflowDeltaY(0.0)
{
}
// NOTE: deltaX, deltaY and deltaZ may be customized by
// mousewheel.*.delta_multiplier_* prefs which are applied by
// nsEventStateManager. So, after widget dispatches this event,
// these delta values may have different values than before.
double deltaX;
double deltaY;
double deltaZ;
// Should be one of nsIDOMWheelEvent::DOM_DELTA_*
uint32_t deltaMode;
// Following members are for internal use only, not for DOM event.
// If the delta values are computed from prefs, this value is true.
// Otherwise, i.e., they are computed from native events, false.
bool customizedByUserPrefs;
// true if the event is caused by momentum.
bool isMomentum;
// If device event handlers don't know when they should set lineOrPageDeltaX
// and lineOrPageDeltaY, this is true. Otherwise, false.
// If isPixelOnlyDevice is true, ESM will generate NS_MOUSE_SCROLL events
// when accumulated pixel delta values reach a line height.
bool isPixelOnlyDevice;
// If widget sets lineOrPageDelta, nsEventStateManager will dispatch
// NS_MOUSE_SCROLL event for compatibility. Note that the delta value means
// pages if the deltaMode is DOM_DELTA_PAGE, otherwise, lines.
int32_t lineOrPageDeltaX;
int32_t lineOrPageDeltaY;
// When the default action for an wheel event is moving history or zooming,
// need to chose a delta value for doing it.
int32_t GetPreferredIntDelta()
{
if (!lineOrPageDeltaX && !lineOrPageDeltaY) {
return 0;
}
if (lineOrPageDeltaY && !lineOrPageDeltaX) {
return lineOrPageDeltaY;
}
if (lineOrPageDeltaX && !lineOrPageDeltaY) {
return lineOrPageDeltaX;
}
if ((lineOrPageDeltaX < 0 && lineOrPageDeltaY > 0) ||
(lineOrPageDeltaX > 0 && lineOrPageDeltaY < 0)) {
return 0; // We cannot guess the answer in this case.
}
return (Abs(lineOrPageDeltaX) > Abs(lineOrPageDeltaY)) ?
lineOrPageDeltaX : lineOrPageDeltaY;
}
// Scroll type
// The default value is SCROLL_DEFAULT, which means nsEventStateManager will
// select preferred scroll type automatically.
enum ScrollType
{
SCROLL_DEFAULT,
SCROLL_SYNCHRONOUSLY,
SCROLL_ASYNCHRONOUSELY,
SCROLL_SMOOTHLY
};
ScrollType scrollType;
// overflowed delta values for scroll, these values are set by
// nsEventStateManger. If the default action of the wheel event isn't scroll,
// these values always zero. Otherwise, remaning delta values which are
// not used by scroll are set.
// NOTE: deltaX, deltaY and deltaZ may be modified by nsEventStateManager.
// However, overflowDeltaX and overflowDeltaY indicate unused original
// delta values which are not applied the delta_multiplier prefs.
// So, if widget wanted to know the actual direction to be scrolled,
// it would need to check the deltaX and deltaY.
double overflowDeltaX;
double overflowDeltaY;
void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
{
AssignMouseEventBaseData(aEvent, aCopyTargets);
deltaX = aEvent.deltaX;
deltaY = aEvent.deltaY;
deltaZ = aEvent.deltaZ;
deltaMode = aEvent.deltaMode;
customizedByUserPrefs = aEvent.customizedByUserPrefs;
isMomentum = aEvent.isMomentum;
isPixelOnlyDevice = aEvent.isPixelOnlyDevice;
lineOrPageDeltaX = aEvent.lineOrPageDeltaX;
lineOrPageDeltaY = aEvent.lineOrPageDeltaY;
scrollType = aEvent.scrollType;
overflowDeltaX = aEvent.overflowDeltaX;
overflowDeltaY = aEvent.overflowDeltaY;
}
};
// TODO: Remove following typedef
typedef WidgetWheelEvent WheelEvent;
} // namespace mozilla
#endif // mozilla_MouseEvents_h__