From 66c09a78d1825e41fa995f2dae2f0b1ff1da5738 Mon Sep 17 00:00:00 2001 From: ia_oi Date: Mon, 21 Oct 2024 12:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=98=E5=8F=A0=E5=B1=8F=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ia_oi --- .../renderer_host/render_widget_host_impl.cc | 5 ++++ .../renderer_host/render_widget_host_impl.h | 2 ++ ohos_nweb/src/cef_delegate/nweb_delegate.cc | 23 +++++++++++++++++++ ohos_nweb/src/cef_delegate/nweb_delegate.h | 4 ++++ .../src/cef_delegate/nweb_display_listener.cc | 20 ++++++++++++++++ .../src/cef_delegate/nweb_display_listener.h | 12 ++++++++++ ohos_nweb/src/nweb_delegate_interface.h | 1 + 7 files changed, 67 insertions(+) diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index b840f13200..3047b0ee44 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -2512,6 +2512,11 @@ void RenderWidgetHostImpl::ClearDisplayedGraphics() { view_->ResetFallbackToFirstNavigationSurface(); } +void OnFoldStatusChanged(uint32_t foldstatus) { + if (view_) + view_->OnFoldStatusChanged(foldstatus); +} + void RenderWidgetHostImpl::OnKeyboardEventAck( const NativeWebKeyboardEventWithLatencyInfo& event, blink::mojom::InputEventResultSource ack_source, diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h index 0e42aef094..d7ea4e6219 100644 --- a/content/browser/renderer_host/render_widget_host_impl.h +++ b/content/browser/renderer_host/render_widget_host_impl.h @@ -896,6 +896,8 @@ class CONTENT_EXPORT RenderWidgetHostImpl // from a newly loaded page. Used for testing. virtual void NotifyNewContentRenderingTimeoutForTesting() {} + void OnFoldStatusChanged(uint32_t foldstatus); + // InputDispositionHandler void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event, blink::mojom::InputEventResultSource ack_source, diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 08bd5d267b..78e0b334b8 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -376,6 +376,20 @@ bool NWebDelegate::Init(bool is_enhance_surface, } else { SetVirtualPixelRatio(display->GetVirtualPixelRatio()); } + if(NWebHelper::Instance().CheckArkWebCoreApiLevel(12005)){ + if (display->IsFoldable()) { + fold_status_listener_ = + std::make_shared(shared_from_this()); + if (fold_status_listener_ == nullptr) { + LOG(ERROR) << "fold_status_listener_ is null"; + } + fold_status_listener_id = display_manager_adapter_->RegisterFoldStatusListener(fold_status_listener_); + if(fold_status_listener_id <= 0){ + LOG(ERROR) << "fold_status_listener_id register error"; + } + OnFoldStatusChanged(display->GetFoldStatus()); + } + } } return true; @@ -2081,6 +2095,15 @@ bool NWebDelegate::ShouldVirtualKeyboardOverlay() { return false; } +void NWebDelegate::OnFoldStatusChanged(FoldStatus foldstatus) { + if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { + LOG(ERROR) << "OnFoldStatusChanged can not get browser"; + return; + } + + GetBrowser()->GetHost()->OnFoldStatusChanged(static_cast(foldstatus)); +} + void NWebDelegate::SetAudioResumeInterval(int32_t resumeInterval) { if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { LOG(ERROR) << "SetAudioResumeInterval can not get browser"; diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 25e07a434b..10cd2ebd2d 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -229,6 +229,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { std::map additionalHttpHeaders) override; void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard) override; bool ShouldVirtualKeyboardOverlay() override; + void OnFoldStatusChanged(FoldStatus foldstatus) override; #if defined (OHOS_NWEB_EX) @@ -322,6 +323,9 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { nullptr; std::shared_ptr display_listener_ = nullptr; + std::shared_ptr fold_status_listener_ = + nullptr; + int32_t fold_status_listener_id = 0; // Members only accessed on the main thread. bool hidden_ = false; bool occluded_ = false; diff --git a/ohos_nweb/src/cef_delegate/nweb_display_listener.cc b/ohos_nweb/src/cef_delegate/nweb_display_listener.cc index 96223b7425..aebdd27cef 100755 --- a/ohos_nweb/src/cef_delegate/nweb_display_listener.cc +++ b/ohos_nweb/src/cef_delegate/nweb_display_listener.cc @@ -47,4 +47,24 @@ void DisplayScreenListener::OnChange(DisplayId id) { } } } + +FoldStatusScreenListener::FoldStatusScreenListener( + std::shared_ptr nweb) + : nweb_(std::weak_ptr(nweb)) { + foldstatus_manager_adapter_ = + OhosAdapterHelper::GetInstance().CreateDisplayMgrAdapter(); +} + +void FoldStatusScreenListener::OnFoldStatusChanged(FoldStatus foldstatus) { + if (foldstatus_manager_adapter_ == nullptr) { + LOG(ERROR) << "fold_status manager adapter is nullptr"; + return; + } + auto nweb = nweb_.lock(); + if (nweb != nullptr && display != nullptr) { + nweb->OnFoldStatusChanged(foldstatus); + } else { + LOG(ERROR) << "notify fold status change failed"; + } +} } \ No newline at end of file diff --git a/ohos_nweb/src/cef_delegate/nweb_display_listener.h b/ohos_nweb/src/cef_delegate/nweb_display_listener.h index 272c4d3b32..999c56a0d8 100755 --- a/ohos_nweb/src/cef_delegate/nweb_display_listener.h +++ b/ohos_nweb/src/cef_delegate/nweb_display_listener.h @@ -35,6 +35,18 @@ class DisplayScreenListener : public DisplayListenerAdapter { std::unique_ptr display_manager_adapter_; }; + +class FoldStatusScreenListener : public FoldStatusListenerAdapter { + public: + explicit FoldStatusScreenListener( + std::shared_ptr nweb); + ~FoldStatusScreenListener() = default; + void FoldStatusChanged(FoldStatus foldstatus) override; + private: + std::weak_ptr nweb_; + std::unique_ptr + foldstatus_manager_adapter_; +}; } #endif \ No newline at end of file diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index a772b32594..9098b724fa 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -181,6 +181,7 @@ class NWebDelegateInterface const std::vector>& args) const = 0; virtual void RegisterNWebJavaScriptCallBack( std::shared_ptr callback) = 0; + virtual void OnFoldStatusChanged(FoldStatus foldstatus) = 0; virtual bool OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) const = 0; virtual void OnBlur() const = 0; virtual void RegisterFindListener( -- Gitee