From 1f421f6131be5e75d1afd8762979eed08e60da66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E9=91=AB?= Date: Mon, 21 Oct 2024 16:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9DPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 丁鑫 --- ohos_nweb/src/cef_delegate/nweb_delegate.cc | 21 ++++++++++++++++++++- ohos_nweb/src/cef_delegate/nweb_delegate.h | 2 ++ ohos_nweb/src/nweb_delegate_interface.h | 1 + ohos_nweb/src/nweb_impl.cc | 14 ++++++++++++++ ohos_nweb/src/nweb_impl.h | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index e44c4a674a..bb53d966d5 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 fd2ac4e7e4..77f8a175e5 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 1496d52e67..4b8f936de8 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 cc5d2f4d83..99eb6db819 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 ab4147d55c..4955a8331f 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); -- Gitee