MouseScrollEvent.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*- Mode: C++; tab-width: 8; 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. #include "mozilla/dom/MouseScrollEvent.h"
  6. #include "mozilla/MouseEvents.h"
  7. #include "prtime.h"
  8. #include "nsIDOMMouseScrollEvent.h"
  9. namespace mozilla {
  10. namespace dom {
  11. MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner,
  12. nsPresContext* aPresContext,
  13. WidgetMouseScrollEvent* aEvent)
  14. : MouseEvent(aOwner, aPresContext,
  15. aEvent ? aEvent :
  16. new WidgetMouseScrollEvent(false, eVoidEvent, nullptr))
  17. {
  18. if (aEvent) {
  19. mEventIsInternal = false;
  20. } else {
  21. mEventIsInternal = true;
  22. mEvent->mTime = PR_Now();
  23. mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
  24. static_cast<WidgetMouseEventBase*>(mEvent)->inputSource =
  25. nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
  26. }
  27. mDetail = mEvent->AsMouseScrollEvent()->mDelta;
  28. }
  29. NS_IMPL_ADDREF_INHERITED(MouseScrollEvent, MouseEvent)
  30. NS_IMPL_RELEASE_INHERITED(MouseScrollEvent, MouseEvent)
  31. NS_INTERFACE_MAP_BEGIN(MouseScrollEvent)
  32. NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
  33. void
  34. MouseScrollEvent::InitMouseScrollEvent(const nsAString& aType,
  35. bool aCanBubble,
  36. bool aCancelable,
  37. nsGlobalWindow* aView,
  38. int32_t aDetail,
  39. int32_t aScreenX,
  40. int32_t aScreenY,
  41. int32_t aClientX,
  42. int32_t aClientY,
  43. bool aCtrlKey,
  44. bool aAltKey,
  45. bool aShiftKey,
  46. bool aMetaKey,
  47. uint16_t aButton,
  48. EventTarget* aRelatedTarget,
  49. int32_t aAxis)
  50. {
  51. NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
  52. MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
  53. aScreenX, aScreenY, aClientX, aClientY,
  54. aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton,
  55. aRelatedTarget);
  56. mEvent->AsMouseScrollEvent()->mIsHorizontal =
  57. (aAxis == nsIDOMMouseScrollEvent::HORIZONTAL_AXIS);
  58. }
  59. int32_t
  60. MouseScrollEvent::Axis()
  61. {
  62. return mEvent->AsMouseScrollEvent()->mIsHorizontal ?
  63. static_cast<int32_t>(nsIDOMMouseScrollEvent::HORIZONTAL_AXIS) :
  64. static_cast<int32_t>(nsIDOMMouseScrollEvent::VERTICAL_AXIS);
  65. }
  66. } // namespace dom
  67. } // namespace mozilla
  68. using namespace mozilla;
  69. using namespace dom;
  70. already_AddRefed<MouseScrollEvent>
  71. NS_NewDOMMouseScrollEvent(EventTarget* aOwner,
  72. nsPresContext* aPresContext,
  73. WidgetMouseScrollEvent* aEvent)
  74. {
  75. RefPtr<MouseScrollEvent> it =
  76. new MouseScrollEvent(aOwner, aPresContext, aEvent);
  77. return it.forget();
  78. }