diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 52f88b64c7e149100525ba28da2996bdf53ea74b..c4cbbc4090f202a135f8ce686ce30e52ff14f520 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -27,6 +27,7 @@ #include "base/ohos/sys_info_utils.h" #include "base/strings/utf_string_conversions.h" #include "base/task/thread_pool.h" +#include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "base/files/file_util.h" #include "cef/include/base/cef_logging.h" @@ -64,6 +65,7 @@ #include "ui/events/gesture_detection/gesture_configuration.h" #include "libcef/common/net/url_util.h" #include "net/base/filename_util.h" +#include "third_party/ohos_ndk/includes/ohos_adapter/soc_perf_client_adapter.h" #if OHOS_URL_TRUST_LIST #include "cef/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_interface.h" @@ -93,6 +95,9 @@ namespace { static const float richtextDisplayRatio = 1.0; +static bool isDoingFocus = false; +static std::unordered_set focus_windows_set; +const int enableDelayTime = 1000; } namespace OHOS::NWeb { @@ -2407,6 +2412,22 @@ void NWebDelegate::RegisterNWebJavaScriptCallBack( handler_delegate_->RegisterNWebJavaScriptCallBack(callback); } +void NWebDelegate::EnableBoost() const { + if(!focus_windows_set.empty()) { + OHOS::NWeb::OhosAdapterHelper::GetInstance().CreateSocPerfClientAdapter() + ->ApplySocPerfConfigByIdEx(OHOS::NWeb::SocPerfClientAdapter::SOC_PERF_SLIDE_NORMAL_ID, true); + isDoingFocus = true; + CEF_POST_DELAYED_TASK(CEF_UIT, + base::BindOnce(&NWebDelegate::EnableBoost, this), enableDelayTime); + } + else { + OHOS::NWeb::OhosAdapterHelper::GetInstance().CreateSocPerfClientAdapter() + ->ApplySocPerfConfigByIdEx(OHOS::NWeb::SocPerfClientAdapter::SOC_PERF_SLIDE_NORMAL_ID, false); + isDoingFocus = false; + return; + } +} + bool NWebDelegate::OnFocus(const FocusReason& focusReason) const { LOG(DEBUG) << "NWebDelegate::OnFocus, nweb_id = " << nweb_id_; if (!GetBrowser().get()) { @@ -2420,7 +2441,12 @@ bool NWebDelegate::OnFocus(const FocusReason& focusReason) const { GetBrowser()->GetHost()->SetFocus(true); } #endif // #ifdef OHOS_FOCUS - + if (base::ohos::IsPcDevice()) { + focus_windows_set.emplace(nweb_id_); + if (!isDoingFocus) { + CEF_POST_TASK(CEF_UIT, base::BindOnce(&NWebDelegate::EnableBoost, this)); + } + } return true; } @@ -2442,6 +2468,9 @@ void NWebDelegate::OnBlur() const { } #endif // defined(OHOS_INPUT_EVENTS) } + if (!isDoingFocus) { + focus_windows_set.erase(nweb_id_); + } #endif // #ifdef OHOS_FOCUS } diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 8e8cf8f7126c5e15953099b1f222c556ab354702..47291514ecc9c3bdd9f542542db11e26c0cb827b 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "capi/nweb_app_client_extension_callback.h" #include "cef/include/cef_command_line.h" #include "content/browser/accessibility/browser_accessibility_manager_ohos.h" @@ -219,6 +220,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { void RegisterNWebJavaScriptCallBack( std::shared_ptr callback) override; + void EnableBoost() const; bool OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) const override; void OnBlur() const override;