dom/plugins/ipc/NPEventOSX.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/NPEventOSX.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,194 @@
     1.4 +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
     1.5 +/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_plugins_NPEventOSX_h
    1.11 +#define mozilla_dom_plugins_NPEventOSX_h 1
    1.12 +
    1.13 +
    1.14 +#include "npapi.h"
    1.15 +
    1.16 +namespace mozilla {
    1.17 +
    1.18 +namespace plugins {
    1.19 +
    1.20 +struct NPRemoteEvent {
    1.21 +    NPCocoaEvent event;
    1.22 +    double contentsScaleFactor;
    1.23 +};
    1.24 +
    1.25 +} // namespace plugins
    1.26 +
    1.27 +} // namespace mozilla
    1.28 +
    1.29 +namespace IPC {
    1.30 +
    1.31 +template <>
    1.32 +struct ParamTraits<mozilla::plugins::NPRemoteEvent>
    1.33 +{
    1.34 +    typedef mozilla::plugins::NPRemoteEvent paramType;
    1.35 +
    1.36 +    static void Write(Message* aMsg, const paramType& aParam)
    1.37 +    {
    1.38 +        aMsg->WriteInt(aParam.event.type);
    1.39 +        aMsg->WriteUInt32(aParam.event.version);
    1.40 +        switch (aParam.event.type) {
    1.41 +            case NPCocoaEventMouseDown:
    1.42 +            case NPCocoaEventMouseUp:
    1.43 +            case NPCocoaEventMouseMoved:
    1.44 +            case NPCocoaEventMouseEntered:
    1.45 +            case NPCocoaEventMouseExited:
    1.46 +            case NPCocoaEventMouseDragged:
    1.47 +            case NPCocoaEventScrollWheel:
    1.48 +                aMsg->WriteUInt32(aParam.event.data.mouse.modifierFlags);
    1.49 +                aMsg->WriteDouble(aParam.event.data.mouse.pluginX);
    1.50 +                aMsg->WriteDouble(aParam.event.data.mouse.pluginY);
    1.51 +                aMsg->WriteInt32(aParam.event.data.mouse.buttonNumber);
    1.52 +                aMsg->WriteInt32(aParam.event.data.mouse.clickCount);
    1.53 +                aMsg->WriteDouble(aParam.event.data.mouse.deltaX);
    1.54 +                aMsg->WriteDouble(aParam.event.data.mouse.deltaY);
    1.55 +                aMsg->WriteDouble(aParam.event.data.mouse.deltaZ);
    1.56 +                break;
    1.57 +            case NPCocoaEventKeyDown:
    1.58 +            case NPCocoaEventKeyUp:
    1.59 +            case NPCocoaEventFlagsChanged:
    1.60 +                aMsg->WriteUInt32(aParam.event.data.key.modifierFlags);
    1.61 +                WriteParam(aMsg, aParam.event.data.key.characters);
    1.62 +                WriteParam(aMsg, aParam.event.data.key.charactersIgnoringModifiers);
    1.63 +                aMsg->WriteUnsignedChar(aParam.event.data.key.isARepeat);
    1.64 +                aMsg->WriteUInt16(aParam.event.data.key.keyCode);
    1.65 +                break;
    1.66 +            case NPCocoaEventFocusChanged:
    1.67 +            case NPCocoaEventWindowFocusChanged:
    1.68 +                aMsg->WriteUnsignedChar(aParam.event.data.focus.hasFocus);
    1.69 +                break;
    1.70 +            case NPCocoaEventDrawRect:
    1.71 +                // We don't write out the context pointer, it would always be
    1.72 +                // nullptr and is just filled in as such on the read.
    1.73 +                aMsg->WriteDouble(aParam.event.data.draw.x);
    1.74 +                aMsg->WriteDouble(aParam.event.data.draw.y);
    1.75 +                aMsg->WriteDouble(aParam.event.data.draw.width);
    1.76 +                aMsg->WriteDouble(aParam.event.data.draw.height);
    1.77 +                break;
    1.78 +            case NPCocoaEventTextInput:
    1.79 +                WriteParam(aMsg, aParam.event.data.text.text);
    1.80 +                break;
    1.81 +            default:
    1.82 +                NS_NOTREACHED("Attempted to serialize unknown event type.");
    1.83 +                return;
    1.84 +        }
    1.85 +        aMsg->WriteDouble(aParam.contentsScaleFactor);
    1.86 +    }
    1.87 +
    1.88 +    static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    1.89 +    {
    1.90 +        int type = 0;
    1.91 +        if (!aMsg->ReadInt(aIter, &type)) {
    1.92 +            return false;
    1.93 +        }
    1.94 +        aResult->event.type = static_cast<NPCocoaEventType>(type);
    1.95 +
    1.96 +        if (!aMsg->ReadUInt32(aIter, &aResult->event.version)) {
    1.97 +            return false;
    1.98 +        }
    1.99 +
   1.100 +        switch (aResult->event.type) {
   1.101 +            case NPCocoaEventMouseDown:
   1.102 +            case NPCocoaEventMouseUp:
   1.103 +            case NPCocoaEventMouseMoved:
   1.104 +            case NPCocoaEventMouseEntered:
   1.105 +            case NPCocoaEventMouseExited:
   1.106 +            case NPCocoaEventMouseDragged:
   1.107 +            case NPCocoaEventScrollWheel:
   1.108 +                if (!aMsg->ReadUInt32(aIter, &aResult->event.data.mouse.modifierFlags)) {
   1.109 +                    return false;
   1.110 +                }
   1.111 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginX)) {
   1.112 +                    return false;
   1.113 +                }
   1.114 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.pluginY)) {
   1.115 +                    return false;
   1.116 +                }
   1.117 +                if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.buttonNumber)) {
   1.118 +                    return false;
   1.119 +                }
   1.120 +                if (!aMsg->ReadInt32(aIter, &aResult->event.data.mouse.clickCount)) {
   1.121 +                    return false;
   1.122 +                }
   1.123 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaX)) {
   1.124 +                    return false;
   1.125 +                }
   1.126 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaY)) {
   1.127 +                    return false;
   1.128 +                }
   1.129 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.mouse.deltaZ)) {
   1.130 +                    return false;
   1.131 +                }
   1.132 +                break;
   1.133 +            case NPCocoaEventKeyDown:
   1.134 +            case NPCocoaEventKeyUp:
   1.135 +            case NPCocoaEventFlagsChanged:
   1.136 +                if (!aMsg->ReadUInt32(aIter, &aResult->event.data.key.modifierFlags)) {
   1.137 +                    return false;
   1.138 +                }
   1.139 +                if (!ReadParam(aMsg, aIter, &aResult->event.data.key.characters)) {
   1.140 +                    return false;
   1.141 +                }
   1.142 +                if (!ReadParam(aMsg, aIter, &aResult->event.data.key.charactersIgnoringModifiers)) {
   1.143 +                    return false;
   1.144 +                }
   1.145 +                if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.key.isARepeat)) {
   1.146 +                    return false;
   1.147 +                }
   1.148 +                if (!aMsg->ReadUInt16(aIter, &aResult->event.data.key.keyCode)) {
   1.149 +                    return false;
   1.150 +                }
   1.151 +                break;
   1.152 +            case NPCocoaEventFocusChanged:
   1.153 +            case NPCocoaEventWindowFocusChanged:
   1.154 +                if (!aMsg->ReadUnsignedChar(aIter, &aResult->event.data.focus.hasFocus)) {
   1.155 +                    return false;
   1.156 +                }
   1.157 +                break;
   1.158 +            case NPCocoaEventDrawRect:
   1.159 +                aResult->event.data.draw.context = nullptr;
   1.160 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.x)) {
   1.161 +                    return false;
   1.162 +                }
   1.163 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.y)) {
   1.164 +                    return false;
   1.165 +                }
   1.166 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.width)) {
   1.167 +                    return false;
   1.168 +                }
   1.169 +                if (!aMsg->ReadDouble(aIter, &aResult->event.data.draw.height)) {
   1.170 +                    return false;
   1.171 +                }
   1.172 +                break;
   1.173 +            case NPCocoaEventTextInput:
   1.174 +                if (!ReadParam(aMsg, aIter, &aResult->event.data.text.text)) {
   1.175 +                    return false;
   1.176 +                }
   1.177 +                break;
   1.178 +            default:
   1.179 +                NS_NOTREACHED("Attempted to de-serialize unknown event type.");
   1.180 +                return false;
   1.181 +        }
   1.182 +        if (!aMsg->ReadDouble(aIter, &aResult->contentsScaleFactor)) {
   1.183 +            return false;
   1.184 +        }
   1.185 +
   1.186 +        return true;
   1.187 +    }
   1.188 +
   1.189 +    static void Log(const paramType& aParam, std::wstring* aLog)
   1.190 +    {
   1.191 +        aLog->append(L"(NPCocoaEvent)");
   1.192 +    }
   1.193 +};
   1.194 +
   1.195 +} // namespace IPC
   1.196 +
   1.197 +#endif // ifndef mozilla_dom_plugins_NPEventOSX_h

mercurial