!81 合入js接口能力

Merge pull request !81 from demon/master
This commit is contained in:
openharmony_ci 2022-02-22 11:48:41 +00:00 committed by Gitee
commit 502674d387
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
57 changed files with 2259 additions and 751 deletions

View File

@ -24,8 +24,8 @@ group("inputmethod_native_packages") {
"frameworks/inputmethod_ability:inputmethod_ability",
"frameworks/inputmethod_controller:inputmethod_client",
"interfaces/kits/js/declaration:inputmethod",
"interfaces/kits/js/napi:inputmethod",
"interfaces/kits/js/napi:inputmethodengine",
"interfaces/kits/js/napi/inputmethod:inputmethod",
"interfaces/kits/js/napi/inputmethodengine:inputmethodengine",
"profile:miscservices_inputmethod_sa_profiles",
"services:inputmethod_service",
]

View File

@ -102,13 +102,30 @@
}
},
{
"name": "//base/miscservices/inputmethod/interfaces/kits/js/napi:inputmethodengine",
"name": "//base/miscservices/inputmethod/interfaces/kits/js/napi/inputmethod:inputmethod",
"header": {
"header_files": [
"js_input_method_engine.h",
"js_input_method_engine_listener.h"
"js_input_method_registry.h",
"js_input_method_utils.h",
"js_input_method_setting.h",
"js_input_method_controller.h"
],
"header_base": "//base/miscservices/inputmethod/interfaces/kits/js/napi/include"
"header_base": "//base/miscservices/inputmethod/interfaces/kits/js/napi/inputmethod/include"
}
},
{
"name": "//base/miscservices/inputmethod/interfaces/kits/js/napi/inputmethodengine:inputmethodengine",
"header": {
"header_files": [
"js_input_method_engine_registry.h",
"js_input_method_engine_listener.h",
"js_input_method_engine.h",
"js_input_method_engine_utils.h",
"js_keyboard_controller.h",
"js_text_input_client.h",
"js_keyboard_delegate.h"
],
"header_base": "//base/miscservices/inputmethod/interfaces/kits/js/napi/inputmethodengine/include"
}
}
],

View File

@ -11,4 +11,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
persist.sys.default_ime=com.example.kikakeyboard/com.example.kikakeyboard.ServiceExtAbility
persist.sys.default_ime=com.example.kikakeyboard/ServiceExtAbility

View File

