From dc475824beda35a16052c4c09707ff703e00d23d Mon Sep 17 00:00:00 2001 From: xujie Date: Fri, 21 Apr 2023 16:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0OnTextChangedListener?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujie --- .../include/imf_adapter_impl.h | 4 +- .../src/imf_adapter_impl.cpp | 52 +++++++++++++++---- ohos_adapter/interfaces/imf_adapter.h | 25 ++++++--- .../imf_adapter_impl_test.cpp | 35 +++++++------ 4 files changed, 85 insertions(+), 31 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h b/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h index ae5211b1c..2d9269f0a 100644 --- a/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h +++ b/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h @@ -34,7 +34,9 @@ public: void SendKeyEventFromInputMethod(const MiscServices::KeyEvent &event) override; - void SendKeyboardInfo(const MiscServices::KeyboardInfo &info) override; + void SendKeyboardStatus(const MiscServices::KeyboardStatus& keyboardStatus) override; + + void SendFunctionKey(const MiscServices::FunctionKey& functionKey) override; void SetKeyboardStatus(bool status) override; diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index c3aaef055..fe92c7102 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -55,19 +55,53 @@ void IMFTextListenerAdapterImpl::SendKeyEventFromInputMethod(const MiscServices: } } -void IMFTextListenerAdapterImpl::SendKeyboardInfo(const MiscServices::KeyboardInfo& info) +void IMFTextListenerAdapterImpl::SendKeyboardStatus(const MiscServices::KeyboardStatus& keyboardStatus) { if (listener_) { - IMFAdapterKeyboardInfo adapterInfo; - if (info.GetKeyboardStatus() == MiscServices::KeyboardStatus::SHOW) { - adapterInfo.keyboardStatus = IMFAdapterKeyboardStatus::SHOW; - } else if (info.GetKeyboardStatus() == MiscServices::KeyboardStatus::HIDE) { - adapterInfo.keyboardStatus = IMFAdapterKeyboardStatus::HIDE; + auto status = IMFAdapterKeyboardStatus::NONE; + if (keyboardStatus == MiscServices::KeyboardStatus::SHOW) { + status = IMFAdapterKeyboardStatus::SHOW; + } else if (keyboardStatus == MiscServices::KeyboardStatus::HIDE) { + status = IMFAdapterKeyboardStatus::HIDE; } - if (info.GetFunctionKey() == MiscServices::FunctionKey::CONFIRM) { - adapterInfo.functionKey = IMFAdapterFunctionKey::CONFIRM; + listener_->SendKeyboardStatus(status); + } +} + +void IMFTextListenerAdapterImpl::SendFunctionKey(const MiscServices::FunctionKey& functionKey) +{ + if (listener_) { + IMFAdapterFunctionKey adapterFunction; + switch (functionKey.GetEnterKeyType()) { + case MiscServices::EnterKeyType::UNSPECIFIED: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::UNSPECIFIED); + break; + case MiscServices::EnterKeyType::NONE: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::NONE); + break; + case MiscServices::EnterKeyType::GO: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::GO); + break; + case MiscServices::EnterKeyType::SEARCH: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::SEARCH); + break; + case MiscServices::EnterKeyType::SEND: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::SEND); + break; + case MiscServices::EnterKeyType::NEXT: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::NEXT); + break; + case MiscServices::EnterKeyType::DONE: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::DONE); + break; + case MiscServices::EnterKeyType::PREVIOUS: + adapterFunction.SetEnterKeyType(IMFAdapterEnterKeyType::PREVIOUS); + break; + default: + WVLOG_E("unknown functionKey"); + break; } - listener_->SendKeyboardInfo(adapterInfo); + listener_->SendFunctionKey(adapterFunction); } } diff --git a/ohos_adapter/interfaces/imf_adapter.h b/ohos_adapter/interfaces/imf_adapter.h index 91e97088f..614dfc019 100644 --- a/ohos_adapter/interfaces/imf_adapter.h +++ b/ohos_adapter/interfaces/imf_adapter.h @@ -31,6 +31,8 @@ enum class IMFAdapterTextInputType { VISIBLE_PASSWORD, }; +enum class IMFAdapterEnterKeyType { UNSPECIFIED = 0, NONE, GO, SEARCH, SEND, NEXT, DONE, PREVIOUS }; + enum class IMFAdapterDirection { NONE = 0, UP = 1, @@ -48,11 +50,20 @@ struct IMFAdapterCursorInfo { enum class IMFAdapterKeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; -enum class IMFAdapterFunctionKey : int32_t { NONE = 0, CONFIRM }; - -struct IMFAdapterKeyboardInfo { - IMFAdapterKeyboardStatus keyboardStatus = IMFAdapterKeyboardStatus::NONE; - IMFAdapterFunctionKey functionKey = IMFAdapterFunctionKey::NONE; +class IMFAdapterFunctionKey { +public: + IMFAdapterEnterKeyType GetEnterKeyType() const + { + return enterKeyType; + } + + void SetEnterKeyType(IMFAdapterEnterKeyType keyType) + { + enterKeyType = keyType; + } + +private: + IMFAdapterEnterKeyType enterKeyType = IMFAdapterEnterKeyType::UNSPECIFIED; }; class IMFTextListenerAdapter { @@ -69,7 +80,9 @@ public: virtual void SendKeyEventFromInputMethod() = 0; - virtual void SendKeyboardInfo(const IMFAdapterKeyboardInfo &info) = 0; + virtual void SendKeyboardStatus(const IMFAdapterKeyboardStatus& keyboardStatus) = 0; + + virtual void SendFunctionKey(const IMFAdapterFunctionKey& functionKey) = 0; virtual void SetKeyboardStatus(bool status) = 0; diff --git a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp index cb164d043..793f62671 100644 --- a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp @@ -62,10 +62,15 @@ public: WVLOG_I("test SendKeyEventFromInputMethod"); isSendKeyEventFromInputMethod_ = true; } - void SendKeyboardInfo(const IMFAdapterKeyboardInfo &info) override + void SendKeyboardStatus(const IMFAdapterKeyboardStatus& adapterKeyboardStatus) override { - WVLOG_I("test SendKeyboardInfo"); - isSendKeyboardInfo_ = true; + WVLOG_I("test SendKeyboardStatus"); + isSendKeyboardStatus_ = true; + } + void SendFunctionKey(const IMFAdapterFunctionKey& adapterFunctionKey) override + { + WVLOG_I("test SendFunctionKey"); + isSendFunctionKey_ = true; } void SetKeyboardStatus(bool status) override { @@ -95,8 +100,8 @@ public: bool VerifyAllSuccess() { return isInsertText_ && isDeleteForward_ && isDeleteBackward_ && isSendKeyEventFromInputMethod_ && - isSendKeyboardInfo_ && isSetKeyboardStatus_ && isMoveCursor_ && isHandleSetSelection_ && - isHandleExtendAction_ && isHandleSelect_; + isSendKeyboardStatus_ && isSendFunctionKey_ && isSetKeyboardStatus_ && isMoveCursor_ && + isHandleSetSelection_ && isHandleExtendAction_ && isHandleSelect_; } private: @@ -104,7 +109,8 @@ private: bool isDeleteForward_ = false; bool isDeleteBackward_ = false; bool isSendKeyEventFromInputMethod_ = false; - bool isSendKeyboardInfo_ = false; + bool isSendKeyboardStatus_ = false; + bool isSendFunctionKey_ = false; bool isSetKeyboardStatus_ = false; bool isMoveCursor_ = false; bool isHandleSetSelection_ = false; @@ -199,17 +205,15 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_IMFAdapterImpl_005, TestSize.Lev auto listenerTest = std::make_shared(listener); std::u16string text; MiscServices::KeyEvent event; - MiscServices::KeyboardInfo info; + MiscServices::FunctionKey functionKey; listenerTest->InsertText(text); listenerTest->DeleteForward(0); listenerTest->DeleteBackward(0); listenerTest->SendKeyEventFromInputMethod(event); - listenerTest->SendKeyboardInfo(info); - info.SetKeyboardStatus(static_cast(MiscServices::KeyboardStatus::SHOW)); - listenerTest->SendKeyboardInfo(info); - info.SetKeyboardStatus(static_cast(MiscServices::KeyboardStatus::HIDE)); - info.SetFunctionKey(static_cast(MiscServices::FunctionKey::CONFIRM)); - listenerTest->SendKeyboardInfo(info); + listenerTest->SendKeyboardStatus(MiscServices::KeyboardStatus::SHOW); + listenerTest->SendFunctionKey(functionKey); + functionKey.SetEnterKeyType(MiscServices::EnterKeyType::UNSPECIFIED); + listenerTest->SendFunctionKey(functionKey); listenerTest->SetKeyboardStatus(true); listenerTest->MoveCursor(MiscServices::Direction::NONE); listenerTest->MoveCursor(MiscServices::Direction::UP); @@ -234,12 +238,13 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_InsertText_006, TestSize.Level1) EXPECT_NE(listenerTest, nullptr); std::u16string text; MiscServices::KeyEvent event; - MiscServices::KeyboardInfo info; + MiscServices::FunctionKey functionKey; listenerTest->InsertText(text); listenerTest->DeleteForward(0); listenerTest->DeleteBackward(0); listenerTest->SendKeyEventFromInputMethod(event); - listenerTest->SendKeyboardInfo(info); + listenerTest->SendKeyboardStatus(MiscServices::KeyboardStatus::SHOW); + listenerTest->SendFunctionKey(functionKey); listenerTest->SetKeyboardStatus(true); listenerTest->MoveCursor(MiscServices::Direction::NONE); listenerTest->HandleSetSelection(0, 0); -- Gitee