blob: ad311f9c7af4b8c3314aa52cd598f79ad75d5c71 [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
Prabir Pradhan2719e822023-02-28 17:39:36 +000048FloatPoint FakePointerController::getPosition() const {
49 return {mX, mY};
Harry Cuttsb57f1702022-11-28 15:34:22 +000050}
51
52int32_t FakePointerController::getDisplayId() const {
53 return mDisplayId;
54}
55
56void FakePointerController::setDisplayViewport(const DisplayViewport& viewport) {
57 mDisplayId = viewport.displayId;
58}
59
Harry Cuttsce86cc32022-12-14 20:36:33 +000060void FakePointerController::assertPosition(float x, float y) {
Prabir Pradhan2719e822023-02-28 17:39:36 +000061 const auto [actualX, actualY] = getPosition();
Harry Cuttsce86cc32022-12-14 20:36:33 +000062 ASSERT_NEAR(x, actualX, 1);
63 ASSERT_NEAR(y, actualY, 1);
64}
65
Seunghwan Choi356026c2023-02-01 14:37:25 +090066bool FakePointerController::isPointerShown() {
67 return mIsPointerShown;
68}
69
Prabir Pradhan2719e822023-02-28 17:39:36 +000070std::optional<FloatRect> FakePointerController::getBounds() const {
71 return mHaveBounds ? std::make_optional<FloatRect>(mMinX, mMinY, mMaxX, mMaxY) : std::nullopt;
Harry Cuttsb57f1702022-11-28 15:34:22 +000072}
73
74void FakePointerController::move(float deltaX, float deltaY) {
75 mX += deltaX;
76 if (mX < mMinX) mX = mMinX;
77 if (mX > mMaxX) mX = mMaxX;
78 mY += deltaY;
79 if (mY < mMinY) mY = mMinY;
80 if (mY > mMaxY) mY = mMaxY;
81}
82
Seunghwan Choi356026c2023-02-01 14:37:25 +090083void FakePointerController::fade(Transition) {
84 mIsPointerShown = false;
85}
86void FakePointerController::unfade(Transition) {
87 mIsPointerShown = true;
88}
89
Harry Cuttsb57f1702022-11-28 15:34:22 +000090void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
91 int32_t displayId) {
92 std::vector<int32_t> newSpots;
93 // Add spots for fingers that are down.
94 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
95 uint32_t id = idBits.clearFirstMarkedBit();
96 newSpots.push_back(id);
97 }
98
99 mSpotsByDisplay[displayId] = newSpots;
100}
101
102void FakePointerController::clearSpots() {
103 mSpotsByDisplay.clear();
104}
105
106} // namespace android