@ -18,7 +18,7 @@ config("inputmethod_ability_native_config") {
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
"${inputmethod_path}/interfaces/kits/js/napi/include",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/include",
"${inputmethod_path}/services/include",
]
}
@ -33,8 +33,15 @@ config("inputmethod_ability_native_public_config") {
ohos_shared_library("inputmethod_ability") {
sources = [
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/src/js_input_method_engine.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/src/js_input_method_engine_listener.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_editor_attribute.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_registry.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_utils.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_controller.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp",
"${inputmethod_path}/interfaces/kits/js/napi/inputmethodengine/src/js_text_input_client.cpp",
"${inputmethod_path}/services/src/input_attribute.cpp",
"${inputmethod_path}/services/src/input_channel.cpp",
"${inputmethod_path}/services/src/input_control_channel_proxy.cpp",

View File

@ -18,6 +18,7 @@
#include <thread>
#include "js_input_method_engine_listener.h"
#include "js_keyboard_delegate_listener.h"
#include "iremote_object.h"
#include "i_input_control_channel.h"
#include "i_input_method_core.h"
@ -44,14 +45,18 @@ namespace MiscServices {
sptr<IInputMethodCore> OnConnect();
bool InsertText(const std::string text);
void setImeListener(sptr<JsInputMethodEngineListener> &imeListener);
void setKdListener(sptr<JsKeyboardDelegateListener> &kdListener);
void DeleteForward(int32_t length);
void DeleteBackward(int32_t length);
void HideKeyboardSelf();
std::u16string GetTextBeforeCursor();
std::u16string GetTextAfterCursor();
std::u16string GetTextBeforeCursor(int32_t number);
std::u16string GetTextAfterCursor(int32_t number);
void SendFunctionKey(int32_t funcKey);
void MoveCursor(int32_t keyCode);
bool DispatchKeyEvent(int32_t keyCode, int32_t keyStatus);
int32_t GetEnterKeyType();
int32_t GetInputPattern();
void StopInput();
private:
std::thread workThreadHandler;
@ -73,6 +78,7 @@ namespace MiscServices {
// communicating with IMC
sptr<IInputDataChannel> inputDataChannel;
sptr<JsInputMethodEngineListener> imeListener_;
sptr<JsKeyboardDelegateListener> kdListener_;
static std::mutex instanceLock_;
static sptr<InputMethodAbility> instance_;
sptr<InputMethodSystemAbilityProxy> mImms;

View File

@ -125,6 +125,14 @@ namespace MiscServices {
}
}
void InputMethodAbility::setKdListener(sptr<JsKeyboardDelegateListener> &kdListener)
{
IMSA_HILOGI("InputMethodAbility::setKdListener");
if (kdListener_ == nullptr) {
kdListener_ = kdListener;
}
}
void InputMethodAbility::WorkThread()
{
while (!stop_) {
@ -170,7 +178,9 @@ namespace MiscServices {
case MSG_ID_STOP_INPUT_SERVICE:{
MessageParcel *data = msg->msgContent_;
std::string imeId = Str16ToStr8(data->ReadString16());
imeListener_->OnInputStop(imeId);
if (imeListener_ != nullptr) {
imeListener_->OnInputStop(imeId);
}
break;
}
default: {
@ -267,22 +277,54 @@ namespace MiscServices {
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent abort. no client");
return false;
}
return imeListener_->OnKeyEvent(keyCode, keyStatus);
if (kdListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent kdListener_ is nullptr");
return false;
}
return kdListener_->OnKeyEvent(keyCode, keyStatus);
}
void InputMethodAbility::OnCursorUpdate(Message *msg)
{
IMSA_HILOGI("InputMethodAbility::OnCursorUpdate");
MessageParcel *data = msg->msgContent_;
int32_t positionX = data->ReadInt32();
int32_t positionY = data->ReadInt32();
int32_t height = data->ReadInt32();
if (kdListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::OnCursorUpdate kdListener_ is nullptr");
return;
}
kdListener_->OnCursorUpdate(positionX, positionY, height);
}
void InputMethodAbility::OnSelectionChange(Message *msg)
{
IMSA_HILOGI("InputMethodAbility::OnSelectionChange");
MessageParcel *data = msg->msgContent_;
std::string text = Str16ToStr8(data->ReadString16());
int32_t oldBegin = data->ReadInt32();
int32_t oldEnd = data->ReadInt32();
int32_t newBegin = data->ReadInt32();
int32_t newEnd = data->ReadInt32();
if (kdListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::OnSelectionChange kdListener_ is nullptr");
return;
}
kdListener_->OnTextChange(text);
kdListener_->OnSelectionChange(oldBegin, oldEnd, newBegin, newEnd);
}
void InputMethodAbility::ShowInputWindow()
{
IMSA_HILOGI("InputMethodAbility::ShowInputWindow");
if (imeListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::ShowInputWindow imeListener_ is nullptr");
return;
}
imeListener_->OnInputStart();
imeListener_->OnKeyboardStatus(true);
if (inputDataChannel != nullptr) {
inputDataChannel->SendKeyboardStatus(KEYBOARD_SHOW);
@ -292,6 +334,10 @@ namespace MiscServices {
void InputMethodAbility::DissmissInputWindow()
{
IMSA_HILOGI("InputMethodAbility::DissmissInputWindow");
if (imeListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::DissmissInputWindow imeListener_ is nullptr");
return;
}
imeListener_->OnKeyboardStatus(false);
if (inputDataChannel != nullptr) {
inputDataChannel->SendKeyboardStatus(KEYBOARD_HIDE);
@ -345,16 +391,26 @@ namespace MiscServices {
inputControlChannel->hideKeyboardSelf(1);
}
std::u16string InputMethodAbility::GetTextBeforeCursor()
std::u16string InputMethodAbility::GetTextBeforeCursor(int32_t number)
{
IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor");
return inputDataChannel->GetTextBeforeCursor();
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor inputDataChanel is nullptr");
return u"";
}
return inputDataChannel->GetTextBeforeCursor(number);
}
std::u16string InputMethodAbility::GetTextAfterCursor()
std::u16string InputMethodAbility::GetTextAfterCursor(int32_t number)
{
IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor");
return inputDataChannel->GetTextAfterCursor();
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor inputDataChanel is nullptr");
return u"";
}
return inputDataChannel->GetTextAfterCursor(number);
}
void InputMethodAbility::MoveCursor(int32_t keyCode)
@ -369,5 +425,35 @@ namespace MiscServices {
inputDataChannel->MoveCursor(keyCode);
return;
}
int32_t InputMethodAbility::GetEnterKeyType() {
IMSA_HILOGI("InputMethodAbility::GetEnterKeyType");
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::GetEnterKeyType inputDataChanel is nullptr");
return 0;
}
return inputDataChannel->GetEnterKeyType();
}
int32_t InputMethodAbility::GetInputPattern() {
IMSA_HILOGI("InputMethodAbility::GetInputPattern");
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::GetInputPattern inputDataChanel is nullptr");
return 0;
}
return inputDataChannel->GetInputPattern();
}
void InputMethodAbility::StopInput() {
IMSA_HILOGI("InputMethodAbility::StopInput");
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::StopInput inputDataChanel is nullptr");
return;
}
inputDataChannel->StopInput();
}
}
}

View File

@ -71,6 +71,7 @@ namespace MiscServices {
if (inputControlChannel == nullptr) {
IMSA_HILOGI("InputMethodCoreProxy::InitInputControlChannel inputControlChannel is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
MessageParcel data, reply;
data.WriteInterfaceToken(GetDescriptor());

View File

@ -234,7 +234,7 @@ namespace MiscServices {
}
MessageParcel *data = new MessageParcel();
if (inputDataChannel != nullptr) {
IMSA_HILOGI("InputMethodCoreStub::startInput inputDataChannel is not nullptr");
IMSA_HILOGI("InputMethodCoreStub::showKeyboard inputDataChannel is not nullptr");
data->WriteRemoteObject(inputDataChannel->AsObject());
}

View File

@ -35,6 +35,9 @@ namespace MiscServices {
CLOSE,
GET_TEXT_BEFORE_CURSOR,
GET_TEXT_AFTER_CURSOR,
GET_ENTER_KEY_TYPE,
GET_INPUT_PATTERN,
STOP_INPUT,
SEND_KEYBOARD_STATUS,
SEND_FUNCTION_KEY,
MOVE_CURSOR,
@ -46,11 +49,14 @@ namespace MiscServices {
virtual bool DeleteForward(int32_t length) = 0;
virtual bool DeleteBackward(int32_t length) = 0;
virtual void Close() = 0;
virtual std::u16string GetTextBeforeCursor() = 0;
virtual std::u16string GetTextAfterCursor() = 0;
virtual std::u16string GetTextBeforeCursor(int32_t number) = 0;
virtual std::u16string GetTextAfterCursor(int32_t number) = 0;
virtual void SendKeyboardStatus(int32_t status) = 0;
virtual void SendFunctionKey(int32_t funcKey) = 0;
virtual void MoveCursor(int32_t keyCode) = 0;
virtual int32_t GetEnterKeyType() = 0;
virtual int32_t GetInputPattern() = 0;
virtual void StopInput() = 0;
};
}
}

View File

@ -32,11 +32,14 @@ namespace MiscServices {
bool DeleteForward(int32_t length) override;
bool DeleteBackward(int32_t length) override;
void Close() override;
std::u16string GetTextBeforeCursor() override;
std::u16string GetTextAfterCursor() override;
std::u16string GetTextBeforeCursor(int32_t number) override;
std::u16string GetTextAfterCursor(int32_t number) override;
void SendKeyboardStatus(int32_t status) override;
void SendFunctionKey(int32_t funcKey) override;
void MoveCursor(int32_t keyCode) override;
int32_t GetEnterKeyType() override;
int32_t GetInputPattern() override;
void StopInput() override;
private:
static inline BrokerDelegator<InputDataChannelProxy> delegator_;

View File

@ -40,11 +40,14 @@ namespace MiscServices {
bool DeleteForward(int32_t length) override;
bool DeleteBackward(int32_t length) override;
void Close() override;
std::u16string GetTextBeforeCursor() override;
std::u16string GetTextAfterCursor() override;
std::u16string GetTextBeforeCursor(int32_t number) override;
std::u16string GetTextAfterCursor(int32_t number) override;
void SendKeyboardStatus(int32_t status) override;
void SendFunctionKey(int32_t funcKey) override;
void MoveCursor(int32_t keyCode) override;
int32_t GetEnterKeyType() override;
int32_t GetInputPattern() override;
void StopInput() override;
private:
MessageHandler *msgHandler;
};

View File

@ -56,8 +56,8 @@ namespace MiscServices {
public:
static sptr<InputMethodController> GetInstance();
void Attach(sptr<OnTextChangedListener> &listener);
std::u16string GetTextBeforeCursor();
std::u16string GetTextAfterCursor();
std::u16string GetTextBeforeCursor(int32_t number);
std::u16string GetTextAfterCursor(int32_t number);
void ShowTextInput();
void HideTextInput();
void Close();
@ -68,6 +68,9 @@ namespace MiscServices {
bool dispatchKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
void DisplayOptionalInputMethod();
std::vector<InputMethodProperty*> ListInputMethod();
int32_t GetEnterKeyType();
int32_t GetInputPattern();
void HideCurrentInput();
private:
InputMethodController();
~InputMethodController();
@ -100,6 +103,8 @@ namespace MiscServices {
std::thread workThreadHandler;
MessageHandler *msgHandler;
bool stop_;
int32_t enterKeyType_ = 0;
int32_t inputPattern_ = 0;
};
}
}

View File

@ -41,6 +41,7 @@ namespace MiscServices {
virtual void startInput(MessageParcel& data) override;
virtual void stopInput(MessageParcel& data) override;
virtual void SetCoreAndAgent(MessageParcel& data) override;
virtual void HideCurrentInput(MessageParcel& data) override;
int32_t Prepare(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel,
InputAttribute &attribute);

View File

@ -84,24 +84,26 @@ namespace MiscServices {
}
}
std::u16string InputDataChannelProxy::GetTextBeforeCursor()
std::u16string InputDataChannelProxy::GetTextBeforeCursor(int32_t number)
{
IMSA_HILOGI("InputDataChannelProxy::GetTextBeforeCursor");
MessageParcel data, reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
data.WriteInt32(number);
Remote()->SendRequest(GET_TEXT_BEFORE_CURSOR, data, reply, option);
auto result = reply.ReadString16();
return result;
}
std::u16string InputDataChannelProxy::GetTextAfterCursor()
std::u16string InputDataChannelProxy::GetTextAfterCursor(int32_t number)
{
IMSA_HILOGI("InputDataChannelProxy::GetTextAfterCursor");
MessageParcel data, reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
data.WriteInt32(number);
Remote()->SendRequest(GET_TEXT_AFTER_CURSOR, data, reply, option);
auto result = reply.ReadString16();
@ -141,5 +143,39 @@ namespace MiscServices {
Remote()->SendRequest(MOVE_CURSOR, data, reply, option);
}
int32_t InputDataChannelProxy::GetEnterKeyType()
{
IMSA_HILOGI("InputDataChannelProxy::GetEnterKeyType");
MessageParcel data, reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
Remote()->SendRequest(GET_ENTER_KEY_TYPE, data, reply, option);
auto result = reply.ReadInt32();
return result;
}
int32_t InputDataChannelProxy::GetInputPattern()
{
IMSA_HILOGI("InputDataChannelProxy::GetInputPattern");
MessageParcel data, reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
Remote()->SendRequest(GET_INPUT_PATTERN, data, reply, option);
auto result = reply.ReadInt32();
return result;
}
void InputDataChannelProxy::StopInput()
{
IMSA_HILOGI("InputDataChannelProxy::StopInput");
MessageParcel data, reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
Remote()->SendRequest(STOP_INPUT, data, reply, option);
}
}
}

View File

@ -59,11 +59,13 @@ namespace MiscServices {
break;
}
case GET_TEXT_BEFORE_CURSOR: {
reply.WriteString16(GetTextBeforeCursor());
auto number = data.ReadInt32();
reply.WriteString16(GetTextBeforeCursor(number));
break;
}
case GET_TEXT_AFTER_CURSOR: {
reply.WriteString16(GetTextAfterCursor());
auto number = data.ReadInt32();
reply.WriteString16(GetTextAfterCursor(number));
break;
}
case SEND_KEYBOARD_STATUS: {
@ -80,6 +82,18 @@ namespace MiscServices {
auto keyCode = data.ReadInt32();
MoveCursor(keyCode);
}
case GET_ENTER_KEY_TYPE: {
reply.WriteInt32(GetEnterKeyType());
break;
}
case GET_INPUT_PATTERN: {
reply.WriteInt32(GetInputPattern());
break;
}
case STOP_INPUT: {
StopInput();
break;
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
@ -131,16 +145,34 @@ namespace MiscServices {
{
}
std::u16string InputDataChannelStub::GetTextBeforeCursor()
std::u16string InputDataChannelStub::GetTextBeforeCursor(int32_t number)
{
IMSA_HILOGI("InputDataChannelStub::GetTextBeforeCursor");
return InputMethodController::GetInstance()->GetTextBeforeCursor();
return InputMethodController::GetInstance()->GetTextBeforeCursor(number);
}
std::u16string InputDataChannelStub::GetTextAfterCursor()
std::u16string InputDataChannelStub::GetTextAfterCursor(int32_t number)
{
IMSA_HILOGI("InputDataChannelStub::GetTextAfterCursor");
return InputMethodController::GetInstance()->GetTextAfterCursor();
return InputMethodController::GetInstance()->GetTextAfterCursor(number);
}
int32_t InputDataChannelStub::GetEnterKeyType()
{
IMSA_HILOGI("InputDataChannelStub::GetEnterKeyType");
return InputMethodController::GetInstance()->GetEnterKeyType();
}
int32_t InputDataChannelStub::GetInputPattern()
{
IMSA_HILOGI("InputDataChannelStub::GetInputPattern");
return InputMethodController::GetInstance()->GetInputPattern();
}
void InputDataChannelStub::StopInput()
{
IMSA_HILOGI("InputDataChannelStub::StopInput");
InputMethodController::GetInstance()->HideTextInput();
}
void InputDataChannelStub::SendKeyboardStatus(int32_t status)

View File

@ -208,6 +208,19 @@ using namespace MessageID;
StopInput(mClient);
}
void InputMethodController::HideCurrentInput()
{
IMSA_HILOGI("InputMethodController::HideCurrentInput");
if (mImms == nullptr) {
return;
}
MessageParcel data;
if (!(data.WriteInterfaceToken(mImms->GetDescriptor()))) {
return;
}
mImms->HideCurrentInput(data);
}
void InputMethodController::Close()
{
ReleaseInput(mClient);
@ -348,24 +361,26 @@ using namespace MessageID;
void InputMethodController::OnConfigurationChange(Configuration info)
{
IMSA_HILOGI("InputMethodController::OnConfigurationChange");
enterKeyType_ = static_cast<uint32_t>(info.GetEnterKeyType());
inputPattern_ = static_cast<uint32_t>(info.GetTextInputType());
}
std::u16string InputMethodController::GetTextBeforeCursor()
std::u16string InputMethodController::GetTextBeforeCursor(int32_t number)
{
IMSA_HILOGI("InputMethodController::GetTextBeforeCursor");
if (!mTextString.empty()) {
return mTextString.substr(0, mSelectNewBegin);
int32_t startPos = (mSelectNewBegin >= number ? (mSelectNewBegin - number + 1) : 0);
return mTextString.substr(startPos, mSelectNewBegin);
}
return u"";
}
std::u16string InputMethodController::GetTextAfterCursor()
std::u16string InputMethodController::GetTextAfterCursor(int32_t number)
{
IMSA_HILOGI("InputMethodController::GetTextBeforeCursor");
if (!mTextString.empty()) {
if (mTextString.size() > mSelectNewEnd) {
return mTextString.substr(mSelectNewEnd);
}
int32_t endPos = (mSelectNewEnd+number<mTextString.size()) ? (mSelectNewEnd + number) : mTextString.size();
return mTextString.substr(mSelectNewEnd, endPos);
}
return u"";
}
@ -386,5 +401,17 @@ using namespace MessageID;
return mAgent->DispatchKeyEvent(data);
}
int32_t InputMethodController::GetEnterKeyType()
{
IMSA_HILOGI("InputMethodController::GetEnterKeyType");
return enterKeyType_;
}
int32_t InputMethodController::GetInputPattern()
{
IMSA_HILOGI("InputMethodController::GetInputPattern");
return inputPattern_;
}
}
}

View File

@ -131,6 +131,25 @@ namespace MiscServices {
Remote()->SendRequest(SET_CORE_AND_AGENT, data, reply, option);
}
void InputMethodSystemAbilityProxy::HideCurrentInput(MessageParcel& data)
{
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput");
MessageParcel reply;
MessageOption option;
auto ret = Remote()->SendRequest(HIDE_CURRENT_INPUT, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput SendRequest failed");
return;
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput reply failed");
return;
}
}
int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr<InputClientStub> &client,
sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
{

View File

@ -22,9 +22,12 @@ import {AsyncCallback} from './basic';
* @devices phone, tablet, tv, wearable
*/
declare namespace inputMethod {
const MAX_TYPE_NUM: number
function getInputMethodSetting(): InputMethodSetting;
function getInputMethodController(): InputMethodController;
interface InputMethodSetting {
listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void;
listInputMethod(): Promise<Array<InputMethodProperty>>;
@ -33,6 +36,11 @@ declare namespace inputMethod {
displayOptionalInputMethod(): Promise<void>;
}
interface InputMethodController {
stopInput(callback: AsyncCallback<boolean>): void;
stopInput(): Promise<boolean>;
}
interface InputMethodProperty {
readonly packageName: string;
readonly methodId: string;

View File

@ -18,38 +18,102 @@ import { AsyncCallback } from './basic';
/**
* inputmethod
*
* @since 7
* @since 8
* @devices phone, tablet, tv, wearable
*/
declare namespace inputMethodEngine {
function on(type: 'keyboardShow', callback: () => void): void;
function off(type: 'keyboardShow', callback: () => void): void;
const ENTER_KEY_TYPE_UNSPECIFIED: number;
const ENTER_KEY_TYPE_GO: number;
const ENTER_KEY_TYPE_SEARCH: number;
const ENTER_KEY_TYPE_SEND: number;
const ENTER_KEY_TYPE_NEXT: number;
const ENTER_KEY_TYPE_DONE: number;
const ENTER_KEY_TYPE_PREVIOUS: number;
function on(type: 'keyboardHide', callback: () => void): void;
function off(type: 'keyboardHide', callback: () => void): void;
const PATTERN_NULL: number;
const PATTERN_TEXT: number;
const PATTERN_NUMBER: number;
const PATTERN_PHONE: number;
const PATTERN_DATETIME: number;
const PATTERN_EMAIL: number;
const PATTERN_URI: number;
const PATTERN_PASSWORD: number;
function InsertText(text: string, callback: AsyncCallback<boolean>): void;
function InsertText(text: string): Promise<boolean>;
function DeleteForward(length: number, callback: () => void): void;
function DeleteForward(length: number): Promise<void>;
const FLAG_SELECTING: number;
const FLAG_SINGLE_LINE: number;
function DeleteBackward(length: number, callback: () => void): void;
function DeleteBackward(length: number): Promise<void>;
const DISPLAY_MODE_PART: number;
const DISPLAY_MODE_FULL: number;
function HideKeyboardSelf(callback: () => void): void;
function HideKeyboardSelf(): Promise<void>;
const OPTION_ASCII: number;
const OPTION_NONE: number;
const OPTION_AUTO_CAP_CHARACTERS: number;
const OPTION_AUTO_CAP_SENTENCES: number;
const OPTION_AUTO_WORDS: number;
const OPTION_MULTI_LINE: number;
const OPTION_NO_FULLSCREEN: number;
function GetTextBeforeCursor(callback: () => string): void;
function GetTextBeforeCursor(): Promise<string>;
function getInputMethodEngine(): InputMethodEngine;
function GetTextAfterCursor(callback: () => string): void;
function GetTextAfterCursor(): Promise<string>;
function createKeyboardDelegate(): KeyboardDelegate;
function SendFunctionKey(callback: () => void): void;
function SendFunctionKey(): Promise<void>;
interface KeyboardController {
hideKeyboard(callbakc: AsyncCallback<void>): void;
hideKeyboard(): Promise<void>;
}
const FUNCTION_KEY_CONFIRM: number;
interface InputMethodEngine {
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
on(type: 'keyboardShow', callback: () => void): void;
off(type: 'keyboardShow', callback: () => void): void;
on(type: 'keyboardHide', callback: () => void): void;
off(type: 'keyboardHide', callback: () => void): void;
}
interface TextInputClient {
sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void;
sendKeyFunction(action: number): Promise<boolean>;
deleteForward(length: number, callback: AsyncCallback<boolean>): void;
deleteForward(length: number): Promise<boolean>;
deleteBackward(length: number, callback: AsyncCallback<boolean>): void;
deleteBackward(length: number): Promise<boolean>;
InsertText(text: string, callback: AsyncCallback<boolean>): void;
InsertText(text: string): Promise<boolean>;
getForward(length: number, callback: AsyncCallback<string>): void;
getForward(length: number): Promise<string>;
getEditorAttribute(lcallback: AsyncCallback<EditorAttribute>): void;
getEditorAttribute(): Promise<EditorAttribute>;
}
interface KeyboardDelegate {
on(type: 'keyDown', callback: (event: KeyEvent) => boolean): void;
off(type: 'keyDown', callback?: (event: KeyEvent) => boolean): void;
on(type: 'keyUp', callback: (event: KeyEvent) => boolean): void;
off(type: 'keyUp', callback?: (event: KeyEvent) => boolean): void;
on(type: 'cursorContextChange', callback: (x: number, y: number, height: number) => void): void;
off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void;
on(type: 'selectionChange', callback: (oldBegine: number, oldEnd: number, newBegine: number, newEnd: number) => void): void;
off(type: 'selectionChange', callback?: (oldBegine: number, oldEnd: number, newBegine: number, newEnd: number) => void): void;
on(type: 'textChange', callback: (text: string) => void): void;
off(type: 'textChange', callback?: (text: string) => void): void;
}
interface EditorAttribute {
readonly inputPattern: number;
readonly enterKeyType: number;
}
}
export default inputMethodEngine;

View File

@ -13,16 +13,6 @@
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethodengine_native_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
config("inputmethodengine_native_public_config") {
visibility = []
include_dirs = [ "include" ]
}
config("inputmethod_native_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
@ -33,57 +23,16 @@ config("inputmethod_native_public_config") {
include_dirs = [ "include" ]
}
ohos_shared_library("inputmethodengine") {
sources = [
"src/input_method_engine_module.cpp",
"src/js_input_method_engine.cpp",
"src/js_input_method_engine_listener.cpp",
]
configs = [ ":inputmethodengine_native_config" ]
deps = [
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/ace/napi/:ace_napi",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//utils/native/base:utils",
]
external_deps = [
"ability_runtime:runtime",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
public_configs = [ ":inputmethodengine_native_public_config" ]
relative_install_dir = "module"
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
ohos_shared_library("inputmethod") {
sources = [
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_method_controller.cpp",
"src/input_method_module.cpp",
"src/js_input_method.cpp",
"src/js_input_method_controller.cpp",
"src/js_input_method_registry.cpp",
"src/js_input_method_setting.cpp",
"src/js_input_method_utils.cpp",
]
configs = [ ":inputmethod_native_config" ]

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_CONTROLLER_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_CONTROLLER_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "global.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace MiscServices {
class JsInputMethodController {
public:
JsInputMethodController() = default;
~JsInputMethodController() = default;
static void Finalizer(NativeEngine *engine, void *data, void *hint);
static NativeValue* StopInput(NativeEngine* engine, NativeCallbackInfo* info);
private:
NativeValue* OnStopInput(NativeEngine& engine, NativeCallbackInfo& info);
};
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_SETTING_H

View File

@ -13,18 +13,20 @@
* limitations under the License.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_REGISTRY_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_REGISTRY_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "global.h"
#include "js_runtime_utils.h"
#include "js_input_method_utils.h"
#include "js_input_method_setting.h"
namespace OHOS {
namespace MiscServices {
NativeValue* JsInputMethodInit(NativeEngine* engine, NativeValue* exportObj);
NativeValue* JsInputMethodRegistryInit(NativeEngine* engine, NativeValue* exportObj);
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_REGISTRY_H

View File

@ -0,0 +1,38 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_SETTING_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_SETTING_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "global.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace MiscServices {
class JsInputMethodSetting {
public:
JsInputMethodSetting() = default;
~JsInputMethodSetting() = default;
static void Finalizer(NativeEngine *engine, void *data, void *hint);
static NativeValue* DisplayOptionalInputMethod(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* ListInputMethod(NativeEngine* engine, NativeCallbackInfo* info);
private:
NativeValue* OnDisplayOptionalInputMethod(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnListInputMethod(NativeEngine& engine, NativeCallbackInfo& info);
};
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_SETTING_H

View File

@ -13,18 +13,18 @@
* limitations under the License.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_UTILS_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_UTILS_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "global.h"
#include "js_runtime_utils.h"
#include "js_input_method_setting.h"
namespace OHOS {
namespace MiscServices {
NativeValue* JsInputMethodEngineInit(NativeEngine* engine, NativeValue* exportObj);
// class JsInputMethodSetting;
NativeValue *CreateInputMethodSetting(NativeEngine& engine);
NativeValue *CreateInputMethodController(NativeEngine& engine);
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_SETTING_UTILS_H

View File

@ -14,7 +14,7 @@
*/
#include "native_engine/native_engine.h"
#include "js_input_method.h"
#include "js_input_method_registry.h"
extern "C" __attribute__((constructor)) void NAPI_inputMethod_AutoRegister()
{
@ -22,7 +22,7 @@ extern "C" __attribute__((constructor)) void NAPI_inputMethod_AutoRegister()
NativeModule newModuleInfo = {
.name = "inputMethod",
.fileName = "inputmethod.so/inputmethod.js",
.registerCallback = OHOS::MiscServices::JsInputMethodInit,
.registerCallback = OHOS::MiscServices::JsInputMethodRegistryInit,
};
moduleManager->Register(&newModuleInfo);

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
#include "js_input_method_controller.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_ZERO = 0;
void JsInputMethodController::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodController::Finalizer is called");
std::unique_ptr<JsInputMethodController>(static_cast<JsInputMethodController*>(data));
}
NativeValue* JsInputMethodController::StopInput(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodController* me = CheckParamsAndGetThis<JsInputMethodController>(engine, info);
return (me != nullptr) ? me->OnStopInput(*engine, *info) : nullptr;
}
NativeValue* JsInputMethodController::OnStopInput(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodController::OnStopInput is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodController::OnStopInput has params, return!");
return engine.CreateUndefined();
}
InputMethodController::GetInstance()->HideCurrentInput();
NativeValue* result = CreateJsValue(engine, true);
return result;
}
}
}

View File

@ -0,0 +1,111 @@
/*
* 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.
*/
#include "js_input_method_registry.h"
#include <map>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "string_ex.h"
#include "event_handler.h"
#include "event_runner.h"
#include "input_method_controller.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
namespace {
constexpr size_t ARGC_ZERO = 0;
constexpr int32_t MAX_TYPE_NUM = 128;
}
class JsInputMethodRegistry {
public:
explicit JsInputMethodRegistry(NativeEngine* engine)
{
IMSA_HILOGI("JsInputMethodRegistry::Constructor is called");
}
~JsInputMethodRegistry() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodRegistry::Finalizer is called");
std::unique_ptr<JsInputMethodRegistry>(static_cast<JsInputMethodRegistry*>(data));
}
static NativeValue* GetInputMethodSetting(NativeEngine* engine, NativeCallbackInfo* info)
{
IMSA_HILOGI("JsInputMethodRegistry::GetInputMethodSetting is called");
JsInputMethodRegistry* me = CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
return (me != nullptr) ? me->OnGetInputMethodSetting(*engine, *info) : nullptr;
}
static NativeValue* GetInputMethodController(NativeEngine* engine, NativeCallbackInfo* info)
{
IMSA_HILOGI("JsInputMethodRegistry::GetInputMethodController is called");
JsInputMethodRegistry* me = CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
return (me != nullptr) ? me->OnGetInputMethodController(*engine, *info) : nullptr;
}
private:
NativeValue* OnGetInputMethodSetting(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodRegistry::OnGetInputMethodSetting is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodRegistry::OnGetInputMethodSetting Params not match");
return engine.CreateUndefined();
}
return CreateInputMethodSetting(engine);
}
NativeValue* OnGetInputMethodController(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodRegistry::OnGetInputMethodController is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodRegistry::OnGetInputMethodController Params not match");
return engine.CreateUndefined();
}
return CreateInputMethodController(engine);
}
};
NativeValue* JsInputMethodRegistryInit(NativeEngine* engine, NativeValue* exportObj)
{
IMSA_HILOGI("JsInputMethodRegistryInit() is called!");
if (engine == nullptr || exportObj == nullptr) {
IMSA_HILOGI("engine or exportObj null");
return nullptr;
}
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
IMSA_HILOGI("object null");
return nullptr;
}
std::unique_ptr<JsInputMethodRegistry> jsInputMethodRegistry = std::make_unique<JsInputMethodRegistry>(engine);
object->SetNativePointer(jsInputMethodRegistry.release(), JsInputMethodRegistry::Finalizer, nullptr);
BindNativeFunction(*engine, *object, "getInputMethodSetting", JsInputMethodRegistry::GetInputMethodSetting);
BindNativeFunction(*engine, *object, "getInputMethodController", JsInputMethodRegistry::GetInputMethodController);
object->SetProperty("MAX_TYPE_NUM", CreateJsValue(*engine, static_cast<uint32_t>(MAX_TYPE_NUM)));
return engine->CreateUndefined();
}
}
}

View File

@ -0,0 +1,88 @@
/*
* 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.
*/
#include "js_input_method_setting.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_ZERO = 0;
void JsInputMethodSetting::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodSetting::Finalizer is called");
std::unique_ptr<JsInputMethodSetting>(static_cast<JsInputMethodSetting*>(data));
}
NativeValue* JsInputMethodSetting::DisplayOptionalInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodSetting* me = CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
return (me != nullptr) ? me->OnDisplayOptionalInputMethod(*engine, *info) : nullptr;
}
NativeValue* JsInputMethodSetting::ListInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodSetting* me = CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
return (me != nullptr) ? me->OnListInputMethod(*engine, *info) : nullptr;
}
NativeValue* JsInputMethodSetting::OnDisplayOptionalInputMethod(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodSetting::OnDisplayOptionalInputMethod is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodSetting::OnDisplayOptionalInputMethod has params, return!");
return engine.CreateUndefined();
}
InputMethodController::GetInstance()->DisplayOptionalInputMethod();
return engine.CreateUndefined();
}
NativeValue* JsInputMethodSetting::OnListInputMethod(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodSetting::ListInputMethod is called");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodSetting::ListInputMethod has params, return!");
return engine.CreateUndefined();
}
std::vector<InputMethodProperty*> properties = InputMethodController::GetInstance()->ListInputMethod();
if (properties.size() == 0) {
IMSA_HILOGI("JsInputMethodSetting::ListInputMethod has no ime");
return engine.CreateUndefined();
}
NativeValue* arrayValue = engine.CreateArray(properties.size());
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
uint32_t index = 0;
for (const auto &info : properties) {
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
IMSA_HILOGI("JsInputMethodSetting::ListInputMethod %{public}s/%{public}s", Str16ToStr8(info->mPackageName).c_str(), Str16ToStr8(info->mAbilityName).c_str());
object->SetProperty("packageName", CreateJsValue(engine, Str16ToStr8(info->mPackageName)));
object->SetProperty("methodId", CreateJsValue(engine, Str16ToStr8(info->mAbilityName)));
array->SetElement(index++, objValue);
}
return arrayValue;
}
}
}

View File

@ -0,0 +1,61 @@
/*
* 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.
*/
#include "js_input_method_utils.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "js_input_method_setting.h"
#include "js_input_method_controller.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
NativeValue* CreateInputMethodSetting(NativeEngine& engine)
{
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodSetting is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodSetting Failed to get object");
return nullptr;
}
std::unique_ptr<JsInputMethodSetting> jsInputMethodSetting = std::make_unique<JsInputMethodSetting>();
object->SetNativePointer(jsInputMethodSetting.release(), JsInputMethodSetting::Finalizer, nullptr);
BindNativeFunction(engine, *object, "displayOptionalInputMethod", JsInputMethodSetting::DisplayOptionalInputMethod);
BindNativeFunction(engine, *object, "listInputMethod", JsInputMethodSetting::ListInputMethod);
return objValue;
}
NativeValue* CreateInputMethodController(NativeEngine& engine)
{
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodController is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodController Failed to get object");
return nullptr;
}
std::unique_ptr<JsInputMethodController> jsInputMethodController = std::make_unique<JsInputMethodController>();
object->SetNativePointer(jsInputMethodController.release(), JsInputMethodController::Finalizer, nullptr);
BindNativeFunction(engine, *object, "stopInput", JsInputMethodController::StopInput);
return objValue;
}
}
}

