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