diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index e44c4a674a757b713e0b23ebb296f0d5bd387fd5..bb53d966d59133b37bf823ceac31f9b1c5773c3d 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -974,7 +974,11 @@ void NWebDelegate::NotifyScreenInfoChanged(RotationType rotation, // Created a richtext component display_ratio = richtextDisplayRatio; } else { - display_ratio = display->GetVirtualPixelRatio(); + if (display_ratio_ == 0.0) { + display_ratio = display->GetVirtualPixelRatio(); + } else { + display_ratio = display_ratio_; + } } if (display_ratio <= 0) { LOG(ERROR) << "Invalid display_ratio, display_ratio = " << display_ratio; @@ -4157,4 +4161,19 @@ void NWebDelegate::SetPopupSurface(void* popupSurface) { } handler_delegate_->SetPopupSurface(popupSurface); } + +void NWebDelegate::SetSurfaceDensity(const double& density) { + display_ratio_ = density; + SetVirtualPixelRatio(density); + if (display_manager_adapter_ == nullptr) { + LOG(ERROR) << "Get display_manager_adapter_ failed"; + return; + } + std::shared_ptr display = + display_manager_adapter_->GetDefaultDisplay(); + LOG(INFO) << "SetSurfaceDensity: " << density; + if (display != nullptr) { + NotifyScreenInfoChanged(display->GetRotation(), display->GetDisplayOrientation(), true); + } +} } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index fd2ac4e7e45f499a1bbf71887f8bae81cc585028..77f8a175e50edeeda2a3528b79dcaf290a8e4983 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -542,6 +542,7 @@ void NotifyForNextTouchEvent() override; #endif void SetPopupSurface(void* popupSurface) override; + void SetSurfaceDensity(const double& density) override; public: int argc_; @@ -682,6 +683,7 @@ void NotifyForNextTouchEvent() override; int pressing_num_ = 0; std::shared_ptr accessibility_event_listener_ = nullptr; + double display_ratio_ = 0.0; }; } // namespace OHOS::NWeb #endif diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 1496d52e6752f1dc995d46a065416febf181b28c..4b8f936de836d87fadc1d08e582f2d232365dbda 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -549,6 +549,7 @@ class NWebDelegateInterface #endif virtual void SetPopupSurface(void* popupSurface) = 0; + virtual void SetSurfaceDensity(const double& density) = 0; }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index cc5d2f4d83a6491323973df7029cb5ac19f309ff..99eb6db819277cee52525e968a2641e960554ba2 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -3560,3 +3560,17 @@ void NWebImpl::SetPopupSurface(void* popupSurface) { } nweb_delegate_->SetPopupSurface(popup_window); } + +void NWebImpl::SetSurfaceDensity(const double& density) { + device_pixel_ratio_ = density; + if (!inputmethod_handler_) { + WVLOG_E("inputmethod_handler_ is nullptr"); + return; + } + inputmethod_handler_->SetVirtualDeviceRatio(device_pixel_ratio_); + if(nweb_delegate_ == nullptr) { + WVLOG_E("SetVirtualDeviceRatio failed, nweb_delegate is nullptr."); + return; + } + nweb_delegate_->SetSurfaceDensity(density); +} \ No newline at end of file diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index ab4147d55c4f77c975c4ebdf997689d7bdafc489..4955a8331f395e60e2d593d63f81a6a4d050756c 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -562,6 +562,7 @@ class NWebImpl : public NWeb { #endif void SetPopupSurface(void* popupSurface) override; + void SetSurfaceDensity(const double& density) override; private: void ProcessInitArgs(std::shared_ptr init_args);