dom/plugins/ipc/NPEventOSX.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:eeea2d08c21b
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_NPEventOSX_h
8 #define mozilla_dom_plugins_NPEventOSX_h 1
9
10
11 #include "npapi.h"
12
13 namespace mozilla {
14
15 namespace plugins {
16
17 struct NPRemoteEvent {
18 NPCocoaEvent event;
19 double contentsScaleFactor;
20 };
21
22 } // namespace plugins
23
24 } // namespace mozilla
25
26 namespace IPC {
27
28 template <>
29 struct ParamTraits<mozilla::plugins::NPRemoteEvent>
30 {
31 typedef mozilla::plugins::NPRemoteEvent paramType;
32
33 static void Write(Message* aMsg, const paramType& aParam)
34 {
35 aMsg->WriteInt(aParam.event.type);
36 aMsg->WriteUInt32(aParam.event.version);
37 switch (aParam.event.type) {
38 case NPCocoaEventMouseDown:
39 case NPCocoaEventMouseUp:
40 case NPCocoaEventMouseMoved:
41 case NPCocoaEventMouseEntered:
42 case NPCocoaEventMouseExited:
43 case NPCocoaEventMouseDragged:
44 case NPCocoaEventScrollWheel:
45 aMsg->WriteUInt32(aParam.event.data.mouse.modifierFlags);
46 aMsg->WriteDouble(aParam.event.data.mouse.pluginX);
47 aMsg->WriteDouble(aParam.event.data.mouse.pluginY);
48 aMsg->WriteInt32(aParam.event.data.mouse.buttonNumber);
49 aMsg->WriteInt32(aParam.event.data.mouse.clickCount);
50 aMsg->WriteDouble(aParam.event.data.mouse.deltaX);
51 aMsg->WriteDouble(aParam.event.data.mouse.deltaY);
52 aMsg->WriteDouble(aParam.event.data.mouse.deltaZ);
53 break;
54 case NPCocoaEventKeyDown:
55 case NPCocoaEventKeyUp:
56 case NPCocoaEventFlagsChanged:
57 aMsg->WriteUInt32(aParam.event.data.key.modifierFlags);
58 WriteParam(aMsg, aParam.event.data.key.characters);
59 WriteParam(aMsg, aParam.event.data.key.charactersIgnoringModifiers);
60 aMsg->WriteUnsignedChar(aParam.event.data.key.isARepeat);
61 aMsg->WriteUInt16(aParam.event.data.key.keyCode);
62 break;
63 case NPCocoaEventFocusChanged:
64 case NPCocoaEventWindowFocusChanged:
65 aMsg->WriteUnsignedChar(aParam.event.data.focus.hasFocus);
66 break;
67 case NPCocoaEventDrawRect:
68 // We don't write out the context pointer, it would always be
69 // nullptr and is just filled in as such on the read.
70 aMsg->WriteDouble(aParam.event.data.draw.x);
71 aMsg->WriteDouble(aParam.event.data.draw.y);
72 aMsg->WriteDouble(aParam.event.data.draw.width);
73 aMsg->WriteDouble(aParam.event.data.draw.height);
74 break;
75 case NPCocoaEventTextInput:
76 WriteParam(aMsg, aParam.event.data.text.text);
77 break;
78 default:
79 NS_NOTREACHED("Attempted to serialize unknown event type.");
80 return;
81 }
82 aMsg->WriteDouble(aParam.contentsScaleFactor);
83 }
84
85 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
86 {
87 int type = 0;
88 if (!aMsg->ReadInt(aIter, &type)) {
89 return false;
90 }
91 aResult->event.type = static_cast<NPCocoaEventType>(type);
92
93 if (!aMsg->ReadUInt32(aIter, &aResult->event.version)) {
94 return false;
95 }
96
97 switch (aResult->event.type) {
98 case NPCocoaEventMouseDown:
99 case NPCocoaEventMouseUp:
100 case NPCocoaEventMouseMoved:
101 case NPCocoaEventMouseEntered:
102 case NPCocoaEventMouseExited:
103 case NPCocoaEventMouseDragged:
104 case NPCocoaEventScrollWheel:
105 if (!aMsg->ReadUInt32(aIter, &aResult->event.data.mouse.modifierFlags)) {
106 return false;
107 }
108 if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginX)) {
109 return false;
110 }
111 if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginY)) {
112 return false;
113 }
114 if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.buttonNumber)) {
115 return false;
116 }
117 if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.clickCount)) {
118 return false;
119 }
120 if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaX)) {
121 return false;
122 }
123 if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaY)) {
124 return false;
125 }
126 if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaZ)) {
127 return false;
128 }
129 break;
130 case NPCocoaEventKeyDown:
131 case NPCocoaEventKeyUp:
132 case NPCocoaEventFlagsChanged:
133 if (!aMsg->ReadUInt32(aIter, &aResult->event.data.key.modifierFlags)) {
134 return false;
135 }
136 if (!ReadParam(aMsg, aIter, &aResult->event.data.key.characters)) {
137 return false;
138 }
139 if (!ReadParam(aMsg, aIter, &aResult->event.data.key.charactersIgnoringModifiers)) {
140 return false;
141 }
142 if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.key.isARepeat)) {
143 return false;
144 }
145 if (!aMsg->ReadUInt16(aIter, &aResult->event.data.key.keyCode)) {
146 return false;
147 }
148 break;
149 case NPCocoaEventFocusChanged:
150 case NPCocoaEventWindowFocusChanged:
151 if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.focus.hasFocus)) {
152 return false;
153 }
154 break;
155 case NPCocoaEventDrawRect:
156 aResult->event.data.draw.context = nullptr;
157 if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.x)) {
158 return false;
159 }
160 if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.y)) {
161 return false;
162 }
163 if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.width)) {
164 return false;
165 }
166 if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.height)) {
167 return false;
168 }
169 break;
170 case NPCocoaEventTextInput:
171 if (!ReadParam(aMsg, aIter, &aResult->event.data.text.text)) {
172 return false;
173 }
174 break;
175 default:
176 NS_NOTREACHED("Attempted to de-serialize unknown event type.");
177 return false;
178 }
179 if (!aMsg->ReadDouble(aIter, &aResult->contentsScaleFactor)) {
180 return false;
181 }
182
183 return true;
184 }
185
186 static void Log(const paramType& aParam, std::wstring* aLog)
187 {
188 aLog->append(L"(NPCocoaEvent)");
189 }
190 };
191
192 } // namespace IPC
193
194 #endif // ifndef mozilla_dom_plugins_NPEventOSX_h

mercurial