diff --git a/ohos_nweb/src/cef_delegate/nweb_inputmethod_client.h b/ohos_nweb/src/cef_delegate/nweb_inputmethod_client.h index d4ad3407cc2b1b21fa15324dda5278b40dced793..f4d3f1cf159c3d1106d244a2e071b6e231b597c1 100644 --- a/ohos_nweb/src/cef_delegate/nweb_inputmethod_client.h +++ b/ohos_nweb/src/cef_delegate/nweb_inputmethod_client.h @@ -40,6 +40,8 @@ class NWebInputMethodClient: public virtual CefBaseRefCounted { const CefString& text, const CefRange& selected_range) = 0; virtual void SetFocusStatus(bool focus_status) = 0; + virtual void OnEditableChanged(CefRefPtr browser, + bool is_editable_node) = 0; }; } diff --git a/ohos_nweb/src/cef_delegate/nweb_render_handler.cc b/ohos_nweb/src/cef_delegate/nweb_render_handler.cc index 14e543c1fd697545605719f2cf9f4d3e234b7ff3..15516e6fbcd3d042d2c3d01f92dd61158c221d48 100755 --- a/ohos_nweb/src/cef_delegate/nweb_render_handler.cc +++ b/ohos_nweb/src/cef_delegate/nweb_render_handler.cc @@ -108,7 +108,7 @@ void NWebRenderHandler::SetInputMethodClient( void NWebRenderHandler::SetNWebDelegateInterface( std::shared_ptr client) { - delegate_interface_ = client; + delegate_interface_ = std::weak_ptr(client); } void NWebRenderHandler::Resize(uint32_t width, uint32_t height) { @@ -232,6 +232,15 @@ void NWebRenderHandler::OnSelectionChanged(CefRefPtr browser, } } +void NWebRenderHandler::OnEditableChanged(CefRefPtr browser, + bool is_editable_node) { + if (!inputmethod_client_) { + LOG(ERROR) << "inputmethod_client_ is nullptr."; + return; + } + inputmethod_client_->OnEditableChanged(browser, is_editable_node); +} + void NWebRenderHandler::OnVirtualKeyboardRequested( CefRefPtr browser, TextInputMode input_mode, @@ -244,7 +253,8 @@ void NWebRenderHandler::OnVirtualKeyboardRequested( } if (input_mode != CEF_TEXT_INPUT_MODE_NONE) { - if (delegate_interface_->OnFocus()) { + auto delegete = delegate_interface_.lock(); + if (delegete && delegete->OnFocus()) { inputmethod_client_->Attach(browser, show_keyboard, input_mode); } } else { diff --git a/ohos_nweb/src/cef_delegate/nweb_render_handler.h b/ohos_nweb/src/cef_delegate/nweb_render_handler.h index d381a6e332fefd4641894e0a00e6e275f2db4368..84b632a734b8434fbfc9392b6037535f21aaf105 100755 --- a/ohos_nweb/src/cef_delegate/nweb_render_handler.h +++ b/ohos_nweb/src/cef_delegate/nweb_render_handler.h @@ -84,6 +84,9 @@ class NWebRenderHandler : public CefRenderHandler { const CefString& text, const CefRange& selected_range) override; + void OnEditableChanged(CefRefPtr browser, + bool is_editable_node) override; + void OnVirtualKeyboardRequested(CefRefPtr browser, TextInputMode input_mode, bool show_keyboard) override; @@ -139,7 +142,7 @@ class NWebRenderHandler : public CefRenderHandler { std::function render_update_cb_ = nullptr; CefRefPtr inputmethod_client_ = nullptr; - std::shared_ptr delegate_interface_ = nullptr; + std::weak_ptr delegate_interface_; uint32_t width_ = 0; uint32_t height_ = 0; int content_height_ = 0; diff --git a/ohos_nweb/src/nweb_inputmethod_handler.cc b/ohos_nweb/src/nweb_inputmethod_handler.cc index 64d9738ec270497042721ae7a09f8ede7cfa5720..7d0a2b293dd2791fefdca6f6d8822096c6e2df76 100644 --- a/ohos_nweb/src/nweb_inputmethod_handler.cc +++ b/ohos_nweb/src/nweb_inputmethod_handler.cc @@ -188,7 +188,7 @@ void NWebInputMethodHandler::Attach(CefRefPtr browser, bool NWebInputMethodHandler::Reattach(uint32_t nwebId, ReattachType type) { nweb_id_ = nwebId; - if (type == ReattachType::FROM_CONTINUE) { + if (type == ReattachType::FROM_CONTINUE || !is_editable_node_) { if (!isNeedReattachOncontinue_) { LOG(INFO) << "don't need reattach input method"; return false; @@ -196,7 +196,7 @@ bool NWebInputMethodHandler::Reattach(uint32_t nwebId, ReattachType type) { isNeedReattachOncontinue_ = false; } - if (type == ReattachType::FROM_ONFOCUS) { + if (type == ReattachType::FROM_ONFOCUS || !is_editable_node_) { if (!isNeedReattachOnfocus_) { LOG(INFO) << "ReAttchOnfocus, don't need reattach input method"; return false; @@ -612,6 +612,11 @@ void NWebInputMethodHandler::SetFocusStatus(bool focus_status) { focus_status_ = focus_status; } +void NWebInputMethodHandler::OnEditableChanged(CefRefPtr browser, + bool is_editable_node) { + is_editable_node_ = is_editable_node; +} + int32_t NWebInputMethodHandler::GetTextIndexAtCursor() { std::unique_lock lock(textCursorMutex_); bool istextCursorReady = textCursorCv_.wait_for( diff --git a/ohos_nweb/src/nweb_inputmethod_handler.h b/ohos_nweb/src/nweb_inputmethod_handler.h index 0649bb8af50d3948d82bbd49505942f7b3cb9eee..9a7e792e0e8aba52258b98b014f307f48d873dd0 100644 --- a/ohos_nweb/src/nweb_inputmethod_handler.h +++ b/ohos_nweb/src/nweb_inputmethod_handler.h @@ -45,6 +45,8 @@ class NWebInputMethodHandler : public NWebInputMethodClient { const CefString& text, const CefRange& selected_range) override; void SetFocusStatus(bool focus_status) override; + void OnEditableChanged(CefRefPtr browser, + bool is_editable_node) override; bool Reattach(uint32_t nwebId, ReattachType type); void SetIMEStatus(bool status); @@ -88,6 +90,7 @@ class NWebInputMethodHandler : public NWebInputMethodClient { std::shared_ptr inputmethod_listener_ = nullptr; bool isAttached_ = false; bool show_keyboard_ = false; + bool is_editable_node_ = false; bool isNeedReattachOncontinue_ = false; IMFAdapterTextInputType input_mode_ = IMFAdapterTextInputType::TEXT; std::chrono::high_resolution_clock::time_point lastCloseInputMethodTime_;