widget/gonk/libui/InputListener.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/InputListener.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     1.4 +/*
     1.5 + * Copyright (C) 2011 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef _UI_INPUT_LISTENER_H
    1.21 +#define _UI_INPUT_LISTENER_H
    1.22 +
    1.23 +#include "Input.h"
    1.24 +#include <utils/RefBase.h>
    1.25 +#include <utils/Vector.h>
    1.26 +
    1.27 +namespace android {
    1.28 +
    1.29 +class InputListenerInterface;
    1.30 +
    1.31 +
    1.32 +/* Superclass of all input event argument objects */
    1.33 +struct NotifyArgs {
    1.34 +    virtual ~NotifyArgs() { }
    1.35 +
    1.36 +    virtual void notify(const sp<InputListenerInterface>& listener) const = 0;
    1.37 +};
    1.38 +
    1.39 +
    1.40 +/* Describes a configuration change event. */
    1.41 +struct NotifyConfigurationChangedArgs : public NotifyArgs {
    1.42 +    nsecs_t eventTime;
    1.43 +
    1.44 +    inline NotifyConfigurationChangedArgs() { }
    1.45 +
    1.46 +    NotifyConfigurationChangedArgs(nsecs_t eventTime);
    1.47 +
    1.48 +    NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other);
    1.49 +
    1.50 +    virtual ~NotifyConfigurationChangedArgs() { }
    1.51 +
    1.52 +    virtual void notify(const sp<InputListenerInterface>& listener) const;
    1.53 +};
    1.54 +
    1.55 +
    1.56 +/* Describes a key event. */
    1.57 +struct NotifyKeyArgs : public NotifyArgs {
    1.58 +    nsecs_t eventTime;
    1.59 +    int32_t deviceId;
    1.60 +    uint32_t source;
    1.61 +    uint32_t policyFlags;
    1.62 +    int32_t action;
    1.63 +    int32_t flags;
    1.64 +    int32_t keyCode;
    1.65 +    int32_t scanCode;
    1.66 +    int32_t metaState;
    1.67 +    nsecs_t downTime;
    1.68 +
    1.69 +    inline NotifyKeyArgs() { }
    1.70 +
    1.71 +    NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
    1.72 +            int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
    1.73 +            int32_t metaState, nsecs_t downTime);
    1.74 +
    1.75 +    NotifyKeyArgs(const NotifyKeyArgs& other);
    1.76 +
    1.77 +    virtual ~NotifyKeyArgs() { }
    1.78 +
    1.79 +    virtual void notify(const sp<InputListenerInterface>& listener) const;
    1.80 +};
    1.81 +
    1.82 +
    1.83 +/* Describes a motion event. */
    1.84 +struct NotifyMotionArgs : public NotifyArgs {
    1.85 +    nsecs_t eventTime;
    1.86 +    int32_t deviceId;
    1.87 +    uint32_t source;
    1.88 +    uint32_t policyFlags;
    1.89 +    int32_t action;
    1.90 +    int32_t flags;
    1.91 +    int32_t metaState;
    1.92 +    int32_t buttonState;
    1.93 +    int32_t edgeFlags;
    1.94 +    int32_t displayId;
    1.95 +    uint32_t pointerCount;
    1.96 +    PointerProperties pointerProperties[MAX_POINTERS];
    1.97 +    PointerCoords pointerCoords[MAX_POINTERS];
    1.98 +    float xPrecision;
    1.99 +    float yPrecision;
   1.100 +    nsecs_t downTime;
   1.101 +
   1.102 +    inline NotifyMotionArgs() { }
   1.103 +
   1.104 +    NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
   1.105 +            int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
   1.106 +            int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
   1.107 +            const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
   1.108 +            float xPrecision, float yPrecision, nsecs_t downTime);
   1.109 +
   1.110 +    NotifyMotionArgs(const NotifyMotionArgs& other);
   1.111 +
   1.112 +    virtual ~NotifyMotionArgs() { }
   1.113 +
   1.114 +    virtual void notify(const sp<InputListenerInterface>& listener) const;
   1.115 +};
   1.116 +
   1.117 +
   1.118 +/* Describes a switch event. */
   1.119 +struct NotifySwitchArgs : public NotifyArgs {
   1.120 +    nsecs_t eventTime;
   1.121 +    uint32_t policyFlags;
   1.122 +    uint32_t switchValues;
   1.123 +    uint32_t switchMask;
   1.124 +
   1.125 +    inline NotifySwitchArgs() { }
   1.126 +
   1.127 +    NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
   1.128 +            uint32_t switchValues, uint32_t switchMask);
   1.129 +
   1.130 +    NotifySwitchArgs(const NotifySwitchArgs& other);
   1.131 +
   1.132 +    virtual ~NotifySwitchArgs() { }
   1.133 +
   1.134 +    virtual void notify(const sp<InputListenerInterface>& listener) const;
   1.135 +};
   1.136 +
   1.137 +
   1.138 +/* Describes a device reset event, such as when a device is added,
   1.139 + * reconfigured, or removed. */
   1.140 +struct NotifyDeviceResetArgs : public NotifyArgs {
   1.141 +    nsecs_t eventTime;
   1.142 +    int32_t deviceId;
   1.143 +
   1.144 +    inline NotifyDeviceResetArgs() { }
   1.145 +
   1.146 +    NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId);
   1.147 +
   1.148 +    NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other);
   1.149 +
   1.150 +    virtual ~NotifyDeviceResetArgs() { }
   1.151 +
   1.152 +    virtual void notify(const sp<InputListenerInterface>& listener) const;
   1.153 +};
   1.154 +
   1.155 +
   1.156 +/*
   1.157 + * The interface used by the InputReader to notify the InputListener about input events.
   1.158 + */
   1.159 +class InputListenerInterface : public virtual RefBase {
   1.160 +protected:
   1.161 +    InputListenerInterface() { }
   1.162 +    virtual ~InputListenerInterface() { }
   1.163 +
   1.164 +public:
   1.165 +    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
   1.166 +    virtual void notifyKey(const NotifyKeyArgs* args) = 0;
   1.167 +    virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
   1.168 +    virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
   1.169 +    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
   1.170 +};
   1.171 +
   1.172 +
   1.173 +/*
   1.174 + * An implementation of the listener interface that queues up and defers dispatch
   1.175 + * of decoded events until flushed.
   1.176 + */
   1.177 +class QueuedInputListener : public InputListenerInterface {
   1.178 +protected:
   1.179 +    virtual ~QueuedInputListener();
   1.180 +
   1.181 +public:
   1.182 +    QueuedInputListener(const sp<InputListenerInterface>& innerListener);
   1.183 +
   1.184 +    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
   1.185 +    virtual void notifyKey(const NotifyKeyArgs* args);
   1.186 +    virtual void notifyMotion(const NotifyMotionArgs* args);
   1.187 +    virtual void notifySwitch(const NotifySwitchArgs* args);
   1.188 +    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
   1.189 +
   1.190 +    void flush();
   1.191 +
   1.192 +private:
   1.193 +    sp<InputListenerInterface> mInnerListener;
   1.194 +    Vector<NotifyArgs*> mArgsQueue;
   1.195 +};
   1.196 +
   1.197 +} // namespace android
   1.198 +
   1.199 +#endif // _UI_INPUT_LISTENER_H

mercurial