1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "touch_event_normalize.h"
17 #include "gesture_transform_processor.h"
18 #include "input_device_manager.h"
19 #include "joystick_transform_processor.h"
20 #ifdef OHOS_BUILD_ENABLE_TOUCH
21 #include "tablet_tool_tranform_processor.h"
22 #include "touch_transform_processor.h"
23 #endif // OHOS_BUILD_ENABLE_TOUCH
24 #ifdef OHOS_BUILD_ENABLE_POINTER
25 #include "touchpad_transform_processor.h"
26 #endif // OHOS_BUILD_ENABLE_POINTER
27
28 #undef MMI_LOG_DOMAIN
29 #define MMI_LOG_DOMAIN MMI_LOG_DISPATCH
30 #undef MMI_LOG_TAG
31 #define MMI_LOG_TAG "TouchEventNormalize"
32
33 namespace OHOS {
34 namespace MMI {
TouchEventNormalize()35 TouchEventNormalize::TouchEventNormalize() {}
~TouchEventNormalize()36 TouchEventNormalize::~TouchEventNormalize() {}
37
OnLibInput(struct libinput_event * event,DeviceType deviceType)38 std::shared_ptr<PointerEvent> TouchEventNormalize::OnLibInput(struct libinput_event *event, DeviceType deviceType)
39 {
40 CHKPP(event);
41 auto device = libinput_event_get_device(event);
42 CHKPP(device);
43 std::shared_ptr<TransformProcessor> processor{ nullptr };
44 auto deviceId = INPUT_DEV_MGR->FindInputDeviceId(device);
45 if (auto it = processors_.find(deviceId); it != processors_.end()) {
46 processor = it->second;
47 } else {
48 processor = MakeTransformProcessor(deviceId, deviceType);
49 CHKPP(processor);
50 auto [tIter, isOk] = processors_.emplace(deviceId, processor);
51 if (!isOk) {
52 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
53 }
54 }
55 return processor->OnEvent(event);
56 }
57
MakeTransformProcessor(int32_t deviceId,DeviceType deviceType) const58 std::shared_ptr<TransformProcessor> TouchEventNormalize::MakeTransformProcessor(int32_t deviceId,
59 DeviceType deviceType) const
60 {
61 std::shared_ptr<TransformProcessor> processor{ nullptr };
62 switch (deviceType) {
63 #ifdef OHOS_BUILD_ENABLE_TOUCH
64 case DeviceType::TOUCH: {
65 processor = std::make_shared<TouchTransformProcessor>(deviceId);
66 break;
67 }
68 case DeviceType::TABLET_TOOL: {
69 processor = std::make_shared<TabletToolTransformProcessor>(deviceId);
70 break;
71 }
72 #endif // OHOS_BUILD_ENABLE_TOUCH
73 #ifdef OHOS_BUILD_ENABLE_POINTER
74 case DeviceType::TOUCH_PAD: {
75 processor = std::make_shared<TouchPadTransformProcessor>(deviceId);
76 break;
77 }
78 case DeviceType::GESTURE: {
79 processor = std::make_shared<GestureTransformProcessor>(deviceId);
80 break;
81 }
82 #endif // OHOS_BUILD_ENABLE_POINTER
83 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
84 case DeviceType::JOYSTICK: {
85 processor = std::make_shared<JoystickTransformProcessor>(deviceId);
86 break;
87 }
88 #endif // OHOS_BUILD_ENABLE_JOYSTICK
89 default: {
90 MMI_HILOGE("Unsupported device type:%{public}d", deviceType);
91 break;
92 }
93 }
94 return processor;
95 }
96
GetPointerEvent(int32_t deviceId)97 std::shared_ptr<PointerEvent> TouchEventNormalize::GetPointerEvent(int32_t deviceId)
98 {
99 CALL_DEBUG_ENTER;
100 auto iter = processors_.find(deviceId);
101 if (iter != processors_.end()) {
102 CHKPP(iter->second);
103 return iter->second->GetPointerEvent();
104 }
105 return nullptr;
106 }
107
108 #ifdef OHOS_BUILD_ENABLE_POINTER
SetTouchpadPinchSwitch(bool switchFlag) const109 int32_t TouchEventNormalize::SetTouchpadPinchSwitch(bool switchFlag) const
110 {
111 return TouchPadTransformProcessor::SetTouchpadPinchSwitch(switchFlag);
112 }
113
GetTouchpadPinchSwitch(bool & switchFlag) const114 void TouchEventNormalize::GetTouchpadPinchSwitch(bool &switchFlag) const
115 {
116 TouchPadTransformProcessor::GetTouchpadPinchSwitch(switchFlag);
117 }
118
SetTouchpadSwipeSwitch(bool switchFlag) const119 int32_t TouchEventNormalize::SetTouchpadSwipeSwitch(bool switchFlag) const
120 {
121 return TouchPadTransformProcessor::SetTouchpadSwipeSwitch(switchFlag);
122 }
123
GetTouchpadSwipeSwitch(bool & switchFlag) const124 void TouchEventNormalize::GetTouchpadSwipeSwitch(bool &switchFlag) const
125 {
126 TouchPadTransformProcessor::GetTouchpadSwipeSwitch(switchFlag);
127 }
128
SetTouchpadRotateSwitch(bool rotateSwitch) const129 int32_t TouchEventNormalize::SetTouchpadRotateSwitch(bool rotateSwitch) const
130 {
131 return TouchPadTransformProcessor::SetTouchpadRotateSwitch(rotateSwitch);
132 }
133
GetTouchpadRotateSwitch(bool & rotateSwitch) const134 void TouchEventNormalize::GetTouchpadRotateSwitch(bool &rotateSwitch) const
135 {
136 TouchPadTransformProcessor::GetTouchpadRotateSwitch(rotateSwitch);
137 }
138
SetTouchpadDoubleTapAndDragState(bool switchFlag) const139 int32_t TouchEventNormalize::SetTouchpadDoubleTapAndDragState(bool switchFlag) const
140 {
141 return TouchPadTransformProcessor::SetTouchpadDoubleTapAndDragState(switchFlag);
142 }
143
GetTouchpadDoubleTapAndDragState(bool & switchFlag) const144 void TouchEventNormalize::GetTouchpadDoubleTapAndDragState(bool &switchFlag) const
145 {
146 TouchPadTransformProcessor::GetTouchpadDoubleTapAndDragState(switchFlag);
147 }
148
149 #endif // OHOS_BUILD_ENABLE_POINTER
150 } // namespace MMI
151 } // namespace OHOS
152