• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/memory/referenced.h"
20 #include "base/utils/singleton.h"
21 #include "base/utils/macros.h"
22 #include "core/event/key_event.h"
23 #include "core/event/touch_event.h"
24 #include "core/common/clipboard/clipboard_proxy.h"
25 #include "flutter/shell/platform/glfw/public/flutter_glfw.h"
26 
27 namespace OHOS::Ace::Platform {
28 
29 using CallbackGetKeyboardStatus = std::function< bool(void) >;
30 
31 class ACE_FORCE_EXPORT_WITH_PREVIEW EventDispatcher : public Singleton<EventDispatcher> {
32     DECLARE_SINGLETON(EventDispatcher);
33 public:
34     void Initialize();
35     void SetGlfwWindowController(const FlutterDesktopWindowControllerRef& controller);
36     void DispatchIdleEvent(int64_t deadline);
37     bool DispatchTouchEvent(const TouchEvent& event);
38     bool DispatchBackPressedEvent();
39     bool DispatchInputMethodEvent(unsigned int code_point);
40     bool DispatchKeyEvent(const KeyEvent& event);
41     void RegisterCallbackGetCapsLockStatus(CallbackGetKeyboardStatus callback);
42     void RegisterCallbackGetNumLockStatus(CallbackGetKeyboardStatus callback);
43 
44 private:
45     // Process all printable characters. If the input method is used, this function is invalid.
46     bool HandleTextKeyEvent(const KeyEvent& event);
47     FlutterDesktopWindowControllerRef controller_ = nullptr;
48     CallbackGetKeyboardStatus callbackGetCapsLockStatus_;
49     CallbackGetKeyboardStatus callbackGetNumLockStatus_;
50 };
51 
52 } // namespace OHOS::Ace::Platform
53 
54 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_EVENT_DISPATCHER_H
55