ContentEvents.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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_ContentEvents_h__
  6. #define mozilla_ContentEvents_h__
  7. #include <stdint.h>
  8. #include "mozilla/BasicEvents.h"
  9. #include "mozilla/dom/DataTransfer.h"
  10. #include "mozilla/dom/EventTarget.h"
  11. #include "nsCOMPtr.h"
  12. #include "nsRect.h"
  13. #include "nsStringGlue.h"
  14. class nsIContent;
  15. namespace mozilla {
  16. /******************************************************************************
  17. * mozilla::InternalScrollPortEvent
  18. ******************************************************************************/
  19. class InternalScrollPortEvent : public WidgetGUIEvent
  20. {
  21. public:
  22. virtual InternalScrollPortEvent* AsScrollPortEvent() override
  23. {
  24. return this;
  25. }
  26. enum OrientType
  27. {
  28. eVertical,
  29. eHorizontal,
  30. eBoth
  31. };
  32. InternalScrollPortEvent(bool aIsTrusted, EventMessage aMessage,
  33. nsIWidget* aWidget)
  34. : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollPortEventClass)
  35. , mOrient(eVertical)
  36. {
  37. }
  38. virtual WidgetEvent* Duplicate() const override
  39. {
  40. MOZ_ASSERT(mClass == eScrollPortEventClass,
  41. "Duplicate() must be overridden by sub class");
  42. // Not copying widget, it is a weak reference.
  43. InternalScrollPortEvent* result =
  44. new InternalScrollPortEvent(false, mMessage, nullptr);
  45. result->AssignScrollPortEventData(*this, true);
  46. result->mFlags = mFlags;
  47. return result;
  48. }
  49. OrientType mOrient;
  50. void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent,
  51. bool aCopyTargets)
  52. {
  53. AssignGUIEventData(aEvent, aCopyTargets);
  54. mOrient = aEvent.mOrient;
  55. }
  56. };
  57. /******************************************************************************
  58. * mozilla::InternalScrollPortEvent
  59. ******************************************************************************/
  60. class InternalScrollAreaEvent : public WidgetGUIEvent
  61. {
  62. public:
  63. virtual InternalScrollAreaEvent* AsScrollAreaEvent() override
  64. {
  65. return this;
  66. }
  67. InternalScrollAreaEvent(bool aIsTrusted, EventMessage aMessage,
  68. nsIWidget* aWidget)
  69. : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollAreaEventClass)
  70. {
  71. }
  72. virtual WidgetEvent* Duplicate() const override
  73. {
  74. MOZ_ASSERT(mClass == eScrollAreaEventClass,
  75. "Duplicate() must be overridden by sub class");
  76. // Not copying widget, it is a weak reference.
  77. InternalScrollAreaEvent* result =
  78. new InternalScrollAreaEvent(false, mMessage, nullptr);
  79. result->AssignScrollAreaEventData(*this, true);
  80. result->mFlags = mFlags;
  81. return result;
  82. }
  83. nsRect mArea;
  84. void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent,
  85. bool aCopyTargets)
  86. {
  87. AssignGUIEventData(aEvent, aCopyTargets);
  88. mArea = aEvent.mArea;
  89. }
  90. };
  91. /******************************************************************************
  92. * mozilla::InternalFormEvent
  93. *
  94. * We hold the originating form control for form submit and reset events.
  95. * mOriginator is a weak pointer (does not hold a strong reference).
  96. ******************************************************************************/
  97. class InternalFormEvent : public WidgetEvent
  98. {
  99. public:
  100. virtual InternalFormEvent* AsFormEvent() override { return this; }
  101. InternalFormEvent(bool aIsTrusted, EventMessage aMessage)
  102. : WidgetEvent(aIsTrusted, aMessage, eFormEventClass)
  103. , mOriginator(nullptr)
  104. {
  105. }
  106. virtual WidgetEvent* Duplicate() const override
  107. {
  108. MOZ_ASSERT(mClass == eFormEventClass,
  109. "Duplicate() must be overridden by sub class");
  110. InternalFormEvent* result = new InternalFormEvent(false, mMessage);
  111. result->AssignFormEventData(*this, true);
  112. result->mFlags = mFlags;
  113. return result;
  114. }
  115. nsIContent* mOriginator;
  116. void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets)
  117. {
  118. AssignEventData(aEvent, aCopyTargets);
  119. // Don't copy mOriginator due to a weak pointer.
  120. }
  121. };
  122. /******************************************************************************
  123. * mozilla::InternalClipboardEvent
  124. ******************************************************************************/
  125. class InternalClipboardEvent : public WidgetEvent
  126. {
  127. public:
  128. virtual InternalClipboardEvent* AsClipboardEvent() override
  129. {
  130. return this;
  131. }
  132. InternalClipboardEvent(bool aIsTrusted, EventMessage aMessage)
  133. : WidgetEvent(aIsTrusted, aMessage, eClipboardEventClass)
  134. {
  135. }
  136. virtual WidgetEvent* Duplicate() const override
  137. {
  138. MOZ_ASSERT(mClass == eClipboardEventClass,
  139. "Duplicate() must be overridden by sub class");
  140. InternalClipboardEvent* result =
  141. new InternalClipboardEvent(false, mMessage);
  142. result->AssignClipboardEventData(*this, true);
  143. result->mFlags = mFlags;
  144. return result;
  145. }
  146. nsCOMPtr<dom::DataTransfer> mClipboardData;
  147. void AssignClipboardEventData(const InternalClipboardEvent& aEvent,
  148. bool aCopyTargets)
  149. {
  150. AssignEventData(aEvent, aCopyTargets);
  151. mClipboardData = aEvent.mClipboardData;
  152. }
  153. };
  154. /******************************************************************************
  155. * mozilla::InternalFocusEvent
  156. ******************************************************************************/
  157. class InternalFocusEvent : public InternalUIEvent
  158. {
  159. public:
  160. virtual InternalFocusEvent* AsFocusEvent() override { return this; }
  161. InternalFocusEvent(bool aIsTrusted, EventMessage aMessage)
  162. : InternalUIEvent(aIsTrusted, aMessage, eFocusEventClass)
  163. , mFromRaise(false)
  164. , mIsRefocus(false)
  165. {
  166. }
  167. virtual WidgetEvent* Duplicate() const override
  168. {
  169. MOZ_ASSERT(mClass == eFocusEventClass,
  170. "Duplicate() must be overridden by sub class");
  171. InternalFocusEvent* result = new InternalFocusEvent(false, mMessage);
  172. result->AssignFocusEventData(*this, true);
  173. result->mFlags = mFlags;
  174. return result;
  175. }
  176. bool mFromRaise;
  177. bool mIsRefocus;
  178. void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets)
  179. {
  180. AssignUIEventData(aEvent, aCopyTargets);
  181. mFromRaise = aEvent.mFromRaise;
  182. mIsRefocus = aEvent.mIsRefocus;
  183. }
  184. };
  185. /******************************************************************************
  186. * mozilla::InternalTransitionEvent
  187. ******************************************************************************/
  188. class InternalTransitionEvent : public WidgetEvent
  189. {
  190. public:
  191. virtual InternalTransitionEvent* AsTransitionEvent() override
  192. {
  193. return this;
  194. }
  195. InternalTransitionEvent(bool aIsTrusted, EventMessage aMessage)
  196. : WidgetEvent(aIsTrusted, aMessage, eTransitionEventClass)
  197. , mElapsedTime(0.0)
  198. {
  199. }
  200. virtual WidgetEvent* Duplicate() const override
  201. {
  202. MOZ_ASSERT(mClass == eTransitionEventClass,
  203. "Duplicate() must be overridden by sub class");
  204. InternalTransitionEvent* result =
  205. new InternalTransitionEvent(false, mMessage);
  206. result->AssignTransitionEventData(*this, true);
  207. result->mFlags = mFlags;
  208. return result;
  209. }
  210. nsString mPropertyName;
  211. nsString mPseudoElement;
  212. float mElapsedTime;
  213. void AssignTransitionEventData(const InternalTransitionEvent& aEvent,
  214. bool aCopyTargets)
  215. {
  216. AssignEventData(aEvent, aCopyTargets);
  217. mPropertyName = aEvent.mPropertyName;
  218. mElapsedTime = aEvent.mElapsedTime;
  219. mPseudoElement = aEvent.mPseudoElement;
  220. }
  221. };
  222. /******************************************************************************
  223. * mozilla::InternalAnimationEvent
  224. ******************************************************************************/
  225. class InternalAnimationEvent : public WidgetEvent
  226. {
  227. public:
  228. virtual InternalAnimationEvent* AsAnimationEvent() override
  229. {
  230. return this;
  231. }
  232. InternalAnimationEvent(bool aIsTrusted, EventMessage aMessage)
  233. : WidgetEvent(aIsTrusted, aMessage, eAnimationEventClass)
  234. , mElapsedTime(0.0)
  235. {
  236. }
  237. virtual WidgetEvent* Duplicate() const override
  238. {
  239. MOZ_ASSERT(mClass == eAnimationEventClass,
  240. "Duplicate() must be overridden by sub class");
  241. InternalAnimationEvent* result =
  242. new InternalAnimationEvent(false, mMessage);
  243. result->AssignAnimationEventData(*this, true);
  244. result->mFlags = mFlags;
  245. return result;
  246. }
  247. nsString mAnimationName;
  248. nsString mPseudoElement;
  249. float mElapsedTime;
  250. void AssignAnimationEventData(const InternalAnimationEvent& aEvent,
  251. bool aCopyTargets)
  252. {
  253. AssignEventData(aEvent, aCopyTargets);
  254. mAnimationName = aEvent.mAnimationName;
  255. mElapsedTime = aEvent.mElapsedTime;
  256. mPseudoElement = aEvent.mPseudoElement;
  257. }
  258. };
  259. /******************************************************************************
  260. * mozilla::InternalSVGZoomEvent
  261. ******************************************************************************/
  262. class InternalSVGZoomEvent : public WidgetGUIEvent
  263. {
  264. public:
  265. virtual InternalSVGZoomEvent* AsSVGZoomEvent() override { return this; }
  266. InternalSVGZoomEvent(bool aIsTrusted, EventMessage aMessage)
  267. : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eSVGZoomEventClass)
  268. {
  269. }
  270. virtual WidgetEvent* Duplicate() const override
  271. {
  272. MOZ_ASSERT(mClass == eSVGZoomEventClass,
  273. "Duplicate() must be overridden by sub class");
  274. // Not copying widget, it is a weak reference.
  275. InternalSVGZoomEvent* result = new InternalSVGZoomEvent(false, mMessage);
  276. result->AssignSVGZoomEventData(*this, true);
  277. result->mFlags = mFlags;
  278. return result;
  279. }
  280. void AssignSVGZoomEventData(const InternalSVGZoomEvent& aEvent,
  281. bool aCopyTargets)
  282. {
  283. AssignGUIEventData(aEvent, aCopyTargets);
  284. }
  285. };
  286. /******************************************************************************
  287. * mozilla::InternalSMILTimeEvent
  288. ******************************************************************************/
  289. class InternalSMILTimeEvent : public InternalUIEvent
  290. {
  291. public:
  292. virtual InternalSMILTimeEvent* AsSMILTimeEvent() override
  293. {
  294. return this;
  295. }
  296. InternalSMILTimeEvent(bool aIsTrusted, EventMessage aMessage)
  297. : InternalUIEvent(aIsTrusted, aMessage, eSMILTimeEventClass)
  298. {
  299. }
  300. virtual WidgetEvent* Duplicate() const override
  301. {
  302. MOZ_ASSERT(mClass == eSMILTimeEventClass,
  303. "Duplicate() must be overridden by sub class");
  304. InternalSMILTimeEvent* result = new InternalSMILTimeEvent(false, mMessage);
  305. result->AssignSMILTimeEventData(*this, true);
  306. result->mFlags = mFlags;
  307. return result;
  308. }
  309. void AssignSMILTimeEventData(const InternalSMILTimeEvent& aEvent,
  310. bool aCopyTargets)
  311. {
  312. AssignUIEventData(aEvent, aCopyTargets);
  313. }
  314. };
  315. } // namespace mozilla
  316. #endif // mozilla_ContentEvents_h__