• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef EVENT_DISPATCH_HANDLER_H
17 #define EVENT_DISPATCH_HANDLER_H
18 
19 #include "i_input_event_handler.h"
20 #include "key_event_value_transformation.h"
21 #include "uds_server.h"
22 #include "window_info.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 class EventDispatchHandler final : public IInputEventHandler {
27     struct DinputSimulateEvent {
28         uint32_t type { PointerEvent::SOURCE_TYPE_UNKNOWN };
29         uint32_t code { PointerEvent::BUTTON_NONE };
30         int32_t value { PointerEvent::POINTER_ACTION_UNKNOWN };
31     };
32 public:
33     EventDispatchHandler() = default;
34     DISALLOW_COPY_AND_MOVE(EventDispatchHandler);
35     ~EventDispatchHandler() override = default;
36 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
37     void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) override;
38 #endif // OHOS_BUILD_ENABLE_KEYBOARD
39 #ifdef OHOS_BUILD_ENABLE_POINTER
40     void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
41 #endif // OHOS_BUILD_ENABLE_POINTER
42 #ifdef OHOS_BUILD_ENABLE_TOUCH
43     void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
44 #endif // OHOS_BUILD_ENABLE_TOUCH
45 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
46     int32_t DispatchKeyEventPid(UDSServer& udsServer, std::shared_ptr<KeyEvent> key);
47     int32_t DispatchKeyEvent(int32_t fd, UDSServer& udsServer, std::shared_ptr<KeyEvent> key);
48 #endif // OHOS_BUILD_ENABLE_KEYBOARD
49 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
50     void HandlePointerEventInner(const std::shared_ptr<PointerEvent> point);
51     void NotifyPointerEventToRS(int32_t pointAction, const std::string& programName, uint32_t pid, int32_t pointCnt);
52 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
53     std::chrono::time_point<std::chrono::high_resolution_clock> LasteventBeginTime_ =
54     std::chrono::high_resolution_clock::now();
55     void SendWindowStateError(int32_t pid, int32_t windowId);
56 private:
57     void DispatchPointerEventInner(std::shared_ptr<PointerEvent> point, int32_t fd);
58     void HandleMultiWindowPointerEvent(std::shared_ptr<PointerEvent> point,
59         PointerEvent::PointerItem pointerItem);
60     bool ReissueEvent(std::shared_ptr<PointerEvent> &point, int32_t windowId, std::optional<WindowInfo> &windowInfo);
61     std::shared_ptr<WindowInfo> SearchCancelList(int32_t pointerId, int32_t windowId);
62     bool SearchWindow(std::vector<std::shared_ptr<WindowInfo>> &windowList, std::shared_ptr<WindowInfo> targetWindow);
63     int32_t GetClientFd(int32_t pid, std::shared_ptr<PointerEvent> point);
64     void UpdateDisplayXY(const std::shared_ptr<PointerEvent> &point);
65     void AddFlagToEsc(const std::shared_ptr<KeyEvent> keyEvent);
66     void ResetDisplayXY(const std::shared_ptr<PointerEvent> &point);
67 #ifdef OHOS_BUILD_ENABLE_POINTER
68     void EnsureMouseEventCycle(std::shared_ptr<PointerEvent> event);
69     void CleanMouseEventCycle(std::shared_ptr<PointerEvent> event);
70 #endif // OHOS_BUILD_ENABLE_POINTER
71 
72     int32_t eventTime_ { 0 };
73     int32_t currentTime_ { 0 };
74     bool enableMark_ { true };
75     bool escToBackFlag_ { false };
76     struct {
77         double x {};
78         double y {};
79         bool fixed { false };
80     } currentXY_;
81     struct {
82         int32_t pid { -1 };
83         int32_t windowId { -1 };
84         int64_t startTime { -1 };
85     } windowStateErrorInfo_;
86     std::map<int32_t, std::vector<std::shared_ptr<WindowInfo>>> cancelEventList_;
87 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
88     void FilterInvalidPointerItem(const std::shared_ptr<PointerEvent> pointEvent, int32_t fd);
89 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
90     bool AcquireEnableMark(std::shared_ptr<PointerEvent> event);
91 };
92 } // namespace MMI
93 } // namespace OHOS
94 #endif // EVENT_DISPATCH_HANDLER_H
95