Bug 1464538 [wpt PR 11173] - [testdriver] Enable manual interaction, a=testonly
[gecko.git] / widget / MouseEvents.h
blob6172cdf7c203a627a72d6239fe60a8e434f2eaf7
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 } // namespace dom
23 class WidgetPointerEvent;
24 class WidgetPointerEventHolder final {
25 public:
26 nsTArray<WidgetPointerEvent> mEvents;
27 NS_INLINE_DECL_REFCOUNTING(WidgetPointerEventHolder)
29 private:
30 virtual ~WidgetPointerEventHolder() {}
33 /******************************************************************************
34 * mozilla::WidgetPointerHelper
35 ******************************************************************************/
37 class WidgetPointerHelper {
38 public:
39 uint32_t pointerId;
40 uint32_t tiltX;
41 uint32_t tiltY;
42 uint32_t twist;
43 float tangentialPressure;
44 bool convertToPointer;
45 RefPtr<WidgetPointerEventHolder> mCoalescedWidgetEvents;
47 WidgetPointerHelper()
48 : pointerId(0),
49 tiltX(0),
50 tiltY(0),
51 twist(0),
52 tangentialPressure(0),
53 convertToPointer(true) {}
55 WidgetPointerHelper(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
56 uint32_t aTwist = 0, float aTangentialPressure = 0)
57 : pointerId(aPointerId),
58 tiltX(aTiltX),
59 tiltY(aTiltY),
60 twist(aTwist),
61 tangentialPressure(aTangentialPressure),
62 convertToPointer(true) {}
64 explicit WidgetPointerHelper(const WidgetPointerHelper& aHelper)
65 : pointerId(aHelper.pointerId),
66 tiltX(aHelper.tiltX),
67 tiltY(aHelper.tiltY),
68 twist(aHelper.twist),
69 tangentialPressure(aHelper.tangentialPressure),
70 convertToPointer(aHelper.convertToPointer),
71 mCoalescedWidgetEvents(aHelper.mCoalescedWidgetEvents) {}
73 void AssignPointerHelperData(const WidgetPointerHelper& aEvent,
74 bool aCopyCoalescedEvents = false) {
75 pointerId = aEvent.pointerId;
76 tiltX = aEvent.tiltX;
77 tiltY = aEvent.tiltY;
78 twist = aEvent.twist;
79 tangentialPressure = aEvent.tangentialPressure;
80 convertToPointer = aEvent.convertToPointer;
81 if (aCopyCoalescedEvents) {
82 mCoalescedWidgetEvents = aEvent.mCoalescedWidgetEvents;
87 /******************************************************************************
88 * mozilla::WidgetMouseEventBase
89 ******************************************************************************/
91 class WidgetMouseEventBase : public WidgetInputEvent {
92 private:
93 friend class dom::PBrowserParent;
94 friend class dom::PBrowserChild;
96 protected:
97 WidgetMouseEventBase()
98 : button(0),
99 buttons(0),
100 pressure(0),
101 hitCluster(false)
102 // Including MouseEventBinding.h here leads to an include loop, so
103 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
105 inputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
107 WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
108 nsIWidget* aWidget, EventClassID aEventClassID)
109 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID),
110 button(0),
111 buttons(0),
112 pressure(0),
113 hitCluster(false)
114 // Including MouseEventBinding.h here leads to an include loop, so
115 // we have to hardcode MouseEvent_Binding::MOZ_SOURCE_MOUSE.
117 inputSource(/* MouseEvent_Binding::MOZ_SOURCE_MOUSE = */ 1) {}
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 enum buttonType {
127 eNoButton = -1,
128 eLeftButton = 0,
129 eMiddleButton = 1,
130 eRightButton = 2
132 // Pressed button ID of mousedown or mouseup event.
133 // This is set only when pressing a button causes the event.
134 int16_t button;
136 enum buttonsFlag {
137 eNoButtonFlag = 0x00,
138 eLeftButtonFlag = 0x01,
139 eRightButtonFlag = 0x02,
140 eMiddleButtonFlag = 0x04,
141 // typicall, "back" button being left side of 5-button
142 // mice, see "buttons" attribute document of DOM3 Events.
143 e4thButtonFlag = 0x08,
144 // typicall, "forward" button being right side of 5-button
145 // mice, see "buttons" attribute document of DOM3 Events.
146 e5thButtonFlag = 0x10
149 // Flags of all pressed buttons at the event fired.
150 // This is set at any mouse event, don't be confused with |button|.
151 int16_t buttons;
153 // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
154 float pressure;
155 // Touch near a cluster of links (true)
156 bool hitCluster;
158 // Possible values a in MouseEvent
159 uint16_t inputSource;
161 // ID of the canvas HitRegion
162 nsString region;
164 bool IsLeftButtonPressed() const { return !!(buttons & eLeftButtonFlag); }
165 bool IsRightButtonPressed() const { return !!(buttons & eRightButtonFlag); }
166 bool IsMiddleButtonPressed() const { return !!(buttons & eMiddleButtonFlag); }
167 bool Is4thButtonPressed() const { return !!(buttons & e4thButtonFlag); }
168 bool Is5thButtonPressed() const { return !!(buttons & e5thButtonFlag); }
170 void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
171 bool aCopyTargets) {
172 AssignInputEventData(aEvent, aCopyTargets);
174 button = aEvent.button;
175 buttons = aEvent.buttons;
176 pressure = aEvent.pressure;
177 hitCluster = aEvent.hitCluster;
178 inputSource = aEvent.inputSource;
182 * Returns true if left click event.
184 bool IsLeftClickEvent() const {
185 return mMessage == eMouseClick && button == eLeftButton;
189 /******************************************************************************
190 * mozilla::WidgetMouseEvent
191 ******************************************************************************/
193 class WidgetMouseEvent : public WidgetMouseEventBase,
194 public WidgetPointerHelper {
195 private:
196 friend class dom::PBrowserParent;
197 friend class dom::PBrowserChild;
199 public:
200 typedef bool ReasonType;
201 enum Reason : ReasonType { eReal, eSynthesized };
203 typedef bool ContextMenuTriggerType;
204 enum ContextMenuTrigger : ContextMenuTriggerType { eNormal, eContextMenuKey };
206 typedef bool ExitFromType;
207 enum ExitFrom : ExitFromType { eChild, eTopLevel };
209 protected:
210 WidgetMouseEvent()
211 : mReason(eReal),
212 mContextMenuTrigger(eNormal),
213 mExitFrom(eChild),
214 mIgnoreRootScrollFrame(false),
215 mClickCount(0) {}
217 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
218 EventClassID aEventClassID, Reason aReason)
219 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID),
220 mReason(aReason),
221 mContextMenuTrigger(eNormal),
222 mExitFrom(eChild),
223 mIgnoreRootScrollFrame(false),
224 mClickCount(0) {}
226 public:
227 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
229 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
230 Reason aReason,
231 ContextMenuTrigger aContextMenuTrigger = eNormal)
232 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass),
233 mReason(aReason),
234 mContextMenuTrigger(aContextMenuTrigger),
235 mExitFrom(eChild),
236 mIgnoreRootScrollFrame(false),
237 mClickCount(0) {
238 if (aMessage == eContextMenu) {
239 button = (mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton;
243 #ifdef DEBUG
244 virtual ~WidgetMouseEvent() {
245 NS_WARNING_ASSERTION(
246 mMessage != eContextMenu ||
247 button ==
248 ((mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton),
249 "Wrong button set to eContextMenu event?");
251 #endif
253 virtual WidgetEvent* Duplicate() const override {
254 MOZ_ASSERT(mClass == eMouseEventClass,
255 "Duplicate() must be overridden by sub class");
256 // Not copying widget, it is a weak reference.
257 WidgetMouseEvent* result = new WidgetMouseEvent(
258 false, mMessage, nullptr, mReason, mContextMenuTrigger);
259 result->AssignMouseEventData(*this, true);
260 result->mFlags = mFlags;
261 return result;
264 // If during mouseup handling we detect that click event might need to be
265 // dispatched, this is setup to be the target of the click event.
266 nsCOMPtr<dom::EventTarget> mClickTarget;
268 // mReason indicates the reason why the event is fired:
269 // - Representing mouse operation.
270 // - Synthesized for emulating mousemove event when the content under the
271 // mouse cursor is scrolled.
272 Reason mReason;
274 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
275 // This indicates if the context menu event is caused by context menu key or
276 // other reasons (typically, a click of right mouse button).
277 ContextMenuTrigger mContextMenuTrigger;
279 // mExitFrom is valid only when mMessage is eMouseExitFromWidget.
280 // This indicates if the mouse cursor exits from a top level widget or
281 // a child widget.
282 ExitFrom mExitFrom;
284 // Whether the event should ignore scroll frame bounds during dispatch.
285 bool mIgnoreRootScrollFrame;
287 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
288 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
289 // Otherwise, this must be 0.
290 uint32_t mClickCount;
292 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) {
293 AssignMouseEventBaseData(aEvent, aCopyTargets);
294 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
296 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
297 mClickCount = aEvent.mClickCount;
301 * Returns true if the event is a context menu event caused by key.
303 bool IsContextMenuKeyEvent() const {
304 return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
308 * Returns true if the event is a real mouse event. Otherwise, i.e., it's
309 * a synthesized event by scroll or something, returns false.
311 bool IsReal() const { return mReason == eReal; }
314 * Returns true if middle click paste is enabled.
316 static bool IsMiddleClickPasteEnabled();
319 /******************************************************************************
320 * mozilla::WidgetDragEvent
321 ******************************************************************************/
323 class WidgetDragEvent : public WidgetMouseEvent {
324 private:
325 friend class mozilla::dom::PBrowserParent;
326 friend class mozilla::dom::PBrowserChild;
328 protected:
329 WidgetDragEvent()
330 : mUserCancelled(false), mDefaultPreventedOnContent(false) {}
332 public:
333 virtual WidgetDragEvent* AsDragEvent() override { return this; }
335 WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
336 : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal),
337 mUserCancelled(false),
338 mDefaultPreventedOnContent(false) {}
340 virtual WidgetEvent* Duplicate() const override {
341 MOZ_ASSERT(mClass == eDragEventClass,
342 "Duplicate() must be overridden by sub class");
343 // Not copying widget, it is a weak reference.
344 WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
345 result->AssignDragEventData(*this, true);
346 result->mFlags = mFlags;
347 return result;
350 // The dragging data.
351 nsCOMPtr<dom::DataTransfer> mDataTransfer;
353 // If this is true, user has cancelled the drag operation.
354 bool mUserCancelled;
355 // If this is true, the drag event's preventDefault() is called on content.
356 bool mDefaultPreventedOnContent;
358 // XXX Not tested by test_assign_event_data.html
359 void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) {
360 AssignMouseEventData(aEvent, aCopyTargets);
362 mDataTransfer = aEvent.mDataTransfer;
363 // XXX mUserCancelled isn't copied, is this intentionally?
364 mUserCancelled = false;
365 mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
369 /******************************************************************************
370 * mozilla::WidgetMouseScrollEvent
372 * This is used for legacy DOM mouse scroll events, i.e.,
373 * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
374 * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
375 ******************************************************************************/
377 class WidgetMouseScrollEvent : public WidgetMouseEventBase {
378 private:
379 WidgetMouseScrollEvent() : mDelta(0), mIsHorizontal(false) {}
381 public:
382 virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override { return this; }
384 WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
385 nsIWidget* aWidget)
386 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
387 eMouseScrollEventClass),
388 mDelta(0),
389 mIsHorizontal(false) {}
391 virtual WidgetEvent* Duplicate() const override {
392 MOZ_ASSERT(mClass == eMouseScrollEventClass,
393 "Duplicate() must be overridden by sub class");
394 // Not copying widget, it is a weak reference.
395 WidgetMouseScrollEvent* result =
396 new WidgetMouseScrollEvent(false, mMessage, nullptr);
397 result->AssignMouseScrollEventData(*this, true);
398 result->mFlags = mFlags;
399 return result;
402 // The delta value of mouse scroll event.
403 // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
404 // scroll amount in lines. However, if the value is
405 // UIEvent::SCROLL_PAGE_UP or UIEvent::SCROLL_PAGE_DOWN, the
406 // value inducates one page scroll. If the event message is
407 // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
408 int32_t mDelta;
410 // If this is true, it may cause to scroll horizontally.
411 // Otherwise, vertically.
412 bool mIsHorizontal;
414 void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
415 bool aCopyTargets) {
416 AssignMouseEventBaseData(aEvent, aCopyTargets);
418 mDelta = aEvent.mDelta;
419 mIsHorizontal = aEvent.mIsHorizontal;
423 /******************************************************************************
424 * mozilla::WidgetWheelEvent
425 ******************************************************************************/
427 class WidgetWheelEvent : public WidgetMouseEventBase {
428 private:
429 friend class mozilla::dom::PBrowserParent;
430 friend class mozilla::dom::PBrowserChild;
432 WidgetWheelEvent()
433 : mDeltaX(0.0),
434 mDeltaY(0.0),
435 mDeltaZ(0.0),
436 mOverflowDeltaX(0.0),
437 mOverflowDeltaY(0.0)
438 // Including WheelEventBinding.h here leads to an include loop, so
439 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
441 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
442 mLineOrPageDeltaX(0),
443 mLineOrPageDeltaY(0),
444 mScrollType(SCROLL_DEFAULT),
445 mCustomizedByUserPrefs(false),
446 mMayHaveMomentum(false),
447 mIsMomentum(false),
448 mIsNoLineOrPageDelta(false),
449 mViewPortIsOverscrolled(false),
450 mCanTriggerSwipe(false),
451 mAllowToOverrideSystemScrollSpeed(false),
452 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
454 public:
455 virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
457 WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
458 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass),
459 mDeltaX(0.0),
460 mDeltaY(0.0),
461 mDeltaZ(0.0),
462 mOverflowDeltaX(0.0),
463 mOverflowDeltaY(0.0)
464 // Including WheelEventBinding.h here leads to an include loop, so
465 // we have to hardcode WheelEvent_Binding::DOM_DELTA_PIXEL.
467 mDeltaMode(/* WheelEvent_Binding::DOM_DELTA_PIXEL = */ 0),
468 mLineOrPageDeltaX(0),
469 mLineOrPageDeltaY(0),
470 mScrollType(SCROLL_DEFAULT),
471 mCustomizedByUserPrefs(false),
472 mMayHaveMomentum(false),
473 mIsMomentum(false),
474 mIsNoLineOrPageDelta(false),
475 mViewPortIsOverscrolled(false),
476 mCanTriggerSwipe(false),
477 mAllowToOverrideSystemScrollSpeed(true),
478 mDeltaValuesHorizontalizedForDefaultHandler(false) {}
480 virtual WidgetEvent* Duplicate() const override {
481 MOZ_ASSERT(mClass == eWheelEventClass,
482 "Duplicate() must be overridden by sub class");
483 // Not copying widget, it is a weak reference.
484 WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
485 result->AssignWheelEventData(*this, true);
486 result->mFlags = mFlags;
487 return result;
490 // On OS X, scroll gestures that start at the edge of the scrollable range
491 // can result in a swipe gesture. For the first wheel event of such a
492 // gesture, call TriggersSwipe() after the event has been processed
493 // in order to find out whether a swipe should be started.
494 bool TriggersSwipe() const {
495 return mCanTriggerSwipe && mViewPortIsOverscrolled &&
496 this->mOverflowDeltaX != 0.0;
499 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
500 // mousewheel.*.delta_multiplier_* prefs which are applied by
501 // EventStateManager. So, after widget dispatches this event,
502 // these delta values may have different values than before.
503 double mDeltaX;
504 double mDeltaY;
505 double mDeltaZ;
507 // overflowed delta values for scroll, these values are set by
508 // EventStateManger. If the default action of the wheel event isn't scroll,
509 // these values are always zero. Otherwise, remaining delta values which are
510 // not used by scroll are set.
511 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
512 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
513 // delta values which are not applied the delta_multiplier prefs.
514 // So, if widget wanted to know the actual direction to be scrolled,
515 // it would need to check the mDeltaX and mDeltaY.
516 double mOverflowDeltaX;
517 double mOverflowDeltaY;
519 // Should be one of WheelEvent_Binding::DOM_DELTA_*
520 uint32_t mDeltaMode;
522 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
523 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
524 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
525 int32_t mLineOrPageDeltaX;
526 int32_t mLineOrPageDeltaY;
528 // When the default action for an wheel event is moving history or zooming,
529 // need to chose a delta value for doing it.
530 int32_t GetPreferredIntDelta() {
531 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
532 return 0;
534 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
535 return mLineOrPageDeltaY;
537 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
538 return mLineOrPageDeltaX;
540 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
541 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
542 return 0; // We cannot guess the answer in this case.
544 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
545 ? mLineOrPageDeltaX
546 : mLineOrPageDeltaY;
549 // Scroll type
550 // The default value is SCROLL_DEFAULT, which means EventStateManager will
551 // select preferred scroll type automatically.
552 enum ScrollType : uint8_t {
553 SCROLL_DEFAULT,
554 SCROLL_SYNCHRONOUSLY,
555 SCROLL_ASYNCHRONOUSELY,
556 SCROLL_SMOOTHLY
558 ScrollType mScrollType;
560 // If the delta values are computed from prefs, this value is true.
561 // Otherwise, i.e., they are computed from native events, false.
562 bool mCustomizedByUserPrefs;
564 // true if the momentum events directly tied to this event may follow it.
565 bool mMayHaveMomentum;
566 // true if the event is caused by momentum.
567 bool mIsMomentum;
569 // If device event handlers don't know when they should set mLineOrPageDeltaX
570 // and mLineOrPageDeltaY, this is true. Otherwise, false.
571 // If mIsNoLineOrPageDelta is true, ESM will generate
572 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
573 // a line height.
574 bool mIsNoLineOrPageDelta;
576 // Whether or not the parent of the currently overscrolled frame is the
577 // ViewPort. This is false in situations when an element on the page is being
578 // overscrolled (such as a text field), but true when the 'page' is being
579 // overscrolled.
580 bool mViewPortIsOverscrolled;
582 // The wheel event can trigger a swipe to start if it's overscrolling the
583 // viewport.
584 bool mCanTriggerSwipe;
586 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
587 // overridden. Otherwise, the scroll speed won't be overridden even if
588 // it's enabled by the pref.
589 bool mAllowToOverrideSystemScrollSpeed;
591 // After the event's default action handler has adjusted its delta's values
592 // for horizontalizing a vertical wheel scroll, this variable will be set to
593 // true.
594 bool mDeltaValuesHorizontalizedForDefaultHandler;
596 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
597 AssignMouseEventBaseData(aEvent, aCopyTargets);
599 mDeltaX = aEvent.mDeltaX;
600 mDeltaY = aEvent.mDeltaY;
601 mDeltaZ = aEvent.mDeltaZ;
602 mDeltaMode = aEvent.mDeltaMode;
603 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
604 mMayHaveMomentum = aEvent.mMayHaveMomentum;
605 mIsMomentum = aEvent.mIsMomentum;
606 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
607 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
608 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
609 mScrollType = aEvent.mScrollType;
610 mOverflowDeltaX = aEvent.mOverflowDeltaX;
611 mOverflowDeltaY = aEvent.mOverflowDeltaY;
612 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
613 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
614 mAllowToOverrideSystemScrollSpeed =
615 aEvent.mAllowToOverrideSystemScrollSpeed;
616 mDeltaValuesHorizontalizedForDefaultHandler =
617 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
620 // System scroll speed settings may be too slow at using Gecko. In such
621 // case, we should override the scroll speed computed with system settings.
622 // Following methods return preferred delta values which are multiplied by
623 // factors specified by prefs. If system scroll speed shouldn't be
624 // overridden (e.g., this feature is disabled by pref), they return raw
625 // delta values.
626 double OverriddenDeltaX() const;
627 double OverriddenDeltaY() const;
629 // Compute the overridden delta value. This may be useful for suppressing
630 // too fast scroll by system scroll speed overriding when widget sets
631 // mAllowToOverrideSystemScrollSpeed.
632 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
634 private:
635 static bool sInitialized;
636 static bool sIsSystemScrollSpeedOverrideEnabled;
637 static int32_t sOverrideFactorX;
638 static int32_t sOverrideFactorY;
639 static void Initialize();
642 /******************************************************************************
643 * mozilla::WidgetPointerEvent
644 ******************************************************************************/
646 class WidgetPointerEvent : public WidgetMouseEvent {
647 friend class mozilla::dom::PBrowserParent;
648 friend class mozilla::dom::PBrowserChild;
650 WidgetPointerEvent() : mWidth(1), mHeight(1), mIsPrimary(true) {}
652 public:
653 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
655 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
656 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal),
657 mWidth(1),
658 mHeight(1),
659 mIsPrimary(true) {}
661 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
662 : WidgetMouseEvent(aEvent), mWidth(1), mHeight(1), mIsPrimary(true) {
663 mClass = ePointerEventClass;
666 virtual WidgetEvent* Duplicate() const override {
667 MOZ_ASSERT(mClass == ePointerEventClass,
668 "Duplicate() must be overridden by sub class");
669 // Not copying widget, it is a weak reference.
670 WidgetPointerEvent* result =
671 new WidgetPointerEvent(false, mMessage, nullptr);
672 result->AssignPointerEventData(*this, true);
673 result->mFlags = mFlags;
674 return result;
677 uint32_t mWidth;
678 uint32_t mHeight;
679 bool mIsPrimary;
681 // XXX Not tested by test_assign_event_data.html
682 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
683 bool aCopyTargets) {
684 AssignMouseEventData(aEvent, aCopyTargets);
686 mWidth = aEvent.mWidth;
687 mHeight = aEvent.mHeight;
688 mIsPrimary = aEvent.mIsPrimary;
692 } // namespace mozilla
694 #endif // mozilla_MouseEvents_h__