no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / widget / MouseEvents.h
blob7ad7d82cd68810d9557adaa31ad5c7cb80bfb079
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/EventForwards.h"
13 #include "mozilla/MathAlgorithms.h"
14 #include "mozilla/dom/DataTransfer.h"
15 #include "mozilla/ipc/IPCForwards.h"
16 #include "nsCOMPtr.h"
18 namespace mozilla {
20 namespace dom {
21 class PBrowserParent;
22 class PBrowserChild;
23 class PBrowserBridgeParent;
24 } // namespace dom
26 class WidgetPointerEvent;
27 } // namespace mozilla
29 namespace mozilla {
30 class WidgetPointerEventHolder final {
31 public:
32 nsTArray<WidgetPointerEvent> mEvents;
33 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
35 private:
36 virtual ~WidgetPointerEventHolder() = default;
39 /******************************************************************************
40 * mozilla::WidgetPointerHelper
41 ******************************************************************************/
43 class WidgetPointerHelper {
44 public:
45 uint32_t pointerId;
46 int32_t tiltX;
47 int32_t tiltY;
48 int32_t twist;
49 float tangentialPressure;
50 bool convertToPointer;
51 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
53 WidgetPointerHelper()
54 : pointerId(0),
55 tiltX(0),
56 tiltY(0),
57 twist(0),
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),
64 tiltX(aTiltX),
65 tiltY(aTiltY),
66 twist(aTwist),
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;
75 tiltX = aEvent.tiltX;
76 tiltY = aEvent.tiltY;
77 twist = aEvent.twist;
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 {
91 private:
92 friend class dom::PBrowserParent;
93 friend class dom::PBrowserChild;
94 friend class dom::PBrowserBridgeParent;
95 ALLOW_DEPRECATED_READPARAM
97 protected:
98 WidgetMouseEventBase()
99 : mPressure(0),
100 mButton(0),
101 mButtons(0),
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),
110 mPressure(0),
111 mButton(0),
112 mButtons(0),
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.
117 public:
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.
125 float mPressure;
127 // Pressed button ID of mousedown or mouseup event.
128 // This is set only when pressing a button causes the event.
129 int16_t mButton;
131 // Flags of all pressed buttons at the event fired.
132 // This is set at any mouse event, don't be confused with |mButton|.
133 int16_t mButtons;
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,
155 bool aCopyTargets) {
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) {
180 return false;
182 // If this is an ePointerDown event whose mButton is not "not pressed", this
183 // is a button pressing event.
184 if (mMessage == ePointerDown) {
185 return true;
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) {
204 return false;
206 // If this is an ePointerUp event whose mButton is not "not pressed", this
207 // is a button release event.
208 if (mMessage == ePointerUp) {
209 return true;
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 {
231 private:
232 friend class dom::PBrowserParent;
233 friend class dom::PBrowserChild;
234 friend class dom::PBrowserBridgeParent;
235 ALLOW_DEPRECATED_READPARAM
237 public:
238 typedef bool ReasonType;
239 enum Reason : ReasonType { eReal, eSynthesized };
241 typedef uint8_t ContextMenuTriggerType;
242 enum ContextMenuTrigger : ContextMenuTriggerType {
243 eNormal,
244 eContextMenuKey,
245 eControlClick
248 typedef uint8_t ExitFromType;
249 enum ExitFrom : ExitFromType {
250 ePlatformChild,
251 ePlatformTopLevel,
252 ePuppet,
253 ePuppetParentToPuppetChild
256 protected:
257 WidgetMouseEvent()
258 : mReason(eReal),
259 mContextMenuTrigger(eNormal),
260 mClickCount(0),
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,
268 aTime),
269 mReason(aReason),
270 mContextMenuTrigger(eNormal),
271 mClickCount(0),
272 mIgnoreRootScrollFrame(false),
273 mClickEventPrevented(false) {}
275 #ifdef DEBUG
276 void AssertContextMenuEventButtonConsistency() const;
277 #endif
279 public:
280 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
282 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
283 Reason aReason,
284 ContextMenuTrigger aContextMenuTrigger = eNormal,
285 const WidgetEventTime* aTime = nullptr)
286 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass,
287 aTime),
288 mReason(aReason),
289 mContextMenuTrigger(aContextMenuTrigger),
290 mClickCount(0),
291 mIgnoreRootScrollFrame(false),
292 mClickEventPrevented(false) {
293 if (aMessage == eContextMenu) {
294 mButton = (mContextMenuTrigger == eNormal) ? MouseButton::eSecondary
295 : MouseButton::ePrimary;
299 #ifdef DEBUG
300 virtual ~WidgetMouseEvent() { AssertContextMenuEventButtonConsistency(); }
301 #endif
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;
311 return result;
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.
322 Reason mReason;
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 {
379 private:
380 friend class mozilla::dom::PBrowserParent;
381 friend class mozilla::dom::PBrowserChild;
382 ALLOW_DEPRECATED_READPARAM
384 protected:
385 WidgetDragEvent()
386 : mUserCancelled(false), mDefaultPreventedOnContent(false) {}
388 public:
389 virtual WidgetDragEvent* AsDragEvent() override { return this; }
391 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
392 const WidgetEventTime* aTime = nullptr)
393 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal,
394 aTime),
395 mUserCancelled(false),
396 mDefaultPreventedOnContent(false),
397 mInHTMLEditorEventListener(false) {}
399 virtual WidgetEvent* Duplicate() const override {
400 MOZ_ASSERT(mClass == eDragEventClass,
401 "Duplicate() must be overridden by sub class");
402 // Not copying widget, it is a weak reference.
403 WidgetDragEvent* result =
404 new WidgetDragEvent(false, mMessage, nullptr, this);
405 result->AssignDragEventData(*this, true);
406 result->mFlags = mFlags;
407 return result;
410 // The dragging data.
411 nsCOMPtr<dom::DataTransfer> mDataTransfer;
413 // If this is true, user has cancelled the drag operation.
414 bool mUserCancelled;
415 // If this is true, the drag event's preventDefault() is called on content.
416 bool mDefaultPreventedOnContent;
417 // If this event is currently being handled by HTMLEditorEventListener.
418 bool mInHTMLEditorEventListener;
420 // XXX Not tested by test_assign_event_data.html
421 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) {
422 AssignMouseEventData(aEvent, aCopyTargets);
424 mDataTransfer = aEvent.mDataTransfer;
425 // XXX mUserCancelled isn't copied, is this intentionally?
426 mUserCancelled = false;
427 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
431 * Should be called before dispatching the DOM tree if this event is
432 * synthesized for tests because drop effect is initialized before
433 * dispatching from widget if it's not synthesized event, but synthesized
434 * events are not initialized in the path.
436 void InitDropEffectForTests();
439 /******************************************************************************
440 * mozilla::WidgetMouseScrollEvent
442 * This is used for legacy DOM mouse scroll events, i.e.,
443 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
444 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
445 ******************************************************************************/
447 class WidgetMouseScrollEvent : public WidgetMouseEventBase {
448 private:
449 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
451 public:
452 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override { return this; }
454 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
455 nsIWidget* aWidget,
456 const WidgetEventTime* aTime = nullptr)
457 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
458 eMouseScrollEventClass, aTime),
459 mDelta(0),
460 mIsHorizontal(false) {}
462 virtual WidgetEvent* Duplicate() const override {
463 MOZ_ASSERT(mClass == eMouseScrollEventClass,
464 "Duplicate() must be overridden by sub class");
465 // Not copying widget, it is a weak reference.
466 WidgetMouseScrollEvent* result =
467 new WidgetMouseScrollEvent(false, mMessage, nullptr, this);
468 result->AssignMouseScrollEventData(*this, true);
469 result->mFlags = mFlags;
470 return result;
473 // The delta value of mouse scroll event.
474 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
475 // scroll amount in lines. However, if the value is
476 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
477 // value inducates one page scroll. If the event message is
478 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
479 int32_t mDelta;
481 // If this is true, it may cause to scroll horizontally.
482 // Otherwise, vertically.
483 bool mIsHorizontal;
485 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
486 bool aCopyTargets) {
487 AssignMouseEventBaseData(aEvent, aCopyTargets);
489 mDelta = aEvent.mDelta;
490 mIsHorizontal = aEvent.mIsHorizontal;
494 /******************************************************************************
495 * mozilla::WidgetWheelEvent
496 ******************************************************************************/
498 class WidgetWheelEvent : public WidgetMouseEventBase {
499 private:
500 friend class mozilla::dom::PBrowserParent;
501 friend class mozilla::dom::PBrowserChild;
502 ALLOW_DEPRECATED_READPARAM
504 WidgetWheelEvent()
505 : mDeltaX(0.0),
506 mDeltaY(0.0),
507 mDeltaZ(0.0),
508 mOverflowDeltaX(0.0),
509 mOverflowDeltaY(0.0)
510 // Including WheelEventBinding.h here leads to an include loop, so
511 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
513 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
514 mLineOrPageDeltaX(0),
515 mLineOrPageDeltaY(0),
516 mScrollType(SCROLL_DEFAULT),
517 mCustomizedByUserPrefs(false),
518 mMayHaveMomentum(false),
519 mIsMomentum(false),
520 mIsNoLineOrPageDelta(false),
521 mViewPortIsOverscrolled(false),
522 mCanTriggerSwipe(false),
523 mAllowToOverrideSystemScrollSpeed(false),
524 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
526 public:
527 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
529 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
530 const WidgetEventTime* aTime = nullptr)
531 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass,
532 aTime),
533 mDeltaX(0.0),
534 mDeltaY(0.0),
535 mDeltaZ(0.0),
536 mOverflowDeltaX(0.0),
537 mOverflowDeltaY(0.0)
538 // Including WheelEventBinding.h here leads to an include loop, so
539 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
541 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
542 mLineOrPageDeltaX(0),
543 mLineOrPageDeltaY(0),
544 mScrollType(SCROLL_DEFAULT),
545 mCustomizedByUserPrefs(false),
546 mMayHaveMomentum(false),
547 mIsMomentum(false),
548 mIsNoLineOrPageDelta(false),
549 mViewPortIsOverscrolled(false),
550 mCanTriggerSwipe(false),
551 mAllowToOverrideSystemScrollSpeed(true),
552 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
554 virtual WidgetEvent* Duplicate() const override {
555 MOZ_ASSERT(mClass == eWheelEventClass,
556 "Duplicate() must be overridden by sub class");
557 // Not copying widget, it is a weak reference.
558 WidgetWheelEvent* result =
559 new WidgetWheelEvent(false, mMessage, nullptr, this);
560 result->AssignWheelEventData(*this, true);
561 result->mFlags = mFlags;
562 return result;
565 // Scroll gestures that start at the edge of the scrollable range can result
566 // in a swipe gesture. For the first wheel event of such a gesture, call
567 // TriggersSwipe() after the event has been processed in order to find out
568 // whether a swipe should be started.
569 bool TriggersSwipe() const {
570 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
571 this->mOverflowDeltaX != 0.0;
574 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
575 // mousewheel.*.delta_multiplier_* prefs which are applied by
576 // EventStateManager. So, after widget dispatches this event,
577 // these delta values may have different values than before.
578 double mDeltaX;
579 double mDeltaY;
580 double mDeltaZ;
582 // The mousewheel tick counts.
583 double mWheelTicksX = 0.0;
584 double mWheelTicksY = 0.0;
586 enum class DeltaModeCheckingState : uint8_t {
587 // Neither deltaMode nor the delta values have been accessed.
588 Unknown,
589 // The delta values have been accessed, without checking deltaMode first.
590 Unchecked,
591 // The deltaMode has been checked.
592 Checked,
595 // For compat reasons, we might expose a DOM_DELTA_LINE event as
596 // DOM_DELTA_PIXEL instead. Whether we do that depends on whether the event
597 // has been asked for the deltaMode before the deltas. If it has, we assume
598 // that the page will correctly handle DOM_DELTA_LINE. This variable tracks
599 // that state. See bug 1392460.
600 DeltaModeCheckingState mDeltaModeCheckingState =
601 DeltaModeCheckingState::Unknown;
603 // The amount of scrolling per line or page, without accounting for mouse
604 // wheel transactions etc.
606 // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta.
607 nsSize mScrollAmount;
609 // overflowed delta values for scroll, these values are set by
610 // EventStateManger. If the default action of the wheel event isn't scroll,
611 // these values are always zero. Otherwise, remaining delta values which are
612 // not used by scroll are set.
613 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
614 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
615 // delta values which are not applied the delta_multiplier prefs.
616 // So, if widget wanted to know the actual direction to be scrolled,
617 // it would need to check the mDeltaX and mDeltaY.
618 double mOverflowDeltaX;
619 double mOverflowDeltaY;
621 // Should be one of WheelEvent_Binding::DOM_DELTA_*
622 uint32_t mDeltaMode;
624 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
625 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
626 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
627 int32_t mLineOrPageDeltaX;
628 int32_t mLineOrPageDeltaY;
630 // When the default action for an wheel event is moving history or zooming,
631 // need to chose a delta value for doing it.
632 int32_t GetPreferredIntDelta() {
633 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
634 return 0;
636 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
637 return mLineOrPageDeltaY;
639 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
640 return mLineOrPageDeltaX;
642 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
643 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
644 return 0; // We cannot guess the answer in this case.
646 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
647 ? mLineOrPageDeltaX
648 : mLineOrPageDeltaY;
651 // Scroll type
652 // The default value is SCROLL_DEFAULT, which means EventStateManager will
653 // select preferred scroll type automatically.
654 enum ScrollType : uint8_t {
655 SCROLL_DEFAULT,
656 SCROLL_SYNCHRONOUSLY,
657 SCROLL_ASYNCHRONOUSLY,
658 SCROLL_SMOOTHLY
660 ScrollType mScrollType;
662 // If the delta values are computed from prefs, this value is true.
663 // Otherwise, i.e., they are computed from native events, false.
664 bool mCustomizedByUserPrefs;
666 // true if the momentum events directly tied to this event may follow it.
667 bool mMayHaveMomentum;
668 // true if the event is caused by momentum.
669 bool mIsMomentum;
671 // If device event handlers don't know when they should set mLineOrPageDeltaX
672 // and mLineOrPageDeltaY, this is true. Otherwise, false.
673 // If mIsNoLineOrPageDelta is true, ESM will generate
674 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
675 // a line height.
676 bool mIsNoLineOrPageDelta;
678 // Whether or not the parent of the currently overscrolled frame is the
679 // ViewPort. This is false in situations when an element on the page is being
680 // overscrolled (such as a text field), but true when the 'page' is being
681 // overscrolled.
682 bool mViewPortIsOverscrolled;
684 // The wheel event can trigger a swipe to start if it's overscrolling the
685 // viewport.
686 bool mCanTriggerSwipe;
688 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
689 // overridden. Otherwise, the scroll speed won't be overridden even if
690 // it's enabled by the pref.
691 bool mAllowToOverrideSystemScrollSpeed;
693 // After the event's default action handler has adjusted its delta's values
694 // for horizontalizing a vertical wheel scroll, this variable will be set to
695 // true.
696 bool mDeltaValuesHorizontalizedForDefaultHandler;
698 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
699 AssignMouseEventBaseData(aEvent, aCopyTargets);
701 mDeltaX = aEvent.mDeltaX;
702 mDeltaY = aEvent.mDeltaY;
703 mDeltaZ = aEvent.mDeltaZ;
704 mDeltaMode = aEvent.mDeltaMode;
705 mScrollAmount = aEvent.mScrollAmount;
706 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
707 mMayHaveMomentum = aEvent.mMayHaveMomentum;
708 mIsMomentum = aEvent.mIsMomentum;
709 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
710 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
711 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
712 mScrollType = aEvent.mScrollType;
713 mOverflowDeltaX = aEvent.mOverflowDeltaX;
714 mOverflowDeltaY = aEvent.mOverflowDeltaY;
715 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
716 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
717 mAllowToOverrideSystemScrollSpeed =
718 aEvent.mAllowToOverrideSystemScrollSpeed;
719 mDeltaValuesHorizontalizedForDefaultHandler =
720 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
723 // System scroll speed settings may be too slow at using Gecko. In such
724 // case, we should override the scroll speed computed with system settings.
725 // Following methods return preferred delta values which are multiplied by
726 // factors specified by prefs. If system scroll speed shouldn't be
727 // overridden (e.g., this feature is disabled by pref), they return raw
728 // delta values.
729 double OverriddenDeltaX() const;
730 double OverriddenDeltaY() const;
732 // Compute the overridden delta value. This may be useful for suppressing
733 // too fast scroll by system scroll speed overriding when widget sets
734 // mAllowToOverrideSystemScrollSpeed.
735 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
737 private:
738 static bool sInitialized;
739 static bool sIsSystemScrollSpeedOverrideEnabled;
740 static int32_t sOverrideFactorX;
741 static int32_t sOverrideFactorY;
742 static void Initialize();
745 /******************************************************************************
746 * mozilla::WidgetPointerEvent
747 ******************************************************************************/
749 class WidgetPointerEvent : public WidgetMouseEvent {
750 friend class mozilla::dom::PBrowserParent;
751 friend class mozilla::dom::PBrowserChild;
752 ALLOW_DEPRECATED_READPARAM
754 public:
755 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
757 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w,
758 const WidgetEventTime* aTime = nullptr)
759 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal, aTime),
760 mWidth(1),
761 mHeight(1),
762 mIsPrimary(true),
763 mFromTouchEvent(false) {}
765 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
766 : WidgetMouseEvent(aEvent),
767 mWidth(1),
768 mHeight(1),
769 mIsPrimary(true),
770 mFromTouchEvent(false) {
771 mClass = ePointerEventClass;
774 virtual WidgetEvent* Duplicate() const override {
775 MOZ_ASSERT(mClass == ePointerEventClass,
776 "Duplicate() must be overridden by sub class");
777 // Not copying widget, it is a weak reference.
778 WidgetPointerEvent* result =
779 new WidgetPointerEvent(false, mMessage, nullptr, this);
780 result->AssignPointerEventData(*this, true);
781 result->mFlags = mFlags;
782 return result;
785 int32_t mWidth;
786 int32_t mHeight;
787 bool mIsPrimary;
788 bool mFromTouchEvent;
790 // XXX Not tested by test_assign_event_data.html
791 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
792 bool aCopyTargets) {
793 AssignMouseEventData(aEvent, aCopyTargets);
795 mWidth = aEvent.mWidth;
796 mHeight = aEvent.mHeight;
797 mIsPrimary = aEvent.mIsPrimary;
798 mFromTouchEvent = aEvent.mFromTouchEvent;
802 } // namespace mozilla
804 #endif // mozilla_MouseEvents_h__