/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INPUT_HANDLER_MANAGER_H #define INPUT_HANDLER_MANAGER_H #include #include #include #include #include "input_device.h" #include "input_handler_type.h" #include "i_input_event_consumer.h" #include "pointer_event.h" namespace OHOS { namespace MMI { class InputHandlerManager { public: InputHandlerManager(); virtual ~InputHandlerManager() = default; DISALLOW_COPY_AND_MOVE(InputHandlerManager); public: #ifdef OHOS_BUILD_ENABLE_KEYBOARD void OnInputEvent(std::shared_ptr keyEvent, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) void OnInputEvent(std::shared_ptr pointerEvent, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) template bool RecoverPointerEvent(std::initializer_list pointerActionEvents, T pointerActionEvent); void OnConnected(); void OnDisconnected(); #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR bool HasHandler(int32_t handlerId); virtual InputHandlerType GetHandlerType() const = 0; HandleEventType GetEventType() const; int32_t GetPriority() const; uint32_t GetDeviceTags() const; std::vector GetActionsType() const; protected: int32_t AddGestureMonitor(InputHandlerType handlerType, std::shared_ptr consumer, HandleEventType eventType, TouchGestureType gestureType, int32_t fingers); int32_t RemoveGestureMonitor(int32_t handlerId, InputHandlerType handlerType); int32_t AddHandler(InputHandlerType handlerType, std::shared_ptr consumer, HandleEventType eventType = HANDLE_EVENT_TYPE_KP, int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); int32_t RemoveHandler(int32_t handlerId, InputHandlerType IsValidHandlerType); int32_t AddHandler(InputHandlerType handlerType, std::shared_ptr consumer, std::vector actions); private: struct GestureHandler { TouchGestureType gestureType { TOUCH_GESTURE_TYPE_NONE }; int32_t fingers { 0 }; bool gestureState { false }; }; struct Handler { int32_t handlerId_ { 0 }; InputHandlerType handlerType_ { NONE }; HandleEventType eventType_ { HANDLE_EVENT_TYPE_KP }; int32_t priority_ { DEFUALT_INTERCEPTOR_PRIORITY }; uint32_t deviceTags_ { CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX) }; std::shared_ptr consumer_ { nullptr }; GestureHandler gestureHandler_; std::vector actionsType_; }; private: int32_t GetNextId(); virtual bool CheckMonitorValid(TouchGestureType type, int32_t fingers) { return false; } bool IsMatchGesture(const Handler &handler, int32_t action, int32_t count); int32_t AddGestureToLocal(int32_t handlerId, HandleEventType eventType, TouchGestureType gestureType, int32_t fingers, std::shared_ptr consumer); int32_t AddLocal(int32_t handlerId, InputHandlerType handlerType, HandleEventType eventType, int32_t priority, uint32_t deviceTags, std::shared_ptr monitor); int32_t AddLocal(int32_t handlerId, InputHandlerType handlerType, std::vector actionsType, std::shared_ptr monitor); int32_t AddToServer(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, uint32_t deviceTags, std::vector actionsType = std::vector()); bool IsNeedAddToServer(std::vector actionsType); int32_t RemoveLocal(int32_t handlerId, InputHandlerType handlerType, uint32_t &deviceTags); void UpdateAddToServerActions(); int32_t RemoveLocalActions(int32_t handlerId, InputHandlerType handlerType); int32_t RemoveFromServer(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, uint32_t deviceTags, std::vector actionsType = std::vector()); std::shared_ptr FindHandler(int32_t handlerId); void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime); void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime, bool isNeedConsume); void AddMouseEventId(std::shared_ptr pointerEvent); int32_t GetMonitorConsumerInfos(std::shared_ptr pointerEvent, std::map> &consumerInfos); #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) bool CheckInputDeviceSource(const std::shared_ptr pointerEvent, uint32_t deviceTags) const; void GetConsumerInfos(std::shared_ptr pointerEvent, uint32_t deviceTags, std::map> &consumerInfos); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH private: std::list interHandlers_; std::map monitorHandlers_; std::map actionsMonitorHandlers_; std::set mouseEventIds_; std::function monitorCallback_ { nullptr }; std::function monitorCallbackConsume_ { nullptr }; int32_t nextId_ { 1 }; std::mutex mtxHandlers_; std::shared_ptr lastPointerEvent_ { nullptr }; std::vector addToServerActions_; }; } // namespace MMI } // namespace OHOS #endif // INPUT_HANDLER_MANAGER_H