Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2011 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #define LOG_TAG "InputListener" |
michael@0 | 18 | |
michael@0 | 19 | //#define LOG_NDEBUG 0 |
michael@0 | 20 | |
michael@0 | 21 | #include "InputListener.h" |
michael@0 | 22 | |
michael@0 | 23 | #include "cutils_log.h" |
michael@0 | 24 | |
michael@0 | 25 | namespace android { |
michael@0 | 26 | |
michael@0 | 27 | // --- NotifyConfigurationChangedArgs --- |
michael@0 | 28 | |
michael@0 | 29 | NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) : |
michael@0 | 30 | eventTime(eventTime) { |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs( |
michael@0 | 34 | const NotifyConfigurationChangedArgs& other) : |
michael@0 | 35 | eventTime(other.eventTime) { |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const { |
michael@0 | 39 | listener->notifyConfigurationChanged(this); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | // --- NotifyKeyArgs --- |
michael@0 | 44 | |
michael@0 | 45 | NotifyKeyArgs::NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, |
michael@0 | 46 | uint32_t policyFlags, |
michael@0 | 47 | int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, |
michael@0 | 48 | int32_t metaState, nsecs_t downTime) : |
michael@0 | 49 | eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags), |
michael@0 | 50 | action(action), flags(flags), keyCode(keyCode), scanCode(scanCode), |
michael@0 | 51 | metaState(metaState), downTime(downTime) { |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other) : |
michael@0 | 55 | eventTime(other.eventTime), deviceId(other.deviceId), source(other.source), |
michael@0 | 56 | policyFlags(other.policyFlags), |
michael@0 | 57 | action(other.action), flags(other.flags), |
michael@0 | 58 | keyCode(other.keyCode), scanCode(other.scanCode), |
michael@0 | 59 | metaState(other.metaState), downTime(other.downTime) { |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const { |
michael@0 | 63 | listener->notifyKey(this); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | // --- NotifyMotionArgs --- |
michael@0 | 68 | |
michael@0 | 69 | NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, |
michael@0 | 70 | uint32_t policyFlags, |
michael@0 | 71 | int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, |
michael@0 | 72 | int32_t edgeFlags, int32_t displayId, uint32_t pointerCount, |
michael@0 | 73 | const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, |
michael@0 | 74 | float xPrecision, float yPrecision, nsecs_t downTime) : |
michael@0 | 75 | eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags), |
michael@0 | 76 | action(action), flags(flags), metaState(metaState), buttonState(buttonState), |
michael@0 | 77 | edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount), |
michael@0 | 78 | xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) { |
michael@0 | 79 | for (uint32_t i = 0; i < pointerCount; i++) { |
michael@0 | 80 | this->pointerProperties[i].copyFrom(pointerProperties[i]); |
michael@0 | 81 | this->pointerCoords[i].copyFrom(pointerCoords[i]); |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) : |
michael@0 | 86 | eventTime(other.eventTime), deviceId(other.deviceId), source(other.source), |
michael@0 | 87 | policyFlags(other.policyFlags), |
michael@0 | 88 | action(other.action), flags(other.flags), |
michael@0 | 89 | metaState(other.metaState), buttonState(other.buttonState), |
michael@0 | 90 | edgeFlags(other.edgeFlags), displayId(other.displayId), |
michael@0 | 91 | pointerCount(other.pointerCount), |
michael@0 | 92 | xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) { |
michael@0 | 93 | for (uint32_t i = 0; i < pointerCount; i++) { |
michael@0 | 94 | pointerProperties[i].copyFrom(other.pointerProperties[i]); |
michael@0 | 95 | pointerCoords[i].copyFrom(other.pointerCoords[i]); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const { |
michael@0 | 100 | listener->notifyMotion(this); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | // --- NotifySwitchArgs --- |
michael@0 | 105 | |
michael@0 | 106 | NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags, |
michael@0 | 107 | uint32_t switchValues, uint32_t switchMask) : |
michael@0 | 108 | eventTime(eventTime), policyFlags(policyFlags), |
michael@0 | 109 | switchValues(switchValues), switchMask(switchMask) { |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) : |
michael@0 | 113 | eventTime(other.eventTime), policyFlags(other.policyFlags), |
michael@0 | 114 | switchValues(other.switchValues), switchMask(other.switchMask) { |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const { |
michael@0 | 118 | listener->notifySwitch(this); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | |
michael@0 | 122 | // --- NotifyDeviceResetArgs --- |
michael@0 | 123 | |
michael@0 | 124 | NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) : |
michael@0 | 125 | eventTime(eventTime), deviceId(deviceId) { |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) : |
michael@0 | 129 | eventTime(other.eventTime), deviceId(other.deviceId) { |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const { |
michael@0 | 133 | listener->notifyDeviceReset(this); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | |
michael@0 | 137 | // --- QueuedInputListener --- |
michael@0 | 138 | |
michael@0 | 139 | QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) : |
michael@0 | 140 | mInnerListener(innerListener) { |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | QueuedInputListener::~QueuedInputListener() { |
michael@0 | 144 | size_t count = mArgsQueue.size(); |
michael@0 | 145 | for (size_t i = 0; i < count; i++) { |
michael@0 | 146 | delete mArgsQueue[i]; |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | void QueuedInputListener::notifyConfigurationChanged( |
michael@0 | 151 | const NotifyConfigurationChangedArgs* args) { |
michael@0 | 152 | mArgsQueue.push(new NotifyConfigurationChangedArgs(*args)); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) { |
michael@0 | 156 | mArgsQueue.push(new NotifyKeyArgs(*args)); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) { |
michael@0 | 160 | mArgsQueue.push(new NotifyMotionArgs(*args)); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) { |
michael@0 | 164 | mArgsQueue.push(new NotifySwitchArgs(*args)); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) { |
michael@0 | 168 | mArgsQueue.push(new NotifyDeviceResetArgs(*args)); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | void QueuedInputListener::flush() { |
michael@0 | 172 | size_t count = mArgsQueue.size(); |
michael@0 | 173 | for (size_t i = 0; i < count; i++) { |
michael@0 | 174 | NotifyArgs* args = mArgsQueue[i]; |
michael@0 | 175 | args->notify(mInnerListener); |
michael@0 | 176 | delete args; |
michael@0 | 177 | } |
michael@0 | 178 | mArgsQueue.clear(); |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | |
michael@0 | 182 | } // namespace android |