michael@0: /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */ michael@0: /* vim: set sw=4 ts=8 et tw=80 ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_plugins_NPEventOSX_h michael@0: #define mozilla_dom_plugins_NPEventOSX_h 1 michael@0: michael@0: michael@0: #include "npapi.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace plugins { michael@0: michael@0: struct NPRemoteEvent { michael@0: NPCocoaEvent event; michael@0: double contentsScaleFactor; michael@0: }; michael@0: michael@0: } // namespace plugins michael@0: michael@0: } // namespace mozilla michael@0: michael@0: namespace IPC { michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::plugins::NPRemoteEvent paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: aMsg->WriteInt(aParam.event.type); michael@0: aMsg->WriteUInt32(aParam.event.version); michael@0: switch (aParam.event.type) { michael@0: case NPCocoaEventMouseDown: michael@0: case NPCocoaEventMouseUp: michael@0: case NPCocoaEventMouseMoved: michael@0: case NPCocoaEventMouseEntered: michael@0: case NPCocoaEventMouseExited: michael@0: case NPCocoaEventMouseDragged: michael@0: case NPCocoaEventScrollWheel: michael@0: aMsg->WriteUInt32(aParam.event.data.mouse.modifierFlags); michael@0: aMsg->WriteDouble(aParam.event.data.mouse.pluginX); michael@0: aMsg->WriteDouble(aParam.event.data.mouse.pluginY); michael@0: aMsg->WriteInt32(aParam.event.data.mouse.buttonNumber); michael@0: aMsg->WriteInt32(aParam.event.data.mouse.clickCount); michael@0: aMsg->WriteDouble(aParam.event.data.mouse.deltaX); michael@0: aMsg->WriteDouble(aParam.event.data.mouse.deltaY); michael@0: aMsg->WriteDouble(aParam.event.data.mouse.deltaZ); michael@0: break; michael@0: case NPCocoaEventKeyDown: michael@0: case NPCocoaEventKeyUp: michael@0: case NPCocoaEventFlagsChanged: michael@0: aMsg->WriteUInt32(aParam.event.data.key.modifierFlags); michael@0: WriteParam(aMsg, aParam.event.data.key.characters); michael@0: WriteParam(aMsg, aParam.event.data.key.charactersIgnoringModifiers); michael@0: aMsg->WriteUnsignedChar(aParam.event.data.key.isARepeat); michael@0: aMsg->WriteUInt16(aParam.event.data.key.keyCode); michael@0: break; michael@0: case NPCocoaEventFocusChanged: michael@0: case NPCocoaEventWindowFocusChanged: michael@0: aMsg->WriteUnsignedChar(aParam.event.data.focus.hasFocus); michael@0: break; michael@0: case NPCocoaEventDrawRect: michael@0: // We don't write out the context pointer, it would always be michael@0: // nullptr and is just filled in as such on the read. michael@0: aMsg->WriteDouble(aParam.event.data.draw.x); michael@0: aMsg->WriteDouble(aParam.event.data.draw.y); michael@0: aMsg->WriteDouble(aParam.event.data.draw.width); michael@0: aMsg->WriteDouble(aParam.event.data.draw.height); michael@0: break; michael@0: case NPCocoaEventTextInput: michael@0: WriteParam(aMsg, aParam.event.data.text.text); michael@0: break; michael@0: default: michael@0: NS_NOTREACHED("Attempted to serialize unknown event type."); michael@0: return; michael@0: } michael@0: aMsg->WriteDouble(aParam.contentsScaleFactor); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: int type = 0; michael@0: if (!aMsg->ReadInt(aIter, &type)) { michael@0: return false; michael@0: } michael@0: aResult->event.type = static_cast(type); michael@0: michael@0: if (!aMsg->ReadUInt32(aIter, &aResult->event.version)) { michael@0: return false; michael@0: } michael@0: michael@0: switch (aResult->event.type) { michael@0: case NPCocoaEventMouseDown: michael@0: case NPCocoaEventMouseUp: michael@0: case NPCocoaEventMouseMoved: michael@0: case NPCocoaEventMouseEntered: michael@0: case NPCocoaEventMouseExited: michael@0: case NPCocoaEventMouseDragged: michael@0: case NPCocoaEventScrollWheel: michael@0: if (!aMsg->ReadUInt32(aIter, &aResult->event.data.mouse.modifierFlags)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginX)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginY)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.buttonNumber)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.clickCount)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaX)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaY)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaZ)) { michael@0: return false; michael@0: } michael@0: break; michael@0: case NPCocoaEventKeyDown: michael@0: case NPCocoaEventKeyUp: michael@0: case NPCocoaEventFlagsChanged: michael@0: if (!aMsg->ReadUInt32(aIter, &aResult->event.data.key.modifierFlags)) { michael@0: return false; michael@0: } michael@0: if (!ReadParam(aMsg, aIter, &aResult->event.data.key.characters)) { michael@0: return false; michael@0: } michael@0: if (!ReadParam(aMsg, aIter, &aResult->event.data.key.charactersIgnoringModifiers)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.key.isARepeat)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadUInt16(aIter, &aResult->event.data.key.keyCode)) { michael@0: return false; michael@0: } michael@0: break; michael@0: case NPCocoaEventFocusChanged: michael@0: case NPCocoaEventWindowFocusChanged: michael@0: if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.focus.hasFocus)) { michael@0: return false; michael@0: } michael@0: break; michael@0: case NPCocoaEventDrawRect: michael@0: aResult->event.data.draw.context = nullptr; michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.x)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.y)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.width)) { michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.height)) { michael@0: return false; michael@0: } michael@0: break; michael@0: case NPCocoaEventTextInput: michael@0: if (!ReadParam(aMsg, aIter, &aResult->event.data.text.text)) { michael@0: return false; michael@0: } michael@0: break; michael@0: default: michael@0: NS_NOTREACHED("Attempted to de-serialize unknown event type."); michael@0: return false; michael@0: } michael@0: if (!aMsg->ReadDouble(aIter, &aResult->contentsScaleFactor)) { michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: aLog->append(L"(NPCocoaEvent)"); michael@0: } michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // ifndef mozilla_dom_plugins_NPEventOSX_h