Bug 1869043 assert that graph set access is main thread only r=padenot
[gecko.git] / widget / ContentEvents.h
blobe43de98c9f4515c1a1943f465641f1b548fb8b43
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/. */
6 #ifndef mozilla_ContentEvents_h__
7 #define mozilla_ContentEvents_h__
9 #include <stdint.h>
11 #include "mozilla/BasicEvents.h"
12 #include "mozilla/dom/DataTransfer.h"
13 #include "mozilla/dom/EventTarget.h"
14 #include "nsCOMPtr.h"
15 #include "nsRect.h"
16 #include "nsString.h"
18 class nsIContent;
20 namespace mozilla {
22 /******************************************************************************
23 * mozilla::InternalScrollPortEvent
24 ******************************************************************************/
26 class InternalScrollPortEvent : public WidgetGUIEvent {
27 public:
28 virtual InternalScrollPortEvent* AsScrollPortEvent() override { return this; }
30 enum OrientType { eVertical, eHorizontal, eBoth };
32 InternalScrollPortEvent(bool aIsTrusted, EventMessage aMessage,
33 nsIWidget* aWidget,
34 const WidgetEventTime* aTime = nullptr)
35 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollPortEventClass,
36 aTime),
37 mOrient(eVertical) {}
39 virtual WidgetEvent* Duplicate() const override {
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, this);
45 result->AssignScrollPortEventData(*this, true);
46 result->mFlags = mFlags;
47 return result;
50 OrientType mOrient;
52 void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent,
53 bool aCopyTargets) {
54 AssignGUIEventData(aEvent, aCopyTargets);
56 mOrient = aEvent.mOrient;
60 /******************************************************************************
61 * mozilla::InternalScrollPortEvent
62 ******************************************************************************/
64 class InternalScrollAreaEvent : public WidgetGUIEvent {
65 public:
66 virtual InternalScrollAreaEvent* AsScrollAreaEvent() override { return this; }
68 InternalScrollAreaEvent(bool aIsTrusted, EventMessage aMessage,
69 nsIWidget* aWidget,
70 const WidgetEventTime* aTime = nullptr)
71 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollAreaEventClass,
72 aTime) {}
74 virtual WidgetEvent* Duplicate() const override {
75 MOZ_ASSERT(mClass == eScrollAreaEventClass,
76 "Duplicate() must be overridden by sub class");
77 // Not copying widget, it is a weak reference.
78 InternalScrollAreaEvent* result =
79 new InternalScrollAreaEvent(false, mMessage, nullptr, this);
80 result->AssignScrollAreaEventData(*this, true);
81 result->mFlags = mFlags;
82 return result;
85 nsRect mArea;
87 void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent,
88 bool aCopyTargets) {
89 AssignGUIEventData(aEvent, aCopyTargets);
91 mArea = aEvent.mArea;
95 /******************************************************************************
96 * mozilla::InternalFormEvent
98 * We hold the originating form control for form submit and reset events.
99 * mOriginator is a weak pointer (does not hold a strong reference).
100 ******************************************************************************/
102 class InternalFormEvent : public WidgetEvent {
103 public:
104 virtual InternalFormEvent* AsFormEvent() override { return this; }
106 InternalFormEvent(bool aIsTrusted, EventMessage aMessage,
107 const WidgetEventTime* aTime = nullptr)
108 : WidgetEvent(aIsTrusted, aMessage, eFormEventClass, aTime),
109 mOriginator(nullptr) {}
111 virtual WidgetEvent* Duplicate() const override {
112 MOZ_ASSERT(mClass == eFormEventClass,
113 "Duplicate() must be overridden by sub class");
114 InternalFormEvent* result = new InternalFormEvent(false, mMessage, this);
115 result->AssignFormEventData(*this, true);
116 result->mFlags = mFlags;
117 return result;
120 nsIContent* mOriginator;
122 void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets) {
123 AssignEventData(aEvent, aCopyTargets);
125 // Don't copy mOriginator due to a weak pointer.
129 /******************************************************************************
130 * mozilla::InternalClipboardEvent
131 ******************************************************************************/
133 class InternalClipboardEvent : public WidgetEvent {
134 public:
135 virtual InternalClipboardEvent* AsClipboardEvent() override { return this; }
137 InternalClipboardEvent(bool aIsTrusted, EventMessage aMessage,
138 const WidgetEventTime* aTime = nullptr)
139 : WidgetEvent(aIsTrusted, aMessage, eClipboardEventClass, aTime) {}
141 virtual WidgetEvent* Duplicate() const override {
142 MOZ_ASSERT(mClass == eClipboardEventClass,
143 "Duplicate() must be overridden by sub class");
144 InternalClipboardEvent* result =
145 new InternalClipboardEvent(false, mMessage, this);
146 result->AssignClipboardEventData(*this, true);
147 result->mFlags = mFlags;
148 return result;
151 nsCOMPtr<dom::DataTransfer> mClipboardData;
153 void AssignClipboardEventData(const InternalClipboardEvent& aEvent,
154 bool aCopyTargets) {
155 AssignEventData(aEvent, aCopyTargets);
157 mClipboardData = aEvent.mClipboardData;
161 /******************************************************************************
162 * mozilla::InternalFocusEvent
163 ******************************************************************************/
165 class InternalFocusEvent : public InternalUIEvent {
166 public:
167 virtual InternalFocusEvent* AsFocusEvent() override { return this; }
169 InternalFocusEvent(bool aIsTrusted, EventMessage aMessage,
170 const WidgetEventTime* aTime = nullptr)
171 : InternalUIEvent(aIsTrusted, aMessage, eFocusEventClass, aTime),
172 mFromRaise(false),
173 mIsRefocus(false) {}
175 virtual WidgetEvent* Duplicate() const override {
176 MOZ_ASSERT(mClass == eFocusEventClass,
177 "Duplicate() must be overridden by sub class");
178 InternalFocusEvent* result = new InternalFocusEvent(false, mMessage, this);
179 result->AssignFocusEventData(*this, true);
180 result->mFlags = mFlags;
181 return result;
184 bool mFromRaise;
185 bool mIsRefocus;
187 void AssignFocusEventData(const InternalFocusEvent& aEvent,
188 bool aCopyTargets) {
189 AssignUIEventData(aEvent, aCopyTargets);
191 mFromRaise = aEvent.mFromRaise;
192 mIsRefocus = aEvent.mIsRefocus;
196 /******************************************************************************
197 * mozilla::InternalTransitionEvent
198 ******************************************************************************/
200 class InternalTransitionEvent : public WidgetEvent {
201 public:
202 virtual InternalTransitionEvent* AsTransitionEvent() override { return this; }
204 InternalTransitionEvent(bool aIsTrusted, EventMessage aMessage,
205 const WidgetEventTime* aTime = nullptr)
206 : WidgetEvent(aIsTrusted, aMessage, eTransitionEventClass, aTime),
207 mElapsedTime(0.0) {}
209 InternalTransitionEvent(const InternalTransitionEvent& aOther) = delete;
210 InternalTransitionEvent& operator=(const InternalTransitionEvent& aOther) =
211 delete;
212 InternalTransitionEvent(InternalTransitionEvent&& aOther) = default;
213 InternalTransitionEvent& operator=(InternalTransitionEvent&& aOther) =
214 default;
216 virtual WidgetEvent* Duplicate() const override {
217 MOZ_ASSERT(mClass == eTransitionEventClass,
218 "Duplicate() must be overridden by sub class");
219 InternalTransitionEvent* result =
220 new InternalTransitionEvent(false, mMessage, this);
221 result->AssignTransitionEventData(*this, true);
222 result->mFlags = mFlags;
223 return result;
226 nsString mPropertyName;
227 nsString mPseudoElement;
228 float mElapsedTime;
230 void AssignTransitionEventData(const InternalTransitionEvent& aEvent,
231 bool aCopyTargets) {
232 AssignEventData(aEvent, aCopyTargets);
234 mPropertyName = aEvent.mPropertyName;
235 mElapsedTime = aEvent.mElapsedTime;
236 mPseudoElement = aEvent.mPseudoElement;
240 /******************************************************************************
241 * mozilla::InternalAnimationEvent
242 ******************************************************************************/
244 class InternalAnimationEvent : public WidgetEvent {
245 public:
246 virtual InternalAnimationEvent* AsAnimationEvent() override { return this; }
248 InternalAnimationEvent(bool aIsTrusted, EventMessage aMessage,
249 const WidgetEventTime* aTime = nullptr)
250 : WidgetEvent(aIsTrusted, aMessage, eAnimationEventClass, aTime),
251 mElapsedTime(0.0) {}
253 InternalAnimationEvent(const InternalAnimationEvent& aOther) = delete;
254 InternalAnimationEvent& operator=(const InternalAnimationEvent& aOther) =
255 delete;
256 InternalAnimationEvent(InternalAnimationEvent&& aOther) = default;
257 InternalAnimationEvent& operator=(InternalAnimationEvent&& aOther) = default;
259 virtual WidgetEvent* Duplicate() const override {
260 MOZ_ASSERT(mClass == eAnimationEventClass,
261 "Duplicate() must be overridden by sub class");
262 InternalAnimationEvent* result =
263 new InternalAnimationEvent(false, mMessage, this);
264 result->AssignAnimationEventData(*this, true);
265 result->mFlags = mFlags;
266 return result;
269 nsString mAnimationName;
270 nsString mPseudoElement;
271 float mElapsedTime;
273 void AssignAnimationEventData(const InternalAnimationEvent& aEvent,
274 bool aCopyTargets) {
275 AssignEventData(aEvent, aCopyTargets);
277 mAnimationName = aEvent.mAnimationName;
278 mElapsedTime = aEvent.mElapsedTime;
279 mPseudoElement = aEvent.mPseudoElement;
283 /******************************************************************************
284 * mozilla::InternalSMILTimeEvent
285 ******************************************************************************/
287 class InternalSMILTimeEvent : public InternalUIEvent {
288 public:
289 virtual InternalSMILTimeEvent* AsSMILTimeEvent() override { return this; }
291 InternalSMILTimeEvent(bool aIsTrusted, EventMessage aMessage,
292 const WidgetEventTime* aTime = nullptr)
293 : InternalUIEvent(aIsTrusted, aMessage, eSMILTimeEventClass, aTime) {}
295 virtual WidgetEvent* Duplicate() const override {
296 MOZ_ASSERT(mClass == eSMILTimeEventClass,
297 "Duplicate() must be overridden by sub class");
298 InternalSMILTimeEvent* result =
299 new InternalSMILTimeEvent(false, mMessage, this);
300 result->AssignSMILTimeEventData(*this, true);
301 result->mFlags = mFlags;
302 return result;
305 void AssignSMILTimeEventData(const InternalSMILTimeEvent& aEvent,
306 bool aCopyTargets) {
307 AssignUIEventData(aEvent, aCopyTargets);
311 } // namespace mozilla
313 #endif // mozilla_ContentEvents_h__