Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "TouchedWindow.h" |
| 18 | |
| 19 | #include <android-base/stringprintf.h> |
| 20 | #include <input/PrintTools.h> |
| 21 | |
| 22 | using android::base::StringPrintf; |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | namespace inputdispatcher { |
| 27 | |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame^] | 28 | bool TouchedWindow::hasHoveringPointers() const { |
| 29 | return !mHoveringPointerIdsByDevice.empty(); |
| 30 | } |
| 31 | |
| 32 | void TouchedWindow::clearHoveringPointers() { |
| 33 | mHoveringPointerIdsByDevice.clear(); |
| 34 | } |
| 35 | |
| 36 | bool TouchedWindow::hasHoveringPointer(int32_t deviceId, int32_t pointerId) const { |
| 37 | auto it = mHoveringPointerIdsByDevice.find(deviceId); |
| 38 | if (it == mHoveringPointerIdsByDevice.end()) { |
| 39 | return false; |
| 40 | } |
| 41 | return it->second.test(pointerId); |
| 42 | } |
| 43 | |
| 44 | void TouchedWindow::addHoveringPointer(int32_t deviceId, int32_t pointerId) { |
| 45 | const auto [it, _] = mHoveringPointerIdsByDevice.insert({deviceId, {}}); |
| 46 | it->second.set(pointerId); |
| 47 | } |
| 48 | |
| 49 | void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) { |
| 50 | const auto it = mHoveringPointerIdsByDevice.find(deviceId); |
| 51 | if (it == mHoveringPointerIdsByDevice.end()) { |
| 52 | return; |
| 53 | } |
| 54 | it->second.set(pointerId, false); |
| 55 | |
| 56 | if (it->second.none()) { |
| 57 | mHoveringPointerIdsByDevice.erase(deviceId); |
| 58 | } |
| 59 | } |
| 60 | |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 61 | std::string TouchedWindow::dump() const { |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame^] | 62 | std::string out; |
| 63 | std::string hoveringPointers = |
| 64 | dumpMap(mHoveringPointerIdsByDevice, constToString, bitsetToString); |
| 65 | out += StringPrintf("name='%s', pointerIds=0x%0x, targetFlags=%s, firstDownTimeInTarget=%s, " |
| 66 | "mHoveringPointerIdsByDevice=%s\n", |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 67 | windowHandle->getName().c_str(), pointerIds.value, |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame^] | 68 | targetFlags.string().c_str(), toString(firstDownTimeInTarget).c_str(), |
| 69 | hoveringPointers.c_str()); |
| 70 | return out; |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace inputdispatcher |
| 74 | } // namespace android |