• 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 * inputmethod
20 *
21 * @since 8
22 * @devices phone, tablet, tv, wearable
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(callbakc: AsyncCallback<void>): void;
62        hideKeyboard(): Promise<void>;
63    }
64
65    interface InputMethodEngine {
66        on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
67        off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
68
69        on(type: 'keyboardShow', callback: () => void): void;
70        off(type: 'keyboardShow', callback: () => void): void;
71
72        on(type: 'keyboardHide', callback: () => void): void;
73        off(type: 'keyboardHide', callback: () => void): void;
74    }
75
76    interface TextInputClient {
77        sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void;
78        sendKeyFunction(action: number): Promise<boolean>;
79
80        deleteForward(length: number, callback: AsyncCallback<boolean>): void;
81        deleteForward(length: number): Promise<boolean>;
82
83        deleteBackward(length: number, callback: AsyncCallback<boolean>): void;
84        deleteBackward(length: number): Promise<boolean>;
85
86        InsertText(text: string, callback: AsyncCallback<boolean>): void;
87        InsertText(text: string): Promise<boolean>;
88
89        getForward(length: number, callback: AsyncCallback<string>): void;
90        getForward(length: number): Promise<string>;
91
92        getEditorAttribute(lcallback: AsyncCallback<EditorAttribute>): void;
93        getEditorAttribute(): Promise<EditorAttribute>;
94    }
95
96    interface KeyboardDelegate {
97        on(type: 'keyDown', callback: (event: KeyEvent) => boolean): void;
98        off(type: 'keyDown', callback?: (event: KeyEvent) => boolean): void;
99
100        on(type: 'keyUp', callback: (event: KeyEvent) => boolean): void;
101        off(type: 'keyUp', callback?: (event: KeyEvent) => boolean): void;
102
103        on(type: 'cursorContextChange', callback: (x: number, y: number, height: number) => void): void;
104        off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void;
105
106        on(type: 'selectionChange', callback: (oldBegine: number, oldEnd: number, newBegine: number, newEnd: number) => void): void;
107        off(type: 'selectionChange', callback?: (oldBegine: number, oldEnd: number, newBegine: number, newEnd: number) => void): void;
108
109        on(type: 'textChange', callback: (text: string) => void): void;
110        off(type: 'textChange', callback?: (text: string) => void): void;
111    }
112
113    interface EditorAttribute {
114        readonly inputPattern: number;
115        readonly enterKeyType: number;
116    }
117}
118
119export default inputMethodEngine;
120