Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / widget / MouseEvents.h
blob18b4394995f5c9d3ba6a3f45167573a00594c7d2
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 "mozilla/ipc/IPCForwards.h"
15 #include "nsCOMPtr.h"
17 namespace mozilla {
19 namespace dom {
20 class PBrowserParent;
21 class PBrowserChild;
22 class PBrowserBridgeParent;
23 } // namespace dom
25 class WidgetPointerEvent;
26 } // namespace mozilla
28 namespace mozilla {
29 class WidgetPointerEventHolder final {
30 public:
31 nsTArray<WidgetPointerEvent> mEvents;
32 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
34 private:
35 virtual ~WidgetPointerEventHolder() = default;
38 /******************************************************************************
39 * mozilla::WidgetPointerHelper
40 ******************************************************************************/
42 class WidgetPointerHelper {
43 public:
44 uint32_t pointerId;
45 int32_t tiltX;
46 int32_t tiltY;
47 int32_t twist;
48 float tangentialPressure;
49 bool convertToPointer;
50 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
52 WidgetPointerHelper()
53 : pointerId(0),
54 tiltX(0),
55 tiltY(0),
56 twist(0),
57 tangentialPressure(0),
58 convertToPointer(true) {}
60 WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
61 uint32_t aTwist = 0, float aTangentialPressure = 0)
62 : pointerId(aPointerId),
63 tiltX(aTiltX),
64 tiltY(aTiltY),
65 twist(aTwist),
66 tangentialPressure(aTangentialPressure),
67 convertToPointer(true) {}
69 explicit WidgetPointerHelper(const WidgetPointerHelper& aHelper) = default;
71 void AssignPointerHelperData(const WidgetPointerHelper& aEvent,
72 bool aCopyCoalescedEvents = false) {
73 pointerId = aEvent.pointerId;
74 tiltX = aEvent.tiltX;
75 tiltY = aEvent.tiltY;
76 twist = aEvent.twist;
77 tangentialPressure = aEvent.tangentialPressure;
78 convertToPointer = aEvent.convertToPointer;
79 if (aCopyCoalescedEvents) {
80 mCoalescedWidgetEvents = aEvent.mCoalescedWidgetEvents;
85 /******************************************************************************
86 * mozilla::WidgetMouseEventBase
87 ******************************************************************************/
89 class WidgetMouseEventBase : public WidgetInputEvent {
90 private:
91 friend class dom::PBrowserParent;
92 friend class dom::PBrowserChild;
93 friend class dom::PBrowserBridgeParent;
94 ALLOW_DEPRECATED_READPARAM
96 protected:
97 WidgetMouseEventBase()
98 : mPressure(0),
99 mButton(0),
100 mButtons(0),
101 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
102 // Including MouseEventBinding.h here leads to an include loop, so
103 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
105 WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
106 nsIWidget* aWidget, EventClassID aEventClassID,
107 const WidgetEventTime* aTime = nullptr)
108 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID, aTime),
109 mPressure(0),
110 mButton(0),
111 mButtons(0),
112 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
113 // Including MouseEventBinding.h here leads to an include loop, so
114 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
116 public:
117 virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
119 virtual WidgetEvent* Duplicate() const override {
120 MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
123 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
124 float mPressure;
126 // Pressed button ID of mousedown or mouseup event.
127 // This is set only when pressing a button causes the event.
128 int16_t mButton;
130 // Flags of all pressed buttons at the event fired.
131 // This is set at any mouse event, don't be confused with |mButton|.
132 int16_t mButtons;
134 // Possible values a in MouseEvent
135 uint16_t mInputSource;
137 bool IsLeftButtonPressed() const {
138 return !!(mButtons & MouseButtonsFlag::ePrimaryFlag);
140 bool IsRightButtonPressed() const {
141 return !!(mButtons & MouseButtonsFlag::eSecondaryFlag);
143 bool IsMiddleButtonPressed() const {
144 return !!(mButtons & MouseButtonsFlag::eMiddleFlag);
146 bool Is4thButtonPressed() const {
147 return !!(mButtons & MouseButtonsFlag::e4thFlag);
149 bool Is5thButtonPressed() const {
150 return !!(mButtons & MouseButtonsFlag::e5thFlag);
153 void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
154 bool aCopyTargets) {
155 AssignInputEventData(aEvent, aCopyTargets);
157 mButton = aEvent.mButton;
158 mButtons = aEvent.mButtons;
159 mPressure = aEvent.mPressure;
160 mInputSource = aEvent.mInputSource;
164 * Returns true if left click event.
166 bool IsLeftClickEvent() const {
167 return mMessage == eMouseClick && mButton == MouseButton::ePrimary;
171 /******************************************************************************
172 * mozilla::WidgetMouseEvent
173 ******************************************************************************/
175 class WidgetMouseEvent : public WidgetMouseEventBase,
176 public WidgetPointerHelper {
177 private:
178 friend class dom::PBrowserParent;
179 friend class dom::PBrowserChild;
180 friend class dom::PBrowserBridgeParent;
181 ALLOW_DEPRECATED_READPARAM
183 public:
184 typedef bool ReasonType;
185 enum Reason : ReasonType { eReal, eSynthesized };
187 typedef uint8_t ContextMenuTriggerType;
188 enum ContextMenuTrigger : ContextMenuTriggerType {
189 eNormal,
190 eContextMenuKey,
191 eControlClick
194 typedef uint8_t ExitFromType;
195 enum ExitFrom : ExitFromType {
196 ePlatformChild,
197 ePlatformTopLevel,
198 ePuppet,
199 ePuppetParentToPuppetChild
202 protected:
203 WidgetMouseEvent()
204 : mReason(eReal),
205 mContextMenuTrigger(eNormal),
206 mClickCount(0),
207 mIgnoreRootScrollFrame(false),
208 mUseLegacyNonPrimaryDispatch(false),
209 mClickEventPrevented(false) {}
211 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
212 EventClassID aEventClassID, Reason aReason,
213 const WidgetEventTime* aTime = nullptr)
214 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID,
215 aTime),
216 mReason(aReason),
217 mContextMenuTrigger(eNormal),
218 mClickCount(0),
219 mIgnoreRootScrollFrame(false),
220 mUseLegacyNonPrimaryDispatch(false),
221 mClickEventPrevented(false) {}
223 #ifdef DEBUG
224 void AssertContextMenuEventButtonConsistency() const;
225 #endif
227 public:
228 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
230 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
231 Reason aReason,
232 ContextMenuTrigger aContextMenuTrigger = eNormal,
233 const WidgetEventTime* aTime = nullptr)
234 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass,
235 aTime),
236 mReason(aReason),
237 mContextMenuTrigger(aContextMenuTrigger),
238 mClickCount(0),
239 mIgnoreRootScrollFrame(false),
240 mUseLegacyNonPrimaryDispatch(false),
241 mClickEventPrevented(false) {
242 if (aMessage == eContextMenu) {
243 mButton = (mContextMenuTrigger == eNormal) ? MouseButton::eSecondary
244 : MouseButton::ePrimary;
248 #ifdef DEBUG
249 virtual ~WidgetMouseEvent() { AssertContextMenuEventButtonConsistency(); }
250 #endif
252 virtual WidgetEvent* Duplicate() const override {
253 MOZ_ASSERT(mClass == eMouseEventClass,
254 "Duplicate() must be overridden by sub class");
255 // Not copying widget, it is a weak reference.
256 WidgetMouseEvent* result = new WidgetMouseEvent(
257 false, mMessage, nullptr, mReason, mContextMenuTrigger, this);
258 result->AssignMouseEventData(*this, true);
259 result->mFlags = mFlags;
260 return result;
263 // If during mouseup handling we detect that click event might need to be
264 // dispatched, this is setup to be the target of the click event.
265 nsCOMPtr<dom::EventTarget> mClickTarget;
267 // mReason indicates the reason why the event is fired:
268 // - Representing mouse operation.
269 // - Synthesized for emulating mousemove event when the content under the
270 // mouse cursor is scrolled.
271 Reason mReason;
273 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
274 // This indicates if the context menu event is caused by context menu key or
275 // other reasons (typically, a click of right mouse button).
276 ContextMenuTrigger mContextMenuTrigger;
278 // mExitFrom contains a value only when mMessage is eMouseExitFromWidget.
279 // This indicates if the mouse cursor exits from a top level platform widget,
280 // a child widget or a puppet widget.
281 Maybe<ExitFrom> mExitFrom;
283 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
284 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
285 // Otherwise, this must be 0.
286 uint32_t mClickCount;
288 // Whether the event should ignore scroll frame bounds during dispatch.
289 bool mIgnoreRootScrollFrame;
291 // Indicates whether the event should dispatch click events for non-primary
292 // mouse buttons on window and document.
293 bool mUseLegacyNonPrimaryDispatch;
295 // Whether the event shouldn't cause click event.
296 bool mClickEventPrevented;
298 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) {
299 AssignMouseEventBaseData(aEvent, aCopyTargets);
300 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
302 mExitFrom = aEvent.mExitFrom;
303 mClickCount = aEvent.mClickCount;
304 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
305 mUseLegacyNonPrimaryDispatch = aEvent.mUseLegacyNonPrimaryDispatch;
306 mClickEventPrevented = aEvent.mClickEventPrevented;
310 * Returns true if the event is a context menu event caused by key.
312 bool IsContextMenuKeyEvent() const {
313 return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
317 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
318 * a synthesized event by scroll or something, returns false.
320 bool IsReal() const { return mReason == eReal; }
323 * Returns true if middle click paste is enabled.
325 static bool IsMiddleClickPasteEnabled();
328 /******************************************************************************
329 * mozilla::WidgetDragEvent
330 ******************************************************************************/
332 class WidgetDragEvent : public WidgetMouseEvent {
333 private:
334 friend class mozilla::dom::PBrowserParent;
335 friend class mozilla::dom::PBrowserChild;
336 ALLOW_DEPRECATED_READPARAM
338 protected:
339 WidgetDragEvent()
340 : mUserCancelled(false), mDefaultPreventedOnContent(false) {}
342 public:
343 virtual WidgetDragEvent* AsDragEvent() override { return this; }
345 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
346 const WidgetEventTime* aTime = nullptr)
347 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal,
348 aTime),
349 mUserCancelled(false),
350 mDefaultPreventedOnContent(false) {}
352 virtual WidgetEvent* Duplicate() const override {
353 MOZ_ASSERT(mClass == eDragEventClass,
354 "Duplicate() must be overridden by sub class");
355 // Not copying widget, it is a weak reference.
356 WidgetDragEvent* result =
357 new WidgetDragEvent(false, mMessage, nullptr, this);
358 result->AssignDragEventData(*this, true);
359 result->mFlags = mFlags;
360 return result;
363 // The dragging data.
364 nsCOMPtr<dom::DataTransfer> mDataTransfer;
366 // If this is true, user has cancelled the drag operation.
367 bool mUserCancelled;
368 // If this is true, the drag event's preventDefault() is called on content.
369 bool mDefaultPreventedOnContent;
371 // XXX Not tested by test_assign_event_data.html
372 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) {
373 AssignMouseEventData(aEvent, aCopyTargets);
375 mDataTransfer = aEvent.mDataTransfer;
376 // XXX mUserCancelled isn't copied, is this intentionally?
377 mUserCancelled = false;
378 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
381 void UpdateDefaultPreventedOnContent(dom::EventTarget* aTarget);
384 * Should be called before dispatching the DOM tree if this event is
385 * synthesized for tests because drop effect is initialized before
386 * dispatching from widget if it's not synthesized event, but synthesized
387 * events are not initialized in the path.
389 void InitDropEffectForTests();
392 /******************************************************************************
393 * mozilla::WidgetMouseScrollEvent
395 * This is used for legacy DOM mouse scroll events, i.e.,
396 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
397 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
398 ******************************************************************************/
400 class WidgetMouseScrollEvent : public WidgetMouseEventBase {
401 private:
402 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
404 public:
405 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override { return this; }
407 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
408 nsIWidget* aWidget,
409 const WidgetEventTime* aTime = nullptr)
410 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
411 eMouseScrollEventClass, aTime),
412 mDelta(0),
413 mIsHorizontal(false) {}
415 virtual WidgetEvent* Duplicate() const override {
416 MOZ_ASSERT(mClass == eMouseScrollEventClass,
417 "Duplicate() must be overridden by sub class");
418 // Not copying widget, it is a weak reference.
419 WidgetMouseScrollEvent* result =
420 new WidgetMouseScrollEvent(false, mMessage, nullptr, this);
421 result->AssignMouseScrollEventData(*this, true);
422 result->mFlags = mFlags;
423 return result;
426 // The delta value of mouse scroll event.
427 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
428 // scroll amount in lines. However, if the value is
429 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
430 // value inducates one page scroll. If the event message is
431 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
432 int32_t mDelta;
434 // If this is true, it may cause to scroll horizontally.
435 // Otherwise, vertically.
436 bool mIsHorizontal;
438 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
439 bool aCopyTargets) {
440 AssignMouseEventBaseData(aEvent, aCopyTargets);
442 mDelta = aEvent.mDelta;
443 mIsHorizontal = aEvent.mIsHorizontal;
447 /******************************************************************************
448 * mozilla::WidgetWheelEvent
449 ******************************************************************************/
451 class WidgetWheelEvent : public WidgetMouseEventBase {
452 private:
453 friend class mozilla::dom::PBrowserParent;
454 friend class mozilla::dom::PBrowserChild;
455 ALLOW_DEPRECATED_READPARAM
457 WidgetWheelEvent()
458 : mDeltaX(0.0),
459 mDeltaY(0.0),
460 mDeltaZ(0.0),
461 mOverflowDeltaX(0.0),
462 mOverflowDeltaY(0.0)
463 // Including WheelEventBinding.h here leads to an include loop, so
464 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
466 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
467 mLineOrPageDeltaX(0),
468 mLineOrPageDeltaY(0),
469 mScrollType(SCROLL_DEFAULT),
470 mCustomizedByUserPrefs(false),
471 mMayHaveMomentum(false),
472 mIsMomentum(false),
473 mIsNoLineOrPageDelta(false),
474 mViewPortIsOverscrolled(false),
475 mCanTriggerSwipe(false),
476 mAllowToOverrideSystemScrollSpeed(false),
477 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
479 public:
480 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
482 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
483 const WidgetEventTime* aTime = nullptr)
484 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass,
485 aTime),
486 mDeltaX(0.0),
487 mDeltaY(0.0),
488 mDeltaZ(0.0),
489 mOverflowDeltaX(0.0),
490 mOverflowDeltaY(0.0)
491 // Including WheelEventBinding.h here leads to an include loop, so
492 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
494 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
495 mLineOrPageDeltaX(0),
496 mLineOrPageDeltaY(0),
497 mScrollType(SCROLL_DEFAULT),
498 mCustomizedByUserPrefs(false),
499 mMayHaveMomentum(false),
500 mIsMomentum(false),
501 mIsNoLineOrPageDelta(false),
502 mViewPortIsOverscrolled(false),
503 mCanTriggerSwipe(false),
504 mAllowToOverrideSystemScrollSpeed(true),
505 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
507 virtual WidgetEvent* Duplicate() const override {
508 MOZ_ASSERT(mClass == eWheelEventClass,
509 "Duplicate() must be overridden by sub class");
510 // Not copying widget, it is a weak reference.
511 WidgetWheelEvent* result =
512 new WidgetWheelEvent(false, mMessage, nullptr, this);
513 result->AssignWheelEventData(*this, true);
514 result->mFlags = mFlags;
515 return result;
518 // Scroll gestures that start at the edge of the scrollable range can result
519 // in a swipe gesture. For the first wheel event of such a gesture, call
520 // TriggersSwipe() after the event has been processed in order to find out
521 // whether a swipe should be started.
522 bool TriggersSwipe() const {
523 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
524 this->mOverflowDeltaX != 0.0;
527 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
528 // mousewheel.*.delta_multiplier_* prefs which are applied by
529 // EventStateManager. So, after widget dispatches this event,
530 // these delta values may have different values than before.
531 double mDeltaX;
532 double mDeltaY;
533 double mDeltaZ;
535 // The mousewheel tick counts.
536 double mWheelTicksX = 0.0;
537 double mWheelTicksY = 0.0;
539 enum class DeltaModeCheckingState : uint8_t {
540 // Neither deltaMode nor the delta values have been accessed.
541 Unknown,
542 // The delta values have been accessed, without checking deltaMode first.
543 Unchecked,
544 // The deltaMode has been checked.
545 Checked,
548 // For compat reasons, we might expose a DOM_DELTA_LINE event as
549 // DOM_DELTA_PIXEL instead. Whether we do that depends on whether the event
550 // has been asked for the deltaMode before the deltas. If it has, we assume
551 // that the page will correctly handle DOM_DELTA_LINE. This variable tracks
552 // that state. See bug 1392460.
553 DeltaModeCheckingState mDeltaModeCheckingState =
554 DeltaModeCheckingState::Unknown;
556 // The amount of scrolling per line or page, without accounting for mouse
557 // wheel transactions etc.
559 // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta.
560 nsSize mScrollAmount;
562 // overflowed delta values for scroll, these values are set by
563 // EventStateManger. If the default action of the wheel event isn't scroll,
564 // these values are always zero. Otherwise, remaining delta values which are
565 // not used by scroll are set.
566 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
567 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
568 // delta values which are not applied the delta_multiplier prefs.
569 // So, if widget wanted to know the actual direction to be scrolled,
570 // it would need to check the mDeltaX and mDeltaY.
571 double mOverflowDeltaX;
572 double mOverflowDeltaY;
574 // Should be one of WheelEvent_Binding::DOM_DELTA_*
575 uint32_t mDeltaMode;
577 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
578 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
579 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
580 int32_t mLineOrPageDeltaX;
581 int32_t mLineOrPageDeltaY;
583 // When the default action for an wheel event is moving history or zooming,
584 // need to chose a delta value for doing it.
585 int32_t GetPreferredIntDelta() {
586 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
587 return 0;
589 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
590 return mLineOrPageDeltaY;
592 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
593 return mLineOrPageDeltaX;
595 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
596 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
597 return 0; // We cannot guess the answer in this case.
599 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
600 ? mLineOrPageDeltaX
601 : mLineOrPageDeltaY;
604 // Scroll type
605 // The default value is SCROLL_DEFAULT, which means EventStateManager will
606 // select preferred scroll type automatically.
607 enum ScrollType : uint8_t {
608 SCROLL_DEFAULT,
609 SCROLL_SYNCHRONOUSLY,
610 SCROLL_ASYNCHRONOUSLY,
611 SCROLL_SMOOTHLY
613 ScrollType mScrollType;
615 // If the delta values are computed from prefs, this value is true.
616 // Otherwise, i.e., they are computed from native events, false.
617 bool mCustomizedByUserPrefs;
619 // true if the momentum events directly tied to this event may follow it.
620 bool mMayHaveMomentum;
621 // true if the event is caused by momentum.
622 bool mIsMomentum;
624 // If device event handlers don't know when they should set mLineOrPageDeltaX
625 // and mLineOrPageDeltaY, this is true. Otherwise, false.
626 // If mIsNoLineOrPageDelta is true, ESM will generate
627 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
628 // a line height.
629 bool mIsNoLineOrPageDelta;
631 // Whether or not the parent of the currently overscrolled frame is the
632 // ViewPort. This is false in situations when an element on the page is being
633 // overscrolled (such as a text field), but true when the 'page' is being
634 // overscrolled.
635 bool mViewPortIsOverscrolled;
637 // The wheel event can trigger a swipe to start if it's overscrolling the
638 // viewport.
639 bool mCanTriggerSwipe;
641 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
642 // overridden. Otherwise, the scroll speed won't be overridden even if
643 // it's enabled by the pref.
644 bool mAllowToOverrideSystemScrollSpeed;
646 // After the event's default action handler has adjusted its delta's values
647 // for horizontalizing a vertical wheel scroll, this variable will be set to
648 // true.
649 bool mDeltaValuesHorizontalizedForDefaultHandler;
651 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
652 AssignMouseEventBaseData(aEvent, aCopyTargets);
654 mDeltaX = aEvent.mDeltaX;
655 mDeltaY = aEvent.mDeltaY;
656 mDeltaZ = aEvent.mDeltaZ;
657 mDeltaMode = aEvent.mDeltaMode;
658 mScrollAmount = aEvent.mScrollAmount;
659 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
660 mMayHaveMomentum = aEvent.mMayHaveMomentum;
661 mIsMomentum = aEvent.mIsMomentum;
662 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
663 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
664 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
665 mScrollType = aEvent.mScrollType;
666 mOverflowDeltaX = aEvent.mOverflowDeltaX;
667 mOverflowDeltaY = aEvent.mOverflowDeltaY;
668 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
669 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
670 mAllowToOverrideSystemScrollSpeed =
671 aEvent.mAllowToOverrideSystemScrollSpeed;
672 mDeltaValuesHorizontalizedForDefaultHandler =
673 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
676 // System scroll speed settings may be too slow at using Gecko. In such
677 // case, we should override the scroll speed computed with system settings.
678 // Following methods return preferred delta values which are multiplied by
679 // factors specified by prefs. If system scroll speed shouldn't be
680 // overridden (e.g., this feature is disabled by pref), they return raw
681 // delta values.
682 double OverriddenDeltaX() const;
683 double OverriddenDeltaY() const;
685 // Compute the overridden delta value. This may be useful for suppressing
686 // too fast scroll by system scroll speed overriding when widget sets
687 // mAllowToOverrideSystemScrollSpeed.
688 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
690 private:
691 static bool sInitialized;
692 static bool sIsSystemScrollSpeedOverrideEnabled;
693 static int32_t sOverrideFactorX;
694 static int32_t sOverrideFactorY;
695 static void Initialize();
698 /******************************************************************************
699 * mozilla::WidgetPointerEvent
700 ******************************************************************************/
702 class WidgetPointerEvent : public WidgetMouseEvent {
703 friend class mozilla::dom::PBrowserParent;
704 friend class mozilla::dom::PBrowserChild;
705 ALLOW_DEPRECATED_READPARAM
707 public:
708 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
710 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w,
711 const WidgetEventTime* aTime = nullptr)
712 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal, aTime),
713 mWidth(1),
714 mHeight(1),
715 mIsPrimary(true),
716 mFromTouchEvent(false) {}
718 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
719 : WidgetMouseEvent(aEvent),
720 mWidth(1),
721 mHeight(1),
722 mIsPrimary(true),
723 mFromTouchEvent(false) {
724 mClass = ePointerEventClass;
727 virtual WidgetEvent* Duplicate() const override {
728 MOZ_ASSERT(mClass == ePointerEventClass,
729 "Duplicate() must be overridden by sub class");
730 // Not copying widget, it is a weak reference.
731 WidgetPointerEvent* result =
732 new WidgetPointerEvent(false, mMessage, nullptr, this);
733 result->AssignPointerEventData(*this, true);
734 result->mFlags = mFlags;
735 return result;
738 int32_t mWidth;
739 int32_t mHeight;
740 bool mIsPrimary;
741 bool mFromTouchEvent;
743 // XXX Not tested by test_assign_event_data.html
744 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
745 bool aCopyTargets) {
746 AssignMouseEventData(aEvent, aCopyTargets);
748 mWidth = aEvent.mWidth;
749 mHeight = aEvent.mHeight;
750 mIsPrimary = aEvent.mIsPrimary;
751 mFromTouchEvent = aEvent.mFromTouchEvent;
755 } // namespace mozilla
757 #endif // mozilla_MouseEvents_h__