Bug 732976 - SingleSourceFactory should generate checksums file. r=ted
[gecko.git] / widget / nsGUIEventIPC.h
blobeb748a994258a96c7283a3a295803e952d040fce
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * The Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Jim Chen <jchen@mozilla.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsGUIEventIPC_h__
40 #define nsGUIEventIPC_h__
42 #include "IPC/IPCMessageUtils.h"
43 #include "nsGUIEvent.h"
45 namespace IPC
48 template<>
49 struct ParamTraits<nsEvent>
51 typedef nsEvent paramType;
53 static void Write(Message* aMsg, const paramType& aParam)
55 WriteParam(aMsg, aParam.eventStructType);
56 WriteParam(aMsg, aParam.message);
57 WriteParam(aMsg, aParam.refPoint);
58 WriteParam(aMsg, aParam.time);
59 WriteParam(aMsg, aParam.flags);
62 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
64 return ReadParam(aMsg, aIter, &aResult->eventStructType) &&
65 ReadParam(aMsg, aIter, &aResult->message) &&
66 ReadParam(aMsg, aIter, &aResult->refPoint) &&
67 ReadParam(aMsg, aIter, &aResult->time) &&
68 ReadParam(aMsg, aIter, &aResult->flags);
72 template<>
73 struct ParamTraits<nsGUIEvent>
75 typedef nsGUIEvent paramType;
77 static void Write(Message* aMsg, const paramType& aParam)
79 WriteParam(aMsg, static_cast<nsEvent>(aParam));
82 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
84 return ReadParam(aMsg, aIter, static_cast<nsEvent*>(aResult));
88 template<>
89 struct ParamTraits<nsInputEvent>
91 typedef nsInputEvent paramType;
93 static void Write(Message* aMsg, const paramType& aParam)
95 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
96 WriteParam(aMsg, aParam.isShift);
97 WriteParam(aMsg, aParam.isControl);
98 WriteParam(aMsg, aParam.isAlt);
99 WriteParam(aMsg, aParam.isMeta);
102 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
104 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
105 ReadParam(aMsg, aIter, &aResult->isShift) &&
106 ReadParam(aMsg, aIter, &aResult->isControl) &&
107 ReadParam(aMsg, aIter, &aResult->isAlt) &&
108 ReadParam(aMsg, aIter, &aResult->isMeta);
112 template<>
113 struct ParamTraits<nsMouseEvent_base>
115 typedef nsMouseEvent_base paramType;
117 static void Write(Message* aMsg, const paramType& aParam)
119 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
120 WriteParam(aMsg, aParam.button);
121 WriteParam(aMsg, aParam.pressure);
122 WriteParam(aMsg, aParam.inputSource);
125 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
127 return ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
128 ReadParam(aMsg, aIter, &aResult->button) &&
129 ReadParam(aMsg, aIter, &aResult->pressure) &&
130 ReadParam(aMsg, aIter, &aResult->inputSource);
134 template<>
135 struct ParamTraits<nsMouseScrollEvent>
137 typedef nsMouseScrollEvent paramType;
139 static void Write(Message* aMsg, const paramType& aParam)
141 WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
142 WriteParam(aMsg, aParam.scrollFlags);
143 WriteParam(aMsg, aParam.delta);
144 WriteParam(aMsg, aParam.scrollOverflow);
147 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
149 return ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
150 ReadParam(aMsg, aIter, &aResult->scrollFlags) &&
151 ReadParam(aMsg, aIter, &aResult->delta) &&
152 ReadParam(aMsg, aIter, &aResult->scrollOverflow);
157 template<>
158 struct ParamTraits<nsMouseEvent>
160 typedef nsMouseEvent paramType;
162 static void Write(Message* aMsg, const paramType& aParam)
164 WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
165 WriteParam(aMsg, aParam.ignoreRootScrollFrame);
166 WriteParam(aMsg, (PRUint8) aParam.reason);
167 WriteParam(aMsg, (PRUint8) aParam.context);
168 WriteParam(aMsg, (PRUint8) aParam.exit);
169 WriteParam(aMsg, aParam.clickCount);
172 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
174 bool rv;
175 PRUint8 reason, context, exit;
176 rv = ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
177 ReadParam(aMsg, aIter, &aResult->ignoreRootScrollFrame) &&
178 ReadParam(aMsg, aIter, &reason) &&
179 ReadParam(aMsg, aIter, &context) &&
180 ReadParam(aMsg, aIter, &exit) &&
181 ReadParam(aMsg, aIter, &aResult->clickCount);
182 aResult->reason = static_cast<nsMouseEvent::reasonType>(reason);
183 aResult->context = static_cast<nsMouseEvent::contextType>(context);
184 aResult->exit = static_cast<nsMouseEvent::exitType>(exit);
185 return rv;
189 template<>
190 struct ParamTraits<nsKeyEvent>
192 typedef nsKeyEvent paramType;
194 static void Write(Message* aMsg, const paramType& aParam)
196 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
197 WriteParam(aMsg, aParam.keyCode);
198 WriteParam(aMsg, aParam.charCode);
199 WriteParam(aMsg, aParam.isChar);
202 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
204 return ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
205 ReadParam(aMsg, aIter, &aResult->keyCode) &&
206 ReadParam(aMsg, aIter, &aResult->charCode) &&
207 ReadParam(aMsg, aIter, &aResult->isChar);
211 template<>
212 struct ParamTraits<nsTextRangeStyle>
214 typedef nsTextRangeStyle paramType;
216 static void Write(Message* aMsg, const paramType& aParam)
218 WriteParam(aMsg, aParam.mDefinedStyles);
219 WriteParam(aMsg, aParam.mLineStyle);
220 WriteParam(aMsg, aParam.mIsBoldLine);
221 WriteParam(aMsg, aParam.mForegroundColor);
222 WriteParam(aMsg, aParam.mBackgroundColor);
223 WriteParam(aMsg, aParam.mUnderlineColor);
226 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
228 return ReadParam(aMsg, aIter, &aResult->mDefinedStyles) &&
229 ReadParam(aMsg, aIter, &aResult->mLineStyle) &&
230 ReadParam(aMsg, aIter, &aResult->mIsBoldLine) &&
231 ReadParam(aMsg, aIter, &aResult->mForegroundColor) &&
232 ReadParam(aMsg, aIter, &aResult->mBackgroundColor) &&
233 ReadParam(aMsg, aIter, &aResult->mUnderlineColor);
237 template<>
238 struct ParamTraits<nsTextRange>
240 typedef nsTextRange paramType;
242 static void Write(Message* aMsg, const paramType& aParam)
244 WriteParam(aMsg, aParam.mStartOffset);
245 WriteParam(aMsg, aParam.mEndOffset);
246 WriteParam(aMsg, aParam.mRangeType);
247 WriteParam(aMsg, aParam.mRangeStyle);
250 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
252 return ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
253 ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
254 ReadParam(aMsg, aIter, &aResult->mRangeType) &&
255 ReadParam(aMsg, aIter, &aResult->mRangeStyle);
259 template<>
260 struct ParamTraits<nsTextEvent>
262 typedef nsTextEvent paramType;
264 static void Write(Message* aMsg, const paramType& aParam)
266 WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
267 WriteParam(aMsg, aParam.seqno);
268 WriteParam(aMsg, aParam.theText);
269 WriteParam(aMsg, aParam.isChar);
270 WriteParam(aMsg, aParam.rangeCount);
271 for (PRUint32 index = 0; index < aParam.rangeCount; index++)
272 WriteParam(aMsg, aParam.rangeArray[index]);
275 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
277 if (!ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) ||
278 !ReadParam(aMsg, aIter, &aResult->seqno) ||
279 !ReadParam(aMsg, aIter, &aResult->theText) ||
280 !ReadParam(aMsg, aIter, &aResult->isChar) ||
281 !ReadParam(aMsg, aIter, &aResult->rangeCount))
282 return false;
284 if (!aResult->rangeCount) {
285 aResult->rangeArray = nsnull;
286 return true;
289 aResult->rangeArray = new nsTextRange[aResult->rangeCount];
290 if (!aResult->rangeArray)
291 return false;
293 for (PRUint32 index = 0; index < aResult->rangeCount; index++)
294 if (!ReadParam(aMsg, aIter, &aResult->rangeArray[index])) {
295 Free(*aResult);
296 return false;
298 return true;
301 static void Free(const paramType& aResult)
303 if (aResult.rangeArray)
304 delete [] aResult.rangeArray;
308 template<>
309 struct ParamTraits<nsCompositionEvent>
311 typedef nsCompositionEvent paramType;
313 static void Write(Message* aMsg, const paramType& aParam)
315 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
316 WriteParam(aMsg, aParam.seqno);
317 WriteParam(aMsg, aParam.data);
320 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
322 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
323 ReadParam(aMsg, aIter, &aResult->seqno) &&
324 ReadParam(aMsg, aIter, &aResult->data);
328 template<>
329 struct ParamTraits<nsQueryContentEvent>
331 typedef nsQueryContentEvent paramType;
333 static void Write(Message* aMsg, const paramType& aParam)
335 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
336 WriteParam(aMsg, aParam.mSucceeded);
337 WriteParam(aMsg, aParam.mInput.mOffset);
338 WriteParam(aMsg, aParam.mInput.mLength);
339 WriteParam(aMsg, *aParam.mInput.mMouseScrollEvent);
340 WriteParam(aMsg, aParam.mReply.mOffset);
341 WriteParam(aMsg, aParam.mReply.mString);
342 WriteParam(aMsg, aParam.mReply.mRect);
343 WriteParam(aMsg, aParam.mReply.mReversed);
344 WriteParam(aMsg, aParam.mReply.mHasSelection);
345 WriteParam(aMsg, aParam.mReply.mWidgetIsHit);
346 WriteParam(aMsg, aParam.mReply.mLineHeight);
347 WriteParam(aMsg, aParam.mReply.mPageHeight);
348 WriteParam(aMsg, aParam.mReply.mPageWidth);
349 WriteParam(aMsg, aParam.mReply.mComputedScrollAmount);
350 WriteParam(aMsg, aParam.mReply.mComputedScrollAction);
353 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
355 aResult->mWasAsync = true;
356 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
357 ReadParam(aMsg, aIter, &aResult->mSucceeded) &&
358 ReadParam(aMsg, aIter, &aResult->mInput.mOffset) &&
359 ReadParam(aMsg, aIter, &aResult->mInput.mLength) &&
360 ReadParam(aMsg, aIter, aResult->mInput.mMouseScrollEvent) &&
361 ReadParam(aMsg, aIter, &aResult->mReply.mOffset) &&
362 ReadParam(aMsg, aIter, &aResult->mReply.mString) &&
363 ReadParam(aMsg, aIter, &aResult->mReply.mRect) &&
364 ReadParam(aMsg, aIter, &aResult->mReply.mReversed) &&
365 ReadParam(aMsg, aIter, &aResult->mReply.mHasSelection) &&
366 ReadParam(aMsg, aIter, &aResult->mReply.mWidgetIsHit) &&
367 ReadParam(aMsg, aIter, &aResult->mReply.mLineHeight) &&
368 ReadParam(aMsg, aIter, &aResult->mReply.mPageHeight) &&
369 ReadParam(aMsg, aIter, &aResult->mReply.mPageWidth) &&
370 ReadParam(aMsg, aIter, &aResult->mReply.mComputedScrollAmount) &&
371 ReadParam(aMsg, aIter, &aResult->mReply.mComputedScrollAction);
375 template<>
376 struct ParamTraits<nsSelectionEvent>
378 typedef nsSelectionEvent paramType;
380 static void Write(Message* aMsg, const paramType& aParam)
382 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
383 WriteParam(aMsg, aParam.seqno);
384 WriteParam(aMsg, aParam.mOffset);
385 WriteParam(aMsg, aParam.mLength);
386 WriteParam(aMsg, aParam.mReversed);
387 WriteParam(aMsg, aParam.mExpandToClusterBoundary);
388 WriteParam(aMsg, aParam.mSucceeded);
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->mOffset) &&
396 ReadParam(aMsg, aIter, &aResult->mLength) &&
397 ReadParam(aMsg, aIter, &aResult->mReversed) &&
398 ReadParam(aMsg, aIter, &aResult->mExpandToClusterBoundary) &&
399 ReadParam(aMsg, aIter, &aResult->mSucceeded);
403 template<>
404 struct ParamTraits<nsIMEUpdatePreference>
406 typedef nsIMEUpdatePreference paramType;
408 static void Write(Message* aMsg, const paramType& aParam)
410 WriteParam(aMsg, aParam.mWantUpdates);
411 WriteParam(aMsg, aParam.mWantHints);
414 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
416 return ReadParam(aMsg, aIter, &aResult->mWantUpdates) &&
417 ReadParam(aMsg, aIter, &aResult->mWantHints);
421 template<>
422 struct ParamTraits<nsPluginEvent>
424 typedef nsPluginEvent paramType;
426 static void Write(Message* aMsg, const paramType& aParam)
428 WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
429 WriteParam(aMsg, aParam.retargetToFocusedDocument);
432 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
434 return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
435 ReadParam(aMsg, aIter, &aResult->retargetToFocusedDocument);
439 } // namespace IPC
441 #endif // nsGUIEventIPC_h__