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