• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #ifndef OHOS_BUILD_ENABLE_WATCH
19 #include "gesture_transform_processor.h"
20 #endif // OHOS_BUILD_ENABLE_WATCH
21 #include "input_device_manager.h"
22 #ifdef OHOS_BUILD_ENABLE_TOUCH
23 #ifndef OHOS_BUILD_ENABLE_WATCH
24 #include "tablet_tool_tranform_processor.h"
25 #endif // OHOS_BUILD_ENABLE_WATCH
26 #include "touch_transform_processor.h"
27 #include "remote_control_transform_processor.h"
28 #endif // OHOS_BUILD_ENABLE_TOUCH
29 #ifdef OHOS_BUILD_ENABLE_POINTER
30 #include "touchpad_transform_processor.h"
31 #endif // OHOS_BUILD_ENABLE_POINTER
32 
33 #undef MMI_LOG_DOMAIN
34 #define MMI_LOG_DOMAIN MMI_LOG_DISPATCH
35 #undef MMI_LOG_TAG
36 #define MMI_LOG_TAG "TouchEventNormalize"
37 
38 namespace OHOS {
39 namespace MMI {
TouchEventNormalize()40 TouchEventNormalize::TouchEventNormalize() {}
~TouchEventNormalize()41 TouchEventNormalize::~TouchEventNormalize() {}
42 
OnLibInput(struct libinput_event * event,DeviceType deviceType)43 std::shared_ptr<PointerEvent> TouchEventNormalize::OnLibInput(struct libinput_event *event, DeviceType deviceType)
44 {
45     CHKPP(event);
46     auto device = libinput_event_get_device(event);
47     CHKPP(device);
48     std::shared_ptr<TransformProcessor> processor{ nullptr };
49     auto deviceId = INPUT_DEV_MGR->FindInputDeviceId(device);
50     if (deviceType == TouchEventNormalize::DeviceType::TOUCH_PAD) {
51         if (auto it = touchpad_processors_.find(deviceId); it != touchpad_processors_.end()) {
52             processor = it->second;
53         } else {
54             processor = MakeTransformProcessor(deviceId, deviceType);
55             CHKPP(processor);
56             auto [tIter, isOk] = touchpad_processors_.emplace(deviceId, processor);
57             if (!isOk) {
58                 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
59             }
60         }
61     } else if (deviceType == TouchEventNormalize::DeviceType::REMOTE_CONTROL) {
62         if (auto it = remote_control_processors_.find(deviceId); it != remote_control_processors_.end()) {
63             processor = it->second;
64         } else {
65             processor = MakeTransformProcessor(deviceId, deviceType);
66             CHKPP(processor);
67             auto [tIter, isOk] = remote_control_processors_.emplace(deviceId, processor);
68             if (!isOk) {
69                 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
70             }
71         }
72     } else {
73         if (auto it = processors_.find(deviceId); it != processors_.end()) {
74             processor = it->second;
75         } else {
76             processor = MakeTransformProcessor(deviceId, deviceType);
77             CHKPP(processor);
78             auto [tIter, isOk] = processors_.emplace(deviceId, processor);
79             if (!isOk) {
80                 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
81             }
82         }
83     }
84     return processor->OnEvent(event);
85 }
86 
87 #ifndef OHOS_BUILD_ENABLE_WATCH
MakeTransformProcessor(int32_t deviceId,DeviceType deviceType) const88 std::shared_ptr<TransformProcessor> TouchEventNormalize::MakeTransformProcessor(int32_t deviceId,
89     DeviceType deviceType) const
90 {
91     std::shared_ptr<TransformProcessor> processor{ nullptr };
92     switch (deviceType) {
93 #ifdef OHOS_BUILD_ENABLE_TOUCH
94         case DeviceType::TOUCH: {
95             processor = std::make_shared<TouchTransformProcessor>(deviceId);
96             break;
97         }
98         case DeviceType::TABLET_TOOL: {
99             processor = std::make_shared<TabletToolTransformProcessor>(deviceId);
100             break;
101         }
102         case DeviceType::REMOTE_CONTROL: {
103             processor = std::make_shared<Remote_ControlTransformProcessor>(deviceId);
104             break;
105         }
106 #endif // OHOS_BUILD_ENABLE_TOUCH
107 #ifdef OHOS_BUILD_ENABLE_POINTER
108         case DeviceType::TOUCH_PAD: {
109             processor = std::make_shared<TouchPadTransformProcessor>(deviceId);
110             break;
111         }
112         case DeviceType::GESTURE: {
113             processor = std::make_shared<GestureTransformProcessor>(deviceId);
114             break;
115         }
116 #endif // OHOS_BUILD_ENABLE_POINTER
117         default: {
118             MMI_HILOGE("Unsupported device type:%{public}d", deviceType);
119             break;
120         }
121     }
122     return processor;
123 }
124 #else
MakeTransformProcessor(int32_t deviceId,DeviceType deviceType) const125 std::shared_ptr<TransformProcessor> TouchEventNormalize::MakeTransformProcessor(int32_t deviceId,
126     DeviceType deviceType) const
127 {
128     std::shared_ptr<TransformProcessor> processor{ nullptr };
129     switch (deviceType) {
130 #ifdef OHOS_BUILD_ENABLE_TOUCH
131         case DeviceType::TOUCH: {
132             processor = std::make_shared<TouchTransformProcessor>(deviceId);
133             break;
134         }
135 #endif // OHOS_BUILD_ENABLE_TOUCH
136         default: {
137             MMI_HILOGE("Unsupported device type:%{public}d", deviceType);
138             break;
139         }
140     }
141     return processor;
142 }
143 #endif //OHOS_BUILD_ENABLE_WATCH
144 
GetPointerEvent(int32_t deviceId)145 std::shared_ptr<PointerEvent> TouchEventNormalize::GetPointerEvent(int32_t deviceId)
146 {
147     CALL_DEBUG_ENTER;
148     auto iter = processors_.find(deviceId);
149     if (iter != processors_.end()) {
150         CHKPP(iter->second);
151         return iter->second->GetPointerEvent();
152     }
153     return nullptr;
154 }
155 
156 #ifdef OHOS_BUILD_ENABLE_POINTER
SetTouchpadPinchSwitch(bool switchFlag) const157 int32_t TouchEventNormalize::SetTouchpadPinchSwitch(bool switchFlag) const
158 {
159     return TouchPadTransformProcessor::SetTouchpadPinchSwitch(switchFlag);
160 }
161 
GetTouchpadPinchSwitch(bool & switchFlag) const162 void TouchEventNormalize::GetTouchpadPinchSwitch(bool &switchFlag) const
163 {
164     TouchPadTransformProcessor::GetTouchpadPinchSwitch(switchFlag);
165 }
166 
SetTouchpadSwipeSwitch(bool switchFlag) const167 int32_t TouchEventNormalize::SetTouchpadSwipeSwitch(bool switchFlag) const
168 {
169     return TouchPadTransformProcessor::SetTouchpadSwipeSwitch(switchFlag);
170 }
171 
GetTouchpadSwipeSwitch(bool & switchFlag) const172 void TouchEventNormalize::GetTouchpadSwipeSwitch(bool &switchFlag) const
173 {
174     TouchPadTransformProcessor::GetTouchpadSwipeSwitch(switchFlag);
175 }
176 
SetTouchpadRotateSwitch(bool rotateSwitch) const177 int32_t TouchEventNormalize::SetTouchpadRotateSwitch(bool rotateSwitch) const
178 {
179     return TouchPadTransformProcessor::SetTouchpadRotateSwitch(rotateSwitch);
180 }
181 
GetTouchpadRotateSwitch(bool & rotateSwitch) const182 void TouchEventNormalize::GetTouchpadRotateSwitch(bool &rotateSwitch) const
183 {
184     TouchPadTransformProcessor::GetTouchpadRotateSwitch(rotateSwitch);
185 }
186 
SetTouchpadDoubleTapAndDragState(bool switchFlag) const187 int32_t TouchEventNormalize::SetTouchpadDoubleTapAndDragState(bool switchFlag) const
188 {
189     return TouchPadTransformProcessor::SetTouchpadDoubleTapAndDragState(switchFlag);
190 }
191 
GetTouchpadDoubleTapAndDragState(bool & switchFlag) const192 void TouchEventNormalize::GetTouchpadDoubleTapAndDragState(bool &switchFlag) const
193 {
194     TouchPadTransformProcessor::GetTouchpadDoubleTapAndDragState(switchFlag);
195 }
196 
SetTouchpadScrollRows(int32_t rows)197 int32_t TouchEventNormalize::SetTouchpadScrollRows(int32_t rows)
198 {
199     return TouchPadTransformProcessor::SetTouchpadScrollRows(rows);
200 }
201 
GetTouchpadScrollRows() const202 int32_t TouchEventNormalize::GetTouchpadScrollRows() const
203 {
204     return TouchPadTransformProcessor::GetTouchpadScrollRows();
205 }
206 
SetTouchpadThreeFingersTapSwitch(bool switchFlag) const207 int32_t TouchEventNormalize::SetTouchpadThreeFingersTapSwitch(bool switchFlag) const
208 {
209     return TouchPadTransformProcessor::SetTouchpadThreeFingersTapSwitch(switchFlag);
210 }
211 
GetTouchpadThreeFingersTapSwitch(bool & switchFlag) const212 int32_t TouchEventNormalize::GetTouchpadThreeFingersTapSwitch(bool &switchFlag) const
213 {
214     return TouchPadTransformProcessor::GetTouchpadThreeFingersTapSwitch(switchFlag);
215 }
216 #endif // OHOS_BUILD_ENABLE_POINTER
217 } // namespace MMI
218 } // namespace OHOS
219