• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef EVENT_NORMALIZE_HANDLER_H
17 #define EVENT_NORMALIZE_HANDLER_H
18 
19 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
20 #include "joystick_event_normalize.h"
21 #endif // OHOS_BUILD_ENABLE_JOYSTICK
22 #include "key_event_normalize.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 class EventNormalizeHandler : public IInputEventHandler {
27 public:
28     EventNormalizeHandler() = default;
29     ~EventNormalizeHandler() = default;
30     void HandleEvent(libinput_event* event, int64_t frameTime);
31 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
32     void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) override;
GetCurrentHandleKeyCode()33     int32_t GetCurrentHandleKeyCode()
34     {
35         return currentHandleKeyCode_;
36     }
37 #endif // OHOS_BUILD_ENABLE_KEYBOARD
38 #ifdef OHOS_BUILD_ENABLE_POINTER
39     void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
40 #endif // OHOS_BUILD_ENABLE_POINTER
41 #ifdef OHOS_BUILD_ENABLE_TOUCH
42     void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
43 #endif // OHOS_BUILD_ENABLE_TOUCH
44     int32_t AddHandleTimer(int32_t timeout = 300);
45 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
46     int32_t SetMoveEventFilters(bool flag);
47 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
48     void BypassChainAndDispatchDirectly(std::shared_ptr<PointerEvent> pointerEvent);
49 
50 private:
51     int32_t OnEventDeviceAdded(libinput_event *event);
52     int32_t OnEventDeviceRemoved(libinput_event *event);
53     int32_t HandleKeyboardEvent(libinput_event* event);
54     void Repeat(const std::shared_ptr<KeyEvent> keyEvent);
55     bool HandleTouchPadTripleTapEvent(std::shared_ptr<PointerEvent> pointerEvent);
56 #ifndef OHOS_BUILD_ENABLE_WATCH
57     int32_t HandleTouchPadEvent(libinput_event* event);
58     int32_t HandleGestureEvent(libinput_event* event);
59     int32_t HandleTableToolEvent(libinput_event* event);
60 #endif // OHOS_BUILD_ENABLE_WATCH
61     int32_t HandleMouseEvent(libinput_event* event);
62     int32_t HandleTouchEvent(libinput_event* event, int64_t frameTime);
63     int32_t HandleSwitchInputEvent(libinput_event* event);
64 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
65     int32_t HandleJoystickButtonEvent(libinput_event *event);
66     int32_t HandleJoystickAxisEvent(libinput_event *event);
67 #endif // OHOS_BUILD_ENABLE_JOYSTICK
68     void HandlePalmEvent(libinput_event* event, std::shared_ptr<PointerEvent> pointerEvent);
69     bool JudgeIfSwipeInward(std::shared_ptr<PointerEvent> pointerEvent,
70         enum libinput_event_type type, libinput_event* event);
71     void SwipeInwardProcess(std::shared_ptr<PointerEvent> pointerEvent,
72         enum libinput_event_type type, libinput_event* event, int32_t* angleTolerance, int32_t lastDirection);
73 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
74     void UpdateKeyEventHandlerChain(const std::shared_ptr<KeyEvent> keyEvent);
75 #endif // OHOS_BUILD_ENABLE_KEYBOARD
76 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
77     bool HandleTouchEventWithFlag(const std::shared_ptr<PointerEvent> pointerEvent);
78     double CalcTouchOffset(const std::shared_ptr<PointerEvent> touchMoveEvent);
79 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
80     int32_t SetOriginPointerId(std::shared_ptr<PointerEvent> pointerEvent);
81     void PointerEventSetPressedKeys(std::shared_ptr<PointerEvent> pointerEvent);
82     bool TouchPadKnuckleDoubleClickHandle(libinput_event* event);
83     bool HandleTouchPadEdgeSwipe(libinput_event* event);
84     int32_t GetToolType(libinput_event* event);
85     void HandleDeviceConsumerEvent(int32_t toolType, libinput_event* event, PointerEvent::PointerItem &pointerItem,
86         std::shared_ptr<PointerEvent> pointerEvent);
87 
88 private:
89     int32_t timerId_ { -1 };
90     bool isShield_ { false };
91     std::set<int32_t> buttonIds_ {};
92     int32_t currentHandleKeyCode_ { -1 };
93 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
94     bool moveEventFilterFlag_ { false };
95     std::list<PointerEvent::PointerItem> lastTouchDownItems_;
96 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
97 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
98     JoystickEventNormalize joystick_;
99 #endif // OHOS_BUILD_ENABLE_JOYSTICK
100 #ifdef OHOS_BUILD_ENABLE_POINTER
101     static int32_t tpRegisterTryCount_;
102 #endif // OHOS_BUILD_ENABLE_POINTER
103     void ResetTouchUpEvent(std::shared_ptr<PointerEvent> pointerEvent, struct libinput_event *event);
104     bool ProcessNullEvent(libinput_event *event, int64_t frameTime);
105 #ifdef OHOS_BUILD_ENABLE_SWITCH
106     void RestoreTouchPadStatus();
107 #endif // OHOS_BUILD_ENABLE_SWITCH
108     void TerminateAxis(libinput_event* event);
109     void CancelTwoFingerAxis(libinput_event* event);
110     bool IsAccessibilityEventWithZOrder(std::shared_ptr<PointerEvent> pointerEvent);
111 };
112 } // namespace MMI
113 } // namespace OHOS
114 #endif // EVENT_NORMALIZE_HANDLER_H