Bug 1676529 [wpt PR 26467] - [LayoutNG] Find sibling spanners using the child iterato...
[gecko.git] / widget / MouseEvents.h
blob865526948875f9dc4036c769b2a03f3c3ca81a3f
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 uint32_t tiltX;
45 uint32_t tiltY;
46 uint32_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 // ID of the canvas HitRegion
121 nsString mRegion;
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;
182 public:
183 typedef bool ReasonType;
184 enum Reason : ReasonType { eReal, eSynthesized };
186 typedef uint8_t ContextMenuTriggerType;
187 enum ContextMenuTrigger : ContextMenuTriggerType {
188 eNormal,
189 eContextMenuKey,
190 eControlClick
193 typedef uint8_t ExitFromType;
194 enum ExitFrom : ExitFromType {
195 eChild,
196 eTopLevel,
197 ePuppet,
198 ePuppetParentToPuppetChild
201 protected:
202 WidgetMouseEvent()
203 : mReason(eReal),
204 mContextMenuTrigger(eNormal),
205 mIgnoreRootScrollFrame(false),
206 mClickCount(0),
207 mUseLegacyNonPrimaryDispatch(false) {}
209 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
210 EventClassID aEventClassID, Reason aReason)
211 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID),
212 mReason(aReason),
213 mContextMenuTrigger(eNormal),
214 mIgnoreRootScrollFrame(false),
215 mClickCount(0),
216 mUseLegacyNonPrimaryDispatch(false) {}
218 public:
219 virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
221 WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
222 Reason aReason,
223 ContextMenuTrigger aContextMenuTrigger = eNormal)
224 : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass),
225 mReason(aReason),
226 mContextMenuTrigger(aContextMenuTrigger),
227 mIgnoreRootScrollFrame(false),
228 mClickCount(0),
229 mUseLegacyNonPrimaryDispatch(false) {
230 if (aMessage == eContextMenu) {
231 mButton = (mContextMenuTrigger == eNormal) ? MouseButton::eSecondary
232 : MouseButton::ePrimary;
236 #ifdef DEBUG
237 virtual ~WidgetMouseEvent() {
238 NS_WARNING_ASSERTION(
239 mMessage != eContextMenu ||
240 (mButton == ((mContextMenuTrigger == eNormal)
241 ? MouseButton::eSecondary
242 : MouseButton::ePrimary) &&
243 (mContextMenuTrigger != eControlClick || IsControl())),
244 "Wrong button set to eContextMenu event?");
246 #endif
248 virtual WidgetEvent* Duplicate() const override {
249 MOZ_ASSERT(mClass == eMouseEventClass,
250 "Duplicate() must be overridden by sub class");
251 // Not copying widget, it is a weak reference.
252 WidgetMouseEvent* result = new WidgetMouseEvent(
253 false, mMessage, nullptr, mReason, mContextMenuTrigger);
254 result->AssignMouseEventData(*this, true);
255 result->mFlags = mFlags;
256 return result;
259 // If during mouseup handling we detect that click event might need to be
260 // dispatched, this is setup to be the target of the click event.
261 nsCOMPtr<dom::EventTarget> mClickTarget;
263 // mReason indicates the reason why the event is fired:
264 // - Representing mouse operation.
265 // - Synthesized for emulating mousemove event when the content under the
266 // mouse cursor is scrolled.
267 Reason mReason;
269 // mContextMenuTrigger is valid only when mMessage is eContextMenu.
270 // This indicates if the context menu event is caused by context menu key or
271 // other reasons (typically, a click of right mouse button).
272 ContextMenuTrigger mContextMenuTrigger;
274 // mExitFrom contains a value only when mMessage is eMouseExitFromWidget.
275 // This indicates if the mouse cursor exits from a top level platform widget,
276 // a child widget or a puppet widget.
277 Maybe<ExitFrom> mExitFrom;
279 // Whether the event should ignore scroll frame bounds during dispatch.
280 bool mIgnoreRootScrollFrame;
282 // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
283 // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
284 // Otherwise, this must be 0.
285 uint32_t mClickCount;
287 // Indicates whether the event should dispatch click events for non-primary
288 // mouse buttons on window and document.
289 bool mUseLegacyNonPrimaryDispatch;
291 void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) {
292 AssignMouseEventBaseData(aEvent, aCopyTargets);
293 AssignPointerHelperData(aEvent, /* aCopyCoalescedEvents */ true);
295 mExitFrom = aEvent.mExitFrom;
296 mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
297 mClickCount = aEvent.mClickCount;
298 mUseLegacyNonPrimaryDispatch = aEvent.mUseLegacyNonPrimaryDispatch;
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 // On OS X, scroll gestures that start at the edge of the scrollable range
500 // can result in a swipe gesture. For the first wheel event of such a
501 // gesture, call TriggersSwipe() after the event has been processed
502 // in order to find out 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 // overflowed delta values for scroll, these values are set by
517 // EventStateManger. If the default action of the wheel event isn't scroll,
518 // these values are always zero. Otherwise, remaining delta values which are
519 // not used by scroll are set.
520 // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
521 // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
522 // delta values which are not applied the delta_multiplier prefs.
523 // So, if widget wanted to know the actual direction to be scrolled,
524 // it would need to check the mDeltaX and mDeltaY.
525 double mOverflowDeltaX;
526 double mOverflowDeltaY;
528 // Should be one of WheelEvent_Binding::DOM_DELTA_*
529 uint32_t mDeltaMode;
531 // If widget sets mLineOrPageDelta, EventStateManager will dispatch
532 // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
533 // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
534 int32_t mLineOrPageDeltaX;
535 int32_t mLineOrPageDeltaY;
537 // When the default action for an wheel event is moving history or zooming,
538 // need to chose a delta value for doing it.
539 int32_t GetPreferredIntDelta() {
540 if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
541 return 0;
543 if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
544 return mLineOrPageDeltaY;
546 if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
547 return mLineOrPageDeltaX;
549 if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
550 (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
551 return 0; // We cannot guess the answer in this case.
553 return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY))
554 ? mLineOrPageDeltaX
555 : mLineOrPageDeltaY;
558 // Scroll type
559 // The default value is SCROLL_DEFAULT, which means EventStateManager will
560 // select preferred scroll type automatically.
561 enum ScrollType : uint8_t {
562 SCROLL_DEFAULT,
563 SCROLL_SYNCHRONOUSLY,
564 SCROLL_ASYNCHRONOUSELY,
565 SCROLL_SMOOTHLY
567 ScrollType mScrollType;
569 // If the delta values are computed from prefs, this value is true.
570 // Otherwise, i.e., they are computed from native events, false.
571 bool mCustomizedByUserPrefs;
573 // true if the momentum events directly tied to this event may follow it.
574 bool mMayHaveMomentum;
575 // true if the event is caused by momentum.
576 bool mIsMomentum;
578 // If device event handlers don't know when they should set mLineOrPageDeltaX
579 // and mLineOrPageDeltaY, this is true. Otherwise, false.
580 // If mIsNoLineOrPageDelta is true, ESM will generate
581 // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
582 // a line height.
583 bool mIsNoLineOrPageDelta;
585 // Whether or not the parent of the currently overscrolled frame is the
586 // ViewPort. This is false in situations when an element on the page is being
587 // overscrolled (such as a text field), but true when the 'page' is being
588 // overscrolled.
589 bool mViewPortIsOverscrolled;
591 // The wheel event can trigger a swipe to start if it's overscrolling the
592 // viewport.
593 bool mCanTriggerSwipe;
595 // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
596 // overridden. Otherwise, the scroll speed won't be overridden even if
597 // it's enabled by the pref.
598 bool mAllowToOverrideSystemScrollSpeed;
600 // After the event's default action handler has adjusted its delta's values
601 // for horizontalizing a vertical wheel scroll, this variable will be set to
602 // true.
603 bool mDeltaValuesHorizontalizedForDefaultHandler;
605 void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) {
606 AssignMouseEventBaseData(aEvent, aCopyTargets);
608 mDeltaX = aEvent.mDeltaX;
609 mDeltaY = aEvent.mDeltaY;
610 mDeltaZ = aEvent.mDeltaZ;
611 mDeltaMode = aEvent.mDeltaMode;
612 mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
613 mMayHaveMomentum = aEvent.mMayHaveMomentum;
614 mIsMomentum = aEvent.mIsMomentum;
615 mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
616 mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
617 mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
618 mScrollType = aEvent.mScrollType;
619 mOverflowDeltaX = aEvent.mOverflowDeltaX;
620 mOverflowDeltaY = aEvent.mOverflowDeltaY;
621 mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
622 mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
623 mAllowToOverrideSystemScrollSpeed =
624 aEvent.mAllowToOverrideSystemScrollSpeed;
625 mDeltaValuesHorizontalizedForDefaultHandler =
626 aEvent.mDeltaValuesHorizontalizedForDefaultHandler;
629 // System scroll speed settings may be too slow at using Gecko. In such
630 // case, we should override the scroll speed computed with system settings.
631 // Following methods return preferred delta values which are multiplied by
632 // factors specified by prefs. If system scroll speed shouldn't be
633 // overridden (e.g., this feature is disabled by pref), they return raw
634 // delta values.
635 double OverriddenDeltaX() const;
636 double OverriddenDeltaY() const;
638 // Compute the overridden delta value. This may be useful for suppressing
639 // too fast scroll by system scroll speed overriding when widget sets
640 // mAllowToOverrideSystemScrollSpeed.
641 static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
643 private:
644 static bool sInitialized;
645 static bool sIsSystemScrollSpeedOverrideEnabled;
646 static int32_t sOverrideFactorX;
647 static int32_t sOverrideFactorY;
648 static void Initialize();
651 /******************************************************************************
652 * mozilla::WidgetPointerEvent
653 ******************************************************************************/
655 class WidgetPointerEvent : public WidgetMouseEvent {
656 friend class mozilla::dom::PBrowserParent;
657 friend class mozilla::dom::PBrowserChild;
659 WidgetPointerEvent() : mWidth(1), mHeight(1), mIsPrimary(true) {}
661 public:
662 virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
664 WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
665 : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal),
666 mWidth(1),
667 mHeight(1),
668 mIsPrimary(true) {}
670 explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
671 : WidgetMouseEvent(aEvent), mWidth(1), mHeight(1), mIsPrimary(true) {
672 mClass = ePointerEventClass;
675 virtual WidgetEvent* Duplicate() const override {
676 MOZ_ASSERT(mClass == ePointerEventClass,
677 "Duplicate() must be overridden by sub class");
678 // Not copying widget, it is a weak reference.
679 WidgetPointerEvent* result =
680 new WidgetPointerEvent(false, mMessage, nullptr);
681 result->AssignPointerEventData(*this, true);
682 result->mFlags = mFlags;
683 return result;
686 uint32_t mWidth;
687 uint32_t mHeight;
688 bool mIsPrimary;
690 // XXX Not tested by test_assign_event_data.html
691 void AssignPointerEventData(const WidgetPointerEvent& aEvent,
692 bool aCopyTargets) {
693 AssignMouseEventData(aEvent, aCopyTargets);
695 mWidth = aEvent.mWidth;
696 mHeight = aEvent.mHeight;
697 mIsPrimary = aEvent.mIsPrimary;
701 } // namespace mozilla
703 #endif // mozilla_MouseEvents_h__