View File

@ -0,0 +1,74 @@
# 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.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethodengine_native_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
config("inputmethodengine_native_public_config") {
visibility = []
include_dirs = [ "include" ]
}
ohos_shared_library("inputmethodengine") {
sources = [
"//base/miscservices/inputmethod/services/src/global.cpp",
"src/input_method_engine_module.cpp",
"src/js_input_method_engine.cpp",
"src/js_input_method_engine_listener.cpp",
"src/js_input_method_engine_registry.cpp",
"src/js_input_method_engine_utils.cpp",
"src/js_keyboard_controller.cpp",
"src/js_keyboard_delegate.cpp",
"src/js_text_input_client.cpp",
]
configs = [ ":inputmethodengine_native_config" ]
deps = [
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/ace/napi/:ace_napi",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//utils/native/base:utils",
]
external_deps = [
"ability_runtime:runtime",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
public_configs = [ ":inputmethodengine_native_public_config" ]
relative_install_dir = "module"
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}

View File

@ -0,0 +1,32 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_EDITOR_ATTRIBUTE_H
#define OHOS_MISCSERVICES_JS_EDITOR_ATTRIBUTE_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace MiscServices {
class JsEditorAttribute {
public:
JsEditorAttribute() = default;
~JsEditorAttribute() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
private:
};
}
}
#endif // OHOS_MISCSERVICES_JS_EDITOR_ATTRIBUTE_H

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H
#include "js_runtime_utils.h"
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_input_method_engine_listener.h"
namespace OHOS {
namespace MiscServices {
class JsInputMethodEngine {
public:
JsInputMethodEngine(NativeEngine* engine);
~JsInputMethodEngine() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info);
private:
sptr<JsInputMethodEngineListener> imeListener_;
std::mutex mtx_;
NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info);
};
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_H

