From e3b11976ebb6f3fb3a2dd01006b8ff6252d29b46 Mon Sep 17 00:00:00 2001 From: lizening0723 Date: Wed, 13 Nov 2024 10:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=AE=E7=9B=98=E6=94=B6?= =?UTF-8?q?=E8=B5=B7=E6=97=B6=E5=A4=B1=E7=84=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizening0723 --- ohos_nweb/src/cef_delegate/nweb_delegate.cc | 8 ++++++++ ohos_nweb/src/cef_delegate/nweb_delegate.h | 1 + .../cef_delegate/nweb_preference_delegate.cc | 10 ++++++++++ .../src/cef_delegate/nweb_preference_delegate.h | 3 +++ ohos_nweb/src/nweb_delegate_interface.h | 1 + ohos_nweb/src/nweb_impl.cc | 10 ++++++++++ ohos_nweb/src/nweb_impl.h | 1 + ohos_nweb/src/nweb_inputmethod_handler.cc | 17 +++++++++++++++++ ohos_nweb/src/nweb_inputmethod_handler.h | 2 ++ 9 files changed, 53 insertions(+) diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index e5af54b351..6903ca0f7d 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -1603,6 +1603,14 @@ void NWebDelegate::OnContinue() { is_onPause_ = false; } +void NWebDelegate::WebComponentsBlur() { + LOG(INFO) << "NWebDelegate::WebComponentsBlur, nweb_id = " << nweb_id_; + if (!GetBrowser().get()) { + return; + } + GetBrowser()->GetHost()->SetFocusOnWeb(); +} + void NWebDelegate::OnOccluded() { LOG(INFO) << "NWebDelegate::OnOccluded, nweb_id = " << nweb_id_; TRACE_EVENT1("base", "NWebDelegate::OnOccluded", "nweb id = ", nweb_id_); diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index fd2ac4e7e4..56c80f9c5e 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -145,6 +145,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { void InitialScale(float scale) const override; void OnPause() override; void OnContinue() override; + void WebComponentsBlur() override; void OnOccluded() override; void OnUnoccluded() override; void SetEnableLowerFrameRate(bool enabled) override; diff --git a/ohos_nweb/src/cef_delegate/nweb_preference_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_preference_delegate.cc index ea1403c6fe..4de7202c31 100644 --- a/ohos_nweb/src/cef_delegate/nweb_preference_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_preference_delegate.cc @@ -166,6 +166,7 @@ void NWebPreferenceDelegate::ComputeBrowserSettings( browser_settings.hide_vertical_scrollbars = !IsVerticalScrollBarAccess() ? STATE_ENABLED : STATE_DISABLED; browser_settings.scroll_enabled = GetScrollable(); + browser_settings.blur_enabled = GetBlurEnable(); #endif // defined(OHOS_INPUT_EVENTS) #if BUILDFLAG(IS_OHOS) browser_settings.native_embed_mode_enabled = @@ -699,6 +700,15 @@ void NWebPreferenceDelegate::SetScrollable(bool enable) { browser_->GetHost()->SetScrollable(enable, static_cast(WebScrollType::UNKNOWN)); } +void NWebPreferenceDelegate::SetBlurOnKeyboardHideMode(int enable) { + blur_enabled_ = enable; + WebPreferencesChanged(); +} + +int NWebPreferenceDelegate::GetBlurEnable() { + return blur_enabled_; +} + void NWebPreferenceDelegate::SetScrollable(bool enable, int32_t scrollType) { scroll_enabled_ = enable; if (scrollType == static_cast(WebScrollType::UNKNOWN) || diff --git a/ohos_nweb/src/cef_delegate/nweb_preference_delegate.h b/ohos_nweb/src/cef_delegate/nweb_preference_delegate.h index 1a703ea9ad..bd72b896c2 100644 --- a/ohos_nweb/src/cef_delegate/nweb_preference_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_preference_delegate.h @@ -157,6 +157,8 @@ class NWebPreferenceDelegate : public NWebPreference { void SetScrollable(bool enable) override; void SetScrollable(bool enable, int32_t scrollType) override; bool GetScrollable() override; + void SetBlurOnKeyboardHideMode(int enable) override; + int GetBlurEnable(); #endif // defined(OHOS_INPUT_EVENTS) void SetNativeEmbedMode(bool flag) override; bool GetNativeEmbedMode() override; @@ -278,6 +280,7 @@ class NWebPreferenceDelegate : public NWebPreference { bool vertical_scrollBar_access_{true}; int overscroll_mode_{0}; bool scroll_enabled_{true}; + int blur_enabled_; #endif // defined(OHOS_INPUT_EVENTS) #if defined(OHOS_VIEWPORT) std::optional viewport_enabled_; diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 1496d52e67..2fd6d2c817 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -192,6 +192,7 @@ class NWebDelegateInterface virtual void InitialScale(float scale) const = 0; virtual void OnPause() = 0; virtual void OnContinue() = 0; + virtual void WebComponentsBlur() = 0; virtual void OnOccluded() = 0; virtual void OnUnoccluded() = 0; virtual void SetEnableLowerFrameRate(bool enabled) = 0; diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index f90d089708..92e501453c 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -1315,6 +1315,16 @@ void NWebImpl::OnContinue() { } } +void NWebImpl::WebComponentsBlur() { + if (nweb_delegate_ == nullptr) { + LOG(ERROR) << "nweb_delegate_ is nullptr."; + return; + } + + LOG(INFO) << "NWebImpl::WebComponentsBlur, Gesture back blur on."; + nweb_delegate_->WebComponentsBlur(); +} + void NWebImpl::OnOccluded() { if (!GetWebOptimizationValue()) { LOG(DEBUG) << "WebOptimization disabled."; diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index eaf2a37091..bbac878d9d 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -86,6 +86,7 @@ class NWebImpl : public NWeb { void InitialScale(float scale) override; void OnPause() override; void OnContinue() override; + void WebComponentsBlur() override; void OnOccluded() override; void OnUnoccluded() override; void SetEnableLowerFrameRate(bool enabled) override; diff --git a/ohos_nweb/src/nweb_inputmethod_handler.cc b/ohos_nweb/src/nweb_inputmethod_handler.cc index 497f7cdc7c..ea73263bde 100644 --- a/ohos_nweb/src/nweb_inputmethod_handler.cc +++ b/ohos_nweb/src/nweb_inputmethod_handler.cc @@ -87,6 +87,10 @@ class OnTextChangedListenerImpl : public IMFTextListenerAdapter { handler_->SetIMEStatus(status); } + void KeyboardUpperRightCornerHide() override { + handler_->WebBlurKeyboardHide(); + } + void MoveCursor(const IMFAdapterDirection direction) override { if (direction == IMFAdapterDirection::NONE) { LOG(ERROR) << "NWebInputMethodHandler::MoveCursor got none direction"; @@ -630,6 +634,14 @@ void NWebInputMethodHandler::SetIMEStatus(bool status) { } } +void NWebInputMethodHandler::WebBlurKeyboardHide() { + if (browser_ != nullptr && browser_->GetHost() != nullptr) { + CefRefPtr task = new InputMethodTask(base::BindOnce( + &NWebInputMethodHandler::WebBlurKeyboardHideOnUI, this)); + browser_->GetHost()->PostTaskToUIThread(task); + } +} + void NWebInputMethodHandler::InsertText(const std::u16string& text) { if (text.empty()) { LOG(ERROR) << "insert text empty!"; @@ -670,6 +682,11 @@ void NWebInputMethodHandler::SetIMEStatusOnUI(bool status) { isAttached_ = status; } +void NWebInputMethodHandler::WebBlurKeyboardHideOnUI() { + LOG(INFO) << "NWebInputMethodHandler::WebBlurKeyboardHideOnUI" ; + browser_->GetHost()->SetFocusOnWeb(); +} + void NWebInputMethodHandler::InsertTextHandlerOnUI(const std::u16string& text) { if (text.empty()) { LOG(ERROR) << "insert text empty!"; diff --git a/ohos_nweb/src/nweb_inputmethod_handler.h b/ohos_nweb/src/nweb_inputmethod_handler.h index 6f5d29be3e..ce29565788 100644 --- a/ohos_nweb/src/nweb_inputmethod_handler.h +++ b/ohos_nweb/src/nweb_inputmethod_handler.h @@ -66,6 +66,7 @@ class NWebInputMethodHandler : public NWebInputMethodClient { bool Reattach(uint32_t nwebId, ReattachType type); void SetIMEStatus(bool status); + void WebBlurKeyboardHide(); void InsertText(const std::u16string& text); void DeleteBackward(int32_t length); void DeleteForward(int32_t length); @@ -116,6 +117,7 @@ class NWebInputMethodHandler : public NWebInputMethodClient { private: void SetIMEStatusOnUI(bool status); + void WebBlurKeyboardHideOnUI(); void InsertTextHandlerOnUI(const std::u16string& text); void DeleteBackwardHandlerOnUI(int32_t length); void DeleteForwardHandlerOnUI(int32_t length); -- Gitee