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_NPEventWindows_h michael@0: #define mozilla_dom_plugins_NPEventWindows_h 1 michael@0: michael@0: michael@0: #include "npapi.h" michael@0: namespace mozilla { michael@0: michael@0: namespace plugins { michael@0: michael@0: // We use an NPRemoteEvent struct so that we can store the extra data on michael@0: // the stack so that we don't need to worry about managing the memory. michael@0: struct NPRemoteEvent michael@0: { michael@0: NPEvent event; michael@0: union { michael@0: RECT rect; michael@0: WINDOWPOS windowpos; michael@0: } lParamData; michael@0: }; michael@0: michael@0: } michael@0: michael@0: } 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: // Make a non-const copy of aParam so that we can muck with michael@0: // its insides for tranport michael@0: paramType paramCopy; michael@0: michael@0: paramCopy.event = aParam.event; michael@0: michael@0: // We can't blindly ipc events because they may sometimes contain michael@0: // pointers to memory in the sending process. For example, the michael@0: // WM_IME_CONTROL with the IMC_GETCOMPOSITIONFONT message has lParam michael@0: // set to a pointer to a LOGFONT structure. michael@0: switch (paramCopy.event.event) { michael@0: case WM_WINDOWPOSCHANGED: michael@0: // The lParam parameter of WM_WINDOWPOSCHANGED holds a pointer to michael@0: // a WINDOWPOS structure that contains information about the michael@0: // window's new size and position michael@0: paramCopy.lParamData.windowpos = *(reinterpret_cast(paramCopy.event.lParam)); michael@0: break; michael@0: case WM_PAINT: michael@0: // The lParam parameter of WM_PAINT holds a pointer to an RECT michael@0: // structure specifying the bounding box of the update area. michael@0: paramCopy.lParamData.rect = *(reinterpret_cast(paramCopy.event.lParam)); michael@0: break; michael@0: michael@0: // the white list of events that we will ipc to the client michael@0: case WM_CHAR: michael@0: case WM_SYSCHAR: michael@0: michael@0: case WM_KEYUP: michael@0: case WM_SYSKEYUP: michael@0: michael@0: case WM_KEYDOWN: michael@0: case WM_SYSKEYDOWN: michael@0: michael@0: case WM_DEADCHAR: michael@0: case WM_SYSDEADCHAR: michael@0: case WM_CONTEXTMENU: michael@0: michael@0: case WM_CUT: michael@0: case WM_COPY: michael@0: case WM_PASTE: michael@0: case WM_CLEAR: michael@0: case WM_UNDO: michael@0: michael@0: case WM_MOUSELEAVE: michael@0: case WM_MOUSEMOVE: michael@0: case WM_LBUTTONDOWN: michael@0: case WM_MBUTTONDOWN: michael@0: case WM_RBUTTONDOWN: michael@0: case WM_LBUTTONUP: michael@0: case WM_MBUTTONUP: michael@0: case WM_RBUTTONUP: michael@0: case WM_LBUTTONDBLCLK: michael@0: case WM_MBUTTONDBLCLK: michael@0: case WM_RBUTTONDBLCLK: michael@0: michael@0: case WM_SETFOCUS: michael@0: case WM_KILLFOCUS: michael@0: break; michael@0: michael@0: default: michael@0: // RegisterWindowMessage events should be passed. michael@0: if (paramCopy.event.event >= 0xC000) michael@0: break; michael@0: michael@0: // FIXME/bug 567465: temporarily work around unhandled michael@0: // events by forwarding a "dummy event". The eventual michael@0: // fix will be to stop trying to send these events michael@0: // entirely. michael@0: paramCopy.event.event = WM_NULL; michael@0: break; michael@0: } michael@0: michael@0: aMsg->WriteBytes(¶mCopy, 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: memcpy(aResult, bytes, sizeof(paramType)); michael@0: michael@0: if (aResult->event.event == WM_PAINT) { michael@0: // restore the lParam to point at the RECT michael@0: aResult->event.lParam = reinterpret_cast(&aResult->lParamData.rect); michael@0: } else if (aResult->event.event == WM_WINDOWPOSCHANGED) { michael@0: // restore the lParam to point at the WINDOWPOS michael@0: aResult->event.lParam = reinterpret_cast(&aResult->lParamData.windowpos); 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"(WINEvent)"); michael@0: } michael@0: michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // ifndef mozilla_dom_plugins_NPEventWindows_h