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 MMI_ADAPTER_IMPL_H 17 #define MMI_ADAPTER_IMPL_H 18 19 #include "mmi_adapter.h" 20 21 #include "input_manager.h" 22 #include "key_event.h" 23 24 namespace OHOS::NWeb { 25 class MMIListenerAdapterImpl : public MMI::IInputDeviceListener { 26 public: 27 explicit MMIListenerAdapterImpl(std::shared_ptr<MMIListenerAdapter> listener); 28 29 ~MMIListenerAdapterImpl() override; 30 31 void OnDeviceAdded(int32_t deviceId, const std::string &type) override; 32 33 void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; 34 35 private: 36 std::shared_ptr<MMIListenerAdapter> listener_ = nullptr; 37 }; 38 39 class MMIInputListenerAdapterImpl : public MMI::IInputEventConsumer { 40 public: 41 explicit MMIInputListenerAdapterImpl(std::shared_ptr<MMIInputListenerAdapter> listener); 42 43 ~MMIInputListenerAdapterImpl() override; 44 45 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 46 47 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 48 49 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 50 51 private: 52 std::shared_ptr<MMIInputListenerAdapter> listener_ = nullptr; 53 }; 54 55 class MMIAdapterImpl : public MMIAdapter { 56 public: 57 MMIAdapterImpl() = default; 58 59 ~MMIAdapterImpl() override = default; 60 61 char* KeyCodeToString(int32_t keyCode) override; 62 63 int32_t RegisterMMIInputListener(std::shared_ptr<MMIInputListenerAdapter> eventCallback) override; 64 65 void UnregisterMMIInputListener(int32_t monitorId) override; 66 67 int32_t RegisterDevListener(std::string type, std::shared_ptr<MMIListenerAdapter> listener) override; 68 69 int32_t UnregisterDevListener(std::string type) override; 70 71 int32_t GetKeyboardType(int32_t deviceId, int32_t& type) override; 72 73 int32_t GetDeviceIds(std::vector<int32_t>& ids) override; 74 75 int32_t GetDeviceInfo(int32_t deviceId, std::shared_ptr<MMIDeviceInfoAdapter> info) override; 76 77 private: 78 std::shared_ptr<MMI::IInputDeviceListener> devListener_ = nullptr; 79 std::shared_ptr<MMI::IInputEventConsumer> inputListener_ = nullptr; 80 }; 81 } // namespace OHOS::NWeb 82 83 #endif // MMI_ADAPTER_IMPL_H 84