View File

@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FM_IMMS_PROJECT_INPUTMETHODENGINELISTENER_H
#define FM_IMMS_PROJECT_INPUTMETHODENGINELISTENER_H
#ifndef FM_IMMS_PROJECT_JS_INPUT_METHOD_ENGINE_LISTENER_H
#define FM_IMMS_PROJECT_JS_INPUT_METHOD_ENGINE_LISTENER_H
#include <map>
#include <mutex>
@ -32,10 +32,7 @@ namespace MiscServices {
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
void UnregisterListenerWithType(std::string type, NativeValue* value);
void OnKeyboardStatus(bool isShow);
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus);
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height);
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd);
void OnTextChange(std::string text);
void OnInputStart();
void OnInputStop(std::string imeId);
private:
void AddCallback(std::string type, NativeValue* jsListenerObject);
@ -49,4 +46,4 @@ namespace MiscServices {
};
}
}
#endif // FM_IMMS_PROJECT_INPUTMETHODENGINELISTENER_H
#endif // FM_IMMS_PROJECT_JS_INPUT_METHOD_ENGINE_LISTENER_H

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_REGISTRY_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_REGISTRY_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_runtime_utils.h"
#include "js_input_method_engine.h"
#include "js_keyboard_controller.h"
#include "js_text_input_client.h"
#include "js_keyboard_delegate.h"
namespace OHOS {
namespace MiscServices {
NativeValue* JsInputMethodEngineRegistryInit(NativeEngine* engine, NativeValue* exportObj);
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_REGISTRY_H

View File

@ -0,0 +1,37 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_UTILS_H
#define OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_UTILS_H
#include "js_runtime_utils.h"
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_input_method_engine.h"
#include "js_keyboard_controller.h"
#include "js_text_input_client.h"
#include "js_keyboard_delegate.h"
#include "js_keyboard_delegate.h"
namespace OHOS {
namespace MiscServices {
NativeValue *CreateInputMethodEngine(NativeEngine &engine);
NativeValue *CreateKeyboardController(NativeEngine& engine);
NativeValue *CreateTextInputClient(NativeEngine& engine);
NativeValue *CreateKeyboardDelegate(NativeEngine& engine);
NativeValue *CreateEditorAttribute(NativeEngine& engine);
}
}
#endif // OHOS_MISCSERVICES_JS_INPUT_METHOD_ENGINE_UTILS_H

View File

@ -0,0 +1,34 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_KEYBOARD_CONTROLLER_H
#define OHOS_MISCSERVICES_JS_KEYBOARD_CONTROLLER_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace MiscServices {
class JsKeyboardController {
public:
JsKeyboardController() = default;
~JsKeyboardController() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info);
private:
NativeValue* OnHideKeyboardSelf(NativeEngine& engine, NativeCallbackInfo& info);
};
}
}
#endif // OHOS_MISCSERVICES_JS_KEYBOARD_CONTROLLER_H

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_KEYBOARD_DELEGATE_H
#define OHOS_MISCSERVICES_JS_KEYBOARD_DELEGATE_H
#include "js_runtime_utils.h"
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_keyboard_delegate_listener.h"
#include "event_handler.h"
#include "event_runner.h"
namespace OHOS {
namespace MiscServices {
class JsKeyboardDelegate {
public:
JsKeyboardDelegate(NativeEngine* engine);
~JsKeyboardDelegate() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info);
private:
sptr<JsKeyboardDelegateListener> kdListener_;
std::mutex mtx_;
NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info);
std::shared_ptr<AppExecFwk::EventHandler> GetMainHandler();
std::shared_ptr<AppExecFwk::EventHandler> mainHandler_ = nullptr;
};
}
}
#endif // OHOS_MISCSERVICES_JS_KEYBOARD_DELEGATE_H

View File

@ -0,0 +1,55 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_JS_KEYBOARD_DELEGATE_LISTENER_H
#define FM_IMMS_PROJECT_JS_KEYBOARD_DELEGATE_LISTENER_H
#include <map>
#include <mutex>
#include <unordered_set>
#include <queue>
#include <condition_variable>
#include <refbase.h>
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "event_handler.h"
#include "event_runner.h"
namespace OHOS {
namespace MiscServices {
class JsKeyboardDelegateListener : virtual public RefBase {
public:
explicit JsKeyboardDelegateListener(NativeEngine* engine) : engine_(engine) {}
JsKeyboardDelegateListener(NativeEngine* engine, std::shared_ptr<AppExecFwk::EventHandler> &handler)
: engine_(engine), mainHandler_(handler) {}
virtual ~JsKeyboardDelegateListener() = default;
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
void UnregisterListenerWithType(std::string type, NativeValue* value);
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus);
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height);
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd);
void OnTextChange(std::string text);
private:
void AddCallback(std::string type, NativeValue* jsListenerObject);
void CallJsMethod(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
bool CallJsMethodReturnBool(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
void RemoveCallback(NativeValue* jsListenerObject);
bool IfCallbackRegistered(std::string type, NativeValue* jsListenerObject);
NativeEngine* engine_ = nullptr;
std::mutex mMutex;
std::map<std::string, std::vector<std::unique_ptr<NativeReference>>> jsCbMap_;
std::shared_ptr<AppExecFwk::EventHandler> mainHandler_ = nullptr;
};
}
}
#endif // FM_IMMS_PROJECT_JS_KEYBOARD_DELEGATE_LISTENER_H

