dom/plugins/ipc/NPEventOSX.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial