• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #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 
49 private:
50     int32_t OnEventDeviceAdded(libinput_event *event);
51     int32_t OnEventDeviceRemoved(libinput_event *event);
52     int32_t HandleKeyboardEvent(libinput_event* event);
53     void Repeat(const std::shared_ptr<KeyEvent> keyEvent);
54     bool HandleTouchPadTripleTapEvent(std::shared_ptr<PointerEvent> pointerEvent);
55 #ifndef OHOS_BUILD_ENABLE_WATCH
56     int32_t HandleTouchPadEvent(libinput_event* event);
57     int32_t HandleGestureEvent(libinput_event* event);
58     int32_t HandleTableToolEvent(libinput_event* event);
59 #endif // OHOS_BUILD_ENABLE_WATCH
60     int32_t HandleMouseEvent(libinput_event* event);
61     int32_t HandleTouchEvent(libinput_event* event, int64_t frameTime);
62     int32_t HandleSwitchInputEvent(libinput_event* event);
63 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
64     int32_t HandleJoystickButtonEvent(libinput_event *event);
65     int32_t HandleJoystickAxisEvent(libinput_event *event);
66 #endif // OHOS_BUILD_ENABLE_JOYSTICK
67     void HandlePalmEvent(libinput_event* event, std::shared_ptr<PointerEvent> pointerEvent);
68     bool JudgeIfSwipeInward(std::shared_ptr<PointerEvent> pointerEvent,
69         enum libinput_event_type type, libinput_event* event);
70     void SwipeInwardProcess(std::shared_ptr<PointerEvent> pointerEvent,
71         enum libinput_event_type type, libinput_event* event, int32_t* angleTolerance, int32_t lastDirection);
72 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
73     void UpdateKeyEventHandlerChain(const std::shared_ptr<KeyEvent> keyEvent);
74 #endif // OHOS_BUILD_ENABLE_KEYBOARD
75 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
76     bool HandleTouchEventWithFlag(const std::shared_ptr<PointerEvent> pointerEvent);
77     double CalcTouchOffset(const std::shared_ptr<PointerEvent> touchMoveEvent);
78 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
79     int32_t SetOriginPointerId(std::shared_ptr<PointerEvent> pointerEvent);
80     void PointerEventSetPressedKeys(std::shared_ptr<PointerEvent> pointerEvent);
81     bool TouchPadKnuckleDoubleClickHandle(libinput_event* event);
82 
83 private:
84     int32_t timerId_ { -1 };
85     bool isShield_ { false };
86     std::set<int32_t> buttonIds_ {};
87     int32_t currentHandleKeyCode_ { -1 };
88 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
89     bool moveEventFilterFlag_ { false };
90     std::list<PointerEvent::PointerItem> lastTouchDownItems_;
91 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
92 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
93     JoystickEventNormalize joystick_;
94 #endif // OHOS_BUILD_ENABLE_JOYSTICK
95     void ResetTouchUpEvent(std::shared_ptr<PointerEvent> pointerEvent, struct libinput_event *event);
96     bool ProcessNullEvent(libinput_event *event, int64_t frameTime);
97 #ifdef OHOS_BUILD_ENABLE_SWITCH
98     void RestoreTouchPadStatus();
99 #endif // OHOS_BUILD_ENABLE_SWITCH
100     void TerminateRotate(libinput_event* event);
101     void TerminateAxis(libinput_event* event);
102     void CancelTwoFingerAxis(libinput_event* event);
103 };
104 } // namespace MMI
105 } // namespace OHOS
106 #endif // EVENT_NORMALIZE_HANDLER_H