1 /* 2 * Copyright (c) 2021 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_GETINPUT_METHOD_CCONTROLLER_H 16 #define INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H 17 18 #include "async_call.h" 19 #include "global.h" 20 #include "js_input_method.h" 21 22 namespace OHOS { 23 namespace MiscServices { 24 struct HandleContext : public AsyncCall::Context { 25 bool isHandle = false; 26 napi_status status = napi_generic_failure; HandleContextHandleContext27 HandleContext() : Context(nullptr, nullptr) { }; HandleContextHandleContext28 HandleContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { }; 29 operatorHandleContext30 napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override 31 { 32 NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg); 33 return Context::operator()(env, argc, argv, self); 34 } operatorHandleContext35 napi_status operator()(napi_env env, napi_value *result) override 36 { 37 if (status != napi_ok) { 38 output_ = nullptr; 39 return status; 40 } 41 return Context::operator()(env, result); 42 } 43 }; 44 45 class JsGetInputMethodController { 46 public: 47 JsGetInputMethodController() = default; 48 ~JsGetInputMethodController() = default; 49 static napi_value Init(napi_env env, napi_value info); 50 static napi_value GetController(napi_env env, napi_callback_info cbInfo); 51 static napi_value GetInputMethodController(napi_env env, napi_callback_info cbInfo); 52 static napi_value HandleSoftKeyboard(napi_env env, napi_callback_info info, std::function<int32_t()> callback, 53 bool isOutput, bool needThrowException); 54 static napi_value HideSoftKeyboard(napi_env env, napi_callback_info info); 55 static napi_value ShowSoftKeyboard(napi_env env, napi_callback_info info); 56 static napi_value StopInputSession(napi_env env, napi_callback_info info); 57 static napi_value StopInput(napi_env env, napi_callback_info info); 58 59 private: 60 static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo); 61 static napi_value GetIMController(napi_env env, napi_callback_info cbInfo, bool needThrowException); 62 static const std::string IMC_CLASS_NAME; 63 static thread_local napi_ref IMCRef_; 64 }; 65 } // namespace MiscServices 66 } // namespace OHOS 67 #endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H 68