blob: 28dad95d47fd1f11db06cfe38bce6bfa1d4c1e17 [file] [log] [blame]
Harry Cuttsb57f1702022-11-28 15:34:22 +00001/*
2 * Copyright 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 "FakePointerController.h"
18
Harry Cuttsce86cc32022-12-14 20:36:33 +000019#include <gtest/gtest.h>
20
Harry Cuttsb57f1702022-11-28 15:34:22 +000021namespace android {
22
23void FakePointerController::setBounds(float minX, float minY, float maxX, float maxY) {
24 mHaveBounds = true;
25 mMinX = minX;
26 mMinY = minY;
27 mMaxX = maxX;
28 mMaxY = maxY;
29}
30
31const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() {
32 return mSpotsByDisplay;
33}
34
35void FakePointerController::setPosition(float x, float y) {
36 mX = x;
37 mY = y;
38}
39
40void FakePointerController::setButtonState(int32_t buttonState) {
41 mButtonState = buttonState;
42}
43
44int32_t FakePointerController::getButtonState() const {
45 return mButtonState;
46}
47
48void FakePointerController::getPosition(float* outX, float* outY) const {
49 *outX = mX;
50 *outY = mY;
51}
52
53int32_t FakePointerController::getDisplayId() const {
54 return mDisplayId;
55}
56
57void FakePointerController::setDisplayViewport(const DisplayViewport& viewport) {
58 mDisplayId = viewport.displayId;
59}
60
Harry Cuttsce86cc32022-12-14 20:36:33 +000061void FakePointerController::assertPosition(float x, float y) {
62 float actualX, actualY;
63 getPosition(&actualX, &actualY);
64 ASSERT_NEAR(x, actualX, 1);
65 ASSERT_NEAR(y, actualY, 1);
66}
67
Seunghwan Choi356026c2023-02-01 14:37:25 +090068bool FakePointerController::isPointerShown() {
69 return mIsPointerShown;
70}
71
Harry Cuttsb57f1702022-11-28 15:34:22 +000072bool FakePointerController::getBounds(float* outMinX, float* outMinY, float* outMaxX,
73 float* outMaxY) const {
74 *outMinX = mMinX;
75 *outMinY = mMinY;
76 *outMaxX = mMaxX;
77 *outMaxY = mMaxY;
78 return mHaveBounds;
79}
80
81void FakePointerController::move(float deltaX, float deltaY) {
82 mX += deltaX;
83 if (mX < mMinX) mX = mMinX;
84 if (mX > mMaxX) mX = mMaxX;
85 mY += deltaY;
86 if (mY < mMinY) mY = mMinY;
87 if (mY > mMaxY) mY = mMaxY;
88}
89
Seunghwan Choi356026c2023-02-01 14:37:25 +090090void FakePointerController::fade(Transition) {
91 mIsPointerShown = false;
92}
93void FakePointerController::unfade(Transition) {
94 mIsPointerShown = true;
95}
96
Harry Cuttsb57f1702022-11-28 15:34:22 +000097void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
98 int32_t displayId) {
99 std::vector<int32_t> newSpots;
100 // Add spots for fingers that are down.
101 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
102 uint32_t id = idBits.clearFirstMarkedBit();
103 newSpots.push_back(id);
104 }
105
106 mSpotsByDisplay[displayId] = newSpots;
107}
108
109void FakePointerController::clearSpots() {
110 mSpotsByDisplay.clear();
111}
112
113} // namespace android