1 /*
2 * Copyright (c) 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 #include "js_input_method_panel.h"
17
18 #include "global.h"
19 #include "js_runtime_utils.h"
20 #include "js_util.h"
21 #include "panel_info.h"
22
23 namespace OHOS {
24 namespace MiscServices {
Init(napi_env env,napi_value exports)25 napi_value JsInputMethodPanel::Init(napi_env env, napi_value exports)
26 {
27 napi_set_named_property(env, exports, "PanelType", GetJsPanelTypeProperty(env));
28 napi_set_named_property(env, exports, "PanelFlag", GetJsPanelFlagProperty(env));
29 return exports;
30 }
31
GetJsPanelTypeProperty(napi_env env)32 napi_value JsInputMethodPanel::GetJsPanelTypeProperty(napi_env env)
33 {
34 napi_value obj = nullptr;
35 napi_create_object(env, &obj);
36
37 auto ret = JsUtil::Object::WriteProperty(env, obj, "SOFT_KEYBOARD", static_cast<int32_t>(PanelType::SOFT_KEYBOARD));
38 ret = ret && JsUtil::Object::WriteProperty(env, obj, "STATUS_BAR", static_cast<int32_t>(PanelType::STATUS_BAR));
39 if (!ret) {
40 IMSA_HILOGE("init module inputMethod.Panel.PanelType failed, ret: %{public}d!", ret);
41 }
42 return obj;
43 }
44
GetJsPanelFlagProperty(napi_env env)45 napi_value JsInputMethodPanel::GetJsPanelFlagProperty(napi_env env)
46 {
47 napi_value obj = nullptr;
48 napi_create_object(env, &obj);
49
50 auto ret = JsUtil::Object::WriteProperty(env, obj, "FLAG_FIXED", static_cast<int32_t>(PanelFlag::FLG_FIXED));
51 ret = ret
52 && JsUtil::Object::WriteProperty(env, obj, "FLAG_FLOATING", static_cast<int32_t>(PanelFlag::FLG_FLOATING));
53 ret = ret
54 && JsUtil::Object::WriteProperty(
55 env, obj, "FLAG_CANDIDATE", static_cast<int32_t>(PanelFlag::FLG_CANDIDATE_COLUMN));
56 if (!ret) {
57 IMSA_HILOGI("init module inputMethod.Panel.PanelFlag failed, ret: %{public}d!", ret);
58 }
59 return obj;
60 }
61 } // namespace MiscServices
62 } // namespace OHOS