• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_SAMPLES_KEY_INPUT_HANDLER_H
17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_SAMPLES_KEY_INPUT_HANDLER_H
18 
19 #include "core/event/key_event.h"
20 
21 #ifndef ENABLE_ROSEN_BACKEND
22 #include "flutter/shell/platform/glfw/public/flutter_glfw.h"
23 #include "flutter/shell/platform/glfw/keyboard_hook_handler.h"
24 #else
25 #include "glfw_render_context.h"
26 #include "GLFW/glfw3.h"
27 #endif
28 
29 namespace OHOS::Ace::Platform {
30 
31 #ifndef ENABLE_ROSEN_BACKEND
32 class KeyInputHandler : public flutter::KeyboardHookHandler {
33 public:
34     KeyInputHandler() = default;
35     ~KeyInputHandler() override = default;
36 
37     static void InitialTextInputCallback(FlutterDesktopWindowControllerRef controller);
38     // A function for hooking into keyboard input.
39     void KeyboardHook(GLFWwindow* window, int key, int scancode, int action, int mods) override;
40 
41     // A function for hooking into unicode code point input.
42     void CharHook(GLFWwindow* window, unsigned int code_point) override;
43 
44 private:
45     bool RecognizeKeyEvent(int key, int action, int mods);
46     KeyEvent keyEvent_;
47 };
48 #else
49 class KeyInputHandler {
50 public:
51     static void InitialTextInputCallback(const std::shared_ptr<OHOS::Rosen::GlfwRenderContext> &controller);
52     static void KeyboardHook(GLFWwindow* window, int key, int scancode, int action, int mods);
53     static void CharHook(GLFWwindow* window, unsigned int code_point);
54 
55 private:
56     static bool RecognizeKeyEvent(int key, int action, int mods);
57     static inline KeyEvent keyEvent_;
58 };
59 #endif
60 
61 } // namespace OHOS::Ace::Platform
62 
63 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_SAMPLES_KEY_INPUT_HANDLER_H
64