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