• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 NATIVE_INPUTMETHOD_TYPES_H
16 #define NATIVE_INPUTMETHOD_TYPES_H
17 #include <string>
18 #include <variant>
19 
20 #include "inputmethod_controller_capi.h"
21 constexpr int32_t MAX_PLACEHOLDER_SIZE = 255; // 255 utf-16 chars
22 constexpr int32_t MAX_ABILITY_NAME_SIZE = 127; // 127 utf-16 chars
23 // Maximum size of char16_t string, including the null terminator (0x0000).
24 // The range of one UTF16 encoded character is [1,2] char16_t.
25 constexpr size_t MAX_PLACEHOLDER_INPUT_SIZE = MAX_PLACEHOLDER_SIZE * 2 + 1;
26 // Maximum size of char16_t string, including the null terminator (0x0000).
27 constexpr size_t MAX_ABILITY_NAME_INPUT_SIZE = MAX_ABILITY_NAME_SIZE * 2 + 1;
28 constexpr char16_t UTF16_ENDING_SYMBOL = u'\0';
29 constexpr size_t ENDING_SYMBOL_SIZE = 1;
30 
31 struct InputMethod_PrivateCommand {
32     std::string key;
33     std::variant<std::string, bool, int32_t> value;
34 };
35 
36 struct InputMethod_CursorInfo {
37     double left = -1.0;
38     double top = -1.0;
39     double width = -1.0;
40     double height = -1.0;
41 };
42 
43 struct InputMethod_TextAvoidInfo {
44     double positionY;
45     double height;
46 };
47 struct InputMethod_TextConfig {
48     InputMethod_TextInputType inputType;
49     InputMethod_EnterKeyType enterKeyType;
50     bool previewTextSupported;
51     InputMethod_CursorInfo cursorInfo;
52     InputMethod_TextAvoidInfo avoidInfo;
53     int32_t selectionStart;
54     int32_t selectionEnd;
55     int32_t windowId;
56     char16_t placeholder[MAX_PLACEHOLDER_INPUT_SIZE];
57     size_t placeholderLength = 1;
58     char16_t abilityName[MAX_ABILITY_NAME_INPUT_SIZE];
59     size_t abilityNameLength = 1;
60 };
61 
62 struct InputMethod_MessageHandlerProxy {
63     OH_MessageHandlerProxy_OnTerminatedFunc onTerminatedFunc;
64     OH_MessageHandlerProxy_OnMessageFunc onMessageFunc;
65 };
66 
67 struct InputMethod_TextEditorProxy {
68     OH_TextEditorProxy_GetTextConfigFunc getTextConfigFunc;
69     OH_TextEditorProxy_InsertTextFunc insertTextFunc;
70     OH_TextEditorProxy_DeleteForwardFunc deleteForwardFunc;
71     OH_TextEditorProxy_DeleteBackwardFunc deleteBackwardFunc;
72     OH_TextEditorProxy_SendKeyboardStatusFunc sendKeyboardStatusFunc;
73     OH_TextEditorProxy_SendEnterKeyFunc sendEnterKeyFunc;
74     OH_TextEditorProxy_MoveCursorFunc moveCursorFunc;
75     OH_TextEditorProxy_HandleSetSelectionFunc handleSetSelectionFunc;
76     OH_TextEditorProxy_HandleExtendActionFunc handleExtendActionFunc;
77     OH_TextEditorProxy_GetLeftTextOfCursorFunc getLeftTextOfCursorFunc;
78     OH_TextEditorProxy_GetRightTextOfCursorFunc getRightTextOfCursorFunc;
79     OH_TextEditorProxy_GetTextIndexAtCursorFunc getTextIndexAtCursorFunc;
80     OH_TextEditorProxy_ReceivePrivateCommandFunc receivePrivateCommandFunc;
81     OH_TextEditorProxy_SetPreviewTextFunc setPreviewTextFunc;
82     OH_TextEditorProxy_FinishTextPreviewFunc finishTextPreviewFunc;
83 };
84 
85 struct InputMethod_AttachOptions {
86     bool showKeyboard;
87     InputMethod_RequestKeyboardReason requestKeyboardReason =
88         InputMethod_RequestKeyboardReason::IME_REQUEST_REASON_NONE;
89 };
90 constexpr int32_t MAX_TEXT_LENGTH = 8 * 1024;
91 #endif  // NATIVE_INPUTMETHOD_TYPES_H
92