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;
434 bool CanConvertToInputData() const {
435 return mMessage
== eDragStart
|| mMessage
== eDragEnd
;
439 * Should be called before dispatching the DOM tree if this event is
440 * synthesized for tests because drop effect is initialized before
441 * dispatching from widget if it's not synthesized event, but synthesized
442 * events are not initialized in the path.
444 void InitDropEffectForTests();
447 /******************************************************************************
448 * mozilla::WidgetMouseScrollEvent
450 * This is used for legacy DOM mouse scroll events, i.e.,
451 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
452 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
453 ******************************************************************************/
455 class WidgetMouseScrollEvent
: public WidgetMouseEventBase
{
457 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
460 virtual WidgetMouseScrollEvent
* AsMouseScrollEvent() override
{ return this; }
462 WidgetMouseScrollEvent(bool aIsTrusted
, EventMessage aMessage
,
464 const WidgetEventTime
* aTime
= nullptr)
465 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
,
466 eMouseScrollEventClass
, aTime
),
468 mIsHorizontal(false) {}
470 virtual WidgetEvent
* Duplicate() const override
{
471 MOZ_ASSERT(mClass
== eMouseScrollEventClass
,
472 "Duplicate() must be overridden by sub class");
473 // Not copying widget, it is a weak reference.
474 WidgetMouseScrollEvent
* result
=
475 new WidgetMouseScrollEvent(false, mMessage
, nullptr, this);
476 result
->AssignMouseScrollEventData(*this, true);
477 result
->mFlags
= mFlags
;
481 // The delta value of mouse scroll event.
482 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
483 // scroll amount in lines. However, if the value is
484 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
485 // value inducates one page scroll. If the event message is
486 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
489 // If this is true, it may cause to scroll horizontally.
490 // Otherwise, vertically.
493 void AssignMouseScrollEventData(const WidgetMouseScrollEvent
& aEvent
,
495 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
497 mDelta
= aEvent
.mDelta
;
498 mIsHorizontal
= aEvent
.mIsHorizontal
;
502 /******************************************************************************
503 * mozilla::WidgetWheelEvent
504 ******************************************************************************/
506 class WidgetWheelEvent
: public WidgetMouseEventBase
{
508 friend class mozilla::dom::PBrowserParent
;
509 friend class mozilla::dom::PBrowserChild
;
510 ALLOW_DEPRECATED_READPARAM
516 mOverflowDeltaX(0.0),
518 // Including WheelEventBinding.h here leads to an include loop, so
519 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
521 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
522 mLineOrPageDeltaX(0),
523 mLineOrPageDeltaY(0),
524 mScrollType(SCROLL_DEFAULT
),
525 mCustomizedByUserPrefs(false),
526 mMayHaveMomentum(false),
528 mIsNoLineOrPageDelta(false),
529 mViewPortIsOverscrolled(false),
530 mCanTriggerSwipe(false),
531 mAllowToOverrideSystemScrollSpeed(false),
532 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
535 virtual WidgetWheelEvent
* AsWheelEvent() override
{ return this; }
537 WidgetWheelEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
,
538 const WidgetEventTime
* aTime
= nullptr)
539 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
, eWheelEventClass
,
544 mOverflowDeltaX(0.0),
546 // Including WheelEventBinding.h here leads to an include loop, so
547 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
549 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
550 mLineOrPageDeltaX(0),
551 mLineOrPageDeltaY(0),
552 mScrollType(SCROLL_DEFAULT
),
553 mCustomizedByUserPrefs(false),
554 mMayHaveMomentum(false),
556 mIsNoLineOrPageDelta(false),
557 mViewPortIsOverscrolled(false),
558 mCanTriggerSwipe(false),
559 mAllowToOverrideSystemScrollSpeed(true),
560 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
562 virtual WidgetEvent
* Duplicate() const override
{
563 MOZ_ASSERT(mClass
== eWheelEventClass
,
564 "Duplicate() must be overridden by sub class");
565 // Not copying widget, it is a weak reference.
566 WidgetWheelEvent
* result
=
567 new WidgetWheelEvent(false, mMessage
, nullptr, this);
568 result
->AssignWheelEventData(*this, true);
569 result
->mFlags
= mFlags
;
573 // Scroll gestures that start at the edge of the scrollable range can result
574 // in a swipe gesture. For the first wheel event of such a gesture, call
575 // TriggersSwipe() after the event has been processed in order to find out
576 // whether a swipe should be started.
577 bool TriggersSwipe() const {
578 return mCanTriggerSwipe
&& mViewPortIsOverscrolled
&&
579 this->mOverflowDeltaX
!= 0.0;
582 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
583 // mousewheel.*.delta_multiplier_* prefs which are applied by
584 // EventStateManager. So, after widget dispatches this event,
585 // these delta values may have different values than before.
590 // The mousewheel tick counts.
591 double mWheelTicksX
= 0.0;
592 double mWheelTicksY
= 0.0;
594 enum class DeltaModeCheckingState
: uint8_t {
595 // Neither deltaMode nor the delta values have been accessed.
597 // The delta values have been accessed, without checking deltaMode first.
599 // The deltaMode has been checked.
603 // For compat reasons, we might expose a DOM_DELTA_LINE event as
604 // DOM_DELTA_PIXEL instead. Whether we do that depends on whether the event
605 // has been asked for the deltaMode before the deltas. If it has, we assume
606 // that the page will correctly handle DOM_DELTA_LINE. This variable tracks
607 // that state. See bug 1392460.
608 DeltaModeCheckingState mDeltaModeCheckingState
=
609 DeltaModeCheckingState::Unknown
;
611 // The amount of scrolling per line or page, without accounting for mouse
612 // wheel transactions etc.
614 // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta.
615 nsSize mScrollAmount
;
617 // overflowed delta values for scroll, these values are set by
618 // EventStateManger. If the default action of the wheel event isn't scroll,
619 // these values are always zero. Otherwise, remaining delta values which are
620 // not used by scroll are set.
621 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
622 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
623 // delta values which are not applied the delta_multiplier prefs.
624 // So, if widget wanted to know the actual direction to be scrolled,
625 // it would need to check the mDeltaX and mDeltaY.
626 double mOverflowDeltaX
;
627 double mOverflowDeltaY
;
629 // Should be one of WheelEvent_Binding::DOM_DELTA_*
632 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
633 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
634 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
635 int32_t mLineOrPageDeltaX
;
636 int32_t mLineOrPageDeltaY
;
638 // When the default action for an wheel event is moving history or zooming,
639 // need to chose a delta value for doing it.
640 int32_t GetPreferredIntDelta() {
641 if (!mLineOrPageDeltaX
&& !mLineOrPageDeltaY
) {
644 if (mLineOrPageDeltaY
&& !mLineOrPageDeltaX
) {
645 return mLineOrPageDeltaY
;
647 if (mLineOrPageDeltaX
&& !mLineOrPageDeltaY
) {
648 return mLineOrPageDeltaX
;
650 if ((mLineOrPageDeltaX
< 0 && mLineOrPageDeltaY
> 0) ||
651 (mLineOrPageDeltaX
> 0 && mLineOrPageDeltaY
< 0)) {
652 return 0; // We cannot guess the answer in this case.
654 return (Abs(mLineOrPageDeltaX
) > Abs(mLineOrPageDeltaY
))
660 // The default value is SCROLL_DEFAULT, which means EventStateManager will
661 // select preferred scroll type automatically.
662 enum ScrollType
: uint8_t {
664 SCROLL_SYNCHRONOUSLY
,
665 SCROLL_ASYNCHRONOUSLY
,
668 ScrollType mScrollType
;
670 // If the delta values are computed from prefs, this value is true.
671 // Otherwise, i.e., they are computed from native events, false.
672 bool mCustomizedByUserPrefs
;
674 // true if the momentum events directly tied to this event may follow it.
675 bool mMayHaveMomentum
;
676 // true if the event is caused by momentum.
679 // If device event handlers don't know when they should set mLineOrPageDeltaX
680 // and mLineOrPageDeltaY, this is true. Otherwise, false.
681 // If mIsNoLineOrPageDelta is true, ESM will generate
682 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
684 bool mIsNoLineOrPageDelta
;
686 // Whether or not the parent of the currently overscrolled frame is the
687 // ViewPort. This is false in situations when an element on the page is being
688 // overscrolled (such as a text field), but true when the 'page' is being
690 bool mViewPortIsOverscrolled
;
692 // The wheel event can trigger a swipe to start if it's overscrolling the
694 bool mCanTriggerSwipe
;
696 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
697 // overridden. Otherwise, the scroll speed won't be overridden even if
698 // it's enabled by the pref.
699 bool mAllowToOverrideSystemScrollSpeed
;
701 // After the event's default action handler has adjusted its delta's values
702 // for horizontalizing a vertical wheel scroll, this variable will be set to
704 bool mDeltaValuesHorizontalizedForDefaultHandler
;
706 void AssignWheelEventData(const WidgetWheelEvent
& aEvent
, bool aCopyTargets
) {
707 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
709 mDeltaX
= aEvent
.mDeltaX
;
710 mDeltaY
= aEvent
.mDeltaY
;
711 mDeltaZ
= aEvent
.mDeltaZ
;
712 mDeltaMode
= aEvent
.mDeltaMode
;
713 mScrollAmount
= aEvent
.mScrollAmount
;
714 mCustomizedByUserPrefs
= aEvent
.mCustomizedByUserPrefs
;
715 mMayHaveMomentum
= aEvent
.mMayHaveMomentum
;
716 mIsMomentum
= aEvent
.mIsMomentum
;
717 mIsNoLineOrPageDelta
= aEvent
.mIsNoLineOrPageDelta
;
718 mLineOrPageDeltaX
= aEvent
.mLineOrPageDeltaX
;
719 mLineOrPageDeltaY
= aEvent
.mLineOrPageDeltaY
;
720 mScrollType
= aEvent
.mScrollType
;
721 mOverflowDeltaX
= aEvent
.mOverflowDeltaX
;
722 mOverflowDeltaY
= aEvent
.mOverflowDeltaY
;
723 mViewPortIsOverscrolled
= aEvent
.mViewPortIsOverscrolled
;
724 mCanTriggerSwipe
= aEvent
.mCanTriggerSwipe
;
725 mAllowToOverrideSystemScrollSpeed
=
726 aEvent
.mAllowToOverrideSystemScrollSpeed
;
727 mDeltaValuesHorizontalizedForDefaultHandler
=
728 aEvent
.mDeltaValuesHorizontalizedForDefaultHandler
;
731 // System scroll speed settings may be too slow at using Gecko. In such
732 // case, we should override the scroll speed computed with system settings.
733 // Following methods return preferred delta values which are multiplied by
734 // factors specified by prefs. If system scroll speed shouldn't be
735 // overridden (e.g., this feature is disabled by pref), they return raw
737 double OverriddenDeltaX() const;
738 double OverriddenDeltaY() const;
740 // Compute the overridden delta value. This may be useful for suppressing
741 // too fast scroll by system scroll speed overriding when widget sets
742 // mAllowToOverrideSystemScrollSpeed.
743 static double ComputeOverriddenDelta(double aDelta
, bool aIsForVertical
);
746 static bool sInitialized
;
747 static bool sIsSystemScrollSpeedOverrideEnabled
;
748 static int32_t sOverrideFactorX
;
749 static int32_t sOverrideFactorY
;
750 static void Initialize();
753 /******************************************************************************
754 * mozilla::WidgetPointerEvent
755 ******************************************************************************/
757 class WidgetPointerEvent
: public WidgetMouseEvent
{
758 friend class mozilla::dom::PBrowserParent
;
759 friend class mozilla::dom::PBrowserChild
;
760 ALLOW_DEPRECATED_READPARAM
763 virtual WidgetPointerEvent
* AsPointerEvent() override
{ return this; }
765 WidgetPointerEvent(bool aIsTrusted
, EventMessage aMsg
, nsIWidget
* w
,
766 const WidgetEventTime
* aTime
= nullptr)
767 : WidgetMouseEvent(aIsTrusted
, aMsg
, w
, ePointerEventClass
, eReal
, aTime
),
771 mFromTouchEvent(false) {}
773 explicit WidgetPointerEvent(const WidgetMouseEvent
& aEvent
)
774 : WidgetMouseEvent(aEvent
),
778 mFromTouchEvent(false) {
779 mClass
= ePointerEventClass
;
782 virtual WidgetEvent
* Duplicate() const override
{
783 MOZ_ASSERT(mClass
== ePointerEventClass
,
784 "Duplicate() must be overridden by sub class");
785 // Not copying widget, it is a weak reference.
786 WidgetPointerEvent
* result
=
787 new WidgetPointerEvent(false, mMessage
, nullptr, this);
788 result
->AssignPointerEventData(*this, true);
789 result
->mFlags
= mFlags
;
796 bool mFromTouchEvent
;
798 // XXX Not tested by test_assign_event_data.html
799 void AssignPointerEventData(const WidgetPointerEvent
& aEvent
,
801 AssignMouseEventData(aEvent
, aCopyTargets
);
803 mWidth
= aEvent
.mWidth
;
804 mHeight
= aEvent
.mHeight
;
805 mIsPrimary
= aEvent
.mIsPrimary
;
806 mFromTouchEvent
= aEvent
.mFromTouchEvent
;
810 } // namespace mozilla
812 #endif // mozilla_MouseEvents_h__