TouchEvent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifndef mozilla_dom_TouchEvent_h_
  6. #define mozilla_dom_TouchEvent_h_
  7. #include "mozilla/dom/Touch.h"
  8. #include "mozilla/dom/TouchEventBinding.h"
  9. #include "mozilla/dom/UIEvent.h"
  10. #include "mozilla/Attributes.h"
  11. #include "mozilla/EventForwards.h"
  12. #include "mozilla/TouchEvents.h"
  13. #include "nsJSEnvironment.h"
  14. #include "nsWrapperCache.h"
  15. class nsAString;
  16. namespace mozilla {
  17. namespace dom {
  18. class TouchList final : public nsISupports
  19. , public nsWrapperCache
  20. {
  21. public:
  22. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  23. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList)
  24. explicit TouchList(nsISupports* aParent)
  25. : mParent(aParent)
  26. {
  27. nsJSContext::LikelyShortLivingObjectCreated();
  28. }
  29. TouchList(nsISupports* aParent,
  30. const WidgetTouchEvent::TouchArray& aTouches)
  31. : mParent(aParent)
  32. , mPoints(aTouches)
  33. {
  34. nsJSContext::LikelyShortLivingObjectCreated();
  35. }
  36. void Append(Touch* aPoint)
  37. {
  38. mPoints.AppendElement(aPoint);
  39. }
  40. virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  41. nsISupports* GetParentObject() const
  42. {
  43. return mParent;
  44. }
  45. static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
  46. uint32_t Length() const
  47. {
  48. return mPoints.Length();
  49. }
  50. Touch* Item(uint32_t aIndex) const
  51. {
  52. return mPoints.SafeElementAt(aIndex);
  53. }
  54. Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const
  55. {
  56. aFound = aIndex < mPoints.Length();
  57. if (!aFound) {
  58. return nullptr;
  59. }
  60. return mPoints[aIndex];
  61. }
  62. protected:
  63. ~TouchList() {}
  64. nsCOMPtr<nsISupports> mParent;
  65. WidgetTouchEvent::TouchArray mPoints;
  66. };
  67. class TouchEvent : public UIEvent
  68. {
  69. public:
  70. TouchEvent(EventTarget* aOwner,
  71. nsPresContext* aPresContext,
  72. WidgetTouchEvent* aEvent);
  73. NS_DECL_ISUPPORTS_INHERITED
  74. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
  75. virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
  76. {
  77. return TouchEventBinding::Wrap(aCx, this, aGivenProto);
  78. }
  79. already_AddRefed<TouchList>
  80. CopyTouches(const Sequence<OwningNonNull<Touch>>& aTouches);
  81. TouchList* Touches();
  82. TouchList* TargetTouches();
  83. TouchList* ChangedTouches();
  84. bool AltKey();
  85. bool MetaKey();
  86. bool CtrlKey();
  87. bool ShiftKey();
  88. void InitTouchEvent(const nsAString& aType,
  89. bool aCanBubble,
  90. bool aCancelable,
  91. nsGlobalWindow* aView,
  92. int32_t aDetail,
  93. bool aCtrlKey,
  94. bool aAltKey,
  95. bool aShiftKey,
  96. bool aMetaKey,
  97. TouchList* aTouches,
  98. TouchList* aTargetTouches,
  99. TouchList* aChangedTouches);
  100. static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
  101. static bool PrefEnabled(nsIDocShell* aDocShell);
  102. static already_AddRefed<Event> Constructor(const GlobalObject& aGlobal,
  103. const nsAString& aType,
  104. const TouchEventInit& aParam,
  105. ErrorResult& aRv);
  106. protected:
  107. ~TouchEvent() {}
  108. RefPtr<TouchList> mTouches;
  109. RefPtr<TouchList> mTargetTouches;
  110. RefPtr<TouchList> mChangedTouches;
  111. };
  112. } // namespace dom
  113. } // namespace mozilla
  114. already_AddRefed<mozilla::dom::TouchEvent>
  115. NS_NewDOMTouchEvent(mozilla::dom::EventTarget* aOwner,
  116. nsPresContext* aPresContext,
  117. mozilla::WidgetTouchEvent* aEvent);
  118. #endif // mozilla_dom_TouchEvent_h_