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 66 int32_t eventTime_ { 0 }; 67 int32_t currentTime_ { 0 }; 68 bool enableMark_ { true }; 69 struct { 70 int32_t pid { -1 }; 71 int32_t windowId { -1 }; 72 int64_t startTime { -1 }; 73 } windowStateErrorInfo_; 74 std::map<int32_t, std::vector<std::shared_ptr<WindowInfo>>> cancelEventList_; 75 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 76 void FilterInvalidPointerItem(const std::shared_ptr<PointerEvent> pointEvent, int32_t fd); 77 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 78 bool AcquireEnableMark(std::shared_ptr<PointerEvent> event); 79 }; 80 } // namespace MMI 81 } // namespace OHOS 82 #endif // EVENT_DISPATCH_HANDLER_H 83