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_NPEventUnix_h michael@0: #define mozilla_dom_plugins_NPEventUnix_h 1 michael@0: michael@0: #include "npapi.h" michael@0: michael@0: #ifdef MOZ_X11 michael@0: #include "mozilla/X11Util.h" michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace plugins { michael@0: michael@0: struct NPRemoteEvent { michael@0: NPEvent event; michael@0: }; michael@0: michael@0: } michael@0: michael@0: } michael@0: michael@0: michael@0: // michael@0: // XEvent is defined as a union of all more specific X*Events. michael@0: // Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer michael@0: // field contained in any of these specific X*Event structs is a michael@0: // |Display*|. So to simplify serializing these XEvents, we make the michael@0: // michael@0: // ********** XXX ASSUMPTION XXX ********** michael@0: // michael@0: // that the process to which the event is forwarded shares the same michael@0: // display as the process on which the event originated. michael@0: // michael@0: // With this simplification, serialization becomes a simple memcpy to michael@0: // the output stream. Deserialization starts as just a memcpy from michael@0: // the input stream, BUT we then have to write the correct |Display*| michael@0: // into the right field of each X*Event that contains one. michael@0: // michael@0: michael@0: namespace IPC { michael@0: michael@0: template <> michael@0: struct ParamTraits // synonym for XEvent 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->WriteBytes(&aParam, sizeof(paramType)); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: const char* bytes = 0; michael@0: michael@0: if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) { michael@0: return false; michael@0: } michael@0: michael@0: memcpy(aResult, bytes, sizeof(paramType)); michael@0: michael@0: #ifdef MOZ_X11 michael@0: SetXDisplay(aResult->event); michael@0: #endif michael@0: return true; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: // TODO michael@0: aLog->append(L"(XEvent)"); michael@0: } michael@0: michael@0: #ifdef MOZ_X11 michael@0: private: michael@0: static void SetXDisplay(XEvent& ev) michael@0: { michael@0: Display* display = mozilla::DefaultXDisplay(); michael@0: if (ev.type >= KeyPress) { michael@0: ev.xany.display = display; michael@0: } michael@0: else { michael@0: // XXX assuming that this is an error event michael@0: // (type == 0? not clear from Xlib.h) michael@0: ev.xerror.display = display; michael@0: } michael@0: } michael@0: #endif michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: michael@0: #endif // ifndef mozilla_dom_plugins_NPEventX11_h