View File

@ -0,0 +1,46 @@
/*
* 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.
*/
#ifndef OHOS_MISCSERVICES_JS_TEXT_INPUT_CLIENT_H
#define OHOS_MISCSERVICES_JS_TEXT_INPUT_CLIENT_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace MiscServices {
class JsTextInputClient {
public:
JsTextInputClient() = default;
~JsTextInputClient() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* InsertText(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* DeleteForward(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetForward(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetBackward(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetEditorAttribute(NativeEngine* engine, NativeCallbackInfo* info);
private:
NativeValue* OnInsertText(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnDeleteForward(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnDeleteBackward(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSendFunctionKey(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetForward(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetBackward(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetEditorAttribute(NativeEngine& engine, NativeCallbackInfo& info);
};
}
}
#endif // OHOS_MISCSERVICES_JS_TEXT_INPUT_CLIENT_H

View File

@ -14,7 +14,7 @@
*/
#include "native_engine/native_engine.h"
#include "js_input_method_engine.h"
#include "js_input_method_engine_registry.h"
extern "C" __attribute__((constructor)) void NAPI_inputMethodEngine_AutoRegister()
{
@ -22,7 +22,7 @@ extern "C" __attribute__((constructor)) void NAPI_inputMethodEngine_AutoRegister
NativeModule newModuleInfo = {
.name = "inputMethodEngine",
.fileName = "inputmethodengine.so/inputmethod_engine.js",
.registerCallback = OHOS::MiscServices::JsInputMethodEngineInit,
.registerCallback = OHOS::MiscServices::JsInputMethodEngineRegistryInit,
};
moduleManager->Register(&newModuleInfo);

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#include "js_editor_attribute.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "global.h"
#include "input_method_ability.h"
namespace OHOS {
namespace MiscServices {
// constexpr size_t ARGC_ZERO = 0;
void JsEditorAttribute::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsEditorAttribute::Finalizer is called");
std::unique_ptr<JsEditorAttribute>(static_cast<JsEditorAttribute*>(data));
}
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.
*/
#include "js_input_method_engine.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "js_input_method_engine_listener.h"
#include "input_method_ability.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_TWO = 2;
JsInputMethodEngine::JsInputMethodEngine(NativeEngine* engine)
{
IMSA_HILOGI("JsInputMethodEngine::Constructor is called");
imeListener_ = new JsInputMethodEngineListener(engine);
InputMethodAbility::GetInstance()->setImeListener(imeListener_);
}
void JsInputMethodEngine::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodEngine::Finalizer is called");
std::unique_ptr<JsInputMethodEngine>(static_cast<JsInputMethodEngine*>(data));
}
NativeValue* JsInputMethodEngine::RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr;
}
NativeValue* JsInputMethodEngine::UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr;
}
NativeValue* JsInputMethodEngine::OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback is called!");
if (info.argc != ARGC_TWO) {
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
NativeValue* value = info.argv[1];
imeListener_->RegisterListenerWithType(engine, cbType, value);
return engine.CreateUndefined();
}
NativeValue* JsInputMethodEngine::OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback is called!");
if (info.argc == 0) {
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
imeListener_->UnregisterListenerWithType(cbType, value);
return engine.CreateUndefined();
}
}
}

View File

@ -15,9 +15,11 @@
#include "js_input_method_engine_listener.h"
#include "global.h"
#include "js_runtime_utils.h"
#include "js_input_method_engine_utils.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
void JsInputMethodEngineListener::RegisterListenerWithType(NativeEngine& engine,
std::string type, NativeValue* value)
{
@ -119,7 +121,7 @@ namespace MiscServices {
for (auto iter = jsCbMap_[methodName].begin(); iter != jsCbMap_[methodName].end(); iter++) {
NativeValue* nativeValue = engine_->CallFunction(engine_->CreateUndefined(), (*iter)->Get(), argv, argc);
bool ret = false;
if (AbilityRuntime::ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
if (ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
result = true;
}
}
@ -132,7 +134,7 @@ namespace MiscServices {
IMSA_HILOGI("JsInputMethodEngineListener::OnKeyboardStatus");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
@ -144,125 +146,19 @@ namespace MiscServices {
} else {
methodName = "keyboardHide";
}
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
CallJsMethod(methodName, argv, ArraySize(argv));
}
bool JsInputMethodEngineListener::OnKeyEvent(int32_t keyCode, int32_t keyStatus)
void JsInputMethodEngineListener::OnInputStart()
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsInputMethodEngineListener::OnKeyEvent");
IMSA_HILOGI("JsInputMethodEngineListener::OnInputStart");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return false;
}
NativeValue* argv[] = {nativeValue};
std::string methodName;
if (keyStatus == 2) {
methodName = "keyDown";
} else {
methodName = "keyUp";
}
object->SetProperty("keyCode", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
object->SetProperty("keyAction", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
return CallJsMethodReturnBool(methodName, argv, AbilityRuntime::ArraySize(argv));
}
void JsInputMethodEngineListener::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsInputMethodEngineListener::OnCursorUpdate");
NativeValue* nativeXValue = engine_->CreateObject();
NativeObject* objectX = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeXValue);
if (objectX == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectX->SetProperty("x", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(positionX)));
NativeValue* nativeYValue = engine_->CreateObject();
NativeObject* objectY = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeYValue);
if (objectY == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectY->SetProperty("y", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(positionY)));
NativeValue* nativeHValue = engine_->CreateObject();
NativeObject* objectH = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeHValue);
if (objectH == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectH->SetProperty("height", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(height)));
NativeValue* argv[] = {nativeXValue, nativeYValue, nativeHValue};
std::string methodName = "cursorContextChange";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
}
void JsInputMethodEngineListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd,
int32_t newBegin, int32_t newEnd)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsInputMethodEngineListener::OnSelectionChange");
NativeValue* nativeOBValue = engine_->CreateObject();
NativeObject* objectOB = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeOBValue);
if (objectOB == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectOB->SetProperty("oldBegin", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(oldBegin)));
NativeValue* nativeOEValue = engine_->CreateObject();
NativeObject* objectOE = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeOEValue);
if (objectOE == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectOE->SetProperty("oldEnd", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(oldEnd)));
NativeValue* nativeNBHValue = engine_->CreateObject();
NativeObject* objectNB = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeNBHValue);
if (objectNB == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectNB->SetProperty("newBegin", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(newBegin)));
NativeValue* nativeNEValue = engine_->CreateObject();
NativeObject* objectNE = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeNEValue);
if (objectNE == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
objectNE->SetProperty("newEnd", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(newEnd)));
NativeValue* argv[] = {nativeOEValue, nativeOEValue, nativeNBHValue, nativeNEValue};
std::string methodName = "selectionChange";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
}
void JsInputMethodEngineListener::OnTextChange(std::string text)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsInputMethodEngineListener::OnTextChange");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
object->SetProperty("text", AbilityRuntime::CreateJsValue(*engine_, text));
NativeValue* argv[] = {nativeValue};
std::string methodName = "textChange";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
NativeValue *nativeValuekb = CreateKeyboardController(*engine_);
NativeValue *nativeValuetx = CreateTextInputClient(*engine_);
NativeValue* argv[] = {nativeValuekb, nativeValuetx};
std::string methodName = "inputStart";
CallJsMethod(methodName, argv, ArraySize(argv));
}
void JsInputMethodEngineListener::OnInputStop(std::string imeId)
@ -271,16 +167,16 @@ namespace MiscServices {
IMSA_HILOGI("JsInputMethodEngineListener::OnInputStop");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
object->SetProperty("imeId", AbilityRuntime::CreateJsValue(*engine_, imeId));
object->SetProperty("imeId", CreateJsValue(*engine_, imeId));
NativeValue* argv[] = {nativeValue};
std::string methodName = "inputStop";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
CallJsMethod(methodName, argv, ArraySize(argv));
}
}
}

View File

