From 38b31bb4c4028b6b11843984b221e6d2f4d5c7c2 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 10 Oct 2022 17:03:56 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../systemplugin/napi/ohos_inputmethod.js | 225 +++++++++++++++--- .../napi/ohos_inputmethodengine.js | 213 ++++++++++++++--- .../napi/ohos_inputmethodextensioncontext.js | 12 + .../napi/ohos_inputmethodsubtype.js | 26 ++ 4 files changed, 409 insertions(+), 67 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/ohos_inputmethodsubtype.js diff --git a/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js index 5ff426d6..c47448a5 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethod.js @@ -14,46 +14,9 @@ */ import { paramMock } from "../utils" +import { InputMethodSubtype } from "../napi/ohos_inputmethodsubtype" export function mockInputMethod() { - const KeyboardType = { - labelId: 1, - iconId: 2, - language: "[PC Preview] unknow language", - inputSource: "[PC Preview] unknow inputSource", - customizedValue: { - key: 1 - }, - supportsAscii: true - } - const KeyboardTypeArry = [ - { - labelId: 1, - iconId: 2, - language: "[PC Preview] unknow language", - inputSource: "[PC Preview] unknow inputSource", - customizedValue: { - key: 1 - }, - supportsAscii: true - } - ] - const InputMethodProperty = { - packageName :"[PC Preview] unknow packageName", - methodId: "[PC Preview] unknow method id" - } - const InputMethodPropertyArry = [ - { - methodId: "[PC Preview] unknow method id", - bundleName: "[PC Preview] unknow bundle name", - abilityName: "[PC Preview] unknow ability name", - configurationPage: "[PC Preview] unknow configuration page", - isSystemIme: true, - typeCount: 1, - defaultImeId: 2, - keyboardTypes: KeyboardTypeArry - } - ] const InputMethodControllerMock = { stopInput: function (...args) { console.warn("InputMethodController.stopInput interface mocked in the Previewer. How this interface works on" + @@ -67,6 +30,18 @@ export function mockInputMethod() { }) } }, + stopInputSession: function (...args) { + console.warn("InputMethodController.stopInputSession interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, showSoftKeyboard: function (...args) { console.warn("InputMethodController.showSoftKeyboard interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") @@ -141,6 +116,18 @@ export function mockInputMethod() { }) } }, + getInputMethods: function (...args) { + console.warn("InputMethodSetting.getInputMethods interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry); + } else { + return new Promise((resolve, reject) => { + resolve(InputMethodPropertyArry); + }) + } + }, displayOptionalInputMethod: function (...args) { console.warn("InputMethodSetting.displayOptionalInputMethod interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") @@ -153,24 +140,107 @@ export function mockInputMethod() { }) } }, + showOptionalInputMethods: function (...args) { + console.warn("InputMethodSetting.showOptionalInputMethods interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + listCurrentInputMethodSubtype: function (...args) { + console.warn("InputMethodSetting.listCurrentInputMethodSubtype interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, InputMethodSubtypeArry); + } else { + return new Promise((resolve, reject) => { + resolve(InputMethodSubtypeArry); + }) + } + }, + listInputMethodSubtype: function (...args) { + console.warn("InputMethodSetting.listInputMethodSubtype interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, InputMethodSubtypeArry); + } else { + return new Promise((resolve, reject) => { + resolve(InputMethodSubtypeArry); + }) + } + }, + on: function (...args) { + console.warn("InputMethodSetting.on interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'imeChange') { + args[len - 1].call(this, InputMethodProperty, InputMethodSubtype); + } + } + }, + off: function (...args) { + console.warn("InputMethodSetting.off interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'imeChange') { + args[len - 1].call(this, InputMethodProperty, InputMethodSubtype); + } + } + }, } const inputMethod = { MAX_TYPE_NUM: 128, + EXCEPTION_OTHERS: 12899999, + EXCEPTION_IMMS: 12800008, + EXCEPTION_SETTINGS: 12800007, + EXCEPTION_CONTROLLER: 12800006, + EXCEPTION_CONFPERSIST: 12800005, + EXCEPTION_KEYEVENT: 12800004, + EXCEPTION_IMCLIENT: 12800003, + EXCEPTION_IMENGINE: 12800002, + EXCEPTION_PACKAGEMANAGER: 12800001, + EXCEPTION_UNSUPPORTED: 12800801, + EXCEPTION_PARAMCHECK: 12800401, + EXCEPTION_PERMISSION: 12800201, getInputMethodController: function () { console.warn("inputmethod.getInputMethodController interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") return InputMethodControllerMock; }, + getController: function () { + console.warn("inputmethod.getController interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return InputMethodControllerMock; + }, getInputMethodSetting: function () { console.warn("inputmethod.getInputMethodSetting interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") return InputMethodSettingMock; }, + getSetting: function () { + console.warn("inputmethod.getSetting interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return InputMethodSettingMock; + }, getCurrentInputMethod: function () { console.warn("inputmethod.getCurrentInputMethod interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") return InputMethodProperty; }, + getCurrentInputMethodSubtype: function () { + console.warn("inputmethod.getCurrentInputMethodSubtype interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return InputMethodSubtype; + }, switchInputMethod: function (...args) { console.warn("inputMethod.switchInputMethod interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") @@ -183,6 +253,85 @@ export function mockInputMethod() { }) } }, + switchCurrentInputMethodSubtype: function (...args) { + console.warn("inputMethod.switchCurrentInputMethodSubtype interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + switchCurrentInputMethodAndSubtype: function (...args) { + console.warn("inputMethod.switchCurrentInputMethodAndSubtype interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + } + const InputMethodProperty = { + packageName :"[PC Preview] unknow packageName", + methodId: "[PC Preview] unknow method methodId", + name: "[PC Preview] unknow method name", + id: "[PC Preview] unknow method id", + label: "[PC Preview] unknow method label", + icon: "[PC Preview] unknow method icon", + iconId: "[PC Preview] unknow method iconId", + extra: "[PC Preview] unknow method extra", } + const KeyboardType = { + labelId: 1, + iconId: 2, + language: "[PC Preview] unknow language", + inputSource: "[PC Preview] unknow inputSource", + customizedValue: { + key: 1 + }, + supportsAscii: true + } + const KeyboardTypeArry = [ + { + labelId: 1, + iconId: 2, + language: "[PC Preview] unknow language", + inputSource: "[PC Preview] unknow inputSource", + customizedValue: { + key: 1 + }, + supportsAscii: true + } + ] + const InputMethodPropertyArry = [ + { + methodId: "[PC Preview] unknow method methodId", + bundleName: "[PC Preview] unknow bundle bundleName", + abilityName: "[PC Preview] unknow ability abilityName", + configurationPage: "[PC Preview] unknow configuration page", + isSystemIme: true, + typeCount: 1, + defaultImeId: 2, + keyboardTypes: KeyboardTypeArry + } + ] + const InputMethodSubtypeArry = [{ + label: "[PC Preview] unknow method label", + name: "[PC Preview] unknow method name", + id: "[PC Preview] unknow method id", + mode: "[PC Preview] unknow method mode", + locale: "[PC Preview] unknow method locale", + language: "[PC Preview] unknow method language", + icon: "[PC Preview] unknow method icon", + iconId: "[PC Preview] unknow method iconId", + extra: "[PC Preview] unknow method extra", + }] return inputMethod } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js index 2151d800..f35e8a62 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethodengine.js @@ -14,37 +14,9 @@ */ import { paramMock } from "../utils" +import { InputMethodSubtype } from "../napi/ohos_inputmethodsubtype" export function mockInputMethodEngine() { - const EditingText = { - textContent: "[PC Preview] unknow textContent", - offset: 1, - changedStart: 2, - changedEnd: 3, - selectionStart: 4, - selectionEnd: 5, - additionalBitFlags: 6, - prompt: "[PC Preview] unknow prompt" - } - const EditingCapability = { - maxLines: 1, - maxChars: 2 - } - const EditorAttribute = { - inputPattern: 1, - enterKeyType: 2, - inputOption: 3 - } - const KeyEvent = { - keyCode: "[PC Preview] unknow keyCode", - keyAction: "[PC Preview] unknow keyAction" - } - const RichContent = { - contentURI: "[PC Preview] unknow contentURI", - linkURI: "[PC Preview] unknow linkURI", - mimeTypes: "[PC Preview] unknow mimeTypes", - detail: "[PC Preview] unknow detail" - } const KeyboardControllerMock = { setDisplayMode: function (...args) { console.warn("KeyboardController.setDisplayMode interface mocked in the Previewer. How this interface works on" + @@ -82,6 +54,18 @@ export function mockInputMethodEngine() { }) } }, + hide: function (...args) { + console.warn("KeyboardController.hide interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, toNextInputMethod: function (...args) { console.warn("KeyboardController.toNextInputMethod interface mocked in the Previewer. How this interface works on" + " the Previewer may be different from that on a real device.") @@ -325,6 +309,104 @@ export function mockInputMethodEngine() { } } } + const InputClientMock = { + getEditorAttribute: function (...args) { + console.warn("InputClientMock.getEditorAttribute interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, EditorAttribute); + } else { + return new Promise((resolve, reject) => { + resolve(EditorAttribute); + }) + } + }, + insertText: function (...args) { + console.warn("InputClientMock.insertText interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + deleteBackward: function (...args) { + console.warn("InputClientMock.deleteBackward interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + deleteForward: function (...args) { + console.warn("InputClientMock.deleteForward interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + getForward: function (...args) { + console.warn("InputClientMock.getForward interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + getBackward: function (...args) { + console.warn("InputClientMock.getBackward interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + sendKeyFunction: function (...args) { + console.warn("InputClientMock.sendKeyFunction interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + moveCursor: function (...args) { + console.warn("InputClientMock.moveCursor interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } + } const InputMethodEngineMock = { on: function (...args) { console.warn("InputMethodEngine.on interface mocked in the Previewer. How this interface works on" + @@ -359,6 +441,40 @@ export function mockInputMethodEngine() { } } } + const InputMethodAbilityMock = { + on: function (...args) { + console.warn("InputMethodAbility.on interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'setSubtype') { + args[len - 1].call(this, InputMethodSubtype); + } else if (args[0] == 'inputStart') { + args[len - 1].call(this, KeyboardControllerMock, InputClientMock); + } else if (args[0] == 'inputStop' || args[0] == 'keyboardShow' || args[0] == 'keyboardHide') { + args[len - 1].call(this); + } else if (args[0] == 'setCallingWindow') { + args[len - 1].call(this, paramMock.paramNumberMock); + } + } + }, + off: function (...args) { + console.warn("InputMethodAbility.off interface mocked in the Previewer. How this interface works on" + + " the Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'setSubtype') { + args[len - 1].call(this, InputMethodSubtype); + } else if (args[0] == 'inputStart') { + args[len - 1].call(this, KeyboardControllerMock, InputClientMock); + } else if (args[0] == 'inputStop' || args[0] == 'keyboardShow' || args[0] == 'keyboardHide') { + args[len - 1].call(this); + } else if (args[0] == 'setCallingWindow') { + args[len - 1].call(this, paramMock.paramNumberMock); + } + } + } + } const KeyboardDelegateMock = { on: function (...args) { console.warn("KeyboardDelegate.on interface mocked in the Previewer. How this interface works on" + @@ -399,11 +515,21 @@ export function mockInputMethodEngine() { " on the Previewer may be different from that on a real device.") return InputMethodEngineMock; }, + getInputMethodAbility: function () { + console.warn("inputMethodEngine.getInputMethodAbility interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return InputMethodAbilityMock; + }, createKeyboardDelegate: function () { console.warn("inputMethodEngine.createKeyboardDelegate interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") return KeyboardDelegateMock; }, + getKeyboardDelegate: function () { + console.warn("inputMethodEngine.getKeyboardDelegate interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return KeyboardDelegateMock; + }, ENTER_KEY_TYPE_UNSPECIFIED: "[PC Preview] unknow ENTER_KEY_TYPE_UNSPECIFIED", ENTER_KEY_TYPE_GO: "[PC Preview] unknow ENTER_KEY_TYPE_GO", ENTER_KEY_TYPE_SEARCH: "[PC Preview] unknow ENTER_KEY_TYPE_SEARCH", @@ -436,5 +562,34 @@ export function mockInputMethodEngine() { CURSOR_RIGHT: "[PC Preview] unknow CURSOR_UP", WINDOW_TYPE_INPUT_METHOD_FLOAT: "[PC Preview] unknow WINDOW_TYPE_INPUT_METHOD_FLOAT" } + const EditingText = { + textContent: "[PC Preview] unknow textContent", + offset: 1, + changedStart: 2, + changedEnd: 3, + selectionStart: 4, + selectionEnd: 5, + additionalBitFlags: 6, + prompt: "[PC Preview] unknow prompt" + } + const EditingCapability = { + maxLines: 1, + maxChars: 2 + } + const EditorAttribute = { + inputPattern: 1, + enterKeyType: 2, + inputOption: 3 + } + const KeyEvent = { + keyCode: "[PC Preview] unknow keyCode", + keyAction: "[PC Preview] unknow keyAction" + } + const RichContent = { + contentURI: "[PC Preview] unknow contentURI", + linkURI: "[PC Preview] unknow linkURI", + mimeTypes: "[PC Preview] unknow mimeTypes", + detail: "[PC Preview] unknow detail" + } return inputMethodEngine } \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_inputmethodextensioncontext.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethodextensioncontext.js index 25bde6ca..941fae7c 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_inputmethodextensioncontext.js +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethodextensioncontext.js @@ -45,5 +45,17 @@ export const InputMethodExtensionContextClass = class InputMethodExtensionContex }) } }; + this.destroy = function (...args) { + console.warn("InputMethodExtensionContext.destroy interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }; } }; \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_inputmethodsubtype.js b/runtime/main/extend/systemplugin/napi/ohos_inputmethodsubtype.js new file mode 100644 index 00000000..37712148 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_inputmethodsubtype.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const InputMethodSubtype = { + label: "[PC Preview] unknow method label", + name: "[PC Preview] unknow method name", + id: "[PC Preview] unknow method id", + mode: "[PC Preview] unknow method mode", + locale: "[PC Preview] unknow method locale", + language: "[PC Preview] unknow method language", + icon: "[PC Preview] unknow method icon", + iconId: "[PC Preview] unknow method iconId", + extra: "[PC Preview] unknow method extra", +} \ No newline at end of file -- Gitee