• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INPUT_METHOD_H
16 #define INTERFACE_KITS_JS_INPUT_METHOD_H
17 
18 #include "async_call.h"
19 #include "element_name.h"
20 #include "global.h"
21 #include "input_method_controller.h"
22 #include "native_engine/native_engine.h"
23 #include "native_engine/native_value.h"
24 
25 namespace OHOS {
26 namespace MiscServices {
27 struct SwitchInputMethodContext : public AsyncCall::Context {
28     bool isSwitchInput = false;
29     std::string packageName; // in InputMethodProperty
30     std::string methodId;    // in InputMethodProperty
31     std::string name;        // in InputMethodSubtype
32     std::string id;          // in InputMethodSubtype
33     SwitchTrigger trigger;
34     napi_status status = napi_generic_failure;
SwitchInputMethodContextSwitchInputMethodContext35     SwitchInputMethodContext() : Context(nullptr, nullptr){};
SwitchInputMethodContextSwitchInputMethodContext36     SwitchInputMethodContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)){};
37 
operatorSwitchInputMethodContext38     napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
39     {
40         CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
41         return Context::operator()(env, argc, argv, self);
42     }
operatorSwitchInputMethodContext43     napi_status operator()(napi_env env, napi_value *result) override
44     {
45         if (status != napi_ok) {
46             output_ = nullptr;
47             return status;
48         }
49         return Context::operator()(env, result);
50     }
51 };
52 
53 class JsInputMethod {
54 public:
55     JsInputMethod() = default;
56     ~JsInputMethod() = default;
57     static napi_value Init(napi_env env, napi_value exports);
58     static napi_value SwitchInputMethod(napi_env env, napi_callback_info info);
59     static napi_value SwitchCurrentInputMethodSubtype(napi_env env, napi_callback_info info);
60     static napi_value SwitchCurrentInputMethodAndSubtype(napi_env env, napi_callback_info info);
61     static napi_value GetCurrentInputMethodSubtype(napi_env env, napi_callback_info info);
62     static napi_value GetCurrentInputMethod(napi_env env, napi_callback_info info);
63     static napi_value GetDefaultInputMethod(napi_env env, napi_callback_info info);
64     static napi_value GetSystemInputMethodConfigAbility(napi_env env, napi_callback_info info);
65     static napi_value GetJsInputMethodProperty(napi_env env, const Property &property);
66     static napi_value GetJSInputMethodSubProperties(napi_env env, const std::vector<SubProperty> &subProperties);
67     static napi_value GetJSInputMethodProperties(napi_env env, const std::vector<Property> &properties);
68     static napi_value GetJsInputMethodSubProperty(napi_env env, const SubProperty &subProperty);
69     static napi_value GetJsInputConfigElement(napi_env env, const OHOS::AppExecFwk::ElementName &elementName);
70 
71 private:
72     static napi_status GetInputMethodProperty(
73         napi_env env, napi_value argv, std::shared_ptr<SwitchInputMethodContext> ctxt);
74     static napi_status GetInputMethodSubProperty(
75         napi_env env, napi_value argv, std::shared_ptr<SwitchInputMethodContext> ctxt);
76     static constexpr std::int32_t MAX_VALUE_LEN = 4096;
77     static constexpr size_t PARAM_POS_TWO = 2;
78     static constexpr size_t PARAM_POS_ONE = 1;
79 };
80 } // namespace MiscServices
81 } // namespace OHOS
82 #endif // INTERFACE_KITS_JS_INPUT_METHOD_H
83