@ -0,0 +1,174 @@
/*
* 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.
*/
#include "js_input_method_engine_registry.h"
#include <map>
#include "js_input_method_engine_listener.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "string_ex.h"
#include "input_method_utils.h"
#include "input_method_ability.h"
#include "js_input_method_engine_utils.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
namespace {
constexpr size_t ARGC_ZERO = 0;
constexpr size_t ARGC_ONE = 1;
}
class JsInputMethodEngineRegistry {
public:
explicit JsInputMethodEngineRegistry(NativeEngine* engine)
{
IMSA_HILOGI("JsInputMethodEngineRegistry::Constructor is called");
}
~JsInputMethodEngineRegistry() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodEngineRegistry::Finalizer is called");
std::unique_ptr<JsInputMethodEngineRegistry>(static_cast<JsInputMethodEngineRegistry*>(data));
}
static NativeValue* GetInputMethodEngine(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
return (me != nullptr) ? me->OnGetInputMethodEngine(*engine, *info) : nullptr;
}
static NativeValue* GetKeyboardDelegate(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
return (me != nullptr) ? me->OnGetKeyboardDelegate(*engine, *info) : nullptr;
}
static NativeValue* MoveCursor(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
return (me != nullptr) ? me->OnMoveCursor(*engine, *info) : nullptr;
}
private:
NativeValue* OnGetInputMethodEngine(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngineRegistry::OnGetInputMethodEngine is called!");
if (info.argc > ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngineRegistry::OnGetInputMethodEngine Params not match");
return engine.CreateUndefined();
}
return CreateInputMethodEngine(engine);
}
NativeValue* OnGetKeyboardDelegate(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngineRegistry::OnGetKeyboardDelegate is called!");
if (info.argc > ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngineRegistry::OnGetKeyboardDelegate Params not match");
return engine.CreateUndefined();
}
return CreateKeyboardDelegate(engine);
}
NativeValue* OnMoveCursor(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngineRegistry::OnMoveCursor is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngineRegistry::OnMoveCursor has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsInputMethodEngineRegistry::OnMoveCursor Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->MoveCursor(number);
NativeValue* result = CreateJsValue(engine, true);
return result;
}
};
NativeValue* JsInputMethodEngineRegistryInit(NativeEngine* engine, NativeValue* exportObj)
{
IMSA_HILOGI("JsInputMethodEngineRegistryInit() is called!");
if (engine == nullptr || exportObj == nullptr) {
IMSA_HILOGI("engine or exportObj null");
return nullptr;
}
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
IMSA_HILOGI("object null");
return nullptr;
}
std::unique_ptr<JsInputMethodEngineRegistry> jsInputMethodEngineRegistry = std::make_unique<JsInputMethodEngineRegistry>(engine);
object->SetNativePointer(jsInputMethodEngineRegistry.release(), JsInputMethodEngineRegistry::Finalizer, nullptr);
BindNativeFunction(*engine, *object, "getInputMethodEngine", JsInputMethodEngineRegistry::GetInputMethodEngine);
BindNativeFunction(*engine, *object, "createKeyboardDelegate", JsInputMethodEngineRegistry::GetKeyboardDelegate);
object->SetProperty("ENTER_KEY_TYPE_UNSPECIFIED", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::UNSPECIFIED)));
object->SetProperty("ENTER_KEY_TYPE_GO", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::GO)));
object->SetProperty("ENTER_KEY_TYPE_SEARCH", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEARCH)));
object->SetProperty("ENTER_KEY_TYPE_SEND", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEND)));
object->SetProperty("ENTER_KEY_TYPE_NEXT", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::NEXT)));
object->SetProperty("ENTER_KEY_TYPE_DONE", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::DONE)));
object->SetProperty("ENTER_KEY_TYPE_PREVIOUS", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::PREVIOUS)));
object->SetProperty("PATTERN_NULL", CreateJsValue(*engine, static_cast<int32_t>(TextInputType::NONE)));
object->SetProperty("PATTERN_TEXT", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::TEXT)));
object->SetProperty("PATTERN_NUMBER", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::NUMBER)));
object->SetProperty("PATTERN_PHONE", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::PHONE)));
object->SetProperty("PATTERN_DATETIME", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::DATETIME)));
object->SetProperty("PATTERN_EMAIL", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::EMAIL_ADDRESS)));
object->SetProperty("PATTERN_URI", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::URL)));
object->SetProperty("PATTERN_PASSWORD", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::VISIBLE_PASSWORD)));
object->SetProperty("FLAG_SELECTING", CreateJsValue(*engine, static_cast<uint32_t>(2)));
object->SetProperty("FLAG_SINGLE_LINE", CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("DISPLAY_MODE_PART", CreateJsValue(*engine, static_cast<uint32_t>(0)));
object->SetProperty("DISPLAY_MODE_FULL", CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("OPTION_ASCII", CreateJsValue(*engine, static_cast<uint32_t>(20)));
object->SetProperty("OPTION_NONE", CreateJsValue(*engine, static_cast<uint32_t>(0)));
object->SetProperty("OPTION_AUTO_CAP_CHARACTERS", CreateJsValue(*engine, static_cast<uint32_t>(2)));
object->SetProperty("OPTION_AUTO_CAP_SENTENCES", CreateJsValue(*engine, static_cast<uint32_t>(8)));
object->SetProperty("OPTION_AUTO_WORDS", CreateJsValue(*engine, static_cast<uint32_t>(4)));
object->SetProperty("OPTION_MULTI_LINE", CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("OPTION_NO_FULLSCREEN", CreateJsValue(*engine, static_cast<uint32_t>(10)));
BindNativeFunction(*engine, *object, "MoveCursor", JsInputMethodEngineRegistry::MoveCursor);
object->SetProperty("CURSOR_UP", CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("CURSOR_DOWN", CreateJsValue(*engine, static_cast<uint32_t>(2)));
object->SetProperty("CURSOR_LEFT", CreateJsValue(*engine, static_cast<uint32_t>(3)));
object->SetProperty("CURSOR_RIGHT", CreateJsValue(*engine, static_cast<uint32_t>(4)));
return engine->CreateUndefined();
}
}
}

View File

@ -0,0 +1,126 @@
/*
* 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.
*/
#include "js_input_method_engine_utils.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "js_input_method_engine_listener.h"
#include "input_method_ability.h"
#include "global.h"
#include "js_input_method_engine.h"
#include "js_editor_attribute.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
NativeValue* CreateInputMethodEngine(NativeEngine &engine)
{
IMSA_HILOGI("JsInputMethodEngineUtils::CreateInputMethodEngine is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("JsInputMethodEngineUtils::CreateInputMethodEngine Failed to get object");
return nullptr;
}
std::unique_ptr<JsInputMethodEngine> jsInputMethodEngine = std::make_unique<JsInputMethodEngine>(&engine);
object->SetNativePointer(jsInputMethodEngine.release(), JsInputMethodEngine::Finalizer, nullptr);
BindNativeFunction(engine, *object, "on", JsInputMethodEngine::RegisterCallback);
BindNativeFunction(engine, *object, "off", JsInputMethodEngine::UnRegisterCallback);
return objValue;
}
NativeValue* CreateKeyboardController(NativeEngine & engine)
{
IMSA_HILOGI("JsInputMethodEngineUtils::CreateKeyboardController is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("CreateKeyboardController Failed to get object");
return nullptr;
}
std::unique_ptr<JsKeyboardController> jsKeyboardController = std::make_unique<JsKeyboardController>();
object->SetNativePointer(jsKeyboardController.release(), JsKeyboardController::Finalizer, nullptr);
BindNativeFunction(engine, *object, "hideKeyboard", JsKeyboardController::HideKeyboardSelf);
return objValue;
}
NativeValue* CreateTextInputClient(NativeEngine & engine)
{
IMSA_HILOGI("JsInputMethodEngineUtils::CreateTextInputClient is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("CreateTextInputClient Failed to get object");
return nullptr;
}
std::unique_ptr<JsTextInputClient> jsTextInputClient = std::make_unique<JsTextInputClient>();
object->SetNativePointer(jsTextInputClient.release(), JsTextInputClient::Finalizer, nullptr);
BindNativeFunction(engine, *object, "insertText", JsTextInputClient::InsertText);
BindNativeFunction(engine, *object, "deleteForward", JsTextInputClient::DeleteForward);
BindNativeFunction(engine, *object, "deleteBackward", JsTextInputClient::DeleteBackward);
BindNativeFunction(engine, *object, "sendKeyFunction", JsTextInputClient::SendFunctionKey);
BindNativeFunction(engine, *object, "getForward", JsTextInputClient::GetForward);
BindNativeFunction(engine, *object, "getBackward", JsTextInputClient::GetBackward);
BindNativeFunction(engine, *object, "getEditorAttribute", JsTextInputClient::GetEditorAttribute);
return objValue;
}
NativeValue* CreateKeyboardDelegate(NativeEngine & engine)
{
IMSA_HILOGI("JsInputMethodEngineUtils::CreateKeyboardDelegate is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("CreateKeyboardDelegate Failed to get object");
return nullptr;
}
std::unique_ptr<JsKeyboardDelegate> jsKeyboardDelegate = std::make_unique<JsKeyboardDelegate>(&engine);
object->SetNativePointer(jsKeyboardDelegate.release(), JsKeyboardDelegate::Finalizer, nullptr);
BindNativeFunction(engine, *object, "on", JsKeyboardDelegate::RegisterCallback);
BindNativeFunction(engine, *object, "off", JsKeyboardDelegate::UnRegisterCallback);
return objValue;
}
NativeValue* CreateEditorAttribute(NativeEngine & engine)
{
IMSA_HILOGI("JsInputMethodEngineUtils::CreateEditorAttribute is called");
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
IMSA_HILOGI("CreateEditorAttribute Failed to get object");
return nullptr;
}
std::unique_ptr<JsEditorAttribute> jsEditorAttribute = std::make_unique<JsEditorAttribute>();
object->SetNativePointer(jsEditorAttribute.release(), JsEditorAttribute::Finalizer, nullptr);
object->SetProperty("enterKeyType", CreateJsValue(engine, InputMethodAbility::GetInstance()->GetEnterKeyType()));
object->SetProperty("inputPattern", CreateJsValue(engine, InputMethodAbility::GetInstance()->GetInputPattern()));
return objValue;
}
}
}

View File

@ -0,0 +1,52 @@
/*
* 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.
*/
#include "js_keyboard_controller.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "input_method_ability.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_ZERO = 0;
void JsKeyboardController::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsKeyboardController::Finalizer is called");
std::unique_ptr<JsKeyboardController>(static_cast<JsKeyboardController*>(data));
}
NativeValue* JsKeyboardController::HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info)
{
JsKeyboardController* me = CheckParamsAndGetThis<JsKeyboardController>(engine, info);
return (me != nullptr) ? me->OnHideKeyboardSelf(*engine, *info) : nullptr;
}
NativeValue* JsKeyboardController::OnHideKeyboardSelf(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsKeyboardController::OnHideKeyboardSelf is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsKeyboardController::OnHideKeyboardSelf has params, return!");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->HideKeyboardSelf();
return engine.CreateUndefined();
}
}
}

View File

@ -0,0 +1,107 @@
/*
* 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.
*/
#include "js_keyboard_delegate.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "js_keyboard_delegate_listener.h"
#include "input_method_ability.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_TWO = 2;
JsKeyboardDelegate::JsKeyboardDelegate(NativeEngine* engine)
{
IMSA_HILOGI("JsKeyboardDelegate::Constructor is called");
auto mainHandler = GetMainHandler();
kdListener_ = new JsKeyboardDelegateListener(engine, mainHandler);
InputMethodAbility::GetInstance()->setKdListener(kdListener_);
}
void JsKeyboardDelegate::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsKeyboardDelegate::Finalizer is called");
std::unique_ptr<JsKeyboardDelegate>(static_cast<JsKeyboardDelegate*>(data));
}
std::shared_ptr<AppExecFwk::EventHandler> JsKeyboardDelegate::GetMainHandler()
{
if (!mainHandler_) {
mainHandler_ =
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
}
return mainHandler_;
}
NativeValue* JsKeyboardDelegate::RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsKeyboardDelegate* me = CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr;
}
NativeValue* JsKeyboardDelegate::UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsKeyboardDelegate* me = CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr;
}
NativeValue* JsKeyboardDelegate::OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsKeyboardDelegate::OnRegisterCallback is called!");
if (info.argc != ARGC_TWO) {
IMSA_HILOGI("JsKeyboardDelegate::OnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsKeyboardDelegate::OnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
NativeValue* value = info.argv[1];
kdListener_->RegisterListenerWithType(engine, cbType, value);
return engine.CreateUndefined();
}
NativeValue* JsKeyboardDelegate::OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsKeyboardDelegate::OnUnRegisterCallback is called!");
if (info.argc == 0) {
IMSA_HILOGI("JsKeyboardDelegate::OnUnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsKeyboardDelegate::OnUnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsKeyboardDelegate::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
kdListener_->UnregisterListenerWithType(cbType, value);
return engine.CreateUndefined();
}
}
}

View File

