Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef mozilla_MouseEvents_h__
7 : #define mozilla_MouseEvents_h__
8 :
9 : #include <stdint.h>
10 :
11 : #include "mozilla/BasicEvents.h"
12 : #include "mozilla/MathAlgorithms.h"
13 : #include "mozilla/dom/DataTransfer.h"
14 : #include "nsCOMPtr.h"
15 : #include "nsIDOMMouseEvent.h"
16 : #include "nsIDOMWheelEvent.h"
17 :
18 : /******************************************************************************
19 : * nsDragDropEventStatus
20 : ******************************************************************************/
21 :
22 : enum nsDragDropEventStatus
23 : {
24 : // The event is a enter
25 : nsDragDropEventStatus_eDragEntered,
26 : // The event is exit
27 : nsDragDropEventStatus_eDragExited,
28 : // The event is drop
29 : nsDragDropEventStatus_eDrop
30 : };
31 :
32 : namespace mozilla {
33 :
34 : namespace dom {
35 : class PBrowserParent;
36 : class PBrowserChild;
37 : } // namespace dom
38 :
39 : /******************************************************************************
40 : * mozilla::WidgetPointerHelper
41 : ******************************************************************************/
42 :
43 : class WidgetPointerHelper
44 : {
45 : public:
46 : uint32_t pointerId;
47 : uint32_t tiltX;
48 : uint32_t tiltY;
49 : uint32_t twist;
50 : float tangentialPressure;
51 : bool convertToPointer;
52 :
53 28 : WidgetPointerHelper()
54 28 : : pointerId(0)
55 : , tiltX(0)
56 : , tiltY(0)
57 : , twist(0)
58 : , tangentialPressure(0)
59 28 : , convertToPointer(true)
60 : {
61 28 : }
62 :
63 : WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
64 : uint32_t aTwist = 0, float aTangentialPressure = 0)
65 : : pointerId(aPointerId)
66 : , tiltX(aTiltX)
67 : , tiltY(aTiltY)
68 : , twist(aTwist)
69 : , tangentialPressure(aTangentialPressure)
70 : , convertToPointer(true)
71 : {
72 : }
73 :
74 10 : void AssignPointerHelperData(const WidgetPointerHelper& aEvent)
75 : {
76 10 : pointerId = aEvent.pointerId;
77 10 : tiltX = aEvent.tiltX;
78 10 : tiltY = aEvent.tiltY;
79 10 : twist = aEvent.twist;
80 10 : tangentialPressure = aEvent.tangentialPressure;
81 10 : convertToPointer = aEvent.convertToPointer;
82 10 : }
83 : };
84 :
85 : /******************************************************************************
86 : * mozilla::WidgetMouseEventBase
87 : ******************************************************************************/
88 :
89 46 : class WidgetMouseEventBase : public WidgetInputEvent
90 : {
91 : private:
92 : friend class dom::PBrowserParent;
93 : friend class dom::PBrowserChild;
94 :
95 : protected:
96 6 : WidgetMouseEventBase()
97 6 : : button(0)
98 : , buttons(0)
99 : , pressure(0)
100 : , hitCluster(false)
101 6 : , inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
102 : {
103 6 : }
104 :
105 22 : WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
106 : nsIWidget* aWidget, EventClassID aEventClassID)
107 22 : : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
108 : , button(0)
109 : , buttons(0)
110 : , pressure(0)
111 : , hitCluster(false)
112 22 : , inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
113 : {
114 22 : }
115 :
116 : public:
117 4 : virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
118 :
119 0 : virtual WidgetEvent* Duplicate() const override
120 : {
121 0 : MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
122 : }
123 :
124 : /// The possible related target
125 : nsCOMPtr<nsISupports> relatedTarget;
126 :
127 : enum buttonType
128 : {
129 : eNoButton = -1,
130 : eLeftButton = 0,
131 : eMiddleButton = 1,
132 : eRightButton = 2
133 : };
134 : // Pressed button ID of mousedown or mouseup event.
135 : // This is set only when pressing a button causes the event.
136 : int16_t button;
137 :
138 : enum buttonsFlag {
139 : eNoButtonFlag = 0x00,
140 : eLeftButtonFlag = 0x01,
141 : eRightButtonFlag = 0x02,
142 : eMiddleButtonFlag = 0x04,
143 : // typicall, "back" button being left side of 5-button
144 : // mice, see "buttons" attribute document of DOM3 Events.
145 : e4thButtonFlag = 0x08,
146 : // typicall, "forward" button being right side of 5-button
147 : // mice, see "buttons" attribute document of DOM3 Events.
148 : e5thButtonFlag = 0x10
149 : };
150 :
151 : // Flags of all pressed buttons at the event fired.
152 : // This is set at any mouse event, don't be confused with |button|.
153 : int16_t buttons;
154 :
155 : // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
156 : float pressure;
157 : // Touch near a cluster of links (true)
158 : bool hitCluster;
159 :
160 : // Possible values at nsIDOMMouseEvent
161 : uint16_t inputSource;
162 :
163 : // ID of the canvas HitRegion
164 : nsString region;
165 :
166 : bool IsLeftButtonPressed() const { return !!(buttons & eLeftButtonFlag); }
167 : bool IsRightButtonPressed() const { return !!(buttons & eRightButtonFlag); }
168 : bool IsMiddleButtonPressed() const { return !!(buttons & eMiddleButtonFlag); }
169 : bool Is4thButtonPressed() const { return !!(buttons & e4thButtonFlag); }
170 : bool Is5thButtonPressed() const { return !!(buttons & e5thButtonFlag); }
171 :
172 10 : void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
173 : bool aCopyTargets)
174 : {
175 10 : AssignInputEventData(aEvent, aCopyTargets);
176 :
177 10 : relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
178 10 : button = aEvent.button;
179 10 : buttons = aEvent.buttons;
180 10 : pressure = aEvent.pressure;
181 10 : hitCluster = aEvent.hitCluster;
182 10 : inputSource = aEvent.inputSource;
183 10 : }
184 :
185 : /**
186 : * Returns true if left click event.
187 : */
188 0 : bool IsLeftClickEvent() const
189 : {
190 0 : return mMessage == eMouseClick && button == eLeftButton;
191 : }
192 : };
193 :
194 : /******************************************************************************
195 : * mozilla::WidgetMouseEvent
196 : ******************************************************************************/
197 :
198 11 : class WidgetMouseEvent : public WidgetMouseEventBase
199 : , public WidgetPointerHelper
200 : {
201 : private:
202 : friend class dom::PBrowserParent;
203 : friend class dom::PBrowserChild;
204 :
205 : public:
206 : typedef bool ReasonType;
207 : enum Reason : ReasonType
208 : {
209 : eReal,
210 : eSynthesized
211 : };
212 :
213 : typedef bool ContextMenuTriggerType;
214 : enum ContextMenuTrigger : ContextMenuTriggerType
215 : {
216 : eNormal,
217 : eContextMenuKey
218 : };
219 :
220 : typedef bool ExitFromType;
221 : enum ExitFrom : ExitFromType
222 : {
223 : eChild,
224 : eTopLevel
225 : };
226 :
227 : protected:
228 6 : WidgetMouseEvent()
229 6 : : mReason(eReal)
230 : , mContextMenuTrigger(eNormal)
231 : , mExitFrom(eChild)
232 : , mIgnoreRootScrollFrame(false)
233 6 : , mClickCount(0)
234 : {
235 6 : }
236 :
237 2 : WidgetMouseEvent(bool aIsTrusted,
238 : EventMessage aMessage,
239 : nsIWidget* aWidget,
240 : EventClassID aEventClassID,
241 : Reason aReason)
242 2 : : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID)
243 : , mReason(aReason)
244 : , mContextMenuTrigger(eNormal)
245 : , mExitFrom(eChild)
246 : , mIgnoreRootScrollFrame(false)
247 2 : , mClickCount(0)
248 : {
249 2 : }
250 :
251 : public:
252 214 : virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
253 :
254 20 : WidgetMouseEvent(bool aIsTrusted,
255 : EventMessage aMessage,
256 : nsIWidget* aWidget,
257 : Reason aReason,
258 : ContextMenuTrigger aContextMenuTrigger = eNormal)
259 20 : : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass)
260 : , mReason(aReason)
261 : , mContextMenuTrigger(aContextMenuTrigger)
262 : , mExitFrom(eChild)
263 : , mIgnoreRootScrollFrame(false)
264 20 : , mClickCount(0)
265 : {
266 20 : if (aMessage == eContextMenu) {
267 0 : button = (mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton;
268 : }
269 20 : }
270 :
271 : #ifdef DEBUG
272 45 : virtual ~WidgetMouseEvent()
273 70 : {
274 35 : NS_WARNING_ASSERTION(
275 : mMessage != eContextMenu ||
276 : button == ((mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton),
277 : "Wrong button set to eContextMenu event?");
278 55 : }
279 : #endif
280 :
281 10 : virtual WidgetEvent* Duplicate() const override
282 : {
283 10 : MOZ_ASSERT(mClass == eMouseEventClass,
284 : "Duplicate() must be overridden by sub class");
285 : // Not copying widget, it is a weak reference.
286 : WidgetMouseEvent* result =
287 10 : new WidgetMouseEvent(false, mMessage, nullptr,
288 20 : mReason, mContextMenuTrigger);
289 10 : result->AssignMouseEventData(*this, true);
290 10 : result->mFlags = mFlags;
291 10 : return result;
292 : }
293 :
294 : // mReason indicates the reason why the event is fired:
295 : // - Representing mouse operation.
296 : // - Synthesized for emulating mousemove event when the content under the
297 : // mouse cursor is scrolled.
298 : Reason mReason;
299 :
300 : // mContextMenuTrigger is valid only when mMessage is eContextMenu.
301 : // This indicates if the context menu event is caused by context menu key or
302 : // other reasons (typically, a click of right mouse button).
303 : ContextMenuTrigger mContextMenuTrigger;
304 :
305 : // mExitFrom is valid only when mMessage is eMouseExitFromWidget.
306 : // This indicates if the mouse cursor exits from a top level widget or
307 : // a child widget.
308 : ExitFrom mExitFrom;
309 :
310 : // Whether the event should ignore scroll frame bounds during dispatch.
311 : bool mIgnoreRootScrollFrame;
312 :
313 : // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
314 : // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
315 : // Otherwise, this must be 0.
316 : uint32_t mClickCount;
317 :
318 10 : void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets)
319 : {
320 10 : AssignMouseEventBaseData(aEvent, aCopyTargets);
321 10 : AssignPointerHelperData(aEvent);
322 :
323 10 : mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
324 10 : mClickCount = aEvent.mClickCount;
325 10 : }
326 :
327 : /**
328 : * Returns true if the event is a context menu event caused by key.
329 : */
330 41 : bool IsContextMenuKeyEvent() const
331 : {
332 41 : return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
333 : }
334 :
335 : /**
336 : * Returns true if the event is a real mouse event. Otherwise, i.e., it's
337 : * a synthesized event by scroll or something, returns false.
338 : */
339 26 : bool IsReal() const
340 : {
341 26 : return mReason == eReal;
342 : }
343 : };
344 :
345 : /******************************************************************************
346 : * mozilla::WidgetDragEvent
347 : ******************************************************************************/
348 :
349 0 : class WidgetDragEvent : public WidgetMouseEvent
350 : {
351 : private:
352 : friend class mozilla::dom::PBrowserParent;
353 : friend class mozilla::dom::PBrowserChild;
354 : protected:
355 0 : WidgetDragEvent()
356 0 : : mUserCancelled(false)
357 0 : , mDefaultPreventedOnContent(false)
358 : {
359 0 : }
360 : public:
361 0 : virtual WidgetDragEvent* AsDragEvent() override { return this; }
362 :
363 0 : WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
364 0 : : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal)
365 : , mUserCancelled(false)
366 0 : , mDefaultPreventedOnContent(false)
367 : {
368 0 : }
369 :
370 0 : virtual WidgetEvent* Duplicate() const override
371 : {
372 0 : MOZ_ASSERT(mClass == eDragEventClass,
373 : "Duplicate() must be overridden by sub class");
374 : // Not copying widget, it is a weak reference.
375 0 : WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
376 0 : result->AssignDragEventData(*this, true);
377 0 : result->mFlags = mFlags;
378 0 : return result;
379 : }
380 :
381 : // The dragging data.
382 : nsCOMPtr<dom::DataTransfer> mDataTransfer;
383 :
384 : // If this is true, user has cancelled the drag operation.
385 : bool mUserCancelled;
386 : // If this is true, the drag event's preventDefault() is called on content.
387 : bool mDefaultPreventedOnContent;
388 :
389 : // XXX Not tested by test_assign_event_data.html
390 0 : void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets)
391 : {
392 0 : AssignMouseEventData(aEvent, aCopyTargets);
393 :
394 0 : mDataTransfer = aEvent.mDataTransfer;
395 : // XXX mUserCancelled isn't copied, is this intentionally?
396 0 : mUserCancelled = false;
397 0 : mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
398 0 : }
399 : };
400 :
401 : /******************************************************************************
402 : * mozilla::WidgetMouseScrollEvent
403 : *
404 : * This is used for legacy DOM mouse scroll events, i.e.,
405 : * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
406 : * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
407 : ******************************************************************************/
408 :
409 0 : class WidgetMouseScrollEvent : public WidgetMouseEventBase
410 : {
411 : private:
412 : WidgetMouseScrollEvent()
413 : : mDelta(0)
414 : , mIsHorizontal(false)
415 : {
416 : }
417 :
418 : public:
419 0 : virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override
420 : {
421 0 : return this;
422 : }
423 :
424 0 : WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
425 : nsIWidget* aWidget)
426 0 : : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
427 : eMouseScrollEventClass)
428 : , mDelta(0)
429 0 : , mIsHorizontal(false)
430 : {
431 0 : }
432 :
433 0 : virtual WidgetEvent* Duplicate() const override
434 : {
435 0 : MOZ_ASSERT(mClass == eMouseScrollEventClass,
436 : "Duplicate() must be overridden by sub class");
437 : // Not copying widget, it is a weak reference.
438 : WidgetMouseScrollEvent* result =
439 0 : new WidgetMouseScrollEvent(false, mMessage, nullptr);
440 0 : result->AssignMouseScrollEventData(*this, true);
441 0 : result->mFlags = mFlags;
442 0 : return result;
443 : }
444 :
445 : // The delta value of mouse scroll event.
446 : // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
447 : // scroll amount in lines. However, if the value is
448 : // nsIDOMUIEvent::SCROLL_PAGE_UP or nsIDOMUIEvent::SCROLL_PAGE_DOWN, the
449 : // value inducates one page scroll. If the event message is
450 : // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
451 : int32_t mDelta;
452 :
453 : // If this is true, it may cause to scroll horizontally.
454 : // Otherwise, vertically.
455 : bool mIsHorizontal;
456 :
457 0 : void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
458 : bool aCopyTargets)
459 : {
460 0 : AssignMouseEventBaseData(aEvent, aCopyTargets);
461 :
462 0 : mDelta = aEvent.mDelta;
463 0 : mIsHorizontal = aEvent.mIsHorizontal;
464 0 : }
465 : };
466 :
467 : /******************************************************************************
468 : * mozilla::WidgetWheelEvent
469 : ******************************************************************************/
470 :
471 0 : class WidgetWheelEvent : public WidgetMouseEventBase
472 : {
473 : private:
474 : friend class mozilla::dom::PBrowserParent;
475 : friend class mozilla::dom::PBrowserChild;
476 :
477 0 : WidgetWheelEvent()
478 0 : : mDeltaX(0.0)
479 : , mDeltaY(0.0)
480 : , mDeltaZ(0.0)
481 : , mOverflowDeltaX(0.0)
482 : , mOverflowDeltaY(0.0)
483 : , mDeltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL)
484 : , mLineOrPageDeltaX(0)
485 : , mLineOrPageDeltaY(0)
486 : , mScrollType(SCROLL_DEFAULT)
487 : , mCustomizedByUserPrefs(false)
488 : , mIsMomentum(false)
489 : , mIsNoLineOrPageDelta(false)
490 : , mViewPortIsOverscrolled(false)
491 : , mCanTriggerSwipe(false)
492 0 : , mAllowToOverrideSystemScrollSpeed(false)
493 : {
494 0 : }
495 :
496 : public:
497 0 : virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
498 :
499 0 : WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
500 0 : : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass)
501 : , mDeltaX(0.0)
502 : , mDeltaY(0.0)
503 : , mDeltaZ(0.0)
504 : , mOverflowDeltaX(0.0)
505 : , mOverflowDeltaY(0.0)
506 : , mDeltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL)
507 : , mLineOrPageDeltaX(0)
508 : , mLineOrPageDeltaY(0)
509 : , mScrollType(SCROLL_DEFAULT)
510 : , mCustomizedByUserPrefs(false)
511 : , mMayHaveMomentum(false)
512 : , mIsMomentum(false)
513 : , mIsNoLineOrPageDelta(false)
514 : , mViewPortIsOverscrolled(false)
515 : , mCanTriggerSwipe(false)
516 0 : , mAllowToOverrideSystemScrollSpeed(true)
517 : {
518 0 : }
519 :
520 0 : virtual WidgetEvent* Duplicate() const override
521 : {
522 0 : MOZ_ASSERT(mClass == eWheelEventClass,
523 : "Duplicate() must be overridden by sub class");
524 : // Not copying widget, it is a weak reference.
525 0 : WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
526 0 : result->AssignWheelEventData(*this, true);
527 0 : result->mFlags = mFlags;
528 0 : return result;
529 : }
530 :
531 : // On OS X, scroll gestures that start at the edge of the scrollable range
532 : // can result in a swipe gesture. For the first wheel event of such a
533 : // gesture, call TriggersSwipe() after the event has been processed
534 : // in order to find out whether a swipe should be started.
535 0 : bool TriggersSwipe() const
536 : {
537 0 : return mCanTriggerSwipe && mViewPortIsOverscrolled &&
538 0 : this->mOverflowDeltaX != 0.0;
539 : }
540 :
541 : // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
542 : // mousewheel.*.delta_multiplier_* prefs which are applied by
543 : // EventStateManager. So, after widget dispatches this event,
544 : // these delta values may have different values than before.
545 : double mDeltaX;
546 : double mDeltaY;
547 : double mDeltaZ;
548 :
549 : // overflowed delta values for scroll, these values are set by
550 : // nsEventStateManger. If the default action of the wheel event isn't scroll,
551 : // these values always zero. Otherwise, remaning delta values which are
552 : // not used by scroll are set.
553 : // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
554 : // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
555 : // delta values which are not applied the delta_multiplier prefs.
556 : // So, if widget wanted to know the actual direction to be scrolled,
557 : // it would need to check the mDeltaX and mDeltaY.
558 : double mOverflowDeltaX;
559 : double mOverflowDeltaY;
560 :
561 : // Should be one of nsIDOMWheelEvent::DOM_DELTA_*
562 : uint32_t mDeltaMode;
563 :
564 : // If widget sets mLineOrPageDelta, EventStateManager will dispatch
565 : // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
566 : // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
567 : int32_t mLineOrPageDeltaX;
568 : int32_t mLineOrPageDeltaY;
569 :
570 : // When the default action for an wheel event is moving history or zooming,
571 : // need to chose a delta value for doing it.
572 0 : int32_t GetPreferredIntDelta()
573 : {
574 0 : if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
575 0 : return 0;
576 : }
577 0 : if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
578 0 : return mLineOrPageDeltaY;
579 : }
580 0 : if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
581 0 : return mLineOrPageDeltaX;
582 : }
583 0 : if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
584 0 : (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
585 0 : return 0; // We cannot guess the answer in this case.
586 : }
587 0 : return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY)) ?
588 0 : mLineOrPageDeltaX : mLineOrPageDeltaY;
589 : }
590 :
591 : // Scroll type
592 : // The default value is SCROLL_DEFAULT, which means EventStateManager will
593 : // select preferred scroll type automatically.
594 : enum ScrollType : uint8_t
595 : {
596 : SCROLL_DEFAULT,
597 : SCROLL_SYNCHRONOUSLY,
598 : SCROLL_ASYNCHRONOUSELY,
599 : SCROLL_SMOOTHLY
600 : };
601 : ScrollType mScrollType;
602 :
603 : // If the delta values are computed from prefs, this value is true.
604 : // Otherwise, i.e., they are computed from native events, false.
605 : bool mCustomizedByUserPrefs;
606 :
607 : // true if the momentum events directly tied to this event may follow it.
608 : bool mMayHaveMomentum;
609 : // true if the event is caused by momentum.
610 : bool mIsMomentum;
611 :
612 : // If device event handlers don't know when they should set mLineOrPageDeltaX
613 : // and mLineOrPageDeltaY, this is true. Otherwise, false.
614 : // If mIsNoLineOrPageDelta is true, ESM will generate
615 : // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
616 : // a line height.
617 : bool mIsNoLineOrPageDelta;
618 :
619 : // Whether or not the parent of the currently overscrolled frame is the
620 : // ViewPort. This is false in situations when an element on the page is being
621 : // overscrolled (such as a text field), but true when the 'page' is being
622 : // overscrolled.
623 : bool mViewPortIsOverscrolled;
624 :
625 : // The wheel event can trigger a swipe to start if it's overscrolling the
626 : // viewport.
627 : bool mCanTriggerSwipe;
628 :
629 : // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
630 : // overridden. Otherwise, the scroll speed won't be overridden even if
631 : // it's enabled by the pref.
632 : bool mAllowToOverrideSystemScrollSpeed;
633 :
634 0 : void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
635 : {
636 0 : AssignMouseEventBaseData(aEvent, aCopyTargets);
637 :
638 0 : mDeltaX = aEvent.mDeltaX;
639 0 : mDeltaY = aEvent.mDeltaY;
640 0 : mDeltaZ = aEvent.mDeltaZ;
641 0 : mDeltaMode = aEvent.mDeltaMode;
642 0 : mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
643 0 : mMayHaveMomentum = aEvent.mMayHaveMomentum;
644 0 : mIsMomentum = aEvent.mIsMomentum;
645 0 : mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
646 0 : mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
647 0 : mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
648 0 : mScrollType = aEvent.mScrollType;
649 0 : mOverflowDeltaX = aEvent.mOverflowDeltaX;
650 0 : mOverflowDeltaY = aEvent.mOverflowDeltaY;
651 0 : mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
652 0 : mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
653 0 : mAllowToOverrideSystemScrollSpeed =
654 0 : aEvent.mAllowToOverrideSystemScrollSpeed;
655 0 : }
656 :
657 : // System scroll speed settings may be too slow at using Gecko. In such
658 : // case, we should override the scroll speed computed with system settings.
659 : // Following methods return preferred delta values which are multiplied by
660 : // factors specified by prefs. If system scroll speed shouldn't be
661 : // overridden (e.g., this feature is disabled by pref), they return raw
662 : // delta values.
663 : double OverriddenDeltaX() const;
664 : double OverriddenDeltaY() const;
665 :
666 : // Compute the overridden delta value. This may be useful for suppressing
667 : // too fast scroll by system scroll speed overriding when widget sets
668 : // mAllowToOverrideSystemScrollSpeed.
669 : static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
670 :
671 : private:
672 : static bool sInitialized;
673 : static bool sIsSystemScrollSpeedOverrideEnabled;
674 : static int32_t sOverrideFactorX;
675 : static int32_t sOverrideFactorY;
676 : static void Initialize();
677 : };
678 :
679 : /******************************************************************************
680 : * mozilla::WidgetPointerEvent
681 : ******************************************************************************/
682 :
683 11 : class WidgetPointerEvent : public WidgetMouseEvent
684 : {
685 : friend class mozilla::dom::PBrowserParent;
686 : friend class mozilla::dom::PBrowserChild;
687 :
688 : WidgetPointerEvent()
689 : : mWidth(1)
690 : , mHeight(1)
691 : , mIsPrimary(true)
692 : {
693 : }
694 :
695 : public:
696 57 : virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
697 :
698 2 : WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
699 2 : : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal)
700 : , mWidth(1)
701 : , mHeight(1)
702 2 : , mIsPrimary(true)
703 : {
704 2 : }
705 :
706 5 : explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
707 5 : : WidgetMouseEvent(aEvent)
708 : , mWidth(1)
709 : , mHeight(1)
710 5 : , mIsPrimary(true)
711 : {
712 5 : mClass = ePointerEventClass;
713 5 : }
714 :
715 0 : virtual WidgetEvent* Duplicate() const override
716 : {
717 0 : MOZ_ASSERT(mClass == ePointerEventClass,
718 : "Duplicate() must be overridden by sub class");
719 : // Not copying widget, it is a weak reference.
720 : WidgetPointerEvent* result =
721 0 : new WidgetPointerEvent(false, mMessage, nullptr);
722 0 : result->AssignPointerEventData(*this, true);
723 0 : result->mFlags = mFlags;
724 0 : return result;
725 : }
726 :
727 : uint32_t mWidth;
728 : uint32_t mHeight;
729 : bool mIsPrimary;
730 :
731 : // XXX Not tested by test_assign_event_data.html
732 0 : void AssignPointerEventData(const WidgetPointerEvent& aEvent,
733 : bool aCopyTargets)
734 : {
735 0 : AssignMouseEventData(aEvent, aCopyTargets);
736 :
737 0 : mWidth = aEvent.mWidth;
738 0 : mHeight = aEvent.mHeight;
739 0 : mIsPrimary = aEvent.mIsPrimary;
740 0 : }
741 : };
742 :
743 : } // namespace mozilla
744 :
745 : #endif // mozilla_MouseEvents_h__
|