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 
16 #include "core/common/ime/text_input_configuration.h"
17 
18 #include "base/json/json_util.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 
23 // Negotiated fields with Java
24 const char TYPE[] = "type";
25 const char OBSCURE_TEXT[] = "obscureText";
26 const char ACTION_LABEL[] = "actionLabel";
27 const char ACTION[] = "action";
28 const char AUTO_CORRECT[] = "autoCorrect";
29 const char CAPITALIZATION[] = "capitalization";
30 const char KEYBOARD_APPEARANCE[] = "keyboardAppearance";
31 const char INPUT_FILTER[] = "inputFilter";
32 const char MAX_LENGTH[] = "maxLength";
33 } // namespace
34 
ToJsonString() const35 std::string TextInputConfiguration::ToJsonString() const
36 {
37     auto json = JsonUtil::Create(true);
38     json->Put(TYPE, static_cast<int32_t>(type));
39     json->Put(OBSCURE_TEXT, obscureText);
40     json->Put(ACTION, static_cast<int32_t>(action));
41     if (!actionLabel.empty()) {
42         json->Put(ACTION_LABEL, actionLabel.c_str());
43     }
44 
45     json->Put(AUTO_CORRECT, autoCorrect);
46     if (!capitalization.empty()) {
47         json->Put(CAPITALIZATION, capitalization.c_str());
48     }
49     if (!keyboardAppearance.empty()) {
50         json->Put(KEYBOARD_APPEARANCE, keyboardAppearance.c_str());
51     }
52     if (!inputFilter.empty()) {
53         json->Put(INPUT_FILTER, inputFilter.c_str());
54     }
55     json->Put(MAX_LENGTH, static_cast<int32_t>(maxLength));
56     return json->ToString();
57 }
58 
59 } // namespace OHOS::Ace
60