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 FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_EVENT_DISPATCHER_H
17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_EVENT_DISPATCHER_H
18 
19 #include "adapter/preview/external/multimodalinput/axis_event.h"
20 #include "adapter/preview/external/multimodalinput/key_event.h"
21 #include "adapter/preview/external/multimodalinput/pointer_event.h"
22 #include "base/memory/referenced.h"
23 #include "base/utils/macros.h"
24 #include "base/utils/singleton.h"
25 #include "core/common/clipboard/clipboard_proxy.h"
26 #ifndef ENABLE_ROSEN_BACKEND
27 #include "flutter/shell/platform/glfw/public/flutter_glfw.h"
28 #endif
29 
30 namespace OHOS::Ace::Platform {
31 
32 class ACE_FORCE_EXPORT EventDispatcher : public Singleton<EventDispatcher> {
33     DECLARE_SINGLETON(EventDispatcher);
34 
35 public:
36     void Initialize();
37     void DispatchIdleEvent(int64_t deadline);
38     bool DispatchTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
39     bool DispatchBackPressedEvent();
40     bool DispatchInputMethodEvent(unsigned int codePoint);
41     bool DispatchKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
42 #ifndef ENABLE_ROSEN_BACKEND
SetGlfwWindowController(const FlutterDesktopWindowControllerRef & controller)43     void SetGlfwWindowController(const FlutterDesktopWindowControllerRef& controller)
44     {
45         controller_ = controller;
46     }
47 #endif
48 
49 private:
50     // Process all printable characters. If the input method is used, this function is invalid.
51     bool HandleTextKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
52 #ifndef ENABLE_ROSEN_BACKEND
53     FlutterDesktopWindowControllerRef controller_ = nullptr;
54 #endif
55 };
56 
57 } // namespace OHOS::Ace::Platform
58 
59 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_EVENT_DISPATCHER_H
60