@ -0,0 +1,204 @@
/*
* 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.
*/
#include "js_keyboard_delegate_listener.h"
#include "global.h"
#include "js_runtime_utils.h"
#include "js_input_method_engine_utils.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
void JsKeyboardDelegateListener::RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value)
{
// should do type check
if (IfCallbackRegistered(type, value)) {
IMSA_HILOGI("JsKeyboardDelegateListener::RegisterListenerWithType callback already registered!");
return;
}
std::unique_ptr<NativeReference> callbackRef;
callbackRef.reset(engine.CreateReference(value, 1));
AddCallback(type, value);
}
void JsKeyboardDelegateListener::AddCallback(std::string type, NativeValue* jsListenerObject)
{
IMSA_HILOGI("JsKeyboardDelegateListener::AddCallback is called");
std::lock_guard<std::mutex> lock(mMutex);
std::unique_ptr<NativeReference> callbackRef;
callbackRef.reset(engine_->CreateReference(jsListenerObject, 1));
jsCbMap_[type].push_back(std::move(callbackRef));
IMSA_HILOGI("JsKeyboardDelegateListener::AddCallback success");
IMSA_HILOGI("jsCbMap_ size: %{public}d, and type[%{public}s] size: %{public}d!",
static_cast<uint32_t>(jsCbMap_.size()), type.c_str(), static_cast<uint32_t>(jsCbMap_[type].size()));
return;
}
void JsKeyboardDelegateListener::UnregisterListenerWithType(std::string type, NativeValue* value)
{
IMSA_HILOGI("JsKeyboardDelegateListener::UnregisterListenerWithType");
// should do type check
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str());
return;
}
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
if (value->StrictEquals((*it)->Get())) {
jsCbMap_[type].erase(it);
break;
}
}
// one type with multi jscallback, erase type when there is no callback in one type
if (jsCbMap_[type].empty()) {
jsCbMap_.erase(type);
}
return;
}
bool JsKeyboardDelegateListener::IfCallbackRegistered(std::string type, NativeValue* jsListenerObject)
{
IMSA_HILOGI("JsKeyboardDelegateListener::IfCallbackRegistered");
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registertd!", type.c_str());
return false;
}
for (auto iter = jsCbMap_[type].begin(); iter != jsCbMap_[type].end(); iter++) {
if (jsListenerObject->StrictEquals((*iter)->Get())) {
IMSA_HILOGI("JsKeyboardDelegateListener::IfCallbackRegistered callback already registered!");
return true;
}
}
return false;
}
void JsKeyboardDelegateListener::CallJsMethod(std::string methodName, NativeValue* const* argv, size_t argc)
{
IMSA_HILOGI("JsKeyboardDelegateListener::CallJsMethod");
if (engine_ == nullptr) {
IMSA_HILOGI("engine_ nullptr");
return;
}
if (jsCbMap_.empty() || jsCbMap_.find(methodName) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registertd!", methodName.c_str());
return;
}
for (auto iter = jsCbMap_[methodName].begin(); iter != jsCbMap_[methodName].end(); iter++) {
engine_->CallFunction(engine_->CreateUndefined(), (*iter)->Get(), argv, argc);
}
}
bool JsKeyboardDelegateListener::CallJsMethodReturnBool(std::string methodName,
NativeValue* const* argv, size_t argc)
{
IMSA_HILOGI("JsKeyboardDelegateListener::CallJsMethodReturnBool");
if (engine_ == nullptr) {
IMSA_HILOGI("engine_ nullptr");
return false;
}
if (jsCbMap_.empty() || jsCbMap_.find(methodName) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registertd!", methodName.c_str());
return false;
}
bool result = false;
for (auto iter = jsCbMap_[methodName].begin(); iter != jsCbMap_[methodName].end(); iter++) {
NativeValue* nativeValue = engine_->CallFunction(engine_->CreateUndefined(), (*iter)->Get(), argv, argc);
bool ret = false;
if (ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
result = true;
}
}
return result;
}
bool JsKeyboardDelegateListener::OnKeyEvent(int32_t keyCode, int32_t keyStatus)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsKeyboardDelegateListener::OnKeyEvent");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return false;
}
NativeValue* argv[] = {nativeValue};
std::string methodName;
if (keyStatus == 2) {
methodName = "keyDown";
} else {
methodName = "keyUp";
}
object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
return CallJsMethodReturnBool(methodName, argv, ArraySize(argv));
}
void JsKeyboardDelegateListener::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsKeyboardDelegateListener::OnCursorUpdate");
auto task = [this, positionX, positionY, height] () {
NativeValue* nativeXValue = CreateJsValue(*engine_, static_cast<uint32_t>(positionX));
NativeValue* nativeYValue = CreateJsValue(*engine_, static_cast<uint32_t>(positionY));
NativeValue* nativeHValue = CreateJsValue(*engine_, static_cast<uint32_t>(height));
NativeValue* argv[] = {nativeXValue, nativeYValue, nativeHValue};
std::string methodName = "cursorContextChange";
CallJsMethod(methodName, argv, ArraySize(argv));
};
mainHandler_->PostTask(task);
}
void JsKeyboardDelegateListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsKeyboardDelegateListener::OnSelectionChange");
auto task = [this, oldBegin, oldEnd, newBegin, newEnd] () {
NativeValue* nativeOBValue = CreateJsValue(*engine_, static_cast<uint32_t>(oldBegin));
NativeValue* nativeOEValue = CreateJsValue(*engine_, static_cast<uint32_t>(oldEnd));
NativeValue* nativeNBHValue = CreateJsValue(*engine_, static_cast<uint32_t>(newBegin));
NativeValue* nativeNEValue = CreateJsValue(*engine_, static_cast<uint32_t>(newEnd));
NativeValue* argv[] = {nativeOBValue, nativeOEValue, nativeNBHValue, nativeNEValue};
std::string methodName = "selectionChange";
CallJsMethod(methodName, argv, ArraySize(argv));
};
mainHandler_->PostTask(task);
}
void JsKeyboardDelegateListener::OnTextChange(std::string text)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsKeyboardDelegateListener::OnTextChange");
auto task = [this, text] () {
NativeValue* nativeValue = CreateJsValue(*engine_, text);
NativeValue* argv[] = {nativeValue};
std::string methodName = "textChange";
CallJsMethod(methodName, argv, ArraySize(argv));
};
mainHandler_->PostTask(task);
}
}
}

View File

@ -0,0 +1,233 @@
/*
* 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.
*/
#include "js_text_input_client.h"
#include "input_method_controller.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "event_handler.h"
#include "event_runner.h"
#include "string_ex.h"
#include "input_method_ability.h"
#include "js_input_method_engine_utils.h"
namespace OHOS {
namespace MiscServices {
using namespace AbilityRuntime;
constexpr size_t ARGC_ZERO = 0;
constexpr size_t ARGC_ONE = 1;
void JsTextInputClient::Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsTextInputClient::Finalizer is called");
std::unique_ptr<JsTextInputClient>(static_cast<JsTextInputClient*>(data));
}
NativeValue* JsTextInputClient::InsertText(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnInsertText(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::DeleteForward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnDeleteForward(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnDeleteBackward(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnSendFunctionKey(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::GetForward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnGetForward(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::GetBackward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnGetBackward(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::GetEditorAttribute(NativeEngine* engine, NativeCallbackInfo* info)
{
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
return (me != nullptr) ? me->OnGetEditorAttribute(*engine, *info) : nullptr;
}
NativeValue* JsTextInputClient::OnInsertText(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnInsertText is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnInsertText has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
std::string textString;
if (!ConvertFromJsValue(engine, nativeString, textString)) {
IMSA_HILOGI("JsTextInputClient::OnInsertText Failed to convert parameter to string");
return engine.CreateUndefined();
}
bool ret = InputMethodAbility::GetInstance()->InsertText(textString);
NativeValue* result = CreateJsValue(engine, ret);
return result;
}
NativeValue* JsTextInputClient::OnDeleteForward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnDeleteForward is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnDeleteForward has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsTextInputClient::OnDeleteForward Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->DeleteForward(number);
NativeValue* result = CreateJsValue(engine, true);
return result;
}
NativeValue* JsTextInputClient::OnDeleteBackward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnDeleteBackward is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnDeleteBackward has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsTextInputClient::OnDeleteBackward Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->DeleteBackward(number);
NativeValue* result = CreateJsValue(engine, true);
return result;
}
NativeValue* JsTextInputClient::OnSendFunctionKey(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnSendFunctionKey is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnSendFunctionKey has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsTextInputClient::OnSendFunctionKey Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->SendFunctionKey(number);
NativeValue* result = CreateJsValue(engine, true);
return result;
}
NativeValue* JsTextInputClient::OnGetForward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnGetForward is called!");
if (info.argc != ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnGetForward has not one params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsTextInputClient::OnGetForward Failed to convert parameter to string");
return engine.CreateUndefined();
}
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextBeforeCursor(number));
NativeValue* result = CreateJsValue(engine, ret);
return result;
}
NativeValue* JsTextInputClient::OnGetBackward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnGetBackward is called!");
if (info.argc != ARGC_ONE) {
IMSA_HILOGI("JsTextInputClient::OnGetBackward has not one params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsTextInputClient::OnGetBackward Failed to convert parameter to string");
return engine.CreateUndefined();
}
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextAfterCursor(number));
NativeValue* result = CreateJsValue(engine, ret);
return result;
}
NativeValue* JsTextInputClient::OnGetEditorAttribute(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsTextInputClient::OnGetEditorAttribute is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsTextInputClient::OnGetEditorAttribute has params!");
return engine.CreateUndefined();
}
return CreateEditorAttribute(engine);
}
}
}

View File

@ -1,136 +0,0 @@
/*
* 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.
*/
#include "js_input_method.h"
#include <map>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "string_ex.h"
#include "input_method_utils.h"
#include "event_handler.h"
#include "event_runner.h"
#include "input_method_controller.h"
namespace OHOS {
namespace MiscServices {
namespace {
constexpr size_t ARGC_ZERO = 0;
}
class JsInputMethod {
public:
explicit JsInputMethod(NativeEngine* engine)
{
IMSA_HILOGI("JsInputMethod::Constructor is called");
}
~JsInputMethod() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethod::Finalizer is called");
std::unique_ptr<JsInputMethod>(static_cast<JsInputMethod*>(data));
}
static NativeValue* GetInputMethodSetting(NativeEngine* engine, NativeCallbackInfo* info)
{
IMSA_HILOGI("JsInputMethod::GetInputMethodSetting is called");
JsInputMethod* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethod>(engine, info);
return (me != nullptr) ? me->OnGetInputMethodSetting(*engine, *info) : nullptr;
}
static NativeValue* DisplayOptionalInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
{
IMSA_HILOGI("JsInputMethod::DisplayOptionalInputMethod is called");
if (info->argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethod::OnDisplayOptionalInputMethod has params, return!");
return engine->CreateUndefined();
}
InputMethodController::GetInstance()->DisplayOptionalInputMethod();
return engine->CreateUndefined();
}
static NativeValue* ListInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
{
IMSA_HILOGI("JsInputMethod::ListInputMethod is called");
if (info->argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethod::ListInputMethod has params, return!");
return engine->CreateUndefined();
}
std::vector<InputMethodProperty*> properties = InputMethodController::GetInstance()->ListInputMethod();
if (properties.size() == 0) {
IMSA_HILOGI("JsInputMethod::ListInputMethod has no ime");
return engine->CreateUndefined();
}
NativeValue* arrayValue = engine->CreateArray(properties.size());
NativeArray* array = AbilityRuntime::ConvertNativeValueTo<NativeArray>(arrayValue);
uint32_t index = 0;
for (const auto &info : properties) {
NativeValue* objValue = engine->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
IMSA_HILOGI("JsInputMethod::ListInputMethod %{public}s/%{public}s", Str16ToStr8(info->mPackageName).c_str(), Str16ToStr8(info->mAbilityName).c_str());
object->SetProperty("packageName", AbilityRuntime::CreateJsValue(*engine, Str16ToStr8(info->mPackageName)));
object->SetProperty("methodId", AbilityRuntime::CreateJsValue(*engine, Str16ToStr8(info->mAbilityName)));
array->SetElement(index++, objValue);
}
return arrayValue;
}
private:
NativeValue* OnGetInputMethodSetting(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethod::OnGetInputMethodSetting is called!");
NativeValue* objValue = engine.CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
AbilityRuntime::BindNativeFunction(engine, *object, "displayOptionalInputMethod",
JsInputMethod::DisplayOptionalInputMethod);
AbilityRuntime::BindNativeFunction(engine, *object, "listInputMethod", JsInputMethod::ListInputMethod);
return objValue;
}
};
NativeValue* JsInputMethodInit(NativeEngine* engine, NativeValue* exportObj)
{
IMSA_HILOGI("JsInputMethodInit() is called!");
if (engine == nullptr || exportObj == nullptr) {
IMSA_HILOGI("engine or exportObj null");
return nullptr;
}
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
IMSA_HILOGI("object null");
return nullptr;
}
std::unique_ptr<JsInputMethod> jsInputMethod = std::make_unique<JsInputMethod>(engine);
object->SetNativePointer(jsInputMethod.release(), JsInputMethod::Finalizer, nullptr);
// create inputMethod
AbilityRuntime::BindNativeFunction(*engine, *object, "getInputMethodSetting",
JsInputMethod::GetInputMethodSetting);
return engine->CreateUndefined();
}
}
}

