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 #include "tablet_tool_tranform_processor.h"
21 #include "touch_transform_processor.h"
22 #include "touchpad_transform_processor.h"
23
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL{ LOG_CORE, MMI_LOG_DOMAIN, "TouchEventNormalize" };
28 } // namespace
29
TouchEventNormalize()30 TouchEventNormalize::TouchEventNormalize() {}
~TouchEventNormalize()31 TouchEventNormalize::~TouchEventNormalize() {}
32
OnLibInput(struct libinput_event * event,DeviceType deviceType)33 std::shared_ptr<PointerEvent> TouchEventNormalize::OnLibInput(struct libinput_event *event, DeviceType deviceType)
34 {
35 CHKPP(event);
36 auto device = libinput_event_get_device(event);
37 CHKPP(device);
38 std::shared_ptr<TransformProcessor> processor{ nullptr };
39 auto deviceId = InputDevMgr->FindInputDeviceId(device);
40 if (auto it = processors_.find(deviceId); it != processors_.end()) {
41 processor = it->second;
42 } else {
43 processor = MakeTransformProcessor(deviceId, deviceType);
44 CHKPP(processor);
45 auto [tIter, isOk] = processors_.emplace(deviceId, processor);
46 if (!isOk) {
47 MMI_HILOGE("Duplicate device record:%{public}d", deviceId);
48 }
49 }
50 return processor->OnEvent(event);
51 }
52
MakeTransformProcessor(int32_t deviceId,DeviceType deviceType) const53 std::shared_ptr<TransformProcessor> TouchEventNormalize::MakeTransformProcessor(int32_t deviceId,
54 DeviceType deviceType) const
55 {
56 std::shared_ptr<TransformProcessor> processor{ nullptr };
57 switch (deviceType) {
58 #ifdef OHOS_BUILD_ENABLE_TOUCH
59 case DeviceType::TOUCH: {
60 processor = std::make_shared<TouchTransformProcessor>(deviceId);
61 break;
62 }
63 case DeviceType::TABLET_TOOL: {
64 processor = std::make_shared<TabletToolTransformProcessor>(deviceId);
65 break;
66 }
67 #endif // OHOS_BUILD_ENABLE_TOUCH
68 #ifdef OHOS_BUILD_ENABLE_POINTER
69 case DeviceType::TOUCH_PAD: {
70 processor = std::make_shared<TouchPadTransformProcessor>(deviceId);
71 break;
72 }
73 case DeviceType::GESTURE: {
74 processor = std::make_shared<GestureTransformProcessor>(deviceId);
75 break;
76 }
77 #endif // OHOS_BUILD_ENABLE_POINTER
78 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
79 case DeviceType::JOYSTICK: {
80 processor = std::make_shared<JoystickTransformProcessor>(deviceId);
81 break;
82 }
83 #endif // OHOS_BUILD_ENABLE_JOYSTICK
84 default: {
85 MMI_HILOGE("Unsupported device type: %{public}d", deviceType);
86 break;
87 }
88 }
89 return processor;
90 }
91
SetTouchpadPinchSwitch(bool switchFlag) const92 int32_t TouchEventNormalize::SetTouchpadPinchSwitch(bool switchFlag) const
93 {
94 return TouchPadTransformProcessor::SetTouchpadPinchSwitch(switchFlag);
95 }
96
GetTouchpadPinchSwitch(bool & switchFlag) const97 int32_t TouchEventNormalize::GetTouchpadPinchSwitch(bool &switchFlag) const
98 {
99 return TouchPadTransformProcessor::GetTouchpadPinchSwitch(switchFlag);
100 }
101
SetTouchpadSwipeSwitch(bool switchFlag) const102 int32_t TouchEventNormalize::SetTouchpadSwipeSwitch(bool switchFlag) const
103 {
104 return TouchPadTransformProcessor::SetTouchpadSwipeSwitch(switchFlag);
105 }
106
GetTouchpadSwipeSwitch(bool & switchFlag) const107 int32_t TouchEventNormalize::GetTouchpadSwipeSwitch(bool &switchFlag) const
108 {
109 return TouchPadTransformProcessor::GetTouchpadSwipeSwitch(switchFlag);
110 }
111 } // namespace MMI
112 } // namespace OHOS
113