Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 "nsStringGlue.h"
18 class nsIContent;
20 namespace mozilla {
22 /******************************************************************************
23 * mozilla::InternalScrollPortEvent
24 ******************************************************************************/
26 class InternalScrollPortEvent : public WidgetGUIEvent
27 {
28 public:
29 virtual InternalScrollPortEvent* AsScrollPortEvent() MOZ_OVERRIDE
30 {
31 return this;
32 }
34 enum orientType
35 {
36 vertical = 0,
37 horizontal = 1,
38 both = 2
39 };
41 InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage,
42 nsIWidget* aWidget) :
43 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLPORT_EVENT),
44 orient(vertical)
45 {
46 }
48 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
49 {
50 MOZ_ASSERT(eventStructType == NS_SCROLLPORT_EVENT,
51 "Duplicate() must be overridden by sub class");
52 // Not copying widget, it is a weak reference.
53 InternalScrollPortEvent* result =
54 new InternalScrollPortEvent(false, message, nullptr);
55 result->AssignScrollPortEventData(*this, true);
56 result->mFlags = mFlags;
57 return result;
58 }
60 orientType orient;
62 void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent,
63 bool aCopyTargets)
64 {
65 AssignGUIEventData(aEvent, aCopyTargets);
67 orient = aEvent.orient;
68 }
69 };
71 /******************************************************************************
72 * mozilla::InternalScrollPortEvent
73 ******************************************************************************/
75 class InternalScrollAreaEvent : public WidgetGUIEvent
76 {
77 public:
78 virtual InternalScrollAreaEvent* AsScrollAreaEvent() MOZ_OVERRIDE
79 {
80 return this;
81 }
83 InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage,
84 nsIWidget* aWidget) :
85 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT)
86 {
87 }
89 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
90 {
91 MOZ_ASSERT(eventStructType == NS_SCROLLAREA_EVENT,
92 "Duplicate() must be overridden by sub class");
93 // Not copying widget, it is a weak reference.
94 InternalScrollAreaEvent* result =
95 new InternalScrollAreaEvent(false, message, nullptr);
96 result->AssignScrollAreaEventData(*this, true);
97 result->mFlags = mFlags;
98 return result;
99 }
101 nsRect mArea;
103 void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent,
104 bool aCopyTargets)
105 {
106 AssignGUIEventData(aEvent, aCopyTargets);
108 mArea = aEvent.mArea;
109 }
110 };
112 /******************************************************************************
113 * mozilla::InternalFormEvent
114 *
115 * We hold the originating form control for form submit and reset events.
116 * originator is a weak pointer (does not hold a strong reference).
117 ******************************************************************************/
119 class InternalFormEvent : public WidgetEvent
120 {
121 public:
122 virtual InternalFormEvent* AsFormEvent() MOZ_OVERRIDE { return this; }
124 InternalFormEvent(bool aIsTrusted, uint32_t aMessage) :
125 WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT),
126 originator(nullptr)
127 {
128 }
130 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
131 {
132 MOZ_ASSERT(eventStructType == NS_FORM_EVENT,
133 "Duplicate() must be overridden by sub class");
134 InternalFormEvent* result = new InternalFormEvent(false, message);
135 result->AssignFormEventData(*this, true);
136 result->mFlags = mFlags;
137 return result;
138 }
140 nsIContent *originator;
142 void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets)
143 {
144 AssignEventData(aEvent, aCopyTargets);
146 // Don't copy originator due to a weak pointer.
147 }
148 };
150 /******************************************************************************
151 * mozilla::InternalClipboardEvent
152 ******************************************************************************/
154 class InternalClipboardEvent : public WidgetEvent
155 {
156 public:
157 virtual InternalClipboardEvent* AsClipboardEvent() MOZ_OVERRIDE
158 {
159 return this;
160 }
162 InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) :
163 WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT)
164 {
165 }
167 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
168 {
169 MOZ_ASSERT(eventStructType == NS_CLIPBOARD_EVENT,
170 "Duplicate() must be overridden by sub class");
171 InternalClipboardEvent* result = new InternalClipboardEvent(false, message);
172 result->AssignClipboardEventData(*this, true);
173 result->mFlags = mFlags;
174 return result;
175 }
177 nsCOMPtr<dom::DataTransfer> clipboardData;
179 void AssignClipboardEventData(const InternalClipboardEvent& aEvent,
180 bool aCopyTargets)
181 {
182 AssignEventData(aEvent, aCopyTargets);
184 clipboardData = aEvent.clipboardData;
185 }
186 };
188 /******************************************************************************
189 * mozilla::InternalFocusEvent
190 ******************************************************************************/
192 class InternalFocusEvent : public InternalUIEvent
193 {
194 public:
195 virtual InternalFocusEvent* AsFocusEvent() MOZ_OVERRIDE { return this; }
197 InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) :
198 InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT),
199 fromRaise(false), isRefocus(false)
200 {
201 }
203 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
204 {
205 MOZ_ASSERT(eventStructType == NS_FOCUS_EVENT,
206 "Duplicate() must be overridden by sub class");
207 InternalFocusEvent* result = new InternalFocusEvent(false, message);
208 result->AssignFocusEventData(*this, true);
209 result->mFlags = mFlags;
210 return result;
211 }
213 /// The possible related target
214 nsCOMPtr<dom::EventTarget> relatedTarget;
216 bool fromRaise;
217 bool isRefocus;
219 void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets)
220 {
221 AssignUIEventData(aEvent, aCopyTargets);
223 relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
224 fromRaise = aEvent.fromRaise;
225 isRefocus = aEvent.isRefocus;
226 }
227 };
229 /******************************************************************************
230 * mozilla::InternalTransitionEvent
231 ******************************************************************************/
233 class InternalTransitionEvent : public WidgetEvent
234 {
235 public:
236 virtual InternalTransitionEvent* AsTransitionEvent() MOZ_OVERRIDE
237 {
238 return this;
239 }
241 InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage)
242 : WidgetEvent(aIsTrusted, aMessage, NS_TRANSITION_EVENT)
243 , elapsedTime(0.0)
244 {
245 mFlags.mCancelable = false;
246 }
248 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
249 {
250 MOZ_ASSERT(eventStructType == NS_TRANSITION_EVENT,
251 "Duplicate() must be overridden by sub class");
252 InternalTransitionEvent* result =
253 new InternalTransitionEvent(false, message);
254 result->AssignTransitionEventData(*this, true);
255 result->mFlags = mFlags;
256 return result;
257 }
259 nsString propertyName;
260 float elapsedTime;
261 nsString pseudoElement;
263 void AssignTransitionEventData(const InternalTransitionEvent& aEvent,
264 bool aCopyTargets)
265 {
266 AssignEventData(aEvent, aCopyTargets);
268 propertyName = aEvent.propertyName;
269 elapsedTime = aEvent.elapsedTime;
270 pseudoElement = aEvent.pseudoElement;
271 }
272 };
274 /******************************************************************************
275 * mozilla::InternalAnimationEvent
276 ******************************************************************************/
278 class InternalAnimationEvent : public WidgetEvent
279 {
280 public:
281 virtual InternalAnimationEvent* AsAnimationEvent() MOZ_OVERRIDE
282 {
283 return this;
284 }
286 InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage)
287 : WidgetEvent(aIsTrusted, aMessage, NS_ANIMATION_EVENT)
288 , elapsedTime(0.0)
289 {
290 mFlags.mCancelable = false;
291 }
293 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
294 {
295 MOZ_ASSERT(eventStructType == NS_ANIMATION_EVENT,
296 "Duplicate() must be overridden by sub class");
297 InternalAnimationEvent* result = new InternalAnimationEvent(false, message);
298 result->AssignAnimationEventData(*this, true);
299 result->mFlags = mFlags;
300 return result;
301 }
303 nsString animationName;
304 float elapsedTime;
305 nsString pseudoElement;
307 void AssignAnimationEventData(const InternalAnimationEvent& aEvent,
308 bool aCopyTargets)
309 {
310 AssignEventData(aEvent, aCopyTargets);
312 animationName = aEvent.animationName;
313 elapsedTime = aEvent.elapsedTime;
314 pseudoElement = aEvent.pseudoElement;
315 }
316 };
318 } // namespace mozilla
320 #endif // mozilla_ContentEvents_h__