MouseEvents.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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/. */
  5. #ifndef mozilla_MouseEvents_h__
  6. #define mozilla_MouseEvents_h__
  7. #include <stdint.h>
  8. #include "mozilla/BasicEvents.h"
  9. #include "mozilla/MathAlgorithms.h"
  10. #include "mozilla/dom/DataTransfer.h"
  11. #include "nsCOMPtr.h"
  12. #include "nsIDOMMouseEvent.h"
  13. #include "nsIDOMWheelEvent.h"
  14. /******************************************************************************
  15. * nsDragDropEventStatus
  16. ******************************************************************************/
  17. enum nsDragDropEventStatus
  18. {
  19. // The event is a enter
  20. nsDragDropEventStatus_eDragEntered,
  21. // The event is exit
  22. nsDragDropEventStatus_eDragExited,
  23. // The event is drop
  24. nsDragDropEventStatus_eDrop
  25. };
  26. namespace mozilla {
  27. namespace dom {
  28. class PBrowserParent;
  29. class PBrowserChild;
  30. } // namespace dom
  31. /******************************************************************************
  32. * mozilla::WidgetPointerHelper
  33. ******************************************************************************/
  34. class WidgetPointerHelper
  35. {
  36. public:
  37. uint32_t pointerId;
  38. uint32_t tiltX;
  39. uint32_t tiltY;
  40. uint32_t twist;
  41. float tangentialPressure;
  42. bool convertToPointer;
  43. WidgetPointerHelper()
  44. : pointerId(0)
  45. , tiltX(0)
  46. , tiltY(0)
  47. , twist(0)
  48. , tangentialPressure(0)
  49. , convertToPointer(true)
  50. {
  51. }
  52. void AssignPointerHelperData(const WidgetPointerHelper& aEvent)
  53. {
  54. pointerId = aEvent.pointerId;
  55. tiltX = aEvent.tiltX;
  56. tiltY = aEvent.tiltY;
  57. twist = aEvent.twist;
  58. tangentialPressure = aEvent.tangentialPressure;
  59. convertToPointer = aEvent.convertToPointer;
  60. }
  61. };
  62. /******************************************************************************
  63. * mozilla::WidgetMouseEventBase
  64. ******************************************************************************/
  65. class WidgetMouseEventBase : public WidgetInputEvent
  66. {
  67. private:
  68. friend class dom::PBrowserParent;
  69. friend class dom::PBrowserChild;
  70. protected:
  71. WidgetMouseEventBase()
  72. : button(0)
  73. , buttons(0)
  74. , pressure(0)
  75. , hitCluster(false)
  76. , inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
  77. {
  78. }
  79. WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage,
  80. nsIWidget* aWidget, EventClassID aEventClassID)
  81. : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
  82. , button(0)
  83. , buttons(0)
  84. , pressure(0)
  85. , hitCluster(false)
  86. , inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
  87. {
  88. }
  89. public:
  90. virtual WidgetMouseEventBase* AsMouseEventBase() override { return this; }
  91. virtual WidgetEvent* Duplicate() const override
  92. {
  93. MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
  94. }
  95. enum buttonType
  96. {
  97. eLeftButton = 0,
  98. eMiddleButton = 1,
  99. eRightButton = 2
  100. };
  101. // Pressed button ID of mousedown or mouseup event.
  102. // This is set only when pressing a button causes the event.
  103. int16_t button;
  104. enum buttonsFlag {
  105. eNoButtonFlag = 0x00,
  106. eLeftButtonFlag = 0x01,
  107. eRightButtonFlag = 0x02,
  108. eMiddleButtonFlag = 0x04,
  109. // typicall, "back" button being left side of 5-button
  110. // mice, see "buttons" attribute document of DOM3 Events.
  111. e4thButtonFlag = 0x08,
  112. // typicall, "forward" button being right side of 5-button
  113. // mice, see "buttons" attribute document of DOM3 Events.
  114. e5thButtonFlag = 0x10
  115. };
  116. // Flags of all pressed buttons at the event fired.
  117. // This is set at any mouse event, don't be confused with |button|.
  118. int16_t buttons;
  119. // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
  120. float pressure;
  121. // Touch near a cluster of links (true)
  122. bool hitCluster;
  123. // Possible values at nsIDOMMouseEvent
  124. uint16_t inputSource;
  125. // ID of the canvas HitRegion
  126. nsString region;
  127. bool IsLeftButtonPressed() const { return !!(buttons & eLeftButtonFlag); }
  128. bool IsRightButtonPressed() const { return !!(buttons & eRightButtonFlag); }
  129. bool IsMiddleButtonPressed() const { return !!(buttons & eMiddleButtonFlag); }
  130. bool Is4thButtonPressed() const { return !!(buttons & e4thButtonFlag); }
  131. bool Is5thButtonPressed() const { return !!(buttons & e5thButtonFlag); }
  132. void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
  133. bool aCopyTargets)
  134. {
  135. AssignInputEventData(aEvent, aCopyTargets);
  136. button = aEvent.button;
  137. buttons = aEvent.buttons;
  138. pressure = aEvent.pressure;
  139. hitCluster = aEvent.hitCluster;
  140. inputSource = aEvent.inputSource;
  141. }
  142. /**
  143. * Returns true if left click event.
  144. */
  145. bool IsLeftClickEvent() const
  146. {
  147. return mMessage == eMouseClick && button == eLeftButton;
  148. }
  149. };
  150. /******************************************************************************
  151. * mozilla::WidgetMouseEvent
  152. ******************************************************************************/
  153. class WidgetMouseEvent : public WidgetMouseEventBase
  154. , public WidgetPointerHelper
  155. {
  156. private:
  157. friend class dom::PBrowserParent;
  158. friend class dom::PBrowserChild;
  159. public:
  160. typedef bool ReasonType;
  161. enum Reason : ReasonType
  162. {
  163. eReal,
  164. eSynthesized
  165. };
  166. typedef bool ContextMenuTriggerType;
  167. enum ContextMenuTrigger : ContextMenuTriggerType
  168. {
  169. eNormal,
  170. eContextMenuKey
  171. };
  172. typedef bool ExitFromType;
  173. enum ExitFrom : ExitFromType
  174. {
  175. eChild,
  176. eTopLevel
  177. };
  178. protected:
  179. WidgetMouseEvent()
  180. : mReason(eReal)
  181. , mContextMenuTrigger(eNormal)
  182. , mExitFrom(eChild)
  183. , mIgnoreRootScrollFrame(false)
  184. , mClickCount(0)
  185. {
  186. }
  187. WidgetMouseEvent(bool aIsTrusted,
  188. EventMessage aMessage,
  189. nsIWidget* aWidget,
  190. EventClassID aEventClassID,
  191. Reason aReason)
  192. : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID)
  193. , mReason(aReason)
  194. , mContextMenuTrigger(eNormal)
  195. , mExitFrom(eChild)
  196. , mIgnoreRootScrollFrame(false)
  197. , mClickCount(0)
  198. {
  199. }
  200. public:
  201. virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
  202. WidgetMouseEvent(bool aIsTrusted,
  203. EventMessage aMessage,
  204. nsIWidget* aWidget,
  205. Reason aReason,
  206. ContextMenuTrigger aContextMenuTrigger = eNormal)
  207. : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass)
  208. , mReason(aReason)
  209. , mContextMenuTrigger(aContextMenuTrigger)
  210. , mExitFrom(eChild)
  211. , mIgnoreRootScrollFrame(false)
  212. , mClickCount(0)
  213. {
  214. if (aMessage == eContextMenu) {
  215. button = (mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton;
  216. }
  217. }
  218. #ifdef DEBUG
  219. virtual ~WidgetMouseEvent()
  220. {
  221. NS_WARNING_ASSERTION(
  222. mMessage != eContextMenu ||
  223. button == ((mContextMenuTrigger == eNormal) ? eRightButton : eLeftButton),
  224. "Wrong button set to eContextMenu event?");
  225. }
  226. #endif
  227. virtual WidgetEvent* Duplicate() const override
  228. {
  229. MOZ_ASSERT(mClass == eMouseEventClass,
  230. "Duplicate() must be overridden by sub class");
  231. // Not copying widget, it is a weak reference.
  232. WidgetMouseEvent* result =
  233. new WidgetMouseEvent(false, mMessage, nullptr,
  234. mReason, mContextMenuTrigger);
  235. result->AssignMouseEventData(*this, true);
  236. result->mFlags = mFlags;
  237. return result;
  238. }
  239. // mReason indicates the reason why the event is fired:
  240. // - Representing mouse operation.
  241. // - Synthesized for emulating mousemove event when the content under the
  242. // mouse cursor is scrolled.
  243. Reason mReason;
  244. // mContextMenuTrigger is valid only when mMessage is eContextMenu.
  245. // This indicates if the context menu event is caused by context menu key or
  246. // other reasons (typically, a click of right mouse button).
  247. ContextMenuTrigger mContextMenuTrigger;
  248. // mExitFrom is valid only when mMessage is eMouseExitFromWidget.
  249. // This indicates if the mouse cursor exits from a top level widget or
  250. // a child widget.
  251. ExitFrom mExitFrom;
  252. // Whether the event should ignore scroll frame bounds during dispatch.
  253. bool mIgnoreRootScrollFrame;
  254. // mClickCount may be non-zero value when mMessage is eMouseDown, eMouseUp,
  255. // eMouseClick or eMouseDoubleClick. The number is count of mouse clicks.
  256. // Otherwise, this must be 0.
  257. uint32_t mClickCount;
  258. void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets)
  259. {
  260. AssignMouseEventBaseData(aEvent, aCopyTargets);
  261. AssignPointerHelperData(aEvent);
  262. mIgnoreRootScrollFrame = aEvent.mIgnoreRootScrollFrame;
  263. mClickCount = aEvent.mClickCount;
  264. }
  265. /**
  266. * Returns true if the event is a context menu event caused by key.
  267. */
  268. bool IsContextMenuKeyEvent() const
  269. {
  270. return mMessage == eContextMenu && mContextMenuTrigger == eContextMenuKey;
  271. }
  272. /**
  273. * Returns true if the event is a real mouse event. Otherwise, i.e., it's
  274. * a synthesized event by scroll or something, returns false.
  275. */
  276. bool IsReal() const
  277. {
  278. return mReason == eReal;
  279. }
  280. };
  281. /******************************************************************************
  282. * mozilla::WidgetDragEvent
  283. ******************************************************************************/
  284. class WidgetDragEvent : public WidgetMouseEvent
  285. {
  286. private:
  287. friend class mozilla::dom::PBrowserParent;
  288. friend class mozilla::dom::PBrowserChild;
  289. protected:
  290. WidgetDragEvent()
  291. : mUserCancelled(false)
  292. , mDefaultPreventedOnContent(false)
  293. {
  294. }
  295. public:
  296. virtual WidgetDragEvent* AsDragEvent() override { return this; }
  297. WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
  298. : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal)
  299. , mUserCancelled(false)
  300. , mDefaultPreventedOnContent(false)
  301. {
  302. }
  303. virtual WidgetEvent* Duplicate() const override
  304. {
  305. MOZ_ASSERT(mClass == eDragEventClass,
  306. "Duplicate() must be overridden by sub class");
  307. // Not copying widget, it is a weak reference.
  308. WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
  309. result->AssignDragEventData(*this, true);
  310. result->mFlags = mFlags;
  311. return result;
  312. }
  313. // The dragging data.
  314. nsCOMPtr<dom::DataTransfer> mDataTransfer;
  315. // If this is true, user has cancelled the drag operation.
  316. bool mUserCancelled;
  317. // If this is true, the drag event's preventDefault() is called on content.
  318. bool mDefaultPreventedOnContent;
  319. // XXX Not tested by test_assign_event_data.html
  320. void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets)
  321. {
  322. AssignMouseEventData(aEvent, aCopyTargets);
  323. mDataTransfer = aEvent.mDataTransfer;
  324. // XXX mUserCancelled isn't copied, is this intentionally?
  325. mUserCancelled = false;
  326. mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
  327. }
  328. };
  329. /******************************************************************************
  330. * mozilla::WidgetMouseScrollEvent
  331. *
  332. * This is used for legacy DOM mouse scroll events, i.e.,
  333. * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled
  334. * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead.
  335. ******************************************************************************/
  336. class WidgetMouseScrollEvent : public WidgetMouseEventBase
  337. {
  338. private:
  339. WidgetMouseScrollEvent()
  340. : mDelta(0)
  341. , mIsHorizontal(false)
  342. {
  343. }
  344. public:
  345. virtual WidgetMouseScrollEvent* AsMouseScrollEvent() override
  346. {
  347. return this;
  348. }
  349. WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage,
  350. nsIWidget* aWidget)
  351. : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
  352. eMouseScrollEventClass)
  353. , mDelta(0)
  354. , mIsHorizontal(false)
  355. {
  356. }
  357. virtual WidgetEvent* Duplicate() const override
  358. {
  359. MOZ_ASSERT(mClass == eMouseScrollEventClass,
  360. "Duplicate() must be overridden by sub class");
  361. // Not copying widget, it is a weak reference.
  362. WidgetMouseScrollEvent* result =
  363. new WidgetMouseScrollEvent(false, mMessage, nullptr);
  364. result->AssignMouseScrollEventData(*this, true);
  365. result->mFlags = mFlags;
  366. return result;
  367. }
  368. // The delta value of mouse scroll event.
  369. // If the event message is eLegacyMouseLineOrPageScroll, the value indicates
  370. // scroll amount in lines. However, if the value is
  371. // nsIDOMUIEvent::SCROLL_PAGE_UP or nsIDOMUIEvent::SCROLL_PAGE_DOWN, the
  372. // value inducates one page scroll. If the event message is
  373. // eLegacyMousePixelScroll, the value indicates scroll amount in pixels.
  374. int32_t mDelta;
  375. // If this is true, it may cause to scroll horizontally.
  376. // Otherwise, vertically.
  377. bool mIsHorizontal;
  378. void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
  379. bool aCopyTargets)
  380. {
  381. AssignMouseEventBaseData(aEvent, aCopyTargets);
  382. mDelta = aEvent.mDelta;
  383. mIsHorizontal = aEvent.mIsHorizontal;
  384. }
  385. };
  386. /******************************************************************************
  387. * mozilla::WidgetWheelEvent
  388. ******************************************************************************/
  389. class WidgetWheelEvent : public WidgetMouseEventBase
  390. {
  391. private:
  392. friend class mozilla::dom::PBrowserParent;
  393. friend class mozilla::dom::PBrowserChild;
  394. WidgetWheelEvent()
  395. : mDeltaX(0.0)
  396. , mDeltaY(0.0)
  397. , mDeltaZ(0.0)
  398. , mOverflowDeltaX(0.0)
  399. , mOverflowDeltaY(0.0)
  400. , mDeltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL)
  401. , mLineOrPageDeltaX(0)
  402. , mLineOrPageDeltaY(0)
  403. , mScrollType(SCROLL_DEFAULT)
  404. , mCustomizedByUserPrefs(false)
  405. , mIsMomentum(false)
  406. , mIsNoLineOrPageDelta(false)
  407. , mViewPortIsOverscrolled(false)
  408. , mCanTriggerSwipe(false)
  409. , mAllowToOverrideSystemScrollSpeed(false)
  410. {
  411. }
  412. public:
  413. virtual WidgetWheelEvent* AsWheelEvent() override { return this; }
  414. WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
  415. : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass)
  416. , mDeltaX(0.0)
  417. , mDeltaY(0.0)
  418. , mDeltaZ(0.0)
  419. , mOverflowDeltaX(0.0)
  420. , mOverflowDeltaY(0.0)
  421. , mDeltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL)
  422. , mLineOrPageDeltaX(0)
  423. , mLineOrPageDeltaY(0)
  424. , mScrollType(SCROLL_DEFAULT)
  425. , mCustomizedByUserPrefs(false)
  426. , mMayHaveMomentum(false)
  427. , mIsMomentum(false)
  428. , mIsNoLineOrPageDelta(false)
  429. , mViewPortIsOverscrolled(false)
  430. , mCanTriggerSwipe(false)
  431. , mAllowToOverrideSystemScrollSpeed(true)
  432. {
  433. }
  434. virtual WidgetEvent* Duplicate() const override
  435. {
  436. MOZ_ASSERT(mClass == eWheelEventClass,
  437. "Duplicate() must be overridden by sub class");
  438. // Not copying widget, it is a weak reference.
  439. WidgetWheelEvent* result = new WidgetWheelEvent(false, mMessage, nullptr);
  440. result->AssignWheelEventData(*this, true);
  441. result->mFlags = mFlags;
  442. return result;
  443. }
  444. // On OS X, scroll gestures that start at the edge of the scrollable range
  445. // can result in a swipe gesture. For the first wheel event of such a
  446. // gesture, call TriggersSwipe() after the event has been processed
  447. // in order to find out whether a swipe should be started.
  448. bool TriggersSwipe() const
  449. {
  450. return mCanTriggerSwipe && mViewPortIsOverscrolled &&
  451. this->mOverflowDeltaX != 0.0;
  452. }
  453. // NOTE: mDeltaX, mDeltaY and mDeltaZ may be customized by
  454. // mousewheel.*.delta_multiplier_* prefs which are applied by
  455. // EventStateManager. So, after widget dispatches this event,
  456. // these delta values may have different values than before.
  457. double mDeltaX;
  458. double mDeltaY;
  459. double mDeltaZ;
  460. // overflowed delta values for scroll, these values are set by
  461. // nsEventStateManger. If the default action of the wheel event isn't scroll,
  462. // these values always zero. Otherwise, remaning delta values which are
  463. // not used by scroll are set.
  464. // NOTE: mDeltaX, mDeltaY and mDeltaZ may be modified by EventStateManager.
  465. // However, mOverflowDeltaX and mOverflowDeltaY indicate unused original
  466. // delta values which are not applied the delta_multiplier prefs.
  467. // So, if widget wanted to know the actual direction to be scrolled,
  468. // it would need to check the mDeltaX and mDeltaY.
  469. double mOverflowDeltaX;
  470. double mOverflowDeltaY;
  471. // Should be one of nsIDOMWheelEvent::DOM_DELTA_*
  472. uint32_t mDeltaMode;
  473. // If widget sets mLineOrPageDelta, EventStateManager will dispatch
  474. // eLegacyMouseLineOrPageScroll event for compatibility. Note that the delta
  475. // value means pages if the mDeltaMode is DOM_DELTA_PAGE, otherwise, lines.
  476. int32_t mLineOrPageDeltaX;
  477. int32_t mLineOrPageDeltaY;
  478. // When the default action for an wheel event is moving history or zooming,
  479. // need to chose a delta value for doing it.
  480. int32_t GetPreferredIntDelta()
  481. {
  482. if (!mLineOrPageDeltaX && !mLineOrPageDeltaY) {
  483. return 0;
  484. }
  485. if (mLineOrPageDeltaY && !mLineOrPageDeltaX) {
  486. return mLineOrPageDeltaY;
  487. }
  488. if (mLineOrPageDeltaX && !mLineOrPageDeltaY) {
  489. return mLineOrPageDeltaX;
  490. }
  491. if ((mLineOrPageDeltaX < 0 && mLineOrPageDeltaY > 0) ||
  492. (mLineOrPageDeltaX > 0 && mLineOrPageDeltaY < 0)) {
  493. return 0; // We cannot guess the answer in this case.
  494. }
  495. return (Abs(mLineOrPageDeltaX) > Abs(mLineOrPageDeltaY)) ?
  496. mLineOrPageDeltaX : mLineOrPageDeltaY;
  497. }
  498. // Scroll type
  499. // The default value is SCROLL_DEFAULT, which means EventStateManager will
  500. // select preferred scroll type automatically.
  501. enum ScrollType : uint8_t
  502. {
  503. SCROLL_DEFAULT,
  504. SCROLL_SYNCHRONOUSLY,
  505. SCROLL_ASYNCHRONOUSELY,
  506. SCROLL_SMOOTHLY
  507. };
  508. ScrollType mScrollType;
  509. // If the delta values are computed from prefs, this value is true.
  510. // Otherwise, i.e., they are computed from native events, false.
  511. bool mCustomizedByUserPrefs;
  512. // true if the momentum events directly tied to this event may follow it.
  513. bool mMayHaveMomentum;
  514. // true if the event is caused by momentum.
  515. bool mIsMomentum;
  516. // If device event handlers don't know when they should set mLineOrPageDeltaX
  517. // and mLineOrPageDeltaY, this is true. Otherwise, false.
  518. // If mIsNoLineOrPageDelta is true, ESM will generate
  519. // eLegacyMouseLineOrPageScroll events when accumulated delta values reach
  520. // a line height.
  521. bool mIsNoLineOrPageDelta;
  522. // Whether or not the parent of the currently overscrolled frame is the
  523. // ViewPort. This is false in situations when an element on the page is being
  524. // overscrolled (such as a text field), but true when the 'page' is being
  525. // overscrolled.
  526. bool mViewPortIsOverscrolled;
  527. // The wheel event can trigger a swipe to start if it's overscrolling the
  528. // viewport.
  529. bool mCanTriggerSwipe;
  530. // If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
  531. // overridden. Otherwise, the scroll speed won't be overridden even if
  532. // it's enabled by the pref.
  533. bool mAllowToOverrideSystemScrollSpeed;
  534. void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
  535. {
  536. AssignMouseEventBaseData(aEvent, aCopyTargets);
  537. mDeltaX = aEvent.mDeltaX;
  538. mDeltaY = aEvent.mDeltaY;
  539. mDeltaZ = aEvent.mDeltaZ;
  540. mDeltaMode = aEvent.mDeltaMode;
  541. mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs;
  542. mMayHaveMomentum = aEvent.mMayHaveMomentum;
  543. mIsMomentum = aEvent.mIsMomentum;
  544. mIsNoLineOrPageDelta = aEvent.mIsNoLineOrPageDelta;
  545. mLineOrPageDeltaX = aEvent.mLineOrPageDeltaX;
  546. mLineOrPageDeltaY = aEvent.mLineOrPageDeltaY;
  547. mScrollType = aEvent.mScrollType;
  548. mOverflowDeltaX = aEvent.mOverflowDeltaX;
  549. mOverflowDeltaY = aEvent.mOverflowDeltaY;
  550. mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
  551. mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
  552. mAllowToOverrideSystemScrollSpeed =
  553. aEvent.mAllowToOverrideSystemScrollSpeed;
  554. }
  555. // System scroll speed settings may be too slow at using Gecko. In such
  556. // case, we should override the scroll speed computed with system settings.
  557. // Following methods return preferred delta values which are multiplied by
  558. // factors specified by prefs. If system scroll speed shouldn't be
  559. // overridden (e.g., this feature is disabled by pref), they return raw
  560. // delta values.
  561. double OverriddenDeltaX() const;
  562. double OverriddenDeltaY() const;
  563. // Compute the overridden delta value. This may be useful for suppressing
  564. // too fast scroll by system scroll speed overriding when widget sets
  565. // mAllowToOverrideSystemScrollSpeed.
  566. static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
  567. private:
  568. static bool sInitialized;
  569. static bool sIsSystemScrollSpeedOverrideEnabled;
  570. static int32_t sOverrideFactorX;
  571. static int32_t sOverrideFactorY;
  572. static void Initialize();
  573. };
  574. /******************************************************************************
  575. * mozilla::WidgetPointerEvent
  576. ******************************************************************************/
  577. class WidgetPointerEvent : public WidgetMouseEvent
  578. {
  579. friend class mozilla::dom::PBrowserParent;
  580. friend class mozilla::dom::PBrowserChild;
  581. WidgetPointerEvent()
  582. : mWidth(1)
  583. , mHeight(1)
  584. , mIsPrimary(true)
  585. {
  586. }
  587. public:
  588. virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
  589. WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
  590. : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal)
  591. , mWidth(1)
  592. , mHeight(1)
  593. , mIsPrimary(true)
  594. {
  595. }
  596. explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
  597. : WidgetMouseEvent(aEvent)
  598. , mWidth(1)
  599. , mHeight(1)
  600. , mIsPrimary(true)
  601. {
  602. mClass = ePointerEventClass;
  603. }
  604. virtual WidgetEvent* Duplicate() const override
  605. {
  606. MOZ_ASSERT(mClass == ePointerEventClass,
  607. "Duplicate() must be overridden by sub class");
  608. // Not copying widget, it is a weak reference.
  609. WidgetPointerEvent* result =
  610. new WidgetPointerEvent(false, mMessage, nullptr);
  611. result->AssignPointerEventData(*this, true);
  612. result->mFlags = mFlags;
  613. return result;
  614. }
  615. uint32_t mWidth;
  616. uint32_t mHeight;
  617. bool mIsPrimary;
  618. // XXX Not tested by test_assign_event_data.html
  619. void AssignPointerEventData(const WidgetPointerEvent& aEvent,
  620. bool aCopyTargets)
  621. {
  622. AssignMouseEventData(aEvent, aCopyTargets);
  623. mWidth = aEvent.mWidth;
  624. mHeight = aEvent.mHeight;
  625. mIsPrimary = aEvent.mIsPrimary;
  626. }
  627. };
  628. } // namespace mozilla
  629. #endif // mozilla_MouseEvents_h__