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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Jim Chen <jchen@mozilla.com>
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsGUIEventIPC_h__
40 : #define nsGUIEventIPC_h__
41 :
42 : #include "IPC/IPCMessageUtils.h"
43 : #include "nsGUIEvent.h"
44 :
45 : namespace IPC
46 : {
47 :
48 : template<>
49 : struct ParamTraits<nsEvent>
50 : {
51 : typedef nsEvent paramType;
52 :
53 0 : static void Write(Message* aMsg, const paramType& aParam)
54 : {
55 0 : WriteParam(aMsg, aParam.eventStructType);
56 0 : WriteParam(aMsg, aParam.message);
57 0 : WriteParam(aMsg, aParam.refPoint);
58 0 : WriteParam(aMsg, aParam.time);
59 0 : WriteParam(aMsg, aParam.flags);
60 0 : }
61 :
62 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
63 : {
64 0 : return ReadParam(aMsg, aIter, &aResult->eventStructType) &&
65 0 : ReadParam(aMsg, aIter, &aResult->message) &&
66 0 : ReadParam(aMsg, aIter, &aResult->refPoint) &&
67 0 : ReadParam(aMsg, aIter, &aResult->time) &&
68 0 : ReadParam(aMsg, aIter, &aResult->flags);
69 : }
70 : };
71 :
72 : template<>
73 : struct ParamTraits<nsGUIEvent>
74 : {
75 : typedef nsGUIEvent paramType;
76 :
77 0 : static void Write(Message* aMsg, const paramType& aParam)
78 : {
79 0 : WriteParam(aMsg, static_cast<nsEvent>(aParam));
80 0 : }
81 :
82 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
83 : {
84 0 : return ReadParam(aMsg, aIter, static_cast<nsEvent*>(aResult));
85 : }
86 : };
87 :
88 : template<>
89 : struct ParamTraits<nsInputEvent>
90 : {
91 : typedef nsInputEvent paramType;
92 :
93 0 : static void Write(Message* aMsg, const paramType& aParam)
94 : {
95 0 : WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
96 0 : WriteParam(aMsg, aParam.isShift);
97 0 : WriteParam(aMsg, aParam.isControl);
98 0 : WriteParam(aMsg, aParam.isAlt);
99 0 : WriteParam(aMsg, aParam.isMeta);
100 0 : }
101 :
102 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
103 : {
104 0 : return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
105 0 : ReadParam(aMsg, aIter, &aResult->isShift) &&
106 0 : ReadParam(aMsg, aIter, &aResult->isControl) &&
107 0 : ReadParam(aMsg, aIter, &aResult->isAlt) &&
108 0 : ReadParam(aMsg, aIter, &aResult->isMeta);
109 : }
110 : };
111 :
112 : template<>
113 : struct ParamTraits<nsMouseEvent_base>
114 : {
115 : typedef nsMouseEvent_base paramType;
116 :
117 0 : static void Write(Message* aMsg, const paramType& aParam)
118 : {
119 0 : WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
120 0 : WriteParam(aMsg, aParam.button);
121 0 : WriteParam(aMsg, aParam.pressure);
122 0 : WriteParam(aMsg, aParam.inputSource);
123 0 : }
124 :
125 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
126 : {
127 0 : return ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
128 0 : ReadParam(aMsg, aIter, &aResult->button) &&
129 0 : ReadParam(aMsg, aIter, &aResult->pressure) &&
130 0 : ReadParam(aMsg, aIter, &aResult->inputSource);
131 : }
132 : };
133 :
134 : template<>
135 : struct ParamTraits<nsMouseScrollEvent>
136 : {
137 : typedef nsMouseScrollEvent paramType;
138 :
139 0 : static void Write(Message* aMsg, const paramType& aParam)
140 : {
141 0 : WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
142 0 : WriteParam(aMsg, aParam.scrollFlags);
143 0 : WriteParam(aMsg, aParam.delta);
144 0 : WriteParam(aMsg, aParam.scrollOverflow);
145 0 : }
146 :
147 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
148 : {
149 0 : return ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
150 0 : ReadParam(aMsg, aIter, &aResult->scrollFlags) &&
151 0 : ReadParam(aMsg, aIter, &aResult->delta) &&
152 0 : ReadParam(aMsg, aIter, &aResult->scrollOverflow);
153 : }
154 : };
155 :
156 :
157 : template<>
158 : struct ParamTraits<nsMouseEvent>
159 : {
160 : typedef nsMouseEvent paramType;
161 :
162 0 : static void Write(Message* aMsg, const paramType& aParam)
163 : {
164 0 : WriteParam(aMsg, static_cast<nsMouseEvent_base>(aParam));
165 0 : WriteParam(aMsg, aParam.ignoreRootScrollFrame);
166 0 : WriteParam(aMsg, (PRUint8) aParam.reason);
167 0 : WriteParam(aMsg, (PRUint8) aParam.context);
168 0 : WriteParam(aMsg, (PRUint8) aParam.exit);
169 0 : WriteParam(aMsg, aParam.clickCount);
170 0 : }
171 :
172 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
173 : {
174 : bool rv;
175 : PRUint8 reason, context, exit;
176 0 : rv = ReadParam(aMsg, aIter, static_cast<nsMouseEvent_base*>(aResult)) &&
177 0 : ReadParam(aMsg, aIter, &aResult->ignoreRootScrollFrame) &&
178 0 : ReadParam(aMsg, aIter, &reason) &&
179 0 : ReadParam(aMsg, aIter, &context) &&
180 0 : ReadParam(aMsg, aIter, &exit) &&
181 0 : ReadParam(aMsg, aIter, &aResult->clickCount);
182 0 : aResult->reason = static_cast<nsMouseEvent::reasonType>(reason);
183 0 : aResult->context = static_cast<nsMouseEvent::contextType>(context);
184 0 : aResult->exit = static_cast<nsMouseEvent::exitType>(exit);
185 0 : return rv;
186 : }
187 : };
188 :
189 : template<>
190 : struct ParamTraits<nsKeyEvent>
191 : {
192 : typedef nsKeyEvent paramType;
193 :
194 0 : static void Write(Message* aMsg, const paramType& aParam)
195 : {
196 0 : WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
197 0 : WriteParam(aMsg, aParam.keyCode);
198 0 : WriteParam(aMsg, aParam.charCode);
199 0 : WriteParam(aMsg, aParam.isChar);
200 0 : }
201 :
202 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
203 : {
204 0 : return ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) &&
205 0 : ReadParam(aMsg, aIter, &aResult->keyCode) &&
206 0 : ReadParam(aMsg, aIter, &aResult->charCode) &&
207 0 : ReadParam(aMsg, aIter, &aResult->isChar);
208 : }
209 : };
210 :
211 : template<>
212 : struct ParamTraits<nsTextRangeStyle>
213 : {
214 : typedef nsTextRangeStyle paramType;
215 :
216 0 : static void Write(Message* aMsg, const paramType& aParam)
217 : {
218 0 : WriteParam(aMsg, aParam.mDefinedStyles);
219 0 : WriteParam(aMsg, aParam.mLineStyle);
220 0 : WriteParam(aMsg, aParam.mIsBoldLine);
221 0 : WriteParam(aMsg, aParam.mForegroundColor);
222 0 : WriteParam(aMsg, aParam.mBackgroundColor);
223 0 : WriteParam(aMsg, aParam.mUnderlineColor);
224 0 : }
225 :
226 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
227 : {
228 0 : return ReadParam(aMsg, aIter, &aResult->mDefinedStyles) &&
229 0 : ReadParam(aMsg, aIter, &aResult->mLineStyle) &&
230 0 : ReadParam(aMsg, aIter, &aResult->mIsBoldLine) &&
231 0 : ReadParam(aMsg, aIter, &aResult->mForegroundColor) &&
232 0 : ReadParam(aMsg, aIter, &aResult->mBackgroundColor) &&
233 0 : ReadParam(aMsg, aIter, &aResult->mUnderlineColor);
234 : }
235 : };
236 :
237 : template<>
238 : struct ParamTraits<nsTextRange>
239 : {
240 : typedef nsTextRange paramType;
241 :
242 0 : static void Write(Message* aMsg, const paramType& aParam)
243 : {
244 0 : WriteParam(aMsg, aParam.mStartOffset);
245 0 : WriteParam(aMsg, aParam.mEndOffset);
246 0 : WriteParam(aMsg, aParam.mRangeType);
247 0 : WriteParam(aMsg, aParam.mRangeStyle);
248 0 : }
249 :
250 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
251 : {
252 0 : return ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
253 0 : ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
254 0 : ReadParam(aMsg, aIter, &aResult->mRangeType) &&
255 0 : ReadParam(aMsg, aIter, &aResult->mRangeStyle);
256 : }
257 : };
258 :
259 : template<>
260 : struct ParamTraits<nsTextEvent>
261 : {
262 : typedef nsTextEvent paramType;
263 :
264 0 : static void Write(Message* aMsg, const paramType& aParam)
265 : {
266 0 : WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
267 0 : WriteParam(aMsg, aParam.seqno);
268 0 : WriteParam(aMsg, aParam.theText);
269 0 : WriteParam(aMsg, aParam.isChar);
270 0 : WriteParam(aMsg, aParam.rangeCount);
271 0 : for (PRUint32 index = 0; index < aParam.rangeCount; index++)
272 0 : WriteParam(aMsg, aParam.rangeArray[index]);
273 0 : }
274 :
275 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
276 : {
277 0 : if (!ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) ||
278 0 : !ReadParam(aMsg, aIter, &aResult->seqno) ||
279 0 : !ReadParam(aMsg, aIter, &aResult->theText) ||
280 0 : !ReadParam(aMsg, aIter, &aResult->isChar) ||
281 0 : !ReadParam(aMsg, aIter, &aResult->rangeCount))
282 0 : return false;
283 :
284 0 : if (!aResult->rangeCount) {
285 0 : aResult->rangeArray = nsnull;
286 0 : return true;
287 : }
288 :
289 0 : aResult->rangeArray = new nsTextRange[aResult->rangeCount];
290 0 : if (!aResult->rangeArray)
291 0 : return false;
292 :
293 0 : for (PRUint32 index = 0; index < aResult->rangeCount; index++)
294 0 : if (!ReadParam(aMsg, aIter, &aResult->rangeArray[index])) {
295 0 : Free(*aResult);
296 0 : return false;
297 : }
298 0 : return true;
299 : }
300 :
301 0 : static void Free(const paramType& aResult)
302 : {
303 0 : if (aResult.rangeArray)
304 0 : delete [] aResult.rangeArray;
305 0 : }
306 : };
307 :
308 : template<>
309 : struct ParamTraits<nsCompositionEvent>
310 : {
311 : typedef nsCompositionEvent paramType;
312 :
313 0 : static void Write(Message* aMsg, const paramType& aParam)
314 : {
315 0 : WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
316 0 : WriteParam(aMsg, aParam.seqno);
317 0 : WriteParam(aMsg, aParam.data);
318 0 : }
319 :
320 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
321 : {
322 0 : return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
323 0 : ReadParam(aMsg, aIter, &aResult->seqno) &&
324 0 : ReadParam(aMsg, aIter, &aResult->data);
325 : }
326 : };
327 :
328 : template<>
329 : struct ParamTraits<nsQueryContentEvent>
330 : {
331 : typedef nsQueryContentEvent paramType;
332 :
333 : static void Write(Message* aMsg, const paramType& aParam)
334 : {
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);
351 : }
352 :
353 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
354 : {
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);
372 : }
373 : };
374 :
375 : template<>
376 : struct ParamTraits<nsSelectionEvent>
377 : {
378 : typedef nsSelectionEvent paramType;
379 :
380 0 : static void Write(Message* aMsg, const paramType& aParam)
381 : {
382 0 : WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
383 0 : WriteParam(aMsg, aParam.seqno);
384 0 : WriteParam(aMsg, aParam.mOffset);
385 0 : WriteParam(aMsg, aParam.mLength);
386 0 : WriteParam(aMsg, aParam.mReversed);
387 0 : WriteParam(aMsg, aParam.mExpandToClusterBoundary);
388 0 : WriteParam(aMsg, aParam.mSucceeded);
389 0 : }
390 :
391 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
392 : {
393 0 : return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
394 0 : ReadParam(aMsg, aIter, &aResult->seqno) &&
395 0 : ReadParam(aMsg, aIter, &aResult->mOffset) &&
396 0 : ReadParam(aMsg, aIter, &aResult->mLength) &&
397 0 : ReadParam(aMsg, aIter, &aResult->mReversed) &&
398 0 : ReadParam(aMsg, aIter, &aResult->mExpandToClusterBoundary) &&
399 0 : ReadParam(aMsg, aIter, &aResult->mSucceeded);
400 : }
401 : };
402 :
403 : template<>
404 : struct ParamTraits<nsIMEUpdatePreference>
405 : {
406 : typedef nsIMEUpdatePreference paramType;
407 :
408 0 : static void Write(Message* aMsg, const paramType& aParam)
409 : {
410 0 : WriteParam(aMsg, aParam.mWantUpdates);
411 0 : WriteParam(aMsg, aParam.mWantHints);
412 0 : }
413 :
414 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
415 : {
416 0 : return ReadParam(aMsg, aIter, &aResult->mWantUpdates) &&
417 0 : ReadParam(aMsg, aIter, &aResult->mWantHints);
418 : }
419 : };
420 :
421 : template<>
422 : struct ParamTraits<nsPluginEvent>
423 : {
424 : typedef nsPluginEvent paramType;
425 :
426 : static void Write(Message* aMsg, const paramType& aParam)
427 : {
428 : WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
429 : WriteParam(aMsg, aParam.retargetToFocusedDocument);
430 : }
431 :
432 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
433 : {
434 : return ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) &&
435 : ReadParam(aMsg, aIter, &aResult->retargetToFocusedDocument);
436 : }
437 : };
438 :
439 : } // namespace IPC
440 :
441 : #endif // nsGUIEventIPC_h__
442 :
|