• 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 #ifndef INTERFACE_KITS_JS_KEYBOARD_CONTROLLER_H
16 #define INTERFACE_KITS_JS_KEYBOARD_CONTROLLER_H
17 
18 #include "async_call.h"
19 #include "global.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 struct HideKeyboardContext : public AsyncCall::Context {
24     napi_status status = napi_generic_failure;
HideKeyboardContextHideKeyboardContext25     HideKeyboardContext() : Context(nullptr, nullptr) { };
HideKeyboardContextHideKeyboardContext26     HideKeyboardContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
27 
operatorHideKeyboardContext28     napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
29     {
30         NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
31         return Context::operator()(env, argc, argv, self);
32     }
operatorHideKeyboardContext33     napi_status operator()(napi_env env, napi_value *result) override
34     {
35         if (status != napi_ok) {
36             output_ = nullptr;
37             return status;
38         }
39         return Context::operator()(env, result);
40     }
41 };
42 
43 struct HideContext : public AsyncCall::Context {
44     napi_status status = napi_generic_failure;
HideContextHideContext45     HideContext() : Context(nullptr, nullptr) { };
HideContextHideContext46     HideContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
47 
operatorHideContext48     napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
49     {
50         NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
51         return Context::operator()(env, argc, argv, self);
52     }
operatorHideContext53     napi_status operator()(napi_env env, napi_value *result) override
54     {
55         if (status != napi_ok) {
56             output_ = nullptr;
57             return status;
58         }
59         return Context::operator()(env, result);
60     }
61 };
62 
63 class JsKeyboardControllerEngine {
64 public:
65     JsKeyboardControllerEngine() = default;
66     ~JsKeyboardControllerEngine() = default;
67     static napi_value Init(napi_env env, napi_value info);
68     static napi_value GetKeyboardControllerInstance(napi_env env);
69     static napi_value HideKeyboard(napi_env env, napi_callback_info info);
70     static napi_value Hide(napi_env env, napi_callback_info info);
71 
72 private:
73     static napi_value JsConstructor(napi_env env, napi_callback_info info);
74     static const std::string KCE_CLASS_NAME;
75     static thread_local napi_ref KCERef_;
76 };
77 } // namespace MiscServices
78 } // namespace OHOS
79 #endif // INTERFACE_KITS_JS_KEYBOARD_CONTROLLER_H