1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include <stdint.h>
20 
21 namespace android {
22 
23 class InputDeviceContext;
24 struct RawEvent;
25 
26 /* Keeps track of cursor scrolling motions. */
27 
28 class CursorScrollAccumulator {
29 public:
30     CursorScrollAccumulator();
31     void configure(InputDeviceContext& deviceContext);
32     void reset(InputDeviceContext& deviceContext);
33 
34     void process(const RawEvent& rawEvent);
35     void finishSync();
36 
haveRelativeVWheel()37     inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
haveRelativeHWheel()38     inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
39 
getRelativeX()40     inline int32_t getRelativeX() const { return mRelX; }
getRelativeY()41     inline int32_t getRelativeY() const { return mRelY; }
getRelativeVWheel()42     inline int32_t getRelativeVWheel() const { return mRelWheel; }
getRelativeHWheel()43     inline int32_t getRelativeHWheel() const { return mRelHWheel; }
44 
45 private:
46     bool mHaveRelWheel;
47     bool mHaveRelHWheel;
48 
49     int32_t mRelX;
50     int32_t mRelY;
51     int32_t mRelWheel;
52     int32_t mRelHWheel;
53 
54     void clearRelativeAxes();
55 };
56 
57 } // namespace android
58