/* * Copyright (c) 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_ADAPTER_H #define INPUT_ADAPTER_H #include "nocopyable.h" #include "i_input_adapter.h" #include "i_input_event_consumer.h" #include "i_input_event_filter.h" namespace OHOS { namespace Msdp { namespace DeviceStatus { class InputAdapter final : public IInputAdapter { public: InputAdapter() = default; ~InputAdapter() = default; DISALLOW_COPY_AND_MOVE(InputAdapter); int32_t AddMonitor(std::function)> callback) override; int32_t AddMonitor(std::function)> callback) override; void RemoveMonitor(int32_t monitorId) override; int32_t AddInterceptor(std::function)> pointerCb) override; int32_t AddInterceptor(std::function)> keyCb) override; int32_t AddInterceptor(std::function)> pointerCb, std::function)> keyCb) override; void RemoveInterceptor(int32_t interceptorId) override; int32_t AddFilter(std::function)> callback) override; void RemoveFilter(int32_t filterId) override; int32_t SetPointerVisibility(bool visible, int32_t priority = 0) override; int32_t SetPointerLocation(int32_t x, int32_t y) override; int32_t EnableInputDevice(bool enable) override; void SimulateInputEvent(std::shared_ptr pointerEvent) override; void SimulateInputEvent(std::shared_ptr keyEvent) override; int32_t AddVirtualInputDevice(std::shared_ptr device, int32_t &deviceId) override; int32_t RemoveVirtualInputDevice(int32_t deviceId) override; }; class PointerFilter : public MMI::IInputEventFilter { public: explicit PointerFilter(std::function)> filter) : filter_(filter) {} bool OnInputEvent(std::shared_ptr pointerEvent) const override { return (filter_ != nullptr ? filter_(pointerEvent) : false); } bool OnInputEvent(std::shared_ptr keyEvent) const override { return false; } private: std::function)> filter_; }; class InterceptorConsumer : public MMI::IInputEventConsumer { public: InterceptorConsumer(std::function)> pointerCb, std::function)> keyCb) : pointerCb_(pointerCb), keyCb_(keyCb) {} void OnInputEvent(std::shared_ptr keyEvent) const override { if (keyCb_ != nullptr) { keyCb_(keyEvent); } } void OnInputEvent(std::shared_ptr pointerEvent) const override { if (pointerCb_ != nullptr) { pointerCb_(pointerEvent); } } void OnInputEvent(std::shared_ptr axisEvent) const override {} private: std::function)> pointerCb_; std::function)> keyCb_; }; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS #endif // INPUT_ADAPTER_H