• 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 
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 
32 } // namespace
33 
ToJsonString() const34 std::string TextInputConfiguration::ToJsonString() const
35 {
36     auto json = JsonUtil::Create(true);
37     json->Put(TYPE, static_cast<int32_t>(type));
38     json->Put(OBSCURE_TEXT, obscureText);
39     json->Put(ACTION, static_cast<int32_t>(action));
40     if (!actionLabel.empty()) {
41         json->Put(ACTION_LABEL, actionLabel.c_str());
42     }
43 
44     json->Put(AUTO_CORRECT, autoCorrect);
45     if (!capitalization.empty()) {
46         json->Put(CAPITALIZATION, capitalization.c_str());
47     }
48     if (!keyboardAppearance.empty()) {
49         json->Put(KEYBOARD_APPEARANCE, keyboardAppearance.c_str());
50     }
51 
52     return json->ToString();
53 }
54 
55 } // namespace OHOS::Ace
56