Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / widget / MouseEvents.h
blobd06298de1208c902adc8b51d0cd763832c30f14d
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/. */
6 #ifndef mozilla_MouseEvents_h__
7 #define mozilla_MouseEvents_h__
9 #include <stdint.h>
11 #include "mozilla/BasicEvents.h"
12 #include "mozilla/MathAlgorithms.h"
13 #include "mozilla/dom/DataTransfer.h"
14 #include "nsCOMPtr.h"
16 /******************************************************************************
17 * nsDragDropEventStatus
18 ******************************************************************************/
20 enum nsDragDropEventStatus
22 // The event is a enter
23 nsDragDropEventStatus_eDragEntered,
24 // The event is exit
25 nsDragDropEventStatus_eDragExited,
26 // The event is drop
27 nsDragDropEventStatus_eDrop
30 namespace mozilla {
32 namespace dom {
33 class PBrowserParent;
34 class PBrowserChild;
35 } // namespace dom
37 class WidgetPointerEvent;
38 class WidgetPointerEventHolder final
40 public:
41 nsTArray<WidgetPointerEvent> mEvents;
42 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
44 private:
45 virtual ~WidgetPointerEventHolder() {}
48 /******************************************************************************
49 * mozilla::WidgetPointerHelper
50 ******************************************************************************/
52 class WidgetPointerHelper
54 public:
55 uint32_t pointerId;
56 uint32_t tiltX;
57 uint32_t tiltY;
58 uint32_t twist;
59 float tangentialPressure;
60 bool convertToPointer;
61 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
63 WidgetPointerHelper()
64 : pointerId(0)
65 , tiltX(0)
66 , tiltY(0)
67 , twist(0)
68 , tangentialPressure(0)
69 , convertToPointer(true)
73 WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
74 uint32_t aTwist = 0, float aTangentialPressure = 0)
75 : pointerId(aPointerId)
76 , tiltX(aTiltX)
77 , tiltY(aTiltY)
78 , twist(aTwist)
79 , tangentialPressure(aTangentialPressure)
80 , convertToPointer(true)
84 explicit WidgetPointerHelper(const WidgetPointerHelper& aHelper)
85 : pointerId(aHelper.pointerId)
86 , tiltX(aHelper.tiltX)
87 , tiltY(aHelper.tiltY)
88 , twist(aHelper.twist)
89 , tangentialPressure(aHelper.tangentialPressure)
90 , convertToPointer(aHelper.convertToPointer)
91 , mCoalescedWidgetEvents(aHelper.mCoalescedWidgetEvents)
95 void AssignPointerHelperData(const WidgetPointerHelper& aEvent,
96 bool aCopyCoalescedEvents = false)
98 pointerId = aEvent.pointerId;
99 tiltX = aEvent.tiltX;
100 tiltY = aEvent.tiltY;
101 twist = aEvent.twist;
102 tangentialPressure = aEvent.tangentialPressure;
103 convertToPointer = aEvent.convertToPointer;
104 if (aCopyCoalescedEvents) {
105 mCoalescedWidgetEvents = aEvent.mCoalescedWidgetEvents;
110 /******************************************************************************
111 * mozilla::WidgetMouseEventBase
112 ******************************************************************************/
114 class WidgetMouseEventBase : public WidgetInputEvent
116 private:
117 friend class dom::PBrowserParent;
118 friend class dom::PBrowserChild;
120 protected:
121 WidgetMouseEventBase()
122 : button(0)
123 , buttons(0)
124 , pressure(0)
125 , hitCluster(false)
126 // Including MouseEventBinding.h here leads to an include loop, so
127 // we have to hardcode MouseEventBinding::MOZ_SOURCE_MOUSE.
128 , inputSource(/* MouseEventBinding::MOZ_SOURCE_MOUSE = */ 1)
132 WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
133 nsIWidget* aWidget, EventClassID aEventClassID)
134 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
135 , button(0)
136 , buttons(0)
137 , pressure(0)
138 , hitCluster(false)
139 // Including MouseEventBinding.h here leads to an include loop, so
140 // we have to hardcode MouseEventBinding::MOZ_SOURCE_MOUSE.
141 , inputSource(/* MouseEventBinding::MOZ_SOURCE_MOUSE = */ 1)
145 public:
146 virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
148 virtual WidgetEvent* Duplicate() const override
150 MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
153 enum buttonType
155 eNoButton = -1,
156 eLeftButton = 0,
157 eMiddleButton = 1,
158 eRightButton = 2
160 // Pressed button ID of mousedown or mouseup event.
161 // This is set only when pressing a button causes the event.
162 int16_t button;
164 enum buttonsFlag {
165 eNoButtonFlag = 0x00,
166 eLeftButtonFlag = 0x01,
167 eRightButtonFlag = 0x02,
168 eMiddleButtonFlag = 0x04,
169 // typicall, "back" button being left side of 5-button
170 // mice, see "buttons" attribute document of DOM3 Events.
171 e4thButtonFlag = 0x08,
172 // typicall, "forward" button being right side of 5-button
173 // mice, see "buttons" attribute document of DOM3 Events.
174 e5thButtonFlag = 0x10
177 // Flags of all pressed buttons at the event fired.
178 // This is set at any mouse event, don't be confused with |button|.
179 int16_t buttons;
181 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
182 float pressure;
183 // Touch near a cluster of links (true)
184 bool hitCluster;
186 // Possible values a in MouseEvent
187 uint16_t inputSource;
189 // ID of the canvas HitRegion
190 nsString region;
192 bool IsLeftButtonPressed() const { return !!(buttons & eLeftButtonFlag); }
193 bool IsRightButtonPressed() const { return !!(buttons & eRightButtonFlag); }
194 bool IsMiddleButtonPressed() const { return !!(buttons & eMiddleButtonFlag); }
195 bool Is4thButtonPressed() const { return !!(buttons & e4thButtonFlag); }
196 bool Is5thButtonPressed() const { return !!(buttons & e5thButtonFlag); }
198 void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
199 bool aCopyTargets)
201 AssignInputEventData(aEvent, aCopyTargets);
203 button = aEvent.button;
204 buttons = aEvent.buttons;
205 pressure = aEvent.pressure;
206 hitCluster = aEvent.hitCluster;
207 inputSource = aEvent.inputSource;
211 * Returns true if left click event.
213 bool IsLeftClickEvent() const
215 return mMessage == eMouseClick && button == eLeftButton;
219 /******************************************************************************
220 * mozilla::WidgetMouseEvent
221 ******************************************************************************/
223 class WidgetMouseEvent : public WidgetMouseEventBase
224 , public WidgetPointerHelper
226 private:
227 friend class dom::PBrowserParent;
228 friend class dom::PBrowserChild;
230 public:
231 typedef bool ReasonType;
232 enum Reason : ReasonType
234 eReal,
235 eSynthesized
238 typedef bool ContextMenuTriggerType;
239 enum ContextMenuTrigger : ContextMenuTriggerType
241 eNormal,
242 eContextMenuKey
245 typedef bool ExitFromType;
246 enum ExitFrom : ExitFromType
248 eChild,
249 eTopLevel
252 protected:
253 WidgetMouseEvent()
254 : mReason(eReal)
255 , mContextMenuTrigger(eNormal)
256 , mExitFrom(eChild)
257 , mIgnoreRootScrollFrame(false)
258 , mClickCount(0)
262 WidgetMouseEvent(bool aIsTrusted,
263 EventMessage aMessage,
264 nsIWidget* aWidget,
265 EventClassID aEventClassID,
266 Reason aReason)
267 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID)
268 , mReason(aReason)
269 , mContextMenuTrigger(eNormal)
270 , mExitFrom(eChild)
271 , mIgnoreRootScrollFrame(false)
272 , mClickCount(0)
276 public:
277 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
279 WidgetMouseEvent(bool aIsTrusted,
280 EventMessage aMessage,
281 nsIWidget* aWidget,
282 Reason aReason,
283 ContextMenuTrigger aContextMenuTrigger = eNormal)
284 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass)
285 , mReason(aReason)
286 , mContextMenuTrigger(aContextMenuTrigger)
287 , mExitFrom(eChild)
288 , mIgnoreRootScrollFrame(false)
289 , mClickCount(0)
291 if (aMessage == eContextMenu) {
292 button = (mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton;
296 #ifdef DEBUG
297 virtual ~WidgetMouseEvent()
299 NS_WARNING_ASSERTION(
300 mMessage != eContextMenu ||
301 button == ((mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton),
302 "Wrong button set to eContextMenu event?");
304 #endif
306 virtual WidgetEvent* Duplicate() const override
308 MOZ_ASSERT(mClass == eMouseEventClass,
309 "Duplicate() must be overridden by sub class");
310 // Not copying widget, it is a weak reference.
311 WidgetMouseEvent* result =
312 new WidgetMouseEvent(false, mMessage, nullptr,
313 mReason, mContextMenuTrigger);
314 result->AssignMouseEventData(*this, true);
315 result->mFlags = mFlags;
316 return result;
319 // mReason indicates the reason why the event is fired:
320 // - Representing mouse operation.
321 // - Synthesized for emulating mousemove event when the content under the
322 // mouse cursor is scrolled.
323 Reason mReason;
325 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
326 // This indicates if the context menu event is caused by context menu key or
327 // other reasons (typically, a click of right mouse button).
328 ContextMenuTrigger mContextMenuTrigger;
330 // mExitFrom is valid only when mMessage is eMouseExitFromWidget.
331 // This indicates if the mouse cursor exits from a top level widget or
332 // a child widget.
333 ExitFrom mExitFrom;
335 // Whether the event should ignore scroll frame bounds during dispatch.
336 bool mIgnoreRootScrollFrame;
338 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
339 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
340 // Otherwise, this must be 0.
341 uint32_t mClickCount;
343 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets)
345 AssignMouseEventBaseData(aEvent, aCopyTargets);
346 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
348 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
349 mClickCount = aEvent.mClickCount;
353 * Returns true if the event is a context menu event caused by key.
355 bool IsContextMenuKeyEvent() const
357 return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
361 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
362 * a synthesized event by scroll or something, returns false.
364 bool IsReal() const
366 return mReason == eReal;
370 /******************************************************************************
371 * mozilla::WidgetDragEvent
372 ******************************************************************************/
374 class WidgetDragEvent : public WidgetMouseEvent
376 private:
377 friend class mozilla::dom::PBrowserParent;
378 friend class mozilla::dom::PBrowserChild;
379 protected:
380 WidgetDragEvent()
381 : mUserCancelled(false)
382 , mDefaultPreventedOnContent(false)
385 public:
386 virtual WidgetDragEvent* AsDragEvent() override { return this; }
388 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
389 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal)
390 , mUserCancelled(false)
391 , mDefaultPreventedOnContent(false)
395 virtual WidgetEvent* Duplicate() const override
397 MOZ_ASSERT(mClass == eDragEventClass,
398 "Duplicate() must be overridden by sub class");
399 // Not copying widget, it is a weak reference.
400 WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
401 result->AssignDragEventData(*this, true);
402 result->mFlags = mFlags;
403 return result;
406 // The dragging data.
407 nsCOMPtr<dom::DataTransfer> mDataTransfer;
409 // If this is true, user has cancelled the drag operation.
410 bool mUserCancelled;
411 // If this is true, the drag event's preventDefault() is called on content.
412 bool mDefaultPreventedOnContent;
414 // XXX Not tested by test_assign_event_data.html
415 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets)
417 AssignMouseEventData(aEvent, aCopyTargets);
419 mDataTransfer = aEvent.mDataTransfer;
420 // XXX mUserCancelled isn't copied, is this intentionally?
421 mUserCancelled = false;
422 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
426 /******************************************************************************
427 * mozilla::WidgetMouseScrollEvent
429 * This is used for legacy DOM mouse scroll events, i.e.,
430 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
431 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
432 ******************************************************************************/
434 class WidgetMouseScrollEvent : public WidgetMouseEventBase
436 private:
437 WidgetMouseScrollEvent()
438 : mDelta(0)
439 , mIsHorizontal(false)
443 public:
444 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override
446 return this;
449 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
450 nsIWidget* aWidget)
451 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
452 eMouseScrollEventClass)
453 , mDelta(0)
454 , mIsHorizontal(false)
458 virtual WidgetEvent* Duplicate() const override
460 MOZ_ASSERT(mClass == eMouseScrollEventClass,
461 "Duplicate() must be overridden by sub class");
462 // Not copying widget, it is a weak reference.
463 WidgetMouseScrollEvent* result =
464 new WidgetMouseScrollEvent(false, mMessage, nullptr);
465 result->AssignMouseScrollEventData(*this, true);
466 result->mFlags = mFlags;
467 return result;
470 // The delta value of mouse scroll event.
471 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
472 // scroll amount in lines. However, if the value is
473 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
474 // value inducates one page scroll. If the event message is
475 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
476 int32_t mDelta;
478 // If this is true, it may cause to scroll horizontally.
479 // Otherwise, vertically.
480 bool mIsHorizontal;
482 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
483 bool aCopyTargets)
485 AssignMouseEventBaseData(aEvent, aCopyTargets);
487 mDelta = aEvent.mDelta;
488 mIsHorizontal = aEvent.mIsHorizontal;
492 /******************************************************************************
493 * mozilla::WidgetWheelEvent
494 ******************************************************************************/
496 class WidgetWheelEvent : public WidgetMouseEventBase
498 private:
499 friend class mozilla::dom::PBrowserParent;
500 friend class mozilla::dom::PBrowserChild;
502 WidgetWheelEvent()
503 : mDeltaX(0.0)
504 , mDeltaY(0.0)
505 , mDeltaZ(0.0)
506 , mOverflowDeltaX(0.0)
507 , mOverflowDeltaY(0.0)
508 // Including WheelEventBinding.h here leads to an include loop, so
509 // we have to hardcode WheelEventBinding::DOM_DELTA_PIXEL.
510 , mDeltaMode(/* WheelEventBinding::DOM_DELTA_PIXEL = */ 0)
511 , mLineOrPageDeltaX(0)
512 , mLineOrPageDeltaY(0)
513 , mScrollType(SCROLL_DEFAULT)
514 , mCustomizedByUserPrefs(false)
515 , mIsMomentum(false)
516 , mIsNoLineOrPageDelta(false)
517 , mViewPortIsOverscrolled(false)
518 , mCanTriggerSwipe(false)
519 , mAllowToOverrideSystemScrollSpeed(false)
520 , mDeltaValuesHorizontalizedForDefaultHandler(false)
524 public:
525 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
527 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
528 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass)
529 , mDeltaX(0.0)
530 , mDeltaY(0.0)
531 , mDeltaZ(0.0)
532 , mOverflowDeltaX(0.0)
533 , mOverflowDeltaY(0.0)
534 // Including WheelEventBinding.h here leads to an include loop, so
535 // we have to hardcode WheelEventBinding::DOM_DELTA_PIXEL.
536 , mDeltaMode(/* WheelEventBinding::DOM_DELTA_PIXEL = */ 0)
537 , mLineOrPageDeltaX(0)
538 , mLineOrPageDeltaY(0)
539 , mScrollType(SCROLL_DEFAULT)
540 , mCustomizedByUserPrefs(false)
541 , mMayHaveMomentum(false)
542 , mIsMomentum(false)
543 , mIsNoLineOrPageDelta(false)
544 , mViewPortIsOverscrolled(false)
545 , mCanTriggerSwipe(false)
546 , mAllowToOverrideSystemScrollSpeed(true)
547 , mDeltaValuesHorizontalizedForDefaultHandler(false)
551 virtual WidgetEvent* Duplicate() const override
553 MOZ_ASSERT(mClass == eWheelEventClass,
554 "Duplicate() must be overridden by sub class");
555 // Not copying widget, it is a weak reference.
556 WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
557 result->AssignWheelEventData(*this, true);
558 result->mFlags = mFlags;
559 return result;
562 // On OS X, scroll gestures that start at the edge of the scrollable range
563 // can result in a swipe gesture. For the first wheel event of such a
564 // gesture, call TriggersSwipe() after the event has been processed
565 // in order to find out whether a swipe should be started.
566 bool TriggersSwipe() const
568 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
569 this->mOverflowDeltaX != 0.0;
572 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
573 // mousewheel.*.delta_multiplier_* prefs which are applied by
574 // EventStateManager. So, after widget dispatches this event,
575 // these delta values may have different values than before.
576 double mDeltaX;
577 double mDeltaY;
578 double mDeltaZ;
580 // overflowed delta values for scroll, these values are set by
581 // EventStateManger. If the default action of the wheel event isn't scroll,
582 // these values are always zero. Otherwise, remaining delta values which are
583 // not used by scroll are set.
584 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
585 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
586 // delta values which are not applied the delta_multiplier prefs.
587 // So, if widget wanted to know the actual direction to be scrolled,
588 // it would need to check the mDeltaX and mDeltaY.
589 double mOverflowDeltaX;
590 double mOverflowDeltaY;
592 // Should be one of WheelEventBinding::DOM_DELTA_*
593 uint32_t mDeltaMode;
595 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
596 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
597 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
598 int32_t mLineOrPageDeltaX;
599 int32_t mLineOrPageDeltaY;
601 // When the default action for an wheel event is moving history or zooming,
602 // need to chose a delta value for doing it.
603 int32_t GetPreferredIntDelta()
605 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
606 return 0;
608 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
609 return mLineOrPageDeltaY;
611 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
612 return mLineOrPageDeltaX;
614 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
615 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
616 return 0; // We cannot guess the answer in this case.
618 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY)) ?
619 mLineOrPageDeltaX : mLineOrPageDeltaY;
622 // Scroll type
623 // The default value is SCROLL_DEFAULT, which means EventStateManager will
624 // select preferred scroll type automatically.
625 enum ScrollType : uint8_t
627 SCROLL_DEFAULT,
628 SCROLL_SYNCHRONOUSLY,
629 SCROLL_ASYNCHRONOUSELY,
630 SCROLL_SMOOTHLY
632 ScrollType mScrollType;
634 // If the delta values are computed from prefs, this value is true.
635 // Otherwise, i.e., they are computed from native events, false.
636 bool mCustomizedByUserPrefs;
638 // true if the momentum events directly tied to this event may follow it.
639 bool mMayHaveMomentum;
640 // true if the event is caused by momentum.
641 bool mIsMomentum;
643 // If device event handlers don't know when they should set mLineOrPageDeltaX
644 // and mLineOrPageDeltaY, this is true. Otherwise, false.
645 // If mIsNoLineOrPageDelta is true, ESM will generate
646 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
647 // a line height.
648 bool mIsNoLineOrPageDelta;
650 // Whether or not the parent of the currently overscrolled frame is the
651 // ViewPort. This is false in situations when an element on the page is being
652 // overscrolled (such as a text field), but true when the 'page' is being
653 // overscrolled.
654 bool mViewPortIsOverscrolled;
656 // The wheel event can trigger a swipe to start if it's overscrolling the
657 // viewport.
658 bool mCanTriggerSwipe;
660 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
661 // overridden. Otherwise, the scroll speed won't be overridden even if
662 // it's enabled by the pref.
663 bool mAllowToOverrideSystemScrollSpeed;
665 // After the event's default action handler has adjusted its delta's values
666 // for horizontalizing a vertical wheel scroll, this variable will be set to
667 // true.
668 bool mDeltaValuesHorizontalizedForDefaultHandler;
670 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
672 AssignMouseEventBaseData(aEvent, aCopyTargets);
674 mDeltaX = aEvent.mDeltaX;
675 mDeltaY = aEvent.mDeltaY;
676 mDeltaZ = aEvent.mDeltaZ;
677 mDeltaMode = aEvent.mDeltaMode;
678 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
679 mMayHaveMomentum = aEvent.mMayHaveMomentum;
680 mIsMomentum = aEvent.mIsMomentum;
681 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
682 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
683 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
684 mScrollType = aEvent.mScrollType;
685 mOverflowDeltaX = aEvent.mOverflowDeltaX;
686 mOverflowDeltaY = aEvent.mOverflowDeltaY;
687 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
688 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
689 mAllowToOverrideSystemScrollSpeed =
690 aEvent.mAllowToOverrideSystemScrollSpeed;
691 mDeltaValuesHorizontalizedForDefaultHandler =
692 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
695 // System scroll speed settings may be too slow at using Gecko. In such
696 // case, we should override the scroll speed computed with system settings.
697 // Following methods return preferred delta values which are multiplied by
698 // factors specified by prefs. If system scroll speed shouldn't be
699 // overridden (e.g., this feature is disabled by pref), they return raw
700 // delta values.
701 double OverriddenDeltaX() const;
702 double OverriddenDeltaY() const;
704 // Compute the overridden delta value. This may be useful for suppressing
705 // too fast scroll by system scroll speed overriding when widget sets
706 // mAllowToOverrideSystemScrollSpeed.
707 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
709 private:
710 static bool sInitialized;
711 static bool sIsSystemScrollSpeedOverrideEnabled;
712 static int32_t sOverrideFactorX;
713 static int32_t sOverrideFactorY;
714 static void Initialize();
717 /******************************************************************************
718 * mozilla::WidgetPointerEvent
719 ******************************************************************************/
721 class WidgetPointerEvent : public WidgetMouseEvent
723 friend class mozilla::dom::PBrowserParent;
724 friend class mozilla::dom::PBrowserChild;
726 WidgetPointerEvent()
727 : mWidth(1)
728 , mHeight(1)
729 , mIsPrimary(true)
733 public:
734 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
736 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
737 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal)
738 , mWidth(1)
739 , mHeight(1)
740 , mIsPrimary(true)
744 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
745 : WidgetMouseEvent(aEvent)
746 , mWidth(1)
747 , mHeight(1)
748 , mIsPrimary(true)
750 mClass = ePointerEventClass;
753 virtual WidgetEvent* Duplicate() const override
755 MOZ_ASSERT(mClass == ePointerEventClass,
756 "Duplicate() must be overridden by sub class");
757 // Not copying widget, it is a weak reference.
758 WidgetPointerEvent* result =
759 new WidgetPointerEvent(false, mMessage, nullptr);
760 result->AssignPointerEventData(*this, true);
761 result->mFlags = mFlags;
762 return result;
765 uint32_t mWidth;
766 uint32_t mHeight;
767 bool mIsPrimary;
769 // XXX Not tested by test_assign_event_data.html
770 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
771 bool aCopyTargets)
773 AssignMouseEventData(aEvent, aCopyTargets);
775 mWidth = aEvent.mWidth;
776 mHeight = aEvent.mHeight;
777 mIsPrimary = aEvent.mIsPrimary;
781 } // namespace mozilla
783 #endif // mozilla_MouseEvents_h__