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__
11 #include "mozilla/BasicEvents.h"
12 #include "mozilla/EventForwards.h"
13 #include "mozilla/MathAlgorithms.h"
14 #include "mozilla/dom/DataTransfer.h"
15 #include "mozilla/ipc/IPCForwards.h"
23 class PBrowserBridgeParent
;
26 class WidgetPointerEvent
;
27 } // namespace mozilla
30 class WidgetPointerEventHolder final
{
32 nsTArray
<WidgetPointerEvent
> mEvents
;
33 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder
)
36 virtual ~WidgetPointerEventHolder() = default;
39 /******************************************************************************
40 * mozilla::WidgetPointerHelper
41 ******************************************************************************/
43 class WidgetPointerHelper
{
49 float tangentialPressure
;
50 bool convertToPointer
;
51 RefPtr
<WidgetPointerEventHolder
> mCoalescedWidgetEvents
;
58 tangentialPressure(0),
59 convertToPointer(true) {}
61 WidgetPointerHelper(uint32_t aPointerId
, uint32_t aTiltX
, uint32_t aTiltY
,
62 uint32_t aTwist
= 0, float aTangentialPressure
= 0)
63 : pointerId(aPointerId
),
67 tangentialPressure(aTangentialPressure
),
68 convertToPointer(true) {}
70 explicit WidgetPointerHelper(const WidgetPointerHelper
& aHelper
) = default;
72 void AssignPointerHelperData(const WidgetPointerHelper
& aEvent
,
73 bool aCopyCoalescedEvents
= false) {
74 pointerId
= aEvent
.pointerId
;
78 tangentialPressure
= aEvent
.tangentialPressure
;
79 convertToPointer
= aEvent
.convertToPointer
;
80 if (aCopyCoalescedEvents
) {
81 mCoalescedWidgetEvents
= aEvent
.mCoalescedWidgetEvents
;
86 /******************************************************************************
87 * mozilla::WidgetMouseEventBase
88 ******************************************************************************/
90 class WidgetMouseEventBase
: public WidgetInputEvent
{
92 friend class dom::PBrowserParent
;
93 friend class dom::PBrowserChild
;
94 friend class dom::PBrowserBridgeParent
;
95 ALLOW_DEPRECATED_READPARAM
98 WidgetMouseEventBase()
102 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
103 // Including MouseEventBinding.h here leads to an include loop, so
104 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
106 WidgetMouseEventBase(bool aIsTrusted
, EventMessage aMessage
,
107 nsIWidget
* aWidget
, EventClassID aEventClassID
,
108 const WidgetEventTime
* aTime
= nullptr)
109 : WidgetInputEvent(aIsTrusted
, aMessage
, aWidget
, aEventClassID
, aTime
),
113 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
114 // Including MouseEventBinding.h here leads to an include loop, so
115 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
118 virtual WidgetMouseEventBase
* AsMouseEventBase() override
{ return this; }
120 virtual WidgetEvent
* Duplicate() const override
{
121 MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
124 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
127 // Pressed button ID of mousedown or mouseup event.
128 // This is set only when pressing a button causes the event.
131 // Flags of all pressed buttons at the event fired.
132 // This is set at any mouse event, don't be confused with |mButton|.
135 // Possible values a in MouseEvent
136 uint16_t mInputSource
;
138 bool IsLeftButtonPressed() const {
139 return !!(mButtons
& MouseButtonsFlag::ePrimaryFlag
);
141 bool IsRightButtonPressed() const {
142 return !!(mButtons
& MouseButtonsFlag::eSecondaryFlag
);
144 bool IsMiddleButtonPressed() const {
145 return !!(mButtons
& MouseButtonsFlag::eMiddleFlag
);
147 bool Is4thButtonPressed() const {
148 return !!(mButtons
& MouseButtonsFlag::e4thFlag
);
150 bool Is5thButtonPressed() const {
151 return !!(mButtons
& MouseButtonsFlag::e5thFlag
);
154 void AssignMouseEventBaseData(const WidgetMouseEventBase
& aEvent
,
156 AssignInputEventData(aEvent
, aCopyTargets
);
158 mButton
= aEvent
.mButton
;
159 mButtons
= aEvent
.mButtons
;
160 mPressure
= aEvent
.mPressure
;
161 mInputSource
= aEvent
.mInputSource
;
165 * Returns true if left click event.
167 bool IsLeftClickEvent() const {
168 return mMessage
== eMouseClick
&& mButton
== MouseButton::ePrimary
;
172 * Returns true if this event changes a button state to "pressed".
174 [[nodiscard
]] bool IsPressingButton() const {
175 MOZ_ASSERT(IsTrusted());
176 if (mClass
== eMouseEventClass
) {
177 return mMessage
== eMouseDown
;
179 if (mButton
== MouseButton::eNotPressed
) {
182 // If this is an ePointerDown event whose mButton is not "not pressed", this
183 // is a button pressing event.
184 if (mMessage
== ePointerDown
) {
187 // If 2 or more buttons are pressed at same time, they are sent with
188 // pointermove rather than pointerdown. Therefore, let's check whether
189 // mButtons contains the proper flag for the pressing button.
190 const bool buttonsContainButton
= !!(
191 mButtons
& MouseButtonsFlagToChange(static_cast<MouseButton
>(mButton
)));
192 return mMessage
== ePointerMove
&& buttonsContainButton
;
196 * Returns true if this event changes a button state to "released".
198 [[nodiscard
]] bool IsReleasingButton() const {
199 MOZ_ASSERT(IsTrusted());
200 if (mClass
== eMouseEventClass
) {
201 return mMessage
== eMouseUp
;
203 if (mButton
== MouseButton::eNotPressed
) {
206 // If this is an ePointerUp event whose mButton is not "not pressed", this
207 // is a button release event.
208 if (mMessage
== ePointerUp
) {
211 // If the releasing button is not the last button of pressing buttons, web
212 // apps notified by pointermove rather than pointerup. Therefore, let's
213 // check whether mButtons loses the proper flag for the releasing button.
214 const bool buttonsLoseTheButton
= !(
215 mButtons
& MouseButtonsFlagToChange(static_cast<MouseButton
>(mButton
)));
216 return mMessage
== ePointerMove
&& buttonsLoseTheButton
;
220 * Returns true if the input source supports hover state like a mouse.
222 [[nodiscard
]] bool InputSourceSupportsHover() const;
225 /******************************************************************************
226 * mozilla::WidgetMouseEvent
227 ******************************************************************************/
229 class WidgetMouseEvent
: public WidgetMouseEventBase
,
230 public WidgetPointerHelper
{
232 friend class dom::PBrowserParent
;
233 friend class dom::PBrowserChild
;
234 friend class dom::PBrowserBridgeParent
;
235 ALLOW_DEPRECATED_READPARAM
238 typedef bool ReasonType
;
239 enum Reason
: ReasonType
{ eReal
, eSynthesized
};
241 typedef uint8_t ContextMenuTriggerType
;
242 enum ContextMenuTrigger
: ContextMenuTriggerType
{
248 typedef uint8_t ExitFromType
;
249 enum ExitFrom
: ExitFromType
{
253 ePuppetParentToPuppetChild
259 mContextMenuTrigger(eNormal
),
261 mIgnoreRootScrollFrame(false),
262 mClickEventPrevented(false) {}
264 WidgetMouseEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
,
265 EventClassID aEventClassID
, Reason aReason
,
266 const WidgetEventTime
* aTime
= nullptr)
267 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
, aEventClassID
,
270 mContextMenuTrigger(eNormal
),
272 mIgnoreRootScrollFrame(false),
273 mClickEventPrevented(false) {}
276 void AssertContextMenuEventButtonConsistency() const;
280 virtual WidgetMouseEvent
* AsMouseEvent() override
{ return this; }
282 WidgetMouseEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
,
284 ContextMenuTrigger aContextMenuTrigger
= eNormal
,
285 const WidgetEventTime
* aTime
= nullptr)
286 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
, eMouseEventClass
,
289 mContextMenuTrigger(aContextMenuTrigger
),
291 mIgnoreRootScrollFrame(false),
292 mClickEventPrevented(false) {
293 if (aMessage
== eContextMenu
) {
294 mButton
= (mContextMenuTrigger
== eNormal
) ? MouseButton::eSecondary
295 : MouseButton::ePrimary
;
300 virtual ~WidgetMouseEvent() { AssertContextMenuEventButtonConsistency(); }
303 virtual WidgetEvent
* Duplicate() const override
{
304 MOZ_ASSERT(mClass
== eMouseEventClass
,
305 "Duplicate() must be overridden by sub class");
306 // Not copying widget, it is a weak reference.
307 WidgetMouseEvent
* result
= new WidgetMouseEvent(
308 false, mMessage
, nullptr, mReason
, mContextMenuTrigger
, this);
309 result
->AssignMouseEventData(*this, true);
310 result
->mFlags
= mFlags
;
314 // If during mouseup handling we detect that click event might need to be
315 // dispatched, this is setup to be the target of the click event.
316 nsCOMPtr
<dom::EventTarget
> mClickTarget
;
318 // mReason indicates the reason why the event is fired:
319 // - Representing mouse operation.
320 // - Synthesized for emulating mousemove event when the content under the
321 // mouse cursor is scrolled.
324 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
325 // This indicates if the context menu event is caused by context menu key or
326 // other reasons (typically, a click of right mouse button).
327 ContextMenuTrigger mContextMenuTrigger
;
329 // mExitFrom contains a value only when mMessage is eMouseExitFromWidget.
330 // This indicates if the mouse cursor exits from a top level platform widget,
331 // a child widget or a puppet widget.
332 Maybe
<ExitFrom
> mExitFrom
;
334 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
335 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
336 // Otherwise, this must be 0.
337 uint32_t mClickCount
;
339 // Whether the event should ignore scroll frame bounds during dispatch.
340 bool mIgnoreRootScrollFrame
;
342 // Whether the event shouldn't cause click event.
343 bool mClickEventPrevented
;
345 void AssignMouseEventData(const WidgetMouseEvent
& aEvent
, bool aCopyTargets
) {
346 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
347 AssignPointerHelperData(aEvent
, /* aCopyCoalescedEvents */ true);
349 mExitFrom
= aEvent
.mExitFrom
;
350 mClickCount
= aEvent
.mClickCount
;
351 mIgnoreRootScrollFrame
= aEvent
.mIgnoreRootScrollFrame
;
352 mClickEventPrevented
= aEvent
.mClickEventPrevented
;
356 * Returns true if the event is a context menu event caused by key.
358 bool IsContextMenuKeyEvent() const {
359 return mMessage
== eContextMenu
&& mContextMenuTrigger
== eContextMenuKey
;
363 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
364 * a synthesized event by scroll or something, returns false.
366 bool IsReal() const { return mReason
== eReal
; }
369 * Returns true if middle click paste is enabled.
371 static bool IsMiddleClickPasteEnabled();
374 /******************************************************************************
375 * mozilla::WidgetDragEvent
376 ******************************************************************************/
378 class WidgetDragEvent
: public WidgetMouseEvent
{
380 friend class mozilla::dom::PBrowserParent
;
381 friend class mozilla::dom::PBrowserChild
;
382 ALLOW_DEPRECATED_READPARAM
386 : mUserCancelled(false),
387 mDefaultPreventedOnContent(false),
388 mInHTMLEditorEventListener(false) {}
391 virtual WidgetDragEvent
* AsDragEvent() override
{ return this; }
393 WidgetDragEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
,
394 const WidgetEventTime
* aTime
= nullptr)
395 : WidgetMouseEvent(aIsTrusted
, aMessage
, aWidget
, eDragEventClass
, eReal
,
397 mUserCancelled(false),
398 mDefaultPreventedOnContent(false),
399 mInHTMLEditorEventListener(false) {}
401 virtual WidgetEvent
* Duplicate() const override
{
402 MOZ_ASSERT(mClass
== eDragEventClass
,
403 "Duplicate() must be overridden by sub class");
404 // Not copying widget, it is a weak reference.
405 WidgetDragEvent
* result
=
406 new WidgetDragEvent(false, mMessage
, nullptr, this);
407 result
->AssignDragEventData(*this, true);
408 result
->mFlags
= mFlags
;
412 // The dragging data.
413 nsCOMPtr
<dom::DataTransfer
> mDataTransfer
;
415 // If this is true, user has cancelled the drag operation.
417 // If this is true, the drag event's preventDefault() is called on content.
418 bool mDefaultPreventedOnContent
;
419 // If this event is currently being handled by HTMLEditorEventListener.
420 bool mInHTMLEditorEventListener
;
422 // XXX Not tested by test_assign_event_data.html
423 void AssignDragEventData(const WidgetDragEvent
& aEvent
, bool aCopyTargets
) {
424 AssignMouseEventData(aEvent
, aCopyTargets
);
426 mDataTransfer
= aEvent
.mDataTransfer
;
427 // XXX mUserCancelled isn't copied, is this intentionally?
428 mUserCancelled
= false;
429 mDefaultPreventedOnContent
= aEvent
.mDefaultPreventedOnContent
;
430 // XXX mInHTMLEditorEventListener isn't copied, is this intentionally?
431 mInHTMLEditorEventListener
= false;
435 * Should be called before dispatching the DOM tree if this event is
436 * synthesized for tests because drop effect is initialized before
437 * dispatching from widget if it's not synthesized event, but synthesized
438 * events are not initialized in the path.
440 void InitDropEffectForTests();
443 /******************************************************************************
444 * mozilla::WidgetMouseScrollEvent
446 * This is used for legacy DOM mouse scroll events, i.e.,
447 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
448 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
449 ******************************************************************************/
451 class WidgetMouseScrollEvent
: public WidgetMouseEventBase
{
453 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
456 virtual WidgetMouseScrollEvent
* AsMouseScrollEvent() override
{ return this; }
458 WidgetMouseScrollEvent(bool aIsTrusted
, EventMessage aMessage
,
460 const WidgetEventTime
* aTime
= nullptr)
461 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
,
462 eMouseScrollEventClass
, aTime
),
464 mIsHorizontal(false) {}
466 virtual WidgetEvent
* Duplicate() const override
{
467 MOZ_ASSERT(mClass
== eMouseScrollEventClass
,
468 "Duplicate() must be overridden by sub class");
469 // Not copying widget, it is a weak reference.
470 WidgetMouseScrollEvent
* result
=
471 new WidgetMouseScrollEvent(false, mMessage
, nullptr, this);
472 result
->AssignMouseScrollEventData(*this, true);
473 result
->mFlags
= mFlags
;
477 // The delta value of mouse scroll event.
478 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
479 // scroll amount in lines. However, if the value is
480 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
481 // value inducates one page scroll. If the event message is
482 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
485 // If this is true, it may cause to scroll horizontally.
486 // Otherwise, vertically.
489 void AssignMouseScrollEventData(const WidgetMouseScrollEvent
& aEvent
,
491 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
493 mDelta
= aEvent
.mDelta
;
494 mIsHorizontal
= aEvent
.mIsHorizontal
;
498 /******************************************************************************
499 * mozilla::WidgetWheelEvent
500 ******************************************************************************/
502 class WidgetWheelEvent
: public WidgetMouseEventBase
{
504 friend class mozilla::dom::PBrowserParent
;
505 friend class mozilla::dom::PBrowserChild
;
506 ALLOW_DEPRECATED_READPARAM
512 mOverflowDeltaX(0.0),
514 // Including WheelEventBinding.h here leads to an include loop, so
515 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
517 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
518 mLineOrPageDeltaX(0),
519 mLineOrPageDeltaY(0),
520 mScrollType(SCROLL_DEFAULT
),
521 mCustomizedByUserPrefs(false),
522 mMayHaveMomentum(false),
524 mIsNoLineOrPageDelta(false),
525 mViewPortIsOverscrolled(false),
526 mCanTriggerSwipe(false),
527 mAllowToOverrideSystemScrollSpeed(false),
528 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
531 virtual WidgetWheelEvent
* AsWheelEvent() override
{ return this; }
533 WidgetWheelEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
,
534 const WidgetEventTime
* aTime
= nullptr)
535 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
, eWheelEventClass
,
540 mOverflowDeltaX(0.0),
542 // Including WheelEventBinding.h here leads to an include loop, so
543 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
545 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
546 mLineOrPageDeltaX(0),
547 mLineOrPageDeltaY(0),
548 mScrollType(SCROLL_DEFAULT
),
549 mCustomizedByUserPrefs(false),
550 mMayHaveMomentum(false),
552 mIsNoLineOrPageDelta(false),
553 mViewPortIsOverscrolled(false),
554 mCanTriggerSwipe(false),
555 mAllowToOverrideSystemScrollSpeed(true),
556 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
558 virtual WidgetEvent
* Duplicate() const override
{
559 MOZ_ASSERT(mClass
== eWheelEventClass
,
560 "Duplicate() must be overridden by sub class");
561 // Not copying widget, it is a weak reference.
562 WidgetWheelEvent
* result
=
563 new WidgetWheelEvent(false, mMessage
, nullptr, this);
564 result
->AssignWheelEventData(*this, true);
565 result
->mFlags
= mFlags
;
569 // Scroll gestures that start at the edge of the scrollable range can result
570 // in a swipe gesture. For the first wheel event of such a gesture, call
571 // TriggersSwipe() after the event has been processed in order to find out
572 // whether a swipe should be started.
573 bool TriggersSwipe() const {
574 return mCanTriggerSwipe
&& mViewPortIsOverscrolled
&&
575 this->mOverflowDeltaX
!= 0.0;
578 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
579 // mousewheel.*.delta_multiplier_* prefs which are applied by
580 // EventStateManager. So, after widget dispatches this event,
581 // these delta values may have different values than before.
586 // The mousewheel tick counts.
587 double mWheelTicksX
= 0.0;
588 double mWheelTicksY
= 0.0;
590 enum class DeltaModeCheckingState
: uint8_t {
591 // Neither deltaMode nor the delta values have been accessed.
593 // The delta values have been accessed, without checking deltaMode first.
595 // The deltaMode has been checked.
599 // For compat reasons, we might expose a DOM_DELTA_LINE event as
600 // DOM_DELTA_PIXEL instead. Whether we do that depends on whether the event
601 // has been asked for the deltaMode before the deltas. If it has, we assume
602 // that the page will correctly handle DOM_DELTA_LINE. This variable tracks
603 // that state. See bug 1392460.
604 DeltaModeCheckingState mDeltaModeCheckingState
=
605 DeltaModeCheckingState::Unknown
;
607 // The amount of scrolling per line or page, without accounting for mouse
608 // wheel transactions etc.
610 // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta.
611 nsSize mScrollAmount
;
613 // overflowed delta values for scroll, these values are set by
614 // EventStateManger. If the default action of the wheel event isn't scroll,
615 // these values are always zero. Otherwise, remaining delta values which are
616 // not used by scroll are set.
617 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
618 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
619 // delta values which are not applied the delta_multiplier prefs.
620 // So, if widget wanted to know the actual direction to be scrolled,
621 // it would need to check the mDeltaX and mDeltaY.
622 double mOverflowDeltaX
;
623 double mOverflowDeltaY
;
625 // Should be one of WheelEvent_Binding::DOM_DELTA_*
628 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
629 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
630 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
631 int32_t mLineOrPageDeltaX
;
632 int32_t mLineOrPageDeltaY
;
634 // When the default action for an wheel event is moving history or zooming,
635 // need to chose a delta value for doing it.
636 int32_t GetPreferredIntDelta() {
637 if (!mLineOrPageDeltaX
&& !mLineOrPageDeltaY
) {
640 if (mLineOrPageDeltaY
&& !mLineOrPageDeltaX
) {
641 return mLineOrPageDeltaY
;
643 if (mLineOrPageDeltaX
&& !mLineOrPageDeltaY
) {
644 return mLineOrPageDeltaX
;
646 if ((mLineOrPageDeltaX
< 0 && mLineOrPageDeltaY
> 0) ||
647 (mLineOrPageDeltaX
> 0 && mLineOrPageDeltaY
< 0)) {
648 return 0; // We cannot guess the answer in this case.
650 return (Abs(mLineOrPageDeltaX
) > Abs(mLineOrPageDeltaY
))
656 // The default value is SCROLL_DEFAULT, which means EventStateManager will
657 // select preferred scroll type automatically.
658 enum ScrollType
: uint8_t {
660 SCROLL_SYNCHRONOUSLY
,
661 SCROLL_ASYNCHRONOUSLY
,
664 ScrollType mScrollType
;
666 // If the delta values are computed from prefs, this value is true.
667 // Otherwise, i.e., they are computed from native events, false.
668 bool mCustomizedByUserPrefs
;
670 // true if the momentum events directly tied to this event may follow it.
671 bool mMayHaveMomentum
;
672 // true if the event is caused by momentum.
675 // If device event handlers don't know when they should set mLineOrPageDeltaX
676 // and mLineOrPageDeltaY, this is true. Otherwise, false.
677 // If mIsNoLineOrPageDelta is true, ESM will generate
678 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
680 bool mIsNoLineOrPageDelta
;
682 // Whether or not the parent of the currently overscrolled frame is the
683 // ViewPort. This is false in situations when an element on the page is being
684 // overscrolled (such as a text field), but true when the 'page' is being
686 bool mViewPortIsOverscrolled
;
688 // The wheel event can trigger a swipe to start if it's overscrolling the
690 bool mCanTriggerSwipe
;
692 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
693 // overridden. Otherwise, the scroll speed won't be overridden even if
694 // it's enabled by the pref.
695 bool mAllowToOverrideSystemScrollSpeed
;
697 // After the event's default action handler has adjusted its delta's values
698 // for horizontalizing a vertical wheel scroll, this variable will be set to
700 bool mDeltaValuesHorizontalizedForDefaultHandler
;
702 void AssignWheelEventData(const WidgetWheelEvent
& aEvent
, bool aCopyTargets
) {
703 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
705 mDeltaX
= aEvent
.mDeltaX
;
706 mDeltaY
= aEvent
.mDeltaY
;
707 mDeltaZ
= aEvent
.mDeltaZ
;
708 mDeltaMode
= aEvent
.mDeltaMode
;
709 mScrollAmount
= aEvent
.mScrollAmount
;
710 mCustomizedByUserPrefs
= aEvent
.mCustomizedByUserPrefs
;
711 mMayHaveMomentum
= aEvent
.mMayHaveMomentum
;
712 mIsMomentum
= aEvent
.mIsMomentum
;
713 mIsNoLineOrPageDelta
= aEvent
.mIsNoLineOrPageDelta
;
714 mLineOrPageDeltaX
= aEvent
.mLineOrPageDeltaX
;
715 mLineOrPageDeltaY
= aEvent
.mLineOrPageDeltaY
;
716 mScrollType
= aEvent
.mScrollType
;
717 mOverflowDeltaX
= aEvent
.mOverflowDeltaX
;
718 mOverflowDeltaY
= aEvent
.mOverflowDeltaY
;
719 mViewPortIsOverscrolled
= aEvent
.mViewPortIsOverscrolled
;
720 mCanTriggerSwipe
= aEvent
.mCanTriggerSwipe
;
721 mAllowToOverrideSystemScrollSpeed
=
722 aEvent
.mAllowToOverrideSystemScrollSpeed
;
723 mDeltaValuesHorizontalizedForDefaultHandler
=
724 aEvent
.mDeltaValuesHorizontalizedForDefaultHandler
;
727 // System scroll speed settings may be too slow at using Gecko. In such
728 // case, we should override the scroll speed computed with system settings.
729 // Following methods return preferred delta values which are multiplied by
730 // factors specified by prefs. If system scroll speed shouldn't be
731 // overridden (e.g., this feature is disabled by pref), they return raw
733 double OverriddenDeltaX() const;
734 double OverriddenDeltaY() const;
736 // Compute the overridden delta value. This may be useful for suppressing
737 // too fast scroll by system scroll speed overriding when widget sets
738 // mAllowToOverrideSystemScrollSpeed.
739 static double ComputeOverriddenDelta(double aDelta
, bool aIsForVertical
);
742 static bool sInitialized
;
743 static bool sIsSystemScrollSpeedOverrideEnabled
;
744 static int32_t sOverrideFactorX
;
745 static int32_t sOverrideFactorY
;
746 static void Initialize();
749 /******************************************************************************
750 * mozilla::WidgetPointerEvent
751 ******************************************************************************/
753 class WidgetPointerEvent
: public WidgetMouseEvent
{
754 friend class mozilla::dom::PBrowserParent
;
755 friend class mozilla::dom::PBrowserChild
;
756 ALLOW_DEPRECATED_READPARAM
759 virtual WidgetPointerEvent
* AsPointerEvent() override
{ return this; }
761 WidgetPointerEvent(bool aIsTrusted
, EventMessage aMsg
, nsIWidget
* w
,
762 const WidgetEventTime
* aTime
= nullptr)
763 : WidgetMouseEvent(aIsTrusted
, aMsg
, w
, ePointerEventClass
, eReal
, aTime
),
767 mFromTouchEvent(false) {}
769 explicit WidgetPointerEvent(const WidgetMouseEvent
& aEvent
)
770 : WidgetMouseEvent(aEvent
),
774 mFromTouchEvent(false) {
775 mClass
= ePointerEventClass
;
778 virtual WidgetEvent
* Duplicate() const override
{
779 MOZ_ASSERT(mClass
== ePointerEventClass
,
780 "Duplicate() must be overridden by sub class");
781 // Not copying widget, it is a weak reference.
782 WidgetPointerEvent
* result
=
783 new WidgetPointerEvent(false, mMessage
, nullptr, this);
784 result
->AssignPointerEventData(*this, true);
785 result
->mFlags
= mFlags
;
792 bool mFromTouchEvent
;
794 // XXX Not tested by test_assign_event_data.html
795 void AssignPointerEventData(const WidgetPointerEvent
& aEvent
,
797 AssignMouseEventData(aEvent
, aCopyTargets
);
799 mWidth
= aEvent
.mWidth
;
800 mHeight
= aEvent
.mHeight
;
801 mIsPrimary
= aEvent
.mIsPrimary
;
802 mFromTouchEvent
= aEvent
.mFromTouchEvent
;
806 } // namespace mozilla
808 #endif // mozilla_MouseEvents_h__