Bug 1812348 [wpt PR 38171] - wake lock: Move tests in web_tests/wake-lock to either...
[gecko.git] / widget / MouseEvents.h
blob86e87ea738b0b694d429cef0acb6e0a8e1bd61b9
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 namespace mozilla {
18 namespace dom {
19 class PBrowserParent;
20 class PBrowserChild;
21 class PBrowserBridgeParent;
22 } // namespace dom
24 class WidgetPointerEvent;
25 } // namespace mozilla
27 namespace mozilla {
28 class WidgetPointerEventHolder final {
29 public:
30 nsTArray<WidgetPointerEvent> mEvents;
31 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
33 private:
34 virtual ~WidgetPointerEventHolder() = default;
37 /******************************************************************************
38 * mozilla::WidgetPointerHelper
39 ******************************************************************************/
41 class WidgetPointerHelper {
42 public:
43 uint32_t pointerId;
44 int32_t tiltX;
45 int32_t tiltY;
46 int32_t twist;
47 float tangentialPressure;
48 bool convertToPointer;
49 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
51 WidgetPointerHelper()
52 : pointerId(0),
53 tiltX(0),
54 tiltY(0),
55 twist(0),
56 tangentialPressure(0),
57 convertToPointer(true) {}
59 WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
60 uint32_t aTwist = 0, float aTangentialPressure = 0)
61 : pointerId(aPointerId),
62 tiltX(aTiltX),
63 tiltY(aTiltY),
64 twist(aTwist),
65 tangentialPressure(aTangentialPressure),
66 convertToPointer(true) {}
68 explicit WidgetPointerHelper(const WidgetPointerHelper& aHelper) = default;
70 void AssignPointerHelperData(const WidgetPointerHelper& aEvent,
71 bool aCopyCoalescedEvents = false) {
72 pointerId = aEvent.pointerId;
73 tiltX = aEvent.tiltX;
74 tiltY = aEvent.tiltY;
75 twist = aEvent.twist;
76 tangentialPressure = aEvent.tangentialPressure;
77 convertToPointer = aEvent.convertToPointer;
78 if (aCopyCoalescedEvents) {
79 mCoalescedWidgetEvents = aEvent.mCoalescedWidgetEvents;
84 /******************************************************************************
85 * mozilla::WidgetMouseEventBase
86 ******************************************************************************/
88 class WidgetMouseEventBase : public WidgetInputEvent {
89 private:
90 friend class dom::PBrowserParent;
91 friend class dom::PBrowserChild;
92 friend class dom::PBrowserBridgeParent;
94 protected:
95 WidgetMouseEventBase()
96 : mPressure(0),
97 mButton(0),
98 mButtons(0),
99 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
100 // Including MouseEventBinding.h here leads to an include loop, so
101 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
103 WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
104 nsIWidget* aWidget, EventClassID aEventClassID)
105 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID),
106 mPressure(0),
107 mButton(0),
108 mButtons(0),
109 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
110 // Including MouseEventBinding.h here leads to an include loop, so
111 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
113 public:
114 virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
116 virtual WidgetEvent* Duplicate() const override {
117 MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
120 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
121 float mPressure;
123 // Pressed button ID of mousedown or mouseup event.
124 // This is set only when pressing a button causes the event.
125 int16_t mButton;
127 // Flags of all pressed buttons at the event fired.
128 // This is set at any mouse event, don't be confused with |mButton|.
129 int16_t mButtons;
131 // Possible values a in MouseEvent
132 uint16_t mInputSource;
134 bool IsLeftButtonPressed() const {
135 return !!(mButtons & MouseButtonsFlag::ePrimaryFlag);
137 bool IsRightButtonPressed() const {
138 return !!(mButtons & MouseButtonsFlag::eSecondaryFlag);
140 bool IsMiddleButtonPressed() const {
141 return !!(mButtons & MouseButtonsFlag::eMiddleFlag);
143 bool Is4thButtonPressed() const {
144 return !!(mButtons & MouseButtonsFlag::e4thFlag);
146 bool Is5thButtonPressed() const {
147 return !!(mButtons & MouseButtonsFlag::e5thFlag);
150 void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
151 bool aCopyTargets) {
152 AssignInputEventData(aEvent, aCopyTargets);
154 mButton = aEvent.mButton;
155 mButtons = aEvent.mButtons;
156 mPressure = aEvent.mPressure;
157 mInputSource = aEvent.mInputSource;
161 * Returns true if left click event.
163 bool IsLeftClickEvent() const {
164 return mMessage == eMouseClick && mButton == MouseButton::ePrimary;
168 /******************************************************************************
169 * mozilla::WidgetMouseEvent
170 ******************************************************************************/
172 class WidgetMouseEvent : public WidgetMouseEventBase,
173 public WidgetPointerHelper {
174 private:
175 friend class dom::PBrowserParent;
176 friend class dom::PBrowserChild;
177 friend class dom::PBrowserBridgeParent;
179 public:
180 typedef bool ReasonType;
181 enum Reason : ReasonType { eReal, eSynthesized };
183 typedef uint8_t ContextMenuTriggerType;
184 enum ContextMenuTrigger : ContextMenuTriggerType {
185 eNormal,
186 eContextMenuKey,
187 eControlClick
190 typedef uint8_t ExitFromType;
191 enum ExitFrom : ExitFromType {
192 ePlatformChild,
193 ePlatformTopLevel,
194 ePuppet,
195 ePuppetParentToPuppetChild
198 protected:
199 WidgetMouseEvent()
200 : mReason(eReal),
201 mContextMenuTrigger(eNormal),
202 mClickCount(0),
203 mIgnoreRootScrollFrame(false),
204 mUseLegacyNonPrimaryDispatch(false),
205 mClickEventPrevented(false) {}
207 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
208 EventClassID aEventClassID, Reason aReason)
209 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID),
210 mReason(aReason),
211 mContextMenuTrigger(eNormal),
212 mClickCount(0),
213 mIgnoreRootScrollFrame(false),
214 mUseLegacyNonPrimaryDispatch(false),
215 mClickEventPrevented(false) {}
217 #ifdef DEBUG
218 void AssertContextMenuEventButtonConsistency() const;
219 #endif
221 public:
222 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
224 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
225 Reason aReason,
226 ContextMenuTrigger aContextMenuTrigger = eNormal)
227 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass),
228 mReason(aReason),
229 mContextMenuTrigger(aContextMenuTrigger),
230 mClickCount(0),
231 mIgnoreRootScrollFrame(false),
232 mUseLegacyNonPrimaryDispatch(false),
233 mClickEventPrevented(false) {
234 if (aMessage == eContextMenu) {
235 mButton = (mContextMenuTrigger == eNormal) ? MouseButton::eSecondary
236 : MouseButton::ePrimary;
240 #ifdef DEBUG
241 virtual ~WidgetMouseEvent() { AssertContextMenuEventButtonConsistency(); }
242 #endif
244 virtual WidgetEvent* Duplicate() const override {
245 MOZ_ASSERT(mClass == eMouseEventClass,
246 "Duplicate() must be overridden by sub class");
247 // Not copying widget, it is a weak reference.
248 WidgetMouseEvent* result = new WidgetMouseEvent(
249 false, mMessage, nullptr, mReason, mContextMenuTrigger);
250 result->AssignMouseEventData(*this, true);
251 result->mFlags = mFlags;
252 return result;
255 // If during mouseup handling we detect that click event might need to be
256 // dispatched, this is setup to be the target of the click event.
257 nsCOMPtr<dom::EventTarget> mClickTarget;
259 // mReason indicates the reason why the event is fired:
260 // - Representing mouse operation.
261 // - Synthesized for emulating mousemove event when the content under the
262 // mouse cursor is scrolled.
263 Reason mReason;
265 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
266 // This indicates if the context menu event is caused by context menu key or
267 // other reasons (typically, a click of right mouse button).
268 ContextMenuTrigger mContextMenuTrigger;
270 // mExitFrom contains a value only when mMessage is eMouseExitFromWidget.
271 // This indicates if the mouse cursor exits from a top level platform widget,
272 // a child widget or a puppet widget.
273 Maybe<ExitFrom> mExitFrom;
275 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
276 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
277 // Otherwise, this must be 0.
278 uint32_t mClickCount;
280 // Whether the event should ignore scroll frame bounds during dispatch.
281 bool mIgnoreRootScrollFrame;
283 // Indicates whether the event should dispatch click events for non-primary
284 // mouse buttons on window and document.
285 bool mUseLegacyNonPrimaryDispatch;
287 // Whether the event shouldn't cause click event.
288 bool mClickEventPrevented;
290 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) {
291 AssignMouseEventBaseData(aEvent, aCopyTargets);
292 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
294 mExitFrom = aEvent.mExitFrom;
295 mClickCount = aEvent.mClickCount;
296 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
297 mUseLegacyNonPrimaryDispatch = aEvent.mUseLegacyNonPrimaryDispatch;
298 mClickEventPrevented = aEvent.mClickEventPrevented;
302 * Returns true if the event is a context menu event caused by key.
304 bool IsContextMenuKeyEvent() const {
305 return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
309 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
310 * a synthesized event by scroll or something, returns false.
312 bool IsReal() const { return mReason == eReal; }
315 * Returns true if middle click paste is enabled.
317 static bool IsMiddleClickPasteEnabled();
320 /******************************************************************************
321 * mozilla::WidgetDragEvent
322 ******************************************************************************/
324 class WidgetDragEvent : public WidgetMouseEvent {
325 private:
326 friend class mozilla::dom::PBrowserParent;
327 friend class mozilla::dom::PBrowserChild;
329 protected:
330 WidgetDragEvent()
331 : mUserCancelled(false), mDefaultPreventedOnContent(false) {}
333 public:
334 virtual WidgetDragEvent* AsDragEvent() override { return this; }
336 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
337 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal),
338 mUserCancelled(false),
339 mDefaultPreventedOnContent(false) {}
341 virtual WidgetEvent* Duplicate() const override {
342 MOZ_ASSERT(mClass == eDragEventClass,
343 "Duplicate() must be overridden by sub class");
344 // Not copying widget, it is a weak reference.
345 WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
346 result->AssignDragEventData(*this, true);
347 result->mFlags = mFlags;
348 return result;
351 // The dragging data.
352 nsCOMPtr<dom::DataTransfer> mDataTransfer;
354 // If this is true, user has cancelled the drag operation.
355 bool mUserCancelled;
356 // If this is true, the drag event's preventDefault() is called on content.
357 bool mDefaultPreventedOnContent;
359 // XXX Not tested by test_assign_event_data.html
360 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) {
361 AssignMouseEventData(aEvent, aCopyTargets);
363 mDataTransfer = aEvent.mDataTransfer;
364 // XXX mUserCancelled isn't copied, is this intentionally?
365 mUserCancelled = false;
366 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
370 * Should be called before dispatching the DOM tree if this event is
371 * synthesized for tests because drop effect is initialized before
372 * dispatching from widget if it's not synthesized event, but synthesized
373 * events are not initialized in the path.
375 void InitDropEffectForTests();
378 /******************************************************************************
379 * mozilla::WidgetMouseScrollEvent
381 * This is used for legacy DOM mouse scroll events, i.e.,
382 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
383 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
384 ******************************************************************************/
386 class WidgetMouseScrollEvent : public WidgetMouseEventBase {
387 private:
388 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
390 public:
391 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override { return this; }
393 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
394 nsIWidget* aWidget)
395 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
396 eMouseScrollEventClass),
397 mDelta(0),
398 mIsHorizontal(false) {}
400 virtual WidgetEvent* Duplicate() const override {
401 MOZ_ASSERT(mClass == eMouseScrollEventClass,
402 "Duplicate() must be overridden by sub class");
403 // Not copying widget, it is a weak reference.
404 WidgetMouseScrollEvent* result =
405 new WidgetMouseScrollEvent(false, mMessage, nullptr);
406 result->AssignMouseScrollEventData(*this, true);
407 result->mFlags = mFlags;
408 return result;
411 // The delta value of mouse scroll event.
412 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
413 // scroll amount in lines. However, if the value is
414 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
415 // value inducates one page scroll. If the event message is
416 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
417 int32_t mDelta;
419 // If this is true, it may cause to scroll horizontally.
420 // Otherwise, vertically.
421 bool mIsHorizontal;
423 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
424 bool aCopyTargets) {
425 AssignMouseEventBaseData(aEvent, aCopyTargets);
427 mDelta = aEvent.mDelta;
428 mIsHorizontal = aEvent.mIsHorizontal;
432 /******************************************************************************
433 * mozilla::WidgetWheelEvent
434 ******************************************************************************/
436 class WidgetWheelEvent : public WidgetMouseEventBase {
437 private:
438 friend class mozilla::dom::PBrowserParent;
439 friend class mozilla::dom::PBrowserChild;
441 WidgetWheelEvent()
442 : mDeltaX(0.0),
443 mDeltaY(0.0),
444 mDeltaZ(0.0),
445 mOverflowDeltaX(0.0),
446 mOverflowDeltaY(0.0)
447 // Including WheelEventBinding.h here leads to an include loop, so
448 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
450 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
451 mLineOrPageDeltaX(0),
452 mLineOrPageDeltaY(0),
453 mScrollType(SCROLL_DEFAULT),
454 mCustomizedByUserPrefs(false),
455 mMayHaveMomentum(false),
456 mIsMomentum(false),
457 mIsNoLineOrPageDelta(false),
458 mViewPortIsOverscrolled(false),
459 mCanTriggerSwipe(false),
460 mAllowToOverrideSystemScrollSpeed(false),
461 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
463 public:
464 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
466 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
467 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass),
468 mDeltaX(0.0),
469 mDeltaY(0.0),
470 mDeltaZ(0.0),
471 mOverflowDeltaX(0.0),
472 mOverflowDeltaY(0.0)
473 // Including WheelEventBinding.h here leads to an include loop, so
474 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
476 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
477 mLineOrPageDeltaX(0),
478 mLineOrPageDeltaY(0),
479 mScrollType(SCROLL_DEFAULT),
480 mCustomizedByUserPrefs(false),
481 mMayHaveMomentum(false),
482 mIsMomentum(false),
483 mIsNoLineOrPageDelta(false),
484 mViewPortIsOverscrolled(false),
485 mCanTriggerSwipe(false),
486 mAllowToOverrideSystemScrollSpeed(true),
487 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
489 virtual WidgetEvent* Duplicate() const override {
490 MOZ_ASSERT(mClass == eWheelEventClass,
491 "Duplicate() must be overridden by sub class");
492 // Not copying widget, it is a weak reference.
493 WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
494 result->AssignWheelEventData(*this, true);
495 result->mFlags = mFlags;
496 return result;
499 // Scroll gestures that start at the edge of the scrollable range can result
500 // in a swipe gesture. For the first wheel event of such a gesture, call
501 // TriggersSwipe() after the event has been processed in order to find out
502 // whether a swipe should be started.
503 bool TriggersSwipe() const {
504 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
505 this->mOverflowDeltaX != 0.0;
508 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
509 // mousewheel.*.delta_multiplier_* prefs which are applied by
510 // EventStateManager. So, after widget dispatches this event,
511 // these delta values may have different values than before.
512 double mDeltaX;
513 double mDeltaY;
514 double mDeltaZ;
516 // The mousewheel tick counts.
517 double mWheelTicksX = 0.0;
518 double mWheelTicksY = 0.0;
520 enum class DeltaModeCheckingState : uint8_t {
521 // Neither deltaMode nor the delta values have been accessed.
522 Unknown,
523 // The delta values have been accessed, without checking deltaMode first.
524 Unchecked,
525 // The deltaMode has been checked.
526 Checked,
529 // For compat reasons, we might expose a DOM_DELTA_LINE event as
530 // DOM_DELTA_PIXEL instead. Whether we do that depends on whether the event
531 // has been asked for the deltaMode before the deltas. If it has, we assume
532 // that the page will correctly handle DOM_DELTA_LINE. This variable tracks
533 // that state. See bug 1392460.
534 DeltaModeCheckingState mDeltaModeCheckingState =
535 DeltaModeCheckingState::Unknown;
537 // The amount of scrolling per line or page, without accounting for mouse
538 // wheel transactions etc.
540 // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta.
541 nsSize mScrollAmount;
543 // overflowed delta values for scroll, these values are set by
544 // EventStateManger. If the default action of the wheel event isn't scroll,
545 // these values are always zero. Otherwise, remaining delta values which are
546 // not used by scroll are set.
547 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
548 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
549 // delta values which are not applied the delta_multiplier prefs.
550 // So, if widget wanted to know the actual direction to be scrolled,
551 // it would need to check the mDeltaX and mDeltaY.
552 double mOverflowDeltaX;
553 double mOverflowDeltaY;
555 // Should be one of WheelEvent_Binding::DOM_DELTA_*
556 uint32_t mDeltaMode;
558 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
559 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
560 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
561 int32_t mLineOrPageDeltaX;
562 int32_t mLineOrPageDeltaY;
564 // When the default action for an wheel event is moving history or zooming,
565 // need to chose a delta value for doing it.
566 int32_t GetPreferredIntDelta() {
567 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
568 return 0;
570 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
571 return mLineOrPageDeltaY;
573 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
574 return mLineOrPageDeltaX;
576 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
577 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
578 return 0; // We cannot guess the answer in this case.
580 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
581 ? mLineOrPageDeltaX
582 : mLineOrPageDeltaY;
585 // Scroll type
586 // The default value is SCROLL_DEFAULT, which means EventStateManager will
587 // select preferred scroll type automatically.
588 enum ScrollType : uint8_t {
589 SCROLL_DEFAULT,
590 SCROLL_SYNCHRONOUSLY,
591 SCROLL_ASYNCHRONOUSLY,
592 SCROLL_SMOOTHLY
594 ScrollType mScrollType;
596 // If the delta values are computed from prefs, this value is true.
597 // Otherwise, i.e., they are computed from native events, false.
598 bool mCustomizedByUserPrefs;
600 // true if the momentum events directly tied to this event may follow it.
601 bool mMayHaveMomentum;
602 // true if the event is caused by momentum.
603 bool mIsMomentum;
605 // If device event handlers don't know when they should set mLineOrPageDeltaX
606 // and mLineOrPageDeltaY, this is true. Otherwise, false.
607 // If mIsNoLineOrPageDelta is true, ESM will generate
608 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
609 // a line height.
610 bool mIsNoLineOrPageDelta;
612 // Whether or not the parent of the currently overscrolled frame is the
613 // ViewPort. This is false in situations when an element on the page is being
614 // overscrolled (such as a text field), but true when the 'page' is being
615 // overscrolled.
616 bool mViewPortIsOverscrolled;
618 // The wheel event can trigger a swipe to start if it's overscrolling the
619 // viewport.
620 bool mCanTriggerSwipe;
622 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
623 // overridden. Otherwise, the scroll speed won't be overridden even if
624 // it's enabled by the pref.
625 bool mAllowToOverrideSystemScrollSpeed;
627 // After the event's default action handler has adjusted its delta's values
628 // for horizontalizing a vertical wheel scroll, this variable will be set to
629 // true.
630 bool mDeltaValuesHorizontalizedForDefaultHandler;
632 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
633 AssignMouseEventBaseData(aEvent, aCopyTargets);
635 mDeltaX = aEvent.mDeltaX;
636 mDeltaY = aEvent.mDeltaY;
637 mDeltaZ = aEvent.mDeltaZ;
638 mDeltaMode = aEvent.mDeltaMode;
639 mScrollAmount = aEvent.mScrollAmount;
640 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
641 mMayHaveMomentum = aEvent.mMayHaveMomentum;
642 mIsMomentum = aEvent.mIsMomentum;
643 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
644 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
645 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
646 mScrollType = aEvent.mScrollType;
647 mOverflowDeltaX = aEvent.mOverflowDeltaX;
648 mOverflowDeltaY = aEvent.mOverflowDeltaY;
649 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
650 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
651 mAllowToOverrideSystemScrollSpeed =
652 aEvent.mAllowToOverrideSystemScrollSpeed;
653 mDeltaValuesHorizontalizedForDefaultHandler =
654 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
657 // System scroll speed settings may be too slow at using Gecko. In such
658 // case, we should override the scroll speed computed with system settings.
659 // Following methods return preferred delta values which are multiplied by
660 // factors specified by prefs. If system scroll speed shouldn't be
661 // overridden (e.g., this feature is disabled by pref), they return raw
662 // delta values.
663 double OverriddenDeltaX() const;
664 double OverriddenDeltaY() const;
666 // Compute the overridden delta value. This may be useful for suppressing
667 // too fast scroll by system scroll speed overriding when widget sets
668 // mAllowToOverrideSystemScrollSpeed.
669 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
671 private:
672 static bool sInitialized;
673 static bool sIsSystemScrollSpeedOverrideEnabled;
674 static int32_t sOverrideFactorX;
675 static int32_t sOverrideFactorY;
676 static void Initialize();
679 /******************************************************************************
680 * mozilla::WidgetPointerEvent
681 ******************************************************************************/
683 class WidgetPointerEvent : public WidgetMouseEvent {
684 friend class mozilla::dom::PBrowserParent;
685 friend class mozilla::dom::PBrowserChild;
687 public:
688 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
690 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
691 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal),
692 mWidth(1),
693 mHeight(1),
694 mIsPrimary(true),
695 mFromTouchEvent(false) {}
697 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
698 : WidgetMouseEvent(aEvent),
699 mWidth(1),
700 mHeight(1),
701 mIsPrimary(true),
702 mFromTouchEvent(false) {
703 mClass = ePointerEventClass;
706 virtual WidgetEvent* Duplicate() const override {
707 MOZ_ASSERT(mClass == ePointerEventClass,
708 "Duplicate() must be overridden by sub class");
709 // Not copying widget, it is a weak reference.
710 WidgetPointerEvent* result =
711 new WidgetPointerEvent(false, mMessage, nullptr);
712 result->AssignPointerEventData(*this, true);
713 result->mFlags = mFlags;
714 return result;
717 int32_t mWidth;
718 int32_t mHeight;
719 bool mIsPrimary;
720 bool mFromTouchEvent;
722 // XXX Not tested by test_assign_event_data.html
723 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
724 bool aCopyTargets) {
725 AssignMouseEventData(aEvent, aCopyTargets);
727 mWidth = aEvent.mWidth;
728 mHeight = aEvent.mHeight;
729 mIsPrimary = aEvent.mIsPrimary;
730 mFromTouchEvent = aEvent.mFromTouchEvent;
734 } // namespace mozilla
736 #endif // mozilla_MouseEvents_h__