diff --git a/media/audio/audio_thread_impl.cc b/media/audio/audio_thread_impl.cc index 414f3ddff405bc1f697cb7297cb516952a4c4f8c..75f3c05f7164904dd3cb69e9064158d532df6750 100644 --- a/media/audio/audio_thread_impl.cc +++ b/media/audio/audio_thread_impl.cc @@ -40,13 +40,6 @@ AudioThreadImpl::AudioThreadImpl() #endif worker_task_runner_ = thread_.task_runner(); -#if BUILDFLAG(IS_OHOS) - OHOS::NWeb::ResSchedClientAdapter::ReportKeyThread( - OHOS::NWeb::ResSchedStatusAdapter::THREAD_CREATED, - base::GetCurrentRealPid(), thread_.GetThreadRealId(), - OHOS::NWeb::ResSchedRoleAdapter::IMPORTANT_AUDIO); -#endif - #if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_ANDROID) // Since we run on the main thread on Mac, we don't need a hang monitor. // https://crbug.com/946968: The hang monitor possibly causes crashes on @@ -66,13 +59,6 @@ void AudioThreadImpl::Stop() { hang_monitor_.reset(); -#if BUILDFLAG(IS_OHOS) - OHOS::NWeb::ResSchedClientAdapter::ReportKeyThread( - OHOS::NWeb::ResSchedStatusAdapter::THREAD_DESTROYED, - base::GetCurrentRealPid(), thread_.GetThreadRealId(), - OHOS::NWeb::ResSchedRoleAdapter::IMPORTANT_AUDIO); -#endif - // Note that on MACOSX, we can still have tasks posted on the |task_runner_|, // since it is the main thread task runner and we do not stop the main thread. // But this is fine because none of those tasks will actually run. diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index c8f7448259361c79e1d0303847dc20cc8906df09..8f08729417abcfc88c9415d25428850bac7eebf8 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -425,7 +425,15 @@ InitRichtextIdentifier(); // Created a richtext component SetVirtualPixelRatio(richtextDisplayRatio); } else { +#if BUILDFLAG(IS_OHOS) + if (GetBaseDisplayWidth() > 0) { + SetVirtualPixelRatio(display->GetWidth() / GetBaseDisplayWidth()); + } else { + SetVirtualPixelRatio(display->GetVirtualPixelRatio()); + } +#else SetVirtualPixelRatio(display->GetVirtualPixelRatio()); +#endif } } @@ -754,7 +762,15 @@ void NWebDelegate::NotifyScreenInfoChanged(RotationType rotation, // Created a richtext component display_ratio = richtextDisplayRatio; } else { +#if BUILDFLAG(IS_OHOS) + if (GetBaseDisplayWidth() > 0) { + display_ratio = display->GetWidth() / GetBaseDisplayWidth(); + } else { + display_ratio = display->GetVirtualPixelRatio(); + } +#else display_ratio = display->GetVirtualPixelRatio(); +#endif } if (display_ratio <= 0) { LOG(ERROR) << "Invalid display_ratio, display_ratio = " << display_ratio; @@ -786,6 +802,12 @@ void NWebDelegate::SetVirtualPixelRatio(float ratio) { ui::GestureConfiguration::GetInstance()->set_virtual_pixel_ratio(default_virtual_pixel_ratio_); } +#if BUILDFLAG(IS_OHOS) +float NWebDelegate::GetBaseDisplayWidth() { + return base_display_width_; +} +#endif + std::shared_ptr NWebDelegate::GetPreference() const { return preference_delegate_; } @@ -1255,6 +1277,13 @@ void NWebDelegate::InitializeCef(std::string url, settings.persist_session_cookies = !is_pc_device; #if BUILDFLAG(IS_OHOS) + if (deviceType == OHOS::NWeb::ProductDeviceType::DEVICE_TYPE_2IN1) { + // To achieve a similar web page display effect on HarmonyOS PC devices as + // on Mac devices of the same size, it is necessary to make the web page + // width around approximately 1512 when in full screen. + base_display_width_ = 1512; + } + if (base::CommandLine::ForCurrentProcess()) { base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( ::switches::kOhosDeviceType, FromProductDeviceType(deviceType)); @@ -2451,7 +2480,7 @@ void NWebDelegate::RegisterAccessibilityIdGenerator( std::function accessibilityIdGenerator) const { content::BrowserAccessibilityManagerOHOS::RegisterAccessibilityIdGenerator( accessibilityIdGenerator); -}; +} void NWebDelegate::SetAccessibilityState(cef_state_t accessibilityState) { if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 52db99b1929d63d79fbec1cd96664e30eb960df6..57ca880468d0f415e8fe71d0eeb45d39a13cd582 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -341,6 +341,10 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { void SetVirtualPixelRatio(float ratio) override; #endif // defined(OHOS_SCREEN_ROTATION) +#if BUILDFLAG(IS_OHOS) + float GetBaseDisplayWidth() override; +#endif + #ifdef OHOS_POST_URL int PostUrl(const std::string& url, std::vector& postData) override; #endif // defined(OHOS_POST_URL) @@ -443,6 +447,10 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { uint32_t nweb_id_; #endif +#if BUILDFLAG(IS_OHOS) + float base_display_width_ = -1.f; +#endif + bool is_enhance_surface_ = false; #if defined(OHOS_INPUT_EVENTS) bool is_onPause_ = false; diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 692daa4113955ace7de9dfcccb7d26185826f4cf..429cf88ee9742274bae14bee8246f41e8a2b4e9b 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -334,6 +334,10 @@ class NWebDelegateInterface virtual void SetVirtualPixelRatio(float ratio) = 0; #endif // defined(OHOS_SCREEN_ROTATION) +#if BUILDFLAG(IS_OHOS) + virtual float GetBaseDisplayWidth() = 0; +#endif + #ifdef OHOS_EX_TOPCONTROLS virtual void UpdateBrowserControlsState(int constraints, int current, diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index 6b12069041b3a281025e7618379f473b46490861..ba3add0c988df2dae0daceec08d9b1473dc42f0d 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -432,7 +432,16 @@ bool NWebImpl::SetVirtualDeviceRatio() { // Created a richtext component device_pixel_ratio_ = richtextDisplayRatio; } else { +#if BUILDFLAG(IS_OHOS) + if (nweb_delegate_ && nweb_delegate_->GetBaseDisplayWidth() > 0) { + device_pixel_ratio_ = + display->GetWidth() / nweb_delegate_->GetBaseDisplayWidth(); + } else { + device_pixel_ratio_ = display->GetVirtualPixelRatio(); + } +#else device_pixel_ratio_ = display->GetVirtualPixelRatio(); +#endif } if (device_pixel_ratio_ <= 0) { WVLOG_E("invalid ratio."); @@ -464,12 +473,6 @@ bool NWebImpl::InitWebEngine(const NWebCreateInfo& create_info) { } } - if (!SetVirtualDeviceRatio()) { - WVLOG_E("fail to set virtual device ratio"); - delete[] argv; - return false; - } - is_enhance_surface_ = create_info.init_args.is_enhance_surface; void* window = nullptr; if (is_enhance_surface_) { @@ -517,6 +520,12 @@ bool NWebImpl::InitWebEngine(const NWebCreateInfo& create_info) { return false; } + if (!SetVirtualDeviceRatio()) { + WVLOG_E("fail to set virtual device ratio"); + delete[] argv; + return false; + } + std::weak_ptr output_handler_weak(output_handler_); auto render_update_cb = [output_handler_weak](const char* buffer) -> void { if (!output_handler_weak.expired()) {