dom/plugins/ipc/NPEventUnix.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:f8daac30855d
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
2 /* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_plugins_NPEventUnix_h
8 #define mozilla_dom_plugins_NPEventUnix_h 1
9
10 #include "npapi.h"
11
12 #ifdef MOZ_X11
13 #include "mozilla/X11Util.h"
14 #endif
15
16 namespace mozilla {
17
18 namespace plugins {
19
20 struct NPRemoteEvent {
21 NPEvent event;
22 };
23
24 }
25
26 }
27
28
29 //
30 // XEvent is defined as a union of all more specific X*Events.
31 // Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
32 // field contained in any of these specific X*Event structs is a
33 // |Display*|. So to simplify serializing these XEvents, we make the
34 //
35 // ********** XXX ASSUMPTION XXX **********
36 //
37 // that the process to which the event is forwarded shares the same
38 // display as the process on which the event originated.
39 //
40 // With this simplification, serialization becomes a simple memcpy to
41 // the output stream. Deserialization starts as just a memcpy from
42 // the input stream, BUT we then have to write the correct |Display*|
43 // into the right field of each X*Event that contains one.
44 //
45
46 namespace IPC {
47
48 template <>
49 struct ParamTraits<mozilla::plugins::NPRemoteEvent> // synonym for XEvent
50 {
51 typedef mozilla::plugins::NPRemoteEvent paramType;
52
53 static void Write(Message* aMsg, const paramType& aParam)
54 {
55 aMsg->WriteBytes(&aParam, sizeof(paramType));
56 }
57
58 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
59 {
60 const char* bytes = 0;
61
62 if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
63 return false;
64 }
65
66 memcpy(aResult, bytes, sizeof(paramType));
67
68 #ifdef MOZ_X11
69 SetXDisplay(aResult->event);
70 #endif
71 return true;
72 }
73
74 static void Log(const paramType& aParam, std::wstring* aLog)
75 {
76 // TODO
77 aLog->append(L"(XEvent)");
78 }
79
80 #ifdef MOZ_X11
81 private:
82 static void SetXDisplay(XEvent& ev)
83 {
84 Display* display = mozilla::DefaultXDisplay();
85 if (ev.type >= KeyPress) {
86 ev.xany.display = display;
87 }
88 else {
89 // XXX assuming that this is an error event
90 // (type == 0? not clear from Xlib.h)
91 ev.xerror.display = display;
92 }
93 }
94 #endif
95 };
96
97 } // namespace IPC
98
99
100 #endif // ifndef mozilla_dom_plugins_NPEventX11_h

mercurial