• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef EVENT_DISPATCH_HANDLER_H
16 #define EVENT_DISPATCH_HANDLER_H
17 
18 #include <mutex>
19 
20 #include "nocopyable.h"
21 
22 #include "i_input_event_handler.h"
23 #include "key_event.h"
24 #include "key_event_value_transformation.h"
25 #include "pointer_event.h"
26 #include "uds_server.h"
27 
28 namespace OHOS {
29 namespace MMI {
30 class EventDispatchHandler : public IInputEventHandler {
31     struct DinputSimulateEvent {
32         uint32_t type { PointerEvent::SOURCE_TYPE_UNKNOWN };
33         uint32_t code { PointerEvent::BUTTON_NONE };
34         int32_t value { PointerEvent::POINTER_ACTION_UNKNOWN };
35     };
36 public:
37     EventDispatchHandler();
38     DISALLOW_COPY_AND_MOVE(EventDispatchHandler);
39     virtual ~EventDispatchHandler();
40 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
41     void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) override;
42 #endif // OHOS_BUILD_ENABLE_KEYBOARD
43 #ifdef OHOS_BUILD_ENABLE_POINTER
44     void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
45 #endif // OHOS_BUILD_ENABLE_POINTER
46 #ifdef OHOS_BUILD_ENABLE_TOUCH
47     void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) override;
48 #endif // OHOS_BUILD_ENABLE_TOUCH
49 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
50     int32_t DispatchKeyEventPid(UDSServer& udsServer, std::shared_ptr<KeyEvent> key);
51 #endif // OHOS_BUILD_ENABLE_KEYBOARD
52 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
53     void HandlePointerEventInner(const std::shared_ptr<PointerEvent> point);
54 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
55 #ifdef OHOS_BUILD_ENABLE_COOPERATE
56     void OnDinputSimulateEvent(uint32_t type, uint32_t code, int32_t value);
57     bool CheckPointerEvent(std::shared_ptr<PointerEvent> pointerEvent);
58 #endif // OHOS_BUILD_ENABLE_COOPERATE
59 
60 private:
61 #ifdef OHOS_BUILD_ENABLE_COOPERATE
62     std::mutex lock_;
63     std::vector<DinputSimulateEvent> dinputSimulateEvent_;
64 #endif // OHOS_BUILD_ENABLE_COOPERATE
65     int32_t eventTime_ { 0 };
66     int32_t currentTime_ { 0 };
67 };
68 } // namespace MMI
69 } // namespace OHOS
70 #endif // EVENT_DISPATCH_HANDLER_H
71