• 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
16import {AsyncCallback} from './basic';
17
18/**
19 * inputmethodengine
20 *
21 * @since 8
22 * @syscap SystemCapability.MiscServices.InputMethodFramework
23 */
24declare namespace inputMethodEngine {
25    const ENTER_KEY_TYPE_UNSPECIFIED: number;
26    const ENTER_KEY_TYPE_GO: number;
27    const ENTER_KEY_TYPE_SEARCH: number;
28    const ENTER_KEY_TYPE_SEND: number;
29    const ENTER_KEY_TYPE_NEXT: number;
30    const ENTER_KEY_TYPE_DONE: number;
31    const ENTER_KEY_TYPE_PREVIOUS: number;
32
33    const PATTERN_NULL: number;
34    const PATTERN_TEXT: number;
35    const PATTERN_NUMBER: number;
36    const PATTERN_PHONE: number;
37    const PATTERN_DATETIME: number;
38    const PATTERN_EMAIL: number;
39    const PATTERN_URI: number;
40    const PATTERN_PASSWORD: number;
41
42    const FLAG_SELECTING: number;
43    const FLAG_SINGLE_LINE: number;
44
45    const DISPLAY_MODE_PART: number;
46    const DISPLAY_MODE_FULL: number;
47
48    const OPTION_ASCII: number;
49    const OPTION_NONE: number;
50    const OPTION_AUTO_CAP_CHARACTERS: number;
51    const OPTION_AUTO_CAP_SENTENCES: number;
52    const OPTION_AUTO_WORDS: number;
53    const OPTION_MULTI_LINE: number;
54    const OPTION_NO_FULLSCREEN: number;
55
56    function getInputMethodEngine(): InputMethodEngine;
57
58    function createKeyboardDelegate(): KeyboardDelegate;
59
60    interface KeyboardController {
61        hideKeyboard(callback: AsyncCallback<void>): void;
62
63        hideKeyboard(): Promise<void>;
64    }
65
66    interface InputMethodEngine {
67        on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
68
69        off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
70
71        on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void;
72
73        off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void;
74    }
75
76    interface TextInputClient {
77        sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void;
78
79        sendKeyFunction(action: number): Promise<boolean>;
80
81        deleteForward(length: number, callback: AsyncCallback<boolean>): void;
82
83        deleteForward(length: number): Promise<boolean>;
84
85        deleteBackward(length: number, callback: AsyncCallback<boolean>): void;
86
87        deleteBackward(length: number): Promise<boolean>;
88
89        insertText(text: string, callback: AsyncCallback<boolean>): void;
90
91        insertText(text: string): Promise<boolean>;
92
93        getForward(length: number, callback: AsyncCallback<string>): void;
94
95        getForward(length: number): Promise<string>;
96
97        getBackward(length: number, callback: AsyncCallback<string>): void;
98
99        getBackward(length: number): Promise<string>;
100
101        getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void;
102
103        getEditorAttribute(): Promise<EditorAttribute>;
104    }
105
106    interface KeyboardDelegate {
107        on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void;
108
109        off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void;
110
111        on(type: 'cursorContextChange', callback: (x: number, y: number, height: number) => void): void;
112
113        off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void;
114
115        on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void;
116
117        off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void;
118
119        on(type: 'textChange', callback: (text: string) => void): void;
120
121        off(type: 'textChange', callback?: (text: string) => void): void;
122    }
123
124    interface EditorAttribute {
125        readonly inputPattern: number;
126        readonly enterKeyType: number;
127    }
128
129    interface KeyEvent {
130        readonly keyCode: number;
131        readonly keyAction: number;
132    }
133}
134
135export default inputMethodEngine;
136