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 #include "CursorScrollAccumulator.h"
18 
19 #include "EventHub.h"
20 #include "InputDevice.h"
21 
22 namespace android {
23 
CursorScrollAccumulator()24 CursorScrollAccumulator::CursorScrollAccumulator() : mHaveRelWheel(false), mHaveRelHWheel(false) {
25     clearRelativeAxes();
26 }
27 
configure(InputDeviceContext & deviceContext)28 void CursorScrollAccumulator::configure(InputDeviceContext& deviceContext) {
29     mHaveRelWheel = deviceContext.hasRelativeAxis(REL_WHEEL);
30     mHaveRelHWheel = deviceContext.hasRelativeAxis(REL_HWHEEL);
31 }
32 
reset(InputDeviceContext & deviceContext)33 void CursorScrollAccumulator::reset(InputDeviceContext& deviceContext) {
34     clearRelativeAxes();
35 }
36 
clearRelativeAxes()37 void CursorScrollAccumulator::clearRelativeAxes() {
38     mRelWheel = 0;
39     mRelHWheel = 0;
40 }
41 
process(const RawEvent & rawEvent)42 void CursorScrollAccumulator::process(const RawEvent& rawEvent) {
43     if (rawEvent.type == EV_REL) {
44         switch (rawEvent.code) {
45             case REL_WHEEL:
46                 mRelWheel = rawEvent.value;
47                 break;
48             case REL_HWHEEL:
49                 mRelHWheel = rawEvent.value;
50                 break;
51         }
52     }
53 }
54 
finishSync()55 void CursorScrollAccumulator::finishSync() {
56     clearRelativeAxes();
57 }
58 
59 } // namespace android
60