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 #ifdef OHOS_BUILD_ENABLE_TOUCH
20 #include "tablet_tool_tranform_processor.h"
21 #include "touch_transform_processor.h"
22 #endif // OHOS_BUILD_ENABLE_TOUCH
23 #ifdef OHOS_BUILD_ENABLE_POINTER
24 #include "touchpad_transform_processor.h"
25 #endif // OHOS_BUILD_ENABLE_POINTER
26
27 #undef MMI_LOG_DOMAIN
28 #define MMI_LOG_DOMAIN MMI_LOG_DISPATCH
29 #undef MMI_LOG_TAG
30 #define MMI_LOG_TAG "TouchEventNormalize"
31
32 namespace OHOS {
33 namespace MMI {
TouchEventNormalize()34 TouchEventNormalize::TouchEventNormalize() {}
~TouchEventNormalize()35 TouchEventNormalize::~TouchEventNormalize() {}
36
OnLibInput(struct libinput_event * event,DeviceType deviceType)37 std::shared_ptr<PointerEvent> TouchEventNormalize::OnLibInput(struct libinput_event *event, DeviceType deviceType)
38 {
39 CHKPP(event);
40 auto device = libinput_event_get_device(event);
41 CHKPP(device);
42 std::shared_ptr<TransformProcessor> processor{ nullptr };
43 auto deviceId = INPUT_DEV_MGR->FindInputDeviceId(device);
44 if (auto it = processors_.find(deviceId); it != processors_.end()) {
45 processor = it->second;
46 } else {
47 processor = MakeTransformProcessor(deviceId, deviceType);
48 CHKPP(processor);
49 auto [tIter, isOk] = processors_.emplace(deviceId, processor);
50 if (!isOk) {
51 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
52 }
53 }
54 return processor->OnEvent(event);
55 }
56
MakeTransformProcessor(int32_t deviceId,DeviceType deviceType) const57 std::shared_ptr<TransformProcessor> TouchEventNormalize::MakeTransformProcessor(int32_t deviceId,
58 DeviceType deviceType) const
59 {
60 std::shared_ptr<TransformProcessor> processor{ nullptr };
61 switch (deviceType) {
62 #ifdef OHOS_BUILD_ENABLE_TOUCH
63 case DeviceType::TOUCH: {
64 processor = std::make_shared<TouchTransformProcessor>(deviceId);
65 break;
66 }
67 case DeviceType::TABLET_TOOL: {
68 processor = std::make_shared<TabletToolTransformProcessor>(deviceId);
69 break;
70 }
71 #endif // OHOS_BUILD_ENABLE_TOUCH
72 #ifdef OHOS_BUILD_ENABLE_POINTER
73 case DeviceType::TOUCH_PAD: {
74 processor = std::make_shared<TouchPadTransformProcessor>(deviceId);
75 break;
76 }
77 case DeviceType::GESTURE: {
78 processor = std::make_shared<GestureTransformProcessor>(deviceId);
79 break;
80 }
81 #endif // OHOS_BUILD_ENABLE_POINTER
82 default: {
83 MMI_HILOGE("Unsupported device type:%{public}d", deviceType);
84 break;
85 }
86 }
87 return processor;
88 }
89
GetPointerEvent(int32_t deviceId)90 std::shared_ptr<PointerEvent> TouchEventNormalize::GetPointerEvent(int32_t deviceId)
91 {
92 CALL_DEBUG_ENTER;
93 auto iter = processors_.find(deviceId);
94 if (iter != processors_.end()) {
95 CHKPP(iter->second);
96 return iter->second->GetPointerEvent();
97 }
98 return nullptr;
99 }
100
101 #ifdef OHOS_BUILD_ENABLE_POINTER
SetTouchpadPinchSwitch(bool switchFlag) const102 int32_t TouchEventNormalize::SetTouchpadPinchSwitch(bool switchFlag) const
103 {
104 return TouchPadTransformProcessor::SetTouchpadPinchSwitch(switchFlag);
105 }
106
GetTouchpadPinchSwitch(bool & switchFlag) const107 void TouchEventNormalize::GetTouchpadPinchSwitch(bool &switchFlag) const
108 {
109 TouchPadTransformProcessor::GetTouchpadPinchSwitch(switchFlag);
110 }
111
SetTouchpadSwipeSwitch(bool switchFlag) const112 int32_t TouchEventNormalize::SetTouchpadSwipeSwitch(bool switchFlag) const
113 {
114 return TouchPadTransformProcessor::SetTouchpadSwipeSwitch(switchFlag);
115 }
116
GetTouchpadSwipeSwitch(bool & switchFlag) const117 void TouchEventNormalize::GetTouchpadSwipeSwitch(bool &switchFlag) const
118 {
119 TouchPadTransformProcessor::GetTouchpadSwipeSwitch(switchFlag);
120 }
121
SetTouchpadRotateSwitch(bool rotateSwitch) const122 int32_t TouchEventNormalize::SetTouchpadRotateSwitch(bool rotateSwitch) const
123 {
124 return TouchPadTransformProcessor::SetTouchpadRotateSwitch(rotateSwitch);
125 }
126
GetTouchpadRotateSwitch(bool & rotateSwitch) const127 void TouchEventNormalize::GetTouchpadRotateSwitch(bool &rotateSwitch) const
128 {
129 TouchPadTransformProcessor::GetTouchpadRotateSwitch(rotateSwitch);
130 }
131
SetTouchpadDoubleTapAndDragState(bool switchFlag) const132 int32_t TouchEventNormalize::SetTouchpadDoubleTapAndDragState(bool switchFlag) const
133 {
134 return TouchPadTransformProcessor::SetTouchpadDoubleTapAndDragState(switchFlag);
135 }
136
GetTouchpadDoubleTapAndDragState(bool & switchFlag) const137 void TouchEventNormalize::GetTouchpadDoubleTapAndDragState(bool &switchFlag) const
138 {
139 TouchPadTransformProcessor::GetTouchpadDoubleTapAndDragState(switchFlag);
140 }
141
142 #endif // OHOS_BUILD_ENABLE_POINTER
143 } // namespace MMI
144 } // namespace OHOS
145