Bug 1610630 [wpt PR 21320] - Add meta:timeout=long to FileSystemBaseHandle-postMessag...
[gecko.git] / widget / MouseEvents.h
blob67f3170792878c6574500293b7f39bf3565c8ba6
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 class WidgetPointerEventHolder final {
26 public:
27 nsTArray<WidgetPointerEvent> mEvents;
28 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
30 private:
31 virtual ~WidgetPointerEventHolder() {}
34 /******************************************************************************
35 * mozilla::WidgetPointerHelper
36 ******************************************************************************/
38 class WidgetPointerHelper {
39 public:
40 uint32_t pointerId;
41 uint32_t tiltX;
42 uint32_t tiltY;
43 uint32_t twist;
44 float tangentialPressure;
45 bool convertToPointer;
46 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
48 WidgetPointerHelper()
49 : pointerId(0),
50 tiltX(0),
51 tiltY(0),
52 twist(0),
53 tangentialPressure(0),
54 convertToPointer(true) {}
56 WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
57 uint32_t aTwist = 0, float aTangentialPressure = 0)
58 : pointerId(aPointerId),
59 tiltX(aTiltX),
60 tiltY(aTiltY),
61 twist(aTwist),
62 tangentialPressure(aTangentialPressure),
63 convertToPointer(true) {}
65 explicit WidgetPointerHelper(const WidgetPointerHelper& aHelper)
66 : pointerId(aHelper.pointerId),
67 tiltX(aHelper.tiltX),
68 tiltY(aHelper.tiltY),
69 twist(aHelper.twist),
70 tangentialPressure(aHelper.tangentialPressure),
71 convertToPointer(aHelper.convertToPointer),
72 mCoalescedWidgetEvents(aHelper.mCoalescedWidgetEvents) {}
74 void AssignPointerHelperData(const WidgetPointerHelper& aEvent,
75 bool aCopyCoalescedEvents = false) {
76 pointerId = aEvent.pointerId;
77 tiltX = aEvent.tiltX;
78 tiltY = aEvent.tiltY;
79 twist = aEvent.twist;
80 tangentialPressure = aEvent.tangentialPressure;
81 convertToPointer = aEvent.convertToPointer;
82 if (aCopyCoalescedEvents) {
83 mCoalescedWidgetEvents = aEvent.mCoalescedWidgetEvents;
88 /******************************************************************************
89 * mozilla::WidgetMouseEventBase
90 ******************************************************************************/
92 class WidgetMouseEventBase : public WidgetInputEvent {
93 private:
94 friend class dom::PBrowserParent;
95 friend class dom::PBrowserChild;
96 friend class dom::PBrowserBridgeParent;
98 protected:
99 WidgetMouseEventBase()
100 : mPressure(0),
101 mButton(0),
102 mButtons(0),
103 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1),
104 mHitCluster(false) {}
105 // Including MouseEventBinding.h here leads to an include loop, so
106 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
108 WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
109 nsIWidget* aWidget, EventClassID aEventClassID)
110 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID),
111 mPressure(0),
112 mButton(0),
113 mButtons(0),
114 mInputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1),
115 mHitCluster(false) {}
116 // Including MouseEventBinding.h here leads to an include loop, so
117 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
119 public:
120 virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
122 virtual WidgetEvent* Duplicate() const override {
123 MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
126 // ID of the canvas HitRegion
127 nsString mRegion;
129 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
130 float mPressure;
132 // Pressed button ID of mousedown or mouseup event.
133 // This is set only when pressing a button causes the event.
134 int16_t mButton;
136 // Flags of all pressed buttons at the event fired.
137 // This is set at any mouse event, don't be confused with |mButton|.
138 int16_t mButtons;
140 // Possible values a in MouseEvent
141 uint16_t mInputSource;
143 // Touch near a cluster of links (true)
144 bool mHitCluster;
146 bool IsLeftButtonPressed() const {
147 return !!(mButtons & MouseButtonsFlag::eLeftFlag);
149 bool IsRightButtonPressed() const {
150 return !!(mButtons & MouseButtonsFlag::eRightFlag);
152 bool IsMiddleButtonPressed() const {
153 return !!(mButtons & MouseButtonsFlag::eMiddleFlag);
155 bool Is4thButtonPressed() const {
156 return !!(mButtons & MouseButtonsFlag::e4thFlag);
158 bool Is5thButtonPressed() const {
159 return !!(mButtons & MouseButtonsFlag::e5thFlag);
162 void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
163 bool aCopyTargets) {
164 AssignInputEventData(aEvent, aCopyTargets);
166 mButton = aEvent.mButton;
167 mButtons = aEvent.mButtons;
168 mPressure = aEvent.mPressure;
169 mHitCluster = aEvent.mHitCluster;
170 mInputSource = aEvent.mInputSource;
174 * Returns true if left click event.
176 bool IsLeftClickEvent() const {
177 return mMessage == eMouseClick && mButton == MouseButton::eLeft;
181 /******************************************************************************
182 * mozilla::WidgetMouseEvent
183 ******************************************************************************/
185 class WidgetMouseEvent : public WidgetMouseEventBase,
186 public WidgetPointerHelper {
187 private:
188 friend class dom::PBrowserParent;
189 friend class dom::PBrowserChild;
190 friend class dom::PBrowserBridgeParent;
192 public:
193 typedef bool ReasonType;
194 enum Reason : ReasonType { eReal, eSynthesized };
196 typedef bool ContextMenuTriggerType;
197 enum ContextMenuTrigger : ContextMenuTriggerType { eNormal, eContextMenuKey };
199 typedef bool ExitFromType;
200 enum ExitFrom : ExitFromType { eChild, eTopLevel };
202 protected:
203 WidgetMouseEvent()
204 : mReason(eReal),
205 mContextMenuTrigger(eNormal),
206 mExitFrom(eChild),
207 mIgnoreRootScrollFrame(false),
208 mClickCount(0),
209 mUseLegacyNonPrimaryDispatch(false) {}
211 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
212 EventClassID aEventClassID, Reason aReason)
213 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID),
214 mReason(aReason),
215 mContextMenuTrigger(eNormal),
216 mExitFrom(eChild),
217 mIgnoreRootScrollFrame(false),
218 mClickCount(0),
219 mUseLegacyNonPrimaryDispatch(false) {}
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 mExitFrom(eChild),
231 mIgnoreRootScrollFrame(false),
232 mClickCount(0),
233 mUseLegacyNonPrimaryDispatch(false) {
234 if (aMessage == eContextMenu) {
235 mButton = (mContextMenuTrigger == eNormal) ? MouseButton::eRight
236 : MouseButton::eLeft;
240 #ifdef DEBUG
241 virtual ~WidgetMouseEvent() {
242 NS_WARNING_ASSERTION(
243 mMessage != eContextMenu ||
244 mButton == ((mContextMenuTrigger == eNormal) ? MouseButton::eRight
245 : MouseButton::eLeft),
246 "Wrong button set to eContextMenu event?");
248 #endif
250 virtual WidgetEvent* Duplicate() const override {
251 MOZ_ASSERT(mClass == eMouseEventClass,
252 "Duplicate() must be overridden by sub class");
253 // Not copying widget, it is a weak reference.
254 WidgetMouseEvent* result = new WidgetMouseEvent(
255 false, mMessage, nullptr, mReason, mContextMenuTrigger);
256 result->AssignMouseEventData(*this, true);
257 result->mFlags = mFlags;
258 return result;
261 // If during mouseup handling we detect that click event might need to be
262 // dispatched, this is setup to be the target of the click event.
263 nsCOMPtr<dom::EventTarget> mClickTarget;
265 // mReason indicates the reason why the event is fired:
266 // - Representing mouse operation.
267 // - Synthesized for emulating mousemove event when the content under the
268 // mouse cursor is scrolled.
269 Reason mReason;
271 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
272 // This indicates if the context menu event is caused by context menu key or
273 // other reasons (typically, a click of right mouse button).
274 ContextMenuTrigger mContextMenuTrigger;
276 // mExitFrom is valid only when mMessage is eMouseExitFromWidget.
277 // This indicates if the mouse cursor exits from a top level widget or
278 // a child widget.
279 ExitFrom mExitFrom;
281 // Whether the event should ignore scroll frame bounds during dispatch.
282 bool mIgnoreRootScrollFrame;
284 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
285 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
286 // Otherwise, this must be 0.
287 uint32_t mClickCount;
289 // Indicates whether the event should dispatch click events for non-primary
290 // mouse buttons on window and document.
291 bool mUseLegacyNonPrimaryDispatch;
293 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) {
294 AssignMouseEventBaseData(aEvent, aCopyTargets);
295 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
297 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
298 mClickCount = aEvent.mClickCount;
299 mUseLegacyNonPrimaryDispatch = aEvent.mUseLegacyNonPrimaryDispatch;
303 * Returns true if the event is a context menu event caused by key.
305 bool IsContextMenuKeyEvent() const {
306 return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
310 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
311 * a synthesized event by scroll or something, returns false.
313 bool IsReal() const { return mReason == eReal; }
316 * Returns true if middle click paste is enabled.
318 static bool IsMiddleClickPasteEnabled();
321 /******************************************************************************
322 * mozilla::WidgetDragEvent
323 ******************************************************************************/
325 class WidgetDragEvent : public WidgetMouseEvent {
326 private:
327 friend class mozilla::dom::PBrowserParent;
328 friend class mozilla::dom::PBrowserChild;
330 protected:
331 WidgetDragEvent()
332 : mUserCancelled(false), mDefaultPreventedOnContent(false) {}
334 public:
335 virtual WidgetDragEvent* AsDragEvent() override { return this; }
337 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
338 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal),
339 mUserCancelled(false),
340 mDefaultPreventedOnContent(false) {}
342 virtual WidgetEvent* Duplicate() const override {
343 MOZ_ASSERT(mClass == eDragEventClass,
344 "Duplicate() must be overridden by sub class");
345 // Not copying widget, it is a weak reference.
346 WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
347 result->AssignDragEventData(*this, true);
348 result->mFlags = mFlags;
349 return result;
352 // The dragging data.
353 nsCOMPtr<dom::DataTransfer> mDataTransfer;
355 // If this is true, user has cancelled the drag operation.
356 bool mUserCancelled;
357 // If this is true, the drag event's preventDefault() is called on content.
358 bool mDefaultPreventedOnContent;
360 // XXX Not tested by test_assign_event_data.html
361 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) {
362 AssignMouseEventData(aEvent, aCopyTargets);
364 mDataTransfer = aEvent.mDataTransfer;
365 // XXX mUserCancelled isn't copied, is this intentionally?
366 mUserCancelled = false;
367 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
371 * Should be called before dispatching the DOM tree if this event is
372 * synthesized for tests because drop effect is initialized before
373 * dispatching from widget if it's not synthesized event, but synthesized
374 * events are not initialized in the path.
376 void InitDropEffectForTests();
379 /******************************************************************************
380 * mozilla::WidgetMouseScrollEvent
382 * This is used for legacy DOM mouse scroll events, i.e.,
383 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
384 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
385 ******************************************************************************/
387 class WidgetMouseScrollEvent : public WidgetMouseEventBase {
388 private:
389 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
391 public:
392 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override { return this; }
394 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
395 nsIWidget* aWidget)
396 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
397 eMouseScrollEventClass),
398 mDelta(0),
399 mIsHorizontal(false) {}
401 virtual WidgetEvent* Duplicate() const override {
402 MOZ_ASSERT(mClass == eMouseScrollEventClass,
403 "Duplicate() must be overridden by sub class");
404 // Not copying widget, it is a weak reference.
405 WidgetMouseScrollEvent* result =
406 new WidgetMouseScrollEvent(false, mMessage, nullptr);
407 result->AssignMouseScrollEventData(*this, true);
408 result->mFlags = mFlags;
409 return result;
412 // The delta value of mouse scroll event.
413 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
414 // scroll amount in lines. However, if the value is
415 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
416 // value inducates one page scroll. If the event message is
417 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
418 int32_t mDelta;
420 // If this is true, it may cause to scroll horizontally.
421 // Otherwise, vertically.
422 bool mIsHorizontal;
424 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
425 bool aCopyTargets) {
426 AssignMouseEventBaseData(aEvent, aCopyTargets);
428 mDelta = aEvent.mDelta;
429 mIsHorizontal = aEvent.mIsHorizontal;
433 /******************************************************************************
434 * mozilla::WidgetWheelEvent
435 ******************************************************************************/
437 class WidgetWheelEvent : public WidgetMouseEventBase {
438 private:
439 friend class mozilla::dom::PBrowserParent;
440 friend class mozilla::dom::PBrowserChild;
442 WidgetWheelEvent()
443 : mDeltaX(0.0),
444 mDeltaY(0.0),
445 mDeltaZ(0.0),
446 mOverflowDeltaX(0.0),
447 mOverflowDeltaY(0.0)
448 // Including WheelEventBinding.h here leads to an include loop, so
449 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
451 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
452 mLineOrPageDeltaX(0),
453 mLineOrPageDeltaY(0),
454 mScrollType(SCROLL_DEFAULT),
455 mCustomizedByUserPrefs(false),
456 mMayHaveMomentum(false),
457 mIsMomentum(false),
458 mIsNoLineOrPageDelta(false),
459 mViewPortIsOverscrolled(false),
460 mCanTriggerSwipe(false),
461 mAllowToOverrideSystemScrollSpeed(false),
462 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
464 public:
465 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
467 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
468 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass),
469 mDeltaX(0.0),
470 mDeltaY(0.0),
471 mDeltaZ(0.0),
472 mOverflowDeltaX(0.0),
473 mOverflowDeltaY(0.0)
474 // Including WheelEventBinding.h here leads to an include loop, so
475 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
477 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
478 mLineOrPageDeltaX(0),
479 mLineOrPageDeltaY(0),
480 mScrollType(SCROLL_DEFAULT),
481 mCustomizedByUserPrefs(false),
482 mMayHaveMomentum(false),
483 mIsMomentum(false),
484 mIsNoLineOrPageDelta(false),
485 mViewPortIsOverscrolled(false),
486 mCanTriggerSwipe(false),
487 mAllowToOverrideSystemScrollSpeed(true),
488 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
490 virtual WidgetEvent* Duplicate() const override {
491 MOZ_ASSERT(mClass == eWheelEventClass,
492 "Duplicate() must be overridden by sub class");
493 // Not copying widget, it is a weak reference.
494 WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
495 result->AssignWheelEventData(*this, true);
496 result->mFlags = mFlags;
497 return result;
500 // On OS X, scroll gestures that start at the edge of the scrollable range
501 // can result in a swipe gesture. For the first wheel event of such a
502 // gesture, call TriggersSwipe() after the event has been processed
503 // in order to find out whether a swipe should be started.
504 bool TriggersSwipe() const {
505 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
506 this->mOverflowDeltaX != 0.0;
509 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
510 // mousewheel.*.delta_multiplier_* prefs which are applied by
511 // EventStateManager. So, after widget dispatches this event,
512 // these delta values may have different values than before.
513 double mDeltaX;
514 double mDeltaY;
515 double mDeltaZ;
517 // overflowed delta values for scroll, these values are set by
518 // EventStateManger. If the default action of the wheel event isn't scroll,
519 // these values are always zero. Otherwise, remaining delta values which are
520 // not used by scroll are set.
521 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
522 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
523 // delta values which are not applied the delta_multiplier prefs.
524 // So, if widget wanted to know the actual direction to be scrolled,
525 // it would need to check the mDeltaX and mDeltaY.
526 double mOverflowDeltaX;
527 double mOverflowDeltaY;
529 // Should be one of WheelEvent_Binding::DOM_DELTA_*
530 uint32_t mDeltaMode;
532 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
533 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
534 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
535 int32_t mLineOrPageDeltaX;
536 int32_t mLineOrPageDeltaY;
538 // When the default action for an wheel event is moving history or zooming,
539 // need to chose a delta value for doing it.
540 int32_t GetPreferredIntDelta() {
541 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
542 return 0;
544 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
545 return mLineOrPageDeltaY;
547 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
548 return mLineOrPageDeltaX;
550 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
551 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
552 return 0; // We cannot guess the answer in this case.
554 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
555 ? mLineOrPageDeltaX
556 : mLineOrPageDeltaY;
559 // Scroll type
560 // The default value is SCROLL_DEFAULT, which means EventStateManager will
561 // select preferred scroll type automatically.
562 enum ScrollType : uint8_t {
563 SCROLL_DEFAULT,
564 SCROLL_SYNCHRONOUSLY,
565 SCROLL_ASYNCHRONOUSELY,
566 SCROLL_SMOOTHLY
568 ScrollType mScrollType;
570 // If the delta values are computed from prefs, this value is true.
571 // Otherwise, i.e., they are computed from native events, false.
572 bool mCustomizedByUserPrefs;
574 // true if the momentum events directly tied to this event may follow it.
575 bool mMayHaveMomentum;
576 // true if the event is caused by momentum.
577 bool mIsMomentum;
579 // If device event handlers don't know when they should set mLineOrPageDeltaX
580 // and mLineOrPageDeltaY, this is true. Otherwise, false.
581 // If mIsNoLineOrPageDelta is true, ESM will generate
582 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
583 // a line height.
584 bool mIsNoLineOrPageDelta;
586 // Whether or not the parent of the currently overscrolled frame is the
587 // ViewPort. This is false in situations when an element on the page is being
588 // overscrolled (such as a text field), but true when the 'page' is being
589 // overscrolled.
590 bool mViewPortIsOverscrolled;
592 // The wheel event can trigger a swipe to start if it's overscrolling the
593 // viewport.
594 bool mCanTriggerSwipe;
596 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
597 // overridden. Otherwise, the scroll speed won't be overridden even if
598 // it's enabled by the pref.
599 bool mAllowToOverrideSystemScrollSpeed;
601 // After the event's default action handler has adjusted its delta's values
602 // for horizontalizing a vertical wheel scroll, this variable will be set to
603 // true.
604 bool mDeltaValuesHorizontalizedForDefaultHandler;
606 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
607 AssignMouseEventBaseData(aEvent, aCopyTargets);
609 mDeltaX = aEvent.mDeltaX;
610 mDeltaY = aEvent.mDeltaY;
611 mDeltaZ = aEvent.mDeltaZ;
612 mDeltaMode = aEvent.mDeltaMode;
613 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
614 mMayHaveMomentum = aEvent.mMayHaveMomentum;
615 mIsMomentum = aEvent.mIsMomentum;
616 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
617 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
618 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
619 mScrollType = aEvent.mScrollType;
620 mOverflowDeltaX = aEvent.mOverflowDeltaX;
621 mOverflowDeltaY = aEvent.mOverflowDeltaY;
622 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
623 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
624 mAllowToOverrideSystemScrollSpeed =
625 aEvent.mAllowToOverrideSystemScrollSpeed;
626 mDeltaValuesHorizontalizedForDefaultHandler =
627 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
630 // System scroll speed settings may be too slow at using Gecko. In such
631 // case, we should override the scroll speed computed with system settings.
632 // Following methods return preferred delta values which are multiplied by
633 // factors specified by prefs. If system scroll speed shouldn't be
634 // overridden (e.g., this feature is disabled by pref), they return raw
635 // delta values.
636 double OverriddenDeltaX() const;
637 double OverriddenDeltaY() const;
639 // Compute the overridden delta value. This may be useful for suppressing
640 // too fast scroll by system scroll speed overriding when widget sets
641 // mAllowToOverrideSystemScrollSpeed.
642 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
644 private:
645 static bool sInitialized;
646 static bool sIsSystemScrollSpeedOverrideEnabled;
647 static int32_t sOverrideFactorX;
648 static int32_t sOverrideFactorY;
649 static void Initialize();
652 /******************************************************************************
653 * mozilla::WidgetPointerEvent
654 ******************************************************************************/
656 class WidgetPointerEvent : public WidgetMouseEvent {
657 friend class mozilla::dom::PBrowserParent;
658 friend class mozilla::dom::PBrowserChild;
660 WidgetPointerEvent() : mWidth(1), mHeight(1), mIsPrimary(true) {}
662 public:
663 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
665 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
666 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal),
667 mWidth(1),
668 mHeight(1),
669 mIsPrimary(true) {}
671 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
672 : WidgetMouseEvent(aEvent), mWidth(1), mHeight(1), mIsPrimary(true) {
673 mClass = ePointerEventClass;
676 virtual WidgetEvent* Duplicate() const override {
677 MOZ_ASSERT(mClass == ePointerEventClass,
678 "Duplicate() must be overridden by sub class");
679 // Not copying widget, it is a weak reference.
680 WidgetPointerEvent* result =
681 new WidgetPointerEvent(false, mMessage, nullptr);
682 result->AssignPointerEventData(*this, true);
683 result->mFlags = mFlags;
684 return result;
687 uint32_t mWidth;
688 uint32_t mHeight;
689 bool mIsPrimary;
691 // XXX Not tested by test_assign_event_data.html
692 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
693 bool aCopyTargets) {
694 AssignMouseEventData(aEvent, aCopyTargets);
696 mWidth = aEvent.mWidth;
697 mHeight = aEvent.mHeight;
698 mIsPrimary = aEvent.mIsPrimary;
702 } // namespace mozilla
704 #endif // mozilla_MouseEvents_h__