SimpleGestureEvent.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/SimpleGestureEvent.h"
  6. #include "mozilla/TouchEvents.h"
  7. #include "prtime.h"
  8. namespace mozilla {
  9. namespace dom {
  10. SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner,
  11. nsPresContext* aPresContext,
  12. WidgetSimpleGestureEvent* aEvent)
  13. : MouseEvent(aOwner, aPresContext,
  14. aEvent ? aEvent :
  15. new WidgetSimpleGestureEvent(false, eVoidEvent,
  16. nullptr))
  17. {
  18. NS_ASSERTION(mEvent->mClass == eSimpleGestureEventClass,
  19. "event type mismatch");
  20. if (aEvent) {
  21. mEventIsInternal = false;
  22. } else {
  23. mEventIsInternal = true;
  24. mEvent->mTime = PR_Now();
  25. mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
  26. static_cast<WidgetMouseEventBase*>(mEvent)->inputSource =
  27. nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
  28. }
  29. }
  30. NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent, MouseEvent)
  31. NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent, MouseEvent)
  32. NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent)
  33. NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent)
  34. NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
  35. uint32_t
  36. SimpleGestureEvent::AllowedDirections()
  37. {
  38. return mEvent->AsSimpleGestureEvent()->mAllowedDirections;
  39. }
  40. NS_IMETHODIMP
  41. SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections)
  42. {
  43. NS_ENSURE_ARG_POINTER(aAllowedDirections);
  44. *aAllowedDirections = AllowedDirections();
  45. return NS_OK;
  46. }
  47. NS_IMETHODIMP
  48. SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections)
  49. {
  50. mEvent->AsSimpleGestureEvent()->mAllowedDirections = aAllowedDirections;
  51. return NS_OK;
  52. }
  53. uint32_t
  54. SimpleGestureEvent::Direction()
  55. {
  56. return mEvent->AsSimpleGestureEvent()->mDirection;
  57. }
  58. NS_IMETHODIMP
  59. SimpleGestureEvent::GetDirection(uint32_t* aDirection)
  60. {
  61. NS_ENSURE_ARG_POINTER(aDirection);
  62. *aDirection = Direction();
  63. return NS_OK;
  64. }
  65. double
  66. SimpleGestureEvent::Delta()
  67. {
  68. return mEvent->AsSimpleGestureEvent()->mDelta;
  69. }
  70. NS_IMETHODIMP
  71. SimpleGestureEvent::GetDelta(double* aDelta)
  72. {
  73. NS_ENSURE_ARG_POINTER(aDelta);
  74. *aDelta = Delta();
  75. return NS_OK;
  76. }
  77. uint32_t
  78. SimpleGestureEvent::ClickCount()
  79. {
  80. return mEvent->AsSimpleGestureEvent()->mClickCount;
  81. }
  82. NS_IMETHODIMP
  83. SimpleGestureEvent::GetClickCount(uint32_t* aClickCount)
  84. {
  85. NS_ENSURE_ARG_POINTER(aClickCount);
  86. *aClickCount = ClickCount();
  87. return NS_OK;
  88. }
  89. void
  90. SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg,
  91. bool aCanBubbleArg,
  92. bool aCancelableArg,
  93. nsGlobalWindow* aViewArg,
  94. int32_t aDetailArg,
  95. int32_t aScreenX,
  96. int32_t aScreenY,
  97. int32_t aClientX,
  98. int32_t aClientY,
  99. bool aCtrlKeyArg,
  100. bool aAltKeyArg,
  101. bool aShiftKeyArg,
  102. bool aMetaKeyArg,
  103. uint16_t aButton,
  104. EventTarget* aRelatedTarget,
  105. uint32_t aAllowedDirectionsArg,
  106. uint32_t aDirectionArg,
  107. double aDeltaArg,
  108. uint32_t aClickCountArg)
  109. {
  110. NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
  111. MouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg,
  112. aViewArg, aDetailArg,
  113. aScreenX, aScreenY, aClientX, aClientY,
  114. aCtrlKeyArg, aAltKeyArg, aShiftKeyArg,
  115. aMetaKeyArg, aButton, aRelatedTarget);
  116. WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent();
  117. simpleGestureEvent->mAllowedDirections = aAllowedDirectionsArg;
  118. simpleGestureEvent->mDirection = aDirectionArg;
  119. simpleGestureEvent->mDelta = aDeltaArg;
  120. simpleGestureEvent->mClickCount = aClickCountArg;
  121. }
  122. } // namespace dom
  123. } // namespace mozilla
  124. using namespace mozilla;
  125. using namespace mozilla::dom;
  126. already_AddRefed<SimpleGestureEvent>
  127. NS_NewDOMSimpleGestureEvent(EventTarget* aOwner,
  128. nsPresContext* aPresContext,
  129. WidgetSimpleGestureEvent* aEvent)
  130. {
  131. RefPtr<SimpleGestureEvent> it =
  132. new SimpleGestureEvent(aOwner, aPresContext, aEvent);
  133. return it.forget();
  134. }