• 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 #include <memory>
20 
21 #include "i_input_event_handler.h"
22 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
23 #include "joystick_event_normalize.h"
24 #endif // OHOS_BUILD_ENABLE_JOYSTICK
25 #include "key_event_normalize.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 class EventNormalizeHandler : public IInputEventHandler {
30 public:
31     EventNormalizeHandler() = default;
32     ~EventNormalizeHandler() = default;
33     void HandleEvent(libinput_event* event, int64_t frameTime);
34 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
35     void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) override;
GetCurrentHandleKeyCode()36     int32_t GetCurrentHandleKeyCode()
37     {
38         return currentHandleKeyCode_;
39     }
40 #endif // OHOS_BUILD_ENABLE_KEYBOARD
41 #ifdef OHOS_BUILD_ENABLE_POINTER
42     void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
43 #endif // OHOS_BUILD_ENABLE_POINTER
44 #ifdef OHOS_BUILD_ENABLE_TOUCH
45     void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
46 #endif // OHOS_BUILD_ENABLE_TOUCH
47     int32_t AddHandleTimer(int32_t timeout = 300);
48 private:
49     int32_t OnEventDeviceAdded(libinput_event *event);
50     int32_t OnEventDeviceRemoved(libinput_event *event);
51     int32_t HandleKeyboardEvent(libinput_event* event);
52     void Repeat(const std::shared_ptr<KeyEvent> keyEvent);
53     int32_t HandleTouchPadEvent(libinput_event* event);
54     int32_t HandleGestureEvent(libinput_event* event);
55     int32_t HandleMouseEvent(libinput_event* event);
56     int32_t HandleTouchEvent(libinput_event* event, int64_t frameTime);
57     int32_t HandleSwitchInputEvent(libinput_event* event);
58     int32_t HandleTableToolEvent(libinput_event* event);
59 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
60     int32_t HandleJoystickButtonEvent(libinput_event *event);
61     int32_t HandleJoystickAxisEvent(libinput_event *event);
62 #endif // OHOS_BUILD_ENABLE_JOYSTICK
63     void HandlePalmEvent(libinput_event* event, std::shared_ptr<PointerEvent> pointerEvent);
64     bool JudgeIfSwipeInward(std::shared_ptr<PointerEvent> pointerEvent,
65         enum libinput_event_type type, libinput_event* event);
66     void SwipeInwardProcess(std::shared_ptr<PointerEvent> pointerEvent,
67         enum libinput_event_type type, libinput_event* event, int32_t* angleTolerance, int32_t lastDirection);
68 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
69     void UpdateKeyEventHandlerChain(const std::shared_ptr<KeyEvent> keyEvent);
70 #endif // OHOS_BUILD_ENABLE_KEYBOARD
71     int32_t SetOriginPointerId(std::shared_ptr<PointerEvent> pointerEvent);
72     void PointerEventSetPressedKeys(std::shared_ptr<PointerEvent> pointerEvent);
73 
74 private:
75     int32_t timerId_ { -1 };
76     bool isShield_ { false };
77     std::set<int32_t> buttonIds_ {};
78     int32_t currentHandleKeyCode_ { -1 };
79 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
80     JoystickEventNormalize joystick_;
81 #endif // OHOS_BUILD_ENABLE_JOYSTICK
82     void ResetTouchUpEvent(std::shared_ptr<PointerEvent> pointerEvent, struct libinput_event *event);
83     bool ProcessNullEvent(libinput_event *event, int64_t frameTime);
84     void TerminateRotate(libinput_event* event);
85     void TerminateAxis(libinput_event* event);
86 #ifdef OHOS_BUILD_ENABLE_SWITCH
87     void RestoreTouchPadStatus();
88 #endif // OHOS_BUILD_ENABLE_SWITCH
89     void CancelTwoFingerAxis(libinput_event* event);
90 };
91 } // namespace MMI
92 } // namespace OHOS
93 #endif // EVENT_NORMALIZE_HANDLER_H