diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index b840f13200dfc5b283c25edc404720c61bc0cc85..3047b0ee44aa7b393cd7aa6bd943574a9647b5e9 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 0e42aef0941c9b71a0b2239ca396f4d6ca25a03b..d7ea4e621945fc679371ab035aebcfa4b4dc2431 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 08bd5d267bb85ae4df18643810d9c627cb706c5a..78e0b334b894193021d88580c53aa2f07e9cf6e2 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 25e07a434b8744970bfe3cb135b4f5ece0a2144b..10cd2ebd2d7b2c67c7cbefccc59c564bb65a856e 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 96223b7425bbeb3ab66115423eabb18108e8c1c6..aebdd27cefab4f0eef0e95618438317e01733b6e 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 272c4d3b32f045468d17cf9c04cdfb38faefadd6..999c56a0d8652c87000cfd2be2ffa06734e938ea 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 a772b325946b51c487ef2681bada8c8538a08db4..9098b724fa7682038abdcc50c06b45a237c5bc10 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(