From 1739bbfded30f03fd6ac684c4bf16b7596c06d78 Mon Sep 17 00:00:00 2001 From: dupengfei Date: Fri, 15 Dec 2023 16:45:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E5=B1=82=E6=B8=B2=E6=9F=93=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dupengfei --- include/capi/cef_browser_capi.h | 6 +- include/cef_browser.h | 7 ++ include/cef_render_handler.h | 22 ++++- include/internal/cef_types.h | 88 +++++++++++++++++++ libcef/browser/browser_host_base.cc | 8 ++ libcef/browser/browser_host_base.h | 2 +- libcef/browser/browser_platform_delegate.h | 1 + libcef/browser/frame_host_impl.cc | 9 ++ libcef/browser/frame_host_impl.h | 1 + .../osr/browser_platform_delegate_osr.cc | 7 ++ .../osr/browser_platform_delegate_osr.h | 1 + .../osr/render_widget_host_view_osr.cc | 23 +++++ .../browser/osr/render_widget_host_view_osr.h | 2 + libcef/common/mojom/cef.mojom | 3 + libcef/renderer/frame_impl.cc | 5 ++ libcef/renderer/frame_impl.h | 1 + libcef_dll/ctocpp/browser_host_ctocpp.cc | 14 +++ libcef_dll/ctocpp/browser_host_ctocpp.h | 1 + 18 files changed, 198 insertions(+), 3 deletions(-) diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 995f15b1a..9b682255c 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -1406,7 +1406,11 @@ typedef struct _cef_browser_host_t { /// void(CEF_CALLBACK *set_overscroll_mode)(struct _cef_browser_host_t *self, int mode); - + /// + // Set the embed mode enable of web + /// + void(CEF_CALLBACK* set_embed_mode)(struct _cef_browser_host_t* self, + bool mode); /// // Set the draw rect /// diff --git a/include/cef_browser.h b/include/cef_browser.h index d556e33bf..d94afda9a 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -1506,6 +1506,13 @@ class CefBrowserHost : public virtual CefBaseRefCounted { /*--cef()--*/ virtual void SetOverscrollMode(int mode) = 0; +#ifdef BUILDFLAG(IS_OHOS) + /// + // Set the embed mode enable of web + /// + /*--cef()--*/ + virtual void SetNativeEmbedModeEnabled(bool mode) = 0; +#endif /// // Set the draw rect /// diff --git a/include/cef_render_handler.h b/include/cef_render_handler.h index 0ea8ebfb8..8858f8f88 100644 --- a/include/cef_render_handler.h +++ b/include/cef_render_handler.h @@ -58,7 +58,12 @@ class CefRenderHandler : public virtual CefBaseRefCounted { typedef std::vector RectList; typedef cef_text_input_mode_t TextInputMode; typedef cef_text_input_type_t TextInputType; - +#ifdef BUILDFLAG(IS_OHOS) + typedef cef_native_embed_data_t CefNativeEmbedData; + typedef cef_embed_touch_event_t CefEmbedTouchEvent; + typedef cef_embed_life_change_t CefEmbedLifeStatus; + typedef cef_embed_touch_type_t CefEmbedTouchType; +#endif /// // Return the handler for accessibility notifications. If no handler is // provided the default implementation will be used. @@ -349,6 +354,21 @@ class CefRenderHandler : public virtual CefBaseRefCounted { const float fling_y) { return false; } + +#ifdef BUILDFLAG(IS_OHOS) + /// + /// Called when embed touch. + /// + /*--cef()--*/ + virtual void OnNativeEmbedGestureEvent(CefRefPtr browser, + const CefEmbedTouchEvent& event) {} + /// + /// Called when embed touch. + /// + /*--cef()--*/ + virtual void OnNativeEmbedLifecycleChange(CefRefPtr browser, + const CefNativeEmbedData& info) {} +#endif }; #endif // CEF_INCLUDE_CEF_RENDER_HANDLER_H_ diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index d57d045ff..3f5c17bac 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -3642,6 +3642,94 @@ typedef enum { VIDEO, AUDIO, } cef_media_type_t; + +#if BUILDFLAG(IS_OHOS) + +/// +// embed life change. +/// +typedef enum { + CREATE = 0, + UPDATE = 1, + DESTROY = 2, +} cef_embed_life_change_t; + +/// +// Structure native embed data. +/// +typedef struct _cef_native_embed_t { + int32_t id; + int32_t width; + int32_t height; + std::string type; + std::string src; + std::string url; +} cef_native_embed_t; + +/// +// Structure native embed data. +/// +typedef struct _cef_native_embed_data_t { + cef_embed_life_change_t status; + std::string surfaceId; + std::string embedId; + cef_native_embed_t info; +} cef_native_embed_data_t; + + +/// +// Touch type. +/// +typedef enum{ + DOWN, + UP, + MOVE, + CANCEL, + PULL_DOWN, + PULL_UP, + PULL_MOVE, + PULL_IN_WINDOW, + PULL_OUT_WINDOW, + TOUCH_UNKNOWN, +}cef_embed_touch_type_t; + +/// +// Structure embed touch point data. +/// +typedef struct _cef_embed_touch_point_t{ + int32_t id = 0; + float x = 0.0f; + float y = 0.0f; + float screenX = 0.0f; + float screenY = 0.0f; + uint64_t downTime; + double size = 0.0; + float force = 0.0f; +}cef_embed_touch_point_t; + +/// +// Structure embed touch data. +/// +typedef struct _cef_embed_touch_event_t{ + std::string embedId; + int32_t id = 0; + float x = 0.0f; + float y = 0.0f; + float screenX = 0.0f; + float screenY = 0.0f; + cef_embed_touch_type_t type; + // nanosecond time stamp. + uint64_t time; + double size = 0.0; + float force = 0.0f; + + // all points on the touch screen. + std::vector<_cef_embed_touch_point_t> pointers; + // historical points + std::vector<_cef_embed_touch_event_t> history; +}cef_embed_touch_event_t; +#endif + #ifdef __cplusplus } #endif diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index 3e52b73c5..049a5fb85 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -2501,6 +2501,14 @@ int CefBrowserHostBase::GetCacheMode() { base::AutoLock lock_scope(state_lock_); return cache_mode_; } + +void CefBrowserHostBase::SetNativeEmbedModeEnabled(bool embedMode) { + auto frame = GetMainFrame(); + if (frame && frame->IsValid()) { + static_cast(frame.get()) + ->SetNativeEmbedModeEnabled(embedMode); + } +} #endif void CefBrowserHostBase::GetImageForContextNode() { diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index f2be928f0..cd88cf46d 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -275,7 +275,7 @@ class CefBrowserHostBase : public CefBrowserHost, int current, bool animate) override; void UpdateBrowserControlsHeight(int height, bool animate) override; - + void SetNativeEmbedModeEnabled(bool embedMode) override; /* ohos webview end */ #endif diff --git a/libcef/browser/browser_platform_delegate.h b/libcef/browser/browser_platform_delegate.h index dfcb220ea..0c606a5fa 100644 --- a/libcef/browser/browser_platform_delegate.h +++ b/libcef/browser/browser_platform_delegate.h @@ -404,6 +404,7 @@ class CefBrowserPlatformDelegate { virtual void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard){}; virtual bool ShouldVirtualKeyboardOverlay(){return false;}; virtual void CreateWebPrintDocumentAdapter(const CefString& jobName, void** webPrintDocumentAdapter) {}; + virtual void OnNativeEmbedLifecycleChange(const CefRenderHandler::CefNativeEmbedData& info) {}; #endif protected: // Allow deletion via std::unique_ptr only. diff --git a/libcef/browser/frame_host_impl.cc b/libcef/browser/frame_host_impl.cc index 8cdcee028..8de29cd91 100644 --- a/libcef/browser/frame_host_impl.cc +++ b/libcef/browser/frame_host_impl.cc @@ -961,6 +961,15 @@ void CefFrameHostImpl::SetOverscrollMode(int mode) { mode)); } +void CefFrameHostImpl::SetNativeEmbedModeEnabled(bool mode) { + SendToRenderFrame(__FUNCTION__, + base::BindOnce( + [](bool mode, const RenderFrameType& render_frame) { + render_frame->SetNativeEmbedModeEnabled(mode); + }, + mode)); +} + void CefFrameHostImpl::GetHitData(int& type, CefString& extra_data) { std::string temp_extra_data; diff --git a/libcef/browser/frame_host_impl.h b/libcef/browser/frame_host_impl.h index 128e346a1..53e6e921a 100644 --- a/libcef/browser/frame_host_impl.h +++ b/libcef/browser/frame_host_impl.h @@ -182,6 +182,7 @@ class CefFrameHostImpl : public CefFrame, public cef::mojom::BrowserFrame { void ZoomBy(float delta, float width, float height); void GetHitData(int& type, CefString& extra_data); void SetOverscrollMode(int mode); + void SetNativeEmbedModeEnabled(bool mode); #endif // BUILDFLAG(IS_OHOS) static const int64_t kMainFrameId; diff --git a/libcef/browser/osr/browser_platform_delegate_osr.cc b/libcef/browser/osr/browser_platform_delegate_osr.cc index f26ce7e35..39d6f0258 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.cc +++ b/libcef/browser/osr/browser_platform_delegate_osr.cc @@ -866,4 +866,11 @@ bool CefBrowserPlatformDelegateOsr::ShouldVirtualKeyboardOverlay() { return view->ShouldVirtualKeyboardOverlayContent(); return false; } + +void CefBrowserPlatformDelegateOsr::OnNativeEmbedLifecycleChange( + const CefRenderHandler::CefNativeEmbedData& info){ + CefRenderWidgetHostViewOSR* view = GetOSRHostView(); + if (view) + view->OnNativeEmbedLifecycleChange(info); +} #endif diff --git a/libcef/browser/osr/browser_platform_delegate_osr.h b/libcef/browser/osr/browser_platform_delegate_osr.h index 84b6fe3da..437d1b0e4 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.h +++ b/libcef/browser/osr/browser_platform_delegate_osr.h @@ -128,6 +128,7 @@ class CefBrowserPlatformDelegateOsr void WasKeyboardResized() override; void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard) override; bool ShouldVirtualKeyboardOverlay() override; + void OnNativeEmbedLifecycleChange(const CefRenderHandler::CefNativeEmbedData& info) override; #endif // CefBrowserPlatformDelegateNative::WindowlessHandler methods: CefWindowHandle GetParentWindowHandle() const override; diff --git a/libcef/browser/osr/render_widget_host_view_osr.cc b/libcef/browser/osr/render_widget_host_view_osr.cc index 96138c480..49afd05c0 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.cc +++ b/libcef/browser/osr/render_widget_host_view_osr.cc @@ -2673,4 +2673,27 @@ void CefRenderWidgetHostViewOSR::FilterScrollEventImpl( web_event.data.fling_start.velocity_y); } } + +void CefRenderWidgetHostViewOSR::DidNativeEmbedEvent(const blink::mojom::EmbedTouchEventPtr& touchEvent) { + if (browser_impl_.get()) { + CefRefPtr handler = + browser_impl_->client()->GetRenderHandler(); + CHECK(handler); + CefRenderHandler::CefEmbedTouchEvent event{touchEvent->embedId,touchEvent->id,touchEvent->x,touchEvent->y, + touchEvent->screenX,touchEvent->screenY, static_cast(touchEvent->type), + touchEvent->time,touchEvent->size,touchEvent->force}; + handler->OnNativeEmbedGestureEvent(browser_impl_.get(), event); + } +} + +void CefRenderWidgetHostViewOSR::OnNativeEmbedLifecycleChange(const CefRenderHandler::CefNativeEmbedData& info){ + if (browser_impl_.get()) { + CefRefPtr handler = + browser_impl_->client()->GetRenderHandler(); + CHECK(handler); + handler->OnNativeEmbedLifecycleChange(browser_impl_.get(), info); + + } +} + #endif \ No newline at end of file diff --git a/libcef/browser/osr/render_widget_host_view_osr.h b/libcef/browser/osr/render_widget_host_view_osr.h index 8b739f674..c412753ef 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.h +++ b/libcef/browser/osr/render_widget_host_view_osr.h @@ -274,6 +274,8 @@ class CefRenderWidgetHostViewOSR std::u16string GetSelectedText() override; std::u16string GetText(); void WasKeyboardResized(); + void DidNativeEmbedEvent(const blink::mojom::EmbedTouchEventPtr& touchEvent) override; + void OnNativeEmbedLifecycleChange(const CefRenderHandler::CefNativeEmbedData& info); #endif bool InstallTransparency(); diff --git a/libcef/common/mojom/cef.mojom b/libcef/common/mojom/cef.mojom index a5eb0367c..b2e3e0864 100644 --- a/libcef/common/mojom/cef.mojom +++ b/libcef/common/mojom/cef.mojom @@ -152,6 +152,9 @@ interface RenderFrame { [EnableIf=is_ohos] SetOverscrollMode(int32 mode); + + [EnableIf=is_ohos] + SetNativeEmbedModeEnabled(bool mode); }; // Interface for communicating with a frame in the browser process. diff --git a/libcef/renderer/frame_impl.cc b/libcef/renderer/frame_impl.cc index a3ee960ec..310963280 100644 --- a/libcef/renderer/frame_impl.cc +++ b/libcef/renderer/frame_impl.cc @@ -1133,6 +1133,11 @@ void CefFrameImpl::SetOverscrollMode(int mode) { DCHECK(render_frame->IsMainFrame()); render_frame->SetOverscrollMode(mode); } +void CefFrameImpl::SetNativeEmbedModeEnabled(bool mode) { + auto render_frame = content::RenderFrame::FromWebFrame(frame_); + DCHECK(render_frame->IsMainFrame()); + render_frame->SetNativeEmbedModeEnabled(mode); +} #endif // BUILDFLAG(IS_OHOS) // Enable deprecation warnings on Windows. See http://crbug.com/585142. diff --git a/libcef/renderer/frame_impl.h b/libcef/renderer/frame_impl.h index da841e827..aa37fd069 100644 --- a/libcef/renderer/frame_impl.h +++ b/libcef/renderer/frame_impl.h @@ -185,6 +185,7 @@ class CefFrameImpl : public CefFrame, public cef::mojom::RenderFrame { const GURL& absolute_image_url, bool is_editable, cef::mojom::HitDataParamsPtr& data); + void SetNativeEmbedModeEnabled(bool mode) override; bool is_update_ = false; CefHitData cef_hit_data_; int total_mem_ = -1; diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index 9acff2528..49ea1a6ed 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -2170,6 +2170,20 @@ void CefBrowserHostCToCpp::SetOverscrollMode(int mode) { _struct->set_overscroll_mode(_struct, mode); } +NO_SANITIZE("cfi-icall") +void CefBrowserHostCToCpp::SetNativeEmbedModeEnabled(bool mode) { + shutdown_checker::AssertNotShutdown(); + + cef_browser_host_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, set_embed_mode)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->set_embed_mode(_struct, mode); +} + NO_SANITIZE("cfi-icall") void CefBrowserHostCToCpp::SetDrawRect(int x, int y, int width, int height) { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.h b/libcef_dll/ctocpp/browser_host_ctocpp.h index 06ecd3aab..89951a89c 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.h +++ b/libcef_dll/ctocpp/browser_host_ctocpp.h @@ -203,6 +203,7 @@ public: double keyboard) override; bool ShouldVirtualKeyboardOverlay() override; void SetOverscrollMode(int mode) override; + void SetNativeEmbedModeEnabled(bool mode) override; void SetDrawRect(int x, int y, int width, int height) override; void SetDrawMode(int mode) override; void CreateWebPrintDocumentAdapter(const CefString &jobName, -- Gitee