1 /* 2 * Copyright (c) 2022-2024 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 I_INPUT_EVENT_HANDLER_H 17 #define I_INPUT_EVENT_HANDLER_H 18 19 #include <memory> 20 21 #include "axis_event.h" 22 #include "define_multimodal.h" 23 #include "key_event.h" 24 #include "pointer_event.h" 25 #include "switch_event.h" 26 27 struct libinput_event; 28 29 namespace OHOS { 30 namespace MMI { 31 class IInputEventHandler { 32 public: 33 struct IInputEventConsumer { 34 public: 35 IInputEventConsumer() = default; 36 virtual ~IInputEventConsumer() = default; 37 38 virtual void OnInputEvent(InputHandlerType type, std::shared_ptr<KeyEvent> event) const; 39 virtual void OnInputEvent(InputHandlerType type, std::shared_ptr<PointerEvent> event) const; 40 virtual void OnInputEvent(InputHandlerType type, std::shared_ptr<AxisEvent> event) const; 41 }; 42 IInputEventHandler() = default; 43 DISALLOW_COPY_AND_MOVE(IInputEventHandler); 44 virtual ~IInputEventHandler() = default; 45 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 46 virtual void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) = 0; 47 #endif // OHOS_BUILD_ENABLE_KEYBOARD 48 #ifdef OHOS_BUILD_ENABLE_POINTER 49 virtual void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) = 0; 50 #endif // OHOS_BUILD_ENABLE_POINTER 51 #ifdef OHOS_BUILD_ENABLE_TOUCH 52 virtual void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) = 0; 53 #endif // OHOS_BUILD_ENABLE_TOUCH 54 #ifdef OHOS_BUILD_ENABLE_SWITCH HandleSwitchEvent(const std::shared_ptr<SwitchEvent> switchEvent)55 virtual void HandleSwitchEvent(const std::shared_ptr<SwitchEvent> switchEvent) 56 { 57 if (nextHandler_ != nullptr) { 58 nextHandler_->HandleSwitchEvent(switchEvent); 59 } 60 } 61 #endif // OHOS_BUILD_ENABLE_SWITCH SetNext(std::shared_ptr<IInputEventHandler> nextHandler)62 virtual void SetNext(std::shared_ptr<IInputEventHandler> nextHandler) 63 { 64 nextHandler_ = nextHandler; 65 }; 66 67 protected: 68 std::shared_ptr<IInputEventHandler> nextHandler_ { nullptr }; 69 }; 70 } // namespace MMI 71 } // namespace OHOS 72 #endif // I_INPUT_EVENT_HANDLER_H