bug 882865 - cryptojs key gen cleanup: use EqualsLiteral() r=bsmith r=Ms2ger r=khuey
[gecko.git] / widget / nsGUIEventIPC.h
blob101bea524fb36a193c7cb46441b41b01bf8deecb
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 nsGUIEventIPC_h__
7 #define nsGUIEventIPC_h__
9 #include "ipc/IPCMessageUtils.h"
10 #include "mozilla/dom/Touch.h"
11 #include "nsGUIEvent.h"
13 namespace IPC
16 template<>
17 struct ParamTraits<mozilla::widget::BaseEventFlags>
19 typedef mozilla::widget::BaseEventFlags paramType;
21 static void Write(Message* aMsg, const paramType& aParam)
23 aMsg->WriteBytes(&aParam, sizeof(aParam));
26 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
28 const char* outp;
29 if (!aMsg->ReadBytes(aIter, &outp, sizeof(*aResult))) {
30 return false;
32 *aResult = *reinterpret_cast<const paramType*>(outp);
33 return true;
37 template<>
38 struct ParamTraits<nsEvent>
40 typedef nsEvent paramType;
42 static void Write(Message* aMsg, const paramType& aParam)
44 WriteParam(aMsg, (uint8_t) aParam.eventStructType);
45 WriteParam(aMsg, aParam.message);
46 WriteParam(aMsg, aParam.refPoint);
47 WriteParam(aMsg, aParam.time);
48 WriteParam(aMsg, aParam.mFlags);
51 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
53 uint8_t eventStructType = 0;
54 bool ret = ReadParam(aMsg, aIter, &eventStructType) &&
55 ReadParam(aMsg, aIter, &aResult->message) &&
56 ReadParam(aMsg, aIter, &aResult->refPoint) &&
57 ReadParam(aMsg, aIter, &aResult->time) &&
58 ReadParam(aMsg, aIter, &aResult->mFlags);
59 aResult->eventStructType = static_cast<nsEventStructType>(eventStructType);
60 return ret;
64 template<>
65 struct ParamTraits<nsGUIEvent>
67 typedef nsGUIEvent paramType;
69 static void Write(Message* aMsg, const paramType& aParam)
71 WriteParam(aMsg, static_cast<nsEvent>(aParam));
74 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
76 return ReadParam(aMsg, aIter, static_cast<nsEvent*>(aResult));
80 template<>
81 struct ParamTraits<nsInputEvent>
83 typedef nsInputEvent paramType;
85 static void Write(Message* aMsg, const paramType& aParam)
87 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
88 WriteParam(aMsg, aParam.modifiers);
91 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
93 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
94 ReadParam(aMsg, aIter, &aResult->modifiers);
98 template<>
99 struct ParamTraits<nsMouseEvent_base>
101 typedef nsMouseEvent_base paramType;
103 static void Write(Message* aMsg, const paramType& aParam)
105 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
106 WriteParam(aMsg, aParam.button);
107 WriteParam(aMsg, aParam.buttons);
108 WriteParam(aMsg, aParam.pressure);
109 WriteParam(aMsg, aParam.inputSource);
112 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
114 return ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
115 ReadParam(aMsg, aIter, &aResult->button) &&
116 ReadParam(aMsg, aIter, &aResult->buttons) &&
117 ReadParam(aMsg, aIter, &aResult->pressure) &&
118 ReadParam(aMsg, aIter, &aResult->inputSource);
122 template<>
123 struct ParamTraits<mozilla::widget::WheelEvent>
125 typedef mozilla::widget::WheelEvent paramType;
127 static void Write(Message* aMsg, const paramType& aParam)
129 WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
130 WriteParam(aMsg, aParam.deltaX);
131 WriteParam(aMsg, aParam.deltaY);
132 WriteParam(aMsg, aParam.deltaZ);
133 WriteParam(aMsg, aParam.deltaMode);
134 WriteParam(aMsg, aParam.customizedByUserPrefs);
135 WriteParam(aMsg, aParam.isMomentum);
136 WriteParam(aMsg, aParam.isPixelOnlyDevice);
137 WriteParam(aMsg, aParam.lineOrPageDeltaX);
138 WriteParam(aMsg, aParam.lineOrPageDeltaY);
139 WriteParam(aMsg, static_cast<int32_t>(aParam.scrollType));
140 WriteParam(aMsg, aParam.overflowDeltaX);
141 WriteParam(aMsg, aParam.overflowDeltaY);
144 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
146 int32_t scrollType = 0;
147 bool rv =
148 ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
149 ReadParam(aMsg, aIter, &aResult->deltaX) &&
150 ReadParam(aMsg, aIter, &aResult->deltaY) &&
151 ReadParam(aMsg, aIter, &aResult->deltaZ) &&
152 ReadParam(aMsg, aIter, &aResult->deltaMode) &&
153 ReadParam(aMsg, aIter, &aResult->customizedByUserPrefs) &&
154 ReadParam(aMsg, aIter, &aResult->isMomentum) &&
155 ReadParam(aMsg, aIter, &aResult->isPixelOnlyDevice) &&
156 ReadParam(aMsg, aIter, &aResult->lineOrPageDeltaX) &&
157 ReadParam(aMsg, aIter, &aResult->lineOrPageDeltaY) &&
158 ReadParam(aMsg, aIter, &scrollType) &&
159 ReadParam(aMsg, aIter, &aResult->overflowDeltaX) &&
160 ReadParam(aMsg, aIter, &aResult->overflowDeltaY);
161 aResult->scrollType =
162 static_cast<mozilla::widget::WheelEvent::ScrollType>(scrollType);
163 return rv;
167 template<>
168 struct ParamTraits<nsMouseEvent>
170 typedef nsMouseEvent paramType;
172 static void Write(Message* aMsg, const paramType& aParam)
174 WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
175 WriteParam(aMsg, aParam.ignoreRootScrollFrame);
176 WriteParam(aMsg, (uint8_t) aParam.reason);
177 WriteParam(aMsg, (uint8_t) aParam.context);
178 WriteParam(aMsg, (uint8_t) aParam.exit);
179 WriteParam(aMsg, aParam.clickCount);
182 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
184 bool rv;
185 uint8_t reason = 0, context = 0, exit = 0;
186 rv = ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
187 ReadParam(aMsg, aIter, &aResult->ignoreRootScrollFrame) &&
188 ReadParam(aMsg, aIter, &reason) &&
189 ReadParam(aMsg, aIter, &context) &&
190 ReadParam(aMsg, aIter, &exit) &&
191 ReadParam(aMsg, aIter, &aResult->clickCount);
192 aResult->reason = static_cast<nsMouseEvent::reasonType>(reason);
193 aResult->context = static_cast<nsMouseEvent::contextType>(context);
194 aResult->exit = static_cast<nsMouseEvent::exitType>(exit);
195 return rv;
199 template<>
200 struct ParamTraits<nsTouchEvent>
202 typedef nsTouchEvent paramType;
204 static void Write(Message* aMsg, const paramType& aParam)
206 WriteParam(aMsg, static_cast<const nsInputEvent&>(aParam));
207 // Sigh, Touch bites us again! We want to be able to do
208 // WriteParam(aMsg, aParam.touches);
209 const nsTArray< nsRefPtr<mozilla::dom::Touch> >& touches = aParam.touches;
210 WriteParam(aMsg, touches.Length());
211 for (uint32_t i = 0; i < touches.Length(); ++i) {
212 mozilla::dom::Touch* touch = touches[i];
213 WriteParam(aMsg, touch->mIdentifier);
214 WriteParam(aMsg, touch->mRefPoint);
215 WriteParam(aMsg, touch->mRadius);
216 WriteParam(aMsg, touch->mRotationAngle);
217 WriteParam(aMsg, touch->mForce);
221 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
223 uint32_t numTouches;
224 if (!ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) ||
225 !ReadParam(aMsg, aIter, &numTouches)) {
226 return false;
228 for (uint32_t i = 0; i < numTouches; ++i) {
229 int32_t identifier;
230 nsIntPoint refPoint;
231 nsIntPoint radius;
232 float rotationAngle;
233 float force;
234 if (!ReadParam(aMsg, aIter, &identifier) ||
235 !ReadParam(aMsg, aIter, &refPoint) ||
236 !ReadParam(aMsg, aIter, &radius) ||
237 !ReadParam(aMsg, aIter, &rotationAngle) ||
238 !ReadParam(aMsg, aIter, &force)) {
239 return false;
241 aResult->touches.AppendElement(
242 new mozilla::dom::Touch(identifier, refPoint, radius, rotationAngle, force));
244 return true;
248 template<>
249 struct ParamTraits<nsKeyEvent>
251 typedef nsKeyEvent paramType;
253 static void Write(Message* aMsg, const paramType& aParam)
255 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
256 WriteParam(aMsg, static_cast<uint32_t>(aParam.mKeyNameIndex));
257 WriteParam(aMsg, aParam.keyCode);
258 WriteParam(aMsg, aParam.charCode);
259 WriteParam(aMsg, aParam.isChar);
260 WriteParam(aMsg, aParam.location);
261 // An OS-specific native event might be attached in |mNativeKeyEvent|, but
262 // that cannot be copied across process boundaries.
265 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
267 uint32_t keyNameIndex = 0;
268 if (ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
269 ReadParam(aMsg, aIter, &keyNameIndex) &&
270 ReadParam(aMsg, aIter, &aResult->keyCode) &&
271 ReadParam(aMsg, aIter, &aResult->charCode) &&
272 ReadParam(aMsg, aIter, &aResult->isChar) &&
273 ReadParam(aMsg, aIter, &aResult->location)) {
274 aResult->mKeyNameIndex =
275 static_cast<mozilla::widget::KeyNameIndex>(keyNameIndex);
276 return true;
278 return false;
282 template<>
283 struct ParamTraits<nsTextRangeStyle>
285 typedef nsTextRangeStyle paramType;
287 static void Write(Message* aMsg, const paramType& aParam)
289 WriteParam(aMsg, aParam.mDefinedStyles);
290 WriteParam(aMsg, aParam.mLineStyle);
291 WriteParam(aMsg, aParam.mIsBoldLine);
292 WriteParam(aMsg, aParam.mForegroundColor);
293 WriteParam(aMsg, aParam.mBackgroundColor);
294 WriteParam(aMsg, aParam.mUnderlineColor);
297 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
299 return ReadParam(aMsg, aIter, &aResult->mDefinedStyles) &&
300 ReadParam(aMsg, aIter, &aResult->mLineStyle) &&
301 ReadParam(aMsg, aIter, &aResult->mIsBoldLine) &&
302 ReadParam(aMsg, aIter, &aResult->mForegroundColor) &&
303 ReadParam(aMsg, aIter, &aResult->mBackgroundColor) &&
304 ReadParam(aMsg, aIter, &aResult->mUnderlineColor);
308 template<>
309 struct ParamTraits<nsTextRange>
311 typedef nsTextRange paramType;
313 static void Write(Message* aMsg, const paramType& aParam)
315 WriteParam(aMsg, aParam.mStartOffset);
316 WriteParam(aMsg, aParam.mEndOffset);
317 WriteParam(aMsg, aParam.mRangeType);
318 WriteParam(aMsg, aParam.mRangeStyle);
321 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
323 return ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
324 ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
325 ReadParam(aMsg, aIter, &aResult->mRangeType) &&
326 ReadParam(aMsg, aIter, &aResult->mRangeStyle);
330 template<>
331 struct ParamTraits<nsTextEvent>
333 typedef nsTextEvent paramType;
335 static void Write(Message* aMsg, const paramType& aParam)
337 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
338 WriteParam(aMsg, aParam.seqno);
339 WriteParam(aMsg, aParam.theText);
340 WriteParam(aMsg, aParam.isChar);
341 WriteParam(aMsg, aParam.rangeCount);
342 for (uint32_t index = 0; index < aParam.rangeCount; index++)
343 WriteParam(aMsg, aParam.rangeArray[index]);
346 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
348 if (!ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) ||
349 !ReadParam(aMsg, aIter, &aResult->seqno) ||
350 !ReadParam(aMsg, aIter, &aResult->theText) ||
351 !ReadParam(aMsg, aIter, &aResult->isChar) ||
352 !ReadParam(aMsg, aIter, &aResult->rangeCount))
353 return false;
355 if (!aResult->rangeCount) {
356 aResult->rangeArray = nullptr;
357 return true;
360 aResult->rangeArray = new nsTextRange[aResult->rangeCount];
361 if (!aResult->rangeArray)
362 return false;
364 for (uint32_t index = 0; index < aResult->rangeCount; index++)
365 if (!ReadParam(aMsg, aIter, &aResult->rangeArray[index])) {
366 Free(*aResult);
367 return false;
369 return true;
372 static void Free(const paramType& aResult)
374 if (aResult.rangeArray)
375 delete [] aResult.rangeArray;
379 template<>
380 struct ParamTraits<nsCompositionEvent>
382 typedef nsCompositionEvent paramType;
384 static void Write(Message* aMsg, const paramType& aParam)
386 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
387 WriteParam(aMsg, aParam.seqno);
388 WriteParam(aMsg, aParam.data);
391 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
393 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
394 ReadParam(aMsg, aIter, &aResult->seqno) &&
395 ReadParam(aMsg, aIter, &aResult->data);
399 template<>
400 struct ParamTraits<nsQueryContentEvent>
402 typedef nsQueryContentEvent paramType;
404 static void Write(Message* aMsg, const paramType& aParam)
406 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
407 WriteParam(aMsg, aParam.mSucceeded);
408 WriteParam(aMsg, aParam.mInput.mOffset);
409 WriteParam(aMsg, aParam.mInput.mLength);
410 WriteParam(aMsg, aParam.mReply.mOffset);
411 WriteParam(aMsg, aParam.mReply.mString);
412 WriteParam(aMsg, aParam.mReply.mRect);
413 WriteParam(aMsg, aParam.mReply.mReversed);
414 WriteParam(aMsg, aParam.mReply.mHasSelection);
415 WriteParam(aMsg, aParam.mReply.mWidgetIsHit);
418 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
420 aResult->mWasAsync = true;
421 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
422 ReadParam(aMsg, aIter, &aResult->mSucceeded) &&
423 ReadParam(aMsg, aIter, &aResult->mInput.mOffset) &&
424 ReadParam(aMsg, aIter, &aResult->mInput.mLength) &&
425 ReadParam(aMsg, aIter, &aResult->mReply.mOffset) &&
426 ReadParam(aMsg, aIter, &aResult->mReply.mString) &&
427 ReadParam(aMsg, aIter, &aResult->mReply.mRect) &&
428 ReadParam(aMsg, aIter, &aResult->mReply.mReversed) &&
429 ReadParam(aMsg, aIter, &aResult->mReply.mHasSelection) &&
430 ReadParam(aMsg, aIter, &aResult->mReply.mWidgetIsHit);
434 template<>
435 struct ParamTraits<nsSelectionEvent>
437 typedef nsSelectionEvent paramType;
439 static void Write(Message* aMsg, const paramType& aParam)
441 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
442 WriteParam(aMsg, aParam.seqno);
443 WriteParam(aMsg, aParam.mOffset);
444 WriteParam(aMsg, aParam.mLength);
445 WriteParam(aMsg, aParam.mReversed);
446 WriteParam(aMsg, aParam.mExpandToClusterBoundary);
447 WriteParam(aMsg, aParam.mSucceeded);
450 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
452 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
453 ReadParam(aMsg, aIter, &aResult->seqno) &&
454 ReadParam(aMsg, aIter, &aResult->mOffset) &&
455 ReadParam(aMsg, aIter, &aResult->mLength) &&
456 ReadParam(aMsg, aIter, &aResult->mReversed) &&
457 ReadParam(aMsg, aIter, &aResult->mExpandToClusterBoundary) &&
458 ReadParam(aMsg, aIter, &aResult->mSucceeded);
462 template<>
463 struct ParamTraits<nsIMEUpdatePreference>
465 typedef nsIMEUpdatePreference paramType;
467 static void Write(Message* aMsg, const paramType& aParam)
469 WriteParam(aMsg, aParam.mWantUpdates);
470 WriteParam(aMsg, aParam.mWantHints);
473 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
475 return ReadParam(aMsg, aIter, &aResult->mWantUpdates) &&
476 ReadParam(aMsg, aIter, &aResult->mWantHints);
480 template<>
481 struct ParamTraits<nsPluginEvent>
483 typedef nsPluginEvent paramType;
485 static void Write(Message* aMsg, const paramType& aParam)
487 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
488 WriteParam(aMsg, aParam.retargetToFocusedDocument);
491 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
493 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
494 ReadParam(aMsg, aIter, &aResult->retargetToFocusedDocument);
498 } // namespace IPC
500 #endif // nsGUIEventIPC_h__