View File

@ -1,357 +0,0 @@
/*
* 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.
*/
#include "js_input_method_engine.h"
#include <map>
#include "js_input_method_engine_listener.h"
#include "input_method_ability.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "string_ex.h"
#include "input_method_utils.h"
namespace OHOS {
namespace MiscServices {
namespace {
constexpr size_t ARGC_ZERO = 0;
constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
}
class JsInputMethodEngine {
public:
sptr<JsInputMethodEngineListener> imeListener_;
explicit JsInputMethodEngine(NativeEngine* engine)
{
IMSA_HILOGI("JsInputMethodEngine::Constructor is called");
imeListener_ = new JsInputMethodEngineListener(engine);
InputMethodAbility::GetInstance()->setImeListener(imeListener_);
}
~JsInputMethodEngine() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
IMSA_HILOGI("JsInputMethodEngine::Finalizer is called");
std::unique_ptr<JsInputMethodEngine>(static_cast<JsInputMethodEngine*>(data));
}
static NativeValue* InsertText(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnInsertText(*engine, *info) : nullptr;
}
static NativeValue* DeleteForward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnDeleteForward(*engine, *info) : nullptr;
}
static NativeValue* DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnDeleteBackward(*engine, *info) : nullptr;
}
static NativeValue* MoveCursor(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnMoveCursor(*engine, *info) : nullptr;
}
static NativeValue* HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnHideKeyboardSelf(*engine, *info) : nullptr;
}
static NativeValue* GetTextBeforeCursor(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnGetTextBeforeCursor(*engine, *info) : nullptr;
}
static NativeValue* GetTextAfterCursor(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnGetTextAfterCursor(*engine, *info) : nullptr;
}
static NativeValue* SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnSendFunctionKey(*engine, *info) : nullptr;
}
static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr;
}
static NativeValue* UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr;
}
private:
std::mutex mtx_;
NativeValue* OnInsertText(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnInsertText is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngine::OnInsertText has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
std::string textString;
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, textString)) {
IMSA_HILOGI("JsInputMethodEngine::OnInsertText Failed to convert parameter to string");
return engine.CreateUndefined();
}
bool ret = InputMethodAbility::GetInstance()->InsertText(textString);
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
return result;
}
NativeValue* OnDeleteForward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->DeleteForward(number);
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
return result;
}
NativeValue* OnDeleteBackward(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->DeleteBackward(number);
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
return result;
}
NativeValue* OnMoveCursor(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->MoveCursor(number);
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
return result;
}
NativeValue* OnHideKeyboardSelf(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf has params, return!");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->HideKeyboardSelf();
return engine.CreateUndefined();
}
NativeValue* OnGetTextBeforeCursor(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor has params, return!");
return engine.CreateUndefined();
}
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextBeforeCursor());
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
return result;
}
NativeValue* OnGetTextAfterCursor(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor is called!");
if (info.argc != ARGC_ZERO) {
IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor has params, return!");
return engine.CreateUndefined();
}
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextAfterCursor());
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
return result;
}
NativeValue* OnSendFunctionKey(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey is called!");
if (info.argc < ARGC_ONE) {
IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey has no params!");
return engine.CreateUndefined();
}
NativeValue* nativeString = nullptr;
nativeString = info.argv[ARGC_ZERO];
int32_t number;
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey Failed to convert parameter to string");
return engine.CreateUndefined();
}
InputMethodAbility::GetInstance()->SendFunctionKey(number);
return engine.CreateUndefined();
}
NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback is called!");
if (info.argc != ARGC_TWO) {
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
NativeValue* value = info.argv[1];
imeListener_->RegisterListenerWithType(engine, cbType, value);
return engine.CreateUndefined();
}
NativeValue* OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback is called!");
if (info.argc == 0) {
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
imeListener_->UnregisterListenerWithType(cbType, value);
return engine.CreateUndefined();
}
};
NativeValue* JsInputMethodEngineInit(NativeEngine* engine, NativeValue* exportObj)
{
IMSA_HILOGI("JsInputMethodEngineInit() is called!");
if (engine == nullptr || exportObj == nullptr) {
IMSA_HILOGI("engine or exportObj null");
return nullptr;
}
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
IMSA_HILOGI("object null");
return nullptr;
}
std::unique_ptr<JsInputMethodEngine> jsIMEngine = std::make_unique<JsInputMethodEngine>(engine);
object->SetNativePointer(jsIMEngine.release(), JsInputMethodEngine::Finalizer, nullptr);
AbilityRuntime::BindNativeFunction(*engine, *object, "InsertText", JsInputMethodEngine::InsertText);
AbilityRuntime::BindNativeFunction(*engine, *object, "DeleteForward", JsInputMethodEngine::DeleteForward);
AbilityRuntime::BindNativeFunction(*engine, *object, "DeleteBackward", JsInputMethodEngine::DeleteBackward);
AbilityRuntime::BindNativeFunction(*engine, *object, "MoveCursor", JsInputMethodEngine::MoveCursor);
AbilityRuntime::BindNativeFunction(*engine, *object, "HideKeyboardSelf", JsInputMethodEngine::HideKeyboardSelf);
AbilityRuntime::BindNativeFunction(*engine, *object, "GetTextBeforeCursor",
JsInputMethodEngine::GetTextBeforeCursor);
AbilityRuntime::BindNativeFunction(*engine, *object, "GetTextAfterCursor", JsInputMethodEngine::GetTextAfterCursor);
AbilityRuntime::BindNativeFunction(*engine, *object, "SendFunctionKey", JsInputMethodEngine::SendFunctionKey);
AbilityRuntime::BindNativeFunction(*engine, *object, "on", JsInputMethodEngine::RegisterCallback);
AbilityRuntime::BindNativeFunction(*engine, *object, "off", JsInputMethodEngine::UnRegisterCallback);
object->SetProperty("FUNCTION_KEY_CONFIRM", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("CURSOR_UP", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
object->SetProperty("CURSOR_DOWN", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(2)));
object->SetProperty("CURSOR_LEFT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(3)));
object->SetProperty("CURSOR_RIGHT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(4)));
return engine->CreateUndefined();
}
}
}

View File

@ -37,6 +37,7 @@ namespace MiscServices {
RELEASE_INPUT,
START_INPUT,
STOP_INPUT,
HIDE_CURRENT_INPUT,
SET_INPUT_METHOD_CORE,
GET_DISPLAY_MODE,
GET_KEYBOARD_WINDOW_HEIGHT,
@ -55,6 +56,7 @@ namespace MiscServices {
virtual void startInput(MessageParcel& data) = 0;
virtual void stopInput(MessageParcel& data) = 0;
virtual void SetCoreAndAgent(MessageParcel& data) = 0;
virtual void HideCurrentInput(MessageParcel& data) = 0;
virtual void displayOptionalInputMethod(MessageParcel& data) = 0;
virtual int32_t getDisplayMode(int32_t retMode) = 0;

View File

@ -34,6 +34,7 @@ namespace MiscServices {
virtual void startInput(MessageParcel& data) override;
virtual void stopInput(MessageParcel& data) override;
virtual void SetCoreAndAgent(MessageParcel& data) override;
virtual void HideCurrentInput(MessageParcel& data) override;
virtual void displayOptionalInputMethod(MessageParcel& data) override;
virtual int32_t listInputMethodByUserId(int32_t userId, std::vector<InputMethodProperty*> *properties) = 0;
protected:

View File

@ -45,6 +45,7 @@ namespace MessageID {
MSG_ID_STOP_INPUT, // stop input
MSG_ID_RELEASE_INPUT, // release input
MSG_ID_SET_CORE_AND_AGENT,
MSG_HIDE_CURRENT_INPUT,
// the request to handle the condition that the remote object died
MSG_ID_CLIENT_DIED, // input client died

View File

@ -491,6 +491,7 @@ namespace MiscServices {
case MSG_ID_RELEASE_INPUT:
case MSG_ID_START_INPUT:
case MSG_ID_STOP_INPUT:
case MSG_HIDE_CURRENT_INPUT:
case MSG_ID_SET_CORE_AND_AGENT:
case MSG_ID_HIDE_KEYBOARD_SELF:
case MSG_ID_SET_DISPLAY_MODE:

View File

@ -165,6 +165,11 @@ namespace MiscServices {
reply.WriteInt32(NO_ERROR);
break;
}
case HIDE_CURRENT_INPUT: {
HideCurrentInput(data);
reply.WriteInt32(NO_ERROR);
break;
}
default: {
return BRemoteObject::OnRemoteRequest(code, data, reply, option);
}
@ -287,6 +292,18 @@ namespace MiscServices {
MessageHandler::Instance()->SendMessage(msg);
}
void InputMethodSystemAbilityStub::HideCurrentInput(MessageParcel& data)
{
IMSA_HILOGI("InputMethodSystemAbilityStub::HideCurrentInput");
int32_t uid = IPCSkeleton::GetCallingUid();
int32_t userId = getUserId(uid);
MessageParcel *parcel = new MessageParcel();
parcel->WriteInt32(userId);
Message *msg = new Message(MSG_HIDE_CURRENT_INPUT, parcel);
MessageHandler::Instance()->SendMessage(msg);
}
/*! Get user id from uid
\param uid the uid from which the remote call is
\return return user id of the remote caller

View File

@ -182,6 +182,9 @@ namespace MiscServices {
OnRestartIms(index, imeId);
break;
}
case MSG_HIDE_CURRENT_INPUT: {
OnHideKeyboardSelf(0);
}
default: {
break;
}