From ee53a9623cd9f72b336202952e2da489656d6a0c Mon Sep 17 00:00:00 2001 From: tengfan66 Date: Thu, 26 Dec 2024 18:46:14 +0800 Subject: [PATCH] 857 Signed-off-by: tengfan66 --- include/capi/cef_browser_capi.h | 10 +++ include/cef_browser.h | 6 ++ libcef/browser/browser_host_base.cc | 8 ++ libcef/browser/browser_host_base.h | 1 + libcef/browser/browser_platform_delegate.cc | 9 +++ libcef/browser/browser_platform_delegate.h | 1 + .../osr/browser_platform_delegate_osr.cc | 11 +++ .../osr/browser_platform_delegate_osr.h | 1 + .../osr/render_widget_host_view_osr.cc | 78 +++++++++++++++++++ .../browser/osr/render_widget_host_view_osr.h | 4 + libcef_dll/cpptoc/browser_host_cpptoc.cc | 21 +++++ libcef_dll/ctocpp/browser_host_ctocpp.cc | 16 ++++ libcef_dll/ctocpp/browser_host_ctocpp.h | 1 + 13 files changed, 167 insertions(+) diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index a99b7841f..c6c5774b5 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -2145,6 +2145,16 @@ typedef struct _cef_browser_host_t { struct _cef_browser_host_t* self, const struct _cef_pdf_print_settings_t* settings, struct _cef_pdf_value_callback_t* callback); + + /// + /// Set zoom with the dela facetor + /// + void(CEF_CALLBACK* scale_gesture_change_v2)(struct _cef_browser_host_t* self, + int type, + float scale, + float originScale, + float width, + float height); } cef_browser_host_t; /// diff --git a/include/cef_browser.h b/include/cef_browser.h index 030db59cc..4ff749ce5 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -2173,5 +2173,11 @@ class CefBrowserHost : public virtual CefBaseRefCounted { /*--cef()--*/ virtual void CreateToPDF(const CefPdfPrintSettings& settings, CefRefPtr callback) = 0; + + /// + /// Set zoom with the dela facetor + /// + /*--cef()--*/ + virtual void ScaleGestureChangeV2(int type, float scale, float originScale, float width, float height) = 0; }; #endif // CEF_INCLUDE_CEF_BROWSER_H_ diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index fddf8c1e7..407a5f12e 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -4228,3 +4228,11 @@ std::string CefBrowserHostBase::GetCustomUserAgent() { return custom_user_agent_; } #endif + +void CefBrowserHostBase::ScaleGestureChangeV2(int type, float scale, float originScale, float centerX, float centerY) +{ + if (platform_delegate_) + { + platform_delegate_->ScaleGestureChangeV2(type, scale, originScale, centerX, centerY); + } +} diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index 21a6452d6..e62ff04a9 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -798,6 +798,7 @@ bool TerminateRenderProcess() override; #ifdef OHOS_USERAGENT std::string GetCustomUserAgent(); #endif + void ScaleGestureChangeV2(int type, float scale, float originScale, float centerX, float centerY) override; protected: bool EnsureDevToolsManager(); diff --git a/libcef/browser/browser_platform_delegate.cc b/libcef/browser/browser_platform_delegate.cc index b20aa1908..14941f070 100644 --- a/libcef/browser/browser_platform_delegate.cc +++ b/libcef/browser/browser_platform_delegate.cc @@ -589,3 +589,12 @@ int CefBrowserPlatformDelegate::TranslateWebEventModifiers( } return result; } + +void CefBrowserPlatformDelegate::ScaleGestureChangeV2(int type, + float scale, + float originScale, + float centerX, + float centerY) +{ + DCHECK(false); +} diff --git a/libcef/browser/browser_platform_delegate.h b/libcef/browser/browser_platform_delegate.h index ef278298f..3cde3c204 100644 --- a/libcef/browser/browser_platform_delegate.h +++ b/libcef/browser/browser_platform_delegate.h @@ -507,6 +507,7 @@ class CefBrowserPlatformDelegate { #if defined(OHOS_INPUT_EVENTS) virtual void ScrollFocusedEditableNodeIntoView(); #endif + virtual void ScaleGestureChangeV2(int type, float scale, float originScale, float centerX, float centerY); protected: // Allow deletion via std::unique_ptr only. diff --git a/libcef/browser/osr/browser_platform_delegate_osr.cc b/libcef/browser/osr/browser_platform_delegate_osr.cc index a409687b2..2345ad009 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.cc +++ b/libcef/browser/osr/browser_platform_delegate_osr.cc @@ -1252,3 +1252,14 @@ bool CefBrowserPlatformDelegateOsr::WebPageSnapshot( return false; } #endif + +void CefBrowserPlatformDelegateOsr::ScaleGestureChangeV2(int type, + float scale, + float originScale, + float centerX, + float centerY) +{ + if (CefRenderWidgetHostViewOSR *view = GetOSRHostView()) { + view->ScaleGestureChangeV2(type, scale, originScale, centerX, centerY); + } +} \ No newline at end of file diff --git a/libcef/browser/osr/browser_platform_delegate_osr.h b/libcef/browser/osr/browser_platform_delegate_osr.h index 2a36be4bf..f8ac0033f 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.h +++ b/libcef/browser/osr/browser_platform_delegate_osr.h @@ -197,6 +197,7 @@ bool WebPageSnapshot(const char* id, int height, cef_web_snapshot_callback_t callback) override; #endif + void ScaleGestureChangeV2(int type, float scale, float originScale, float centerX, float centerY) override; protected: // Platform-specific behaviors will be delegated to |native_delegate|. diff --git a/libcef/browser/osr/render_widget_host_view_osr.cc b/libcef/browser/osr/render_widget_host_view_osr.cc index 239db1d50..1e70a8222 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.cc +++ b/libcef/browser/osr/render_widget_host_view_osr.cc @@ -81,6 +81,7 @@ std::unordered_map #endif #if defined(OHOS_INPUT_EVENTS) +#include "content/public/common/input_event_ack_state.h" #include "ui/base/ime/text_input_flags.h" #include "ui/events/blink/did_overscroll_params.h" #endif // defined(OHOS_INPUT_EVENTS) @@ -97,6 +98,13 @@ const float kDefaultScaleFactor = 1.0; const int SOC_PERF_WEB_GESTURE_ID = 10012; const int TOUCH_DOWN_DELAY_TIME = 200; const int TOUCH_UP_DURATION_TIME = 100; + +constexpr int32_t PINCH_START_TYPE = 1; +constexpr int32_t PINCH_UPDATE_TYPE = 3; +constexpr int32_t PINCH_END_TYPE = 2; + +const int32_t DEFAULT_PINCH_FINGER = 2; + #endif display::mojom::ScreenOrientation ConvertOrientationType( cef_screen_orientation_type_t type) { @@ -2676,6 +2684,64 @@ void CefRenderWidgetHostViewOSR::OnGestureEvent( SendGestureEvent(gesture); } +void CefRenderWidgetHostViewOSR::ScaleGestureChangeV2(int type, + float scale, + float originScale, + float centerX, + float centerY) +{ + LOG(DEBUG) << "CefRenderWidgetHostViewOSR::ScaleGestureChangeV2 type: " << type + << " scale: " << scale << " originScale: " << originScale; + auto event_type = ui::ET_UNKNOWN; + switch (type) + { + case PINCH_START_TYPE: + event_type = ui::ET_GESTURE_PINCH_BEGIN; + break; + case PINCH_UPDATE_TYPE: + event_type = ui::ET_GESTURE_PINCH_UPDATE; + break; + case PINCH_END_TYPE: + event_type = ui::ET_GESTURE_PINCH_END; + break; + default: + LOG(ERROR) << "CefRenderWidgetHostViewOSR::ScaleGestureChangeV2 type invalid."; + return; + } + + ui::GestureEventDetails details(event_type); + details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHPAD); + details.set_scale(originScale); + SendGestureEvent(ui::GestureEventData(details, + 0, + ui::MotionEvent::ToolType::MOUSE, + base::TimeTicks::Now(), + centerX, + centerY, + centerX, + centerY, + DEFAULT_PINCH_FINGER, + gfx::RectF(), + 0, + 0U)); + + ui::GestureEventDetails details2(event_type); + details2.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN); + details2.set_scale(scale); + pending_touchpad_pinch_events_.push(ui::GestureEventData(details2, + 0, + ui::MotionEvent::ToolType::FINGER, + base::TimeTicks::Now(), + centerX, + centerY, + centerX, + centerY, + DEFAULT_PINCH_FINGER, + gfx::RectF(), + 0, + 0U)); +} + void CefRenderWidgetHostViewOSR::SendGestureEvent( const ui::GestureEventData& gesture) { #endif @@ -3131,6 +3197,18 @@ void CefRenderWidgetHostViewOSR::GestureEventAck( const blink::WebGestureEvent& event, blink::mojom::InputEventResultState ack_result, blink::mojom::ScrollResultDataPtr scroll_result_data) { + if (event.SourceDevice() == blink::WebGestureDevice::kTouchpad && + event.primary_pointer_type == ui::EventPointerType::kMouse) { + if (ack_result != blink::mojom::InputEventResultState::kConsumed) { + while (pending_touchpad_pinch_events_.size()) { + SendGestureEvent(pending_touchpad_pinch_events_.front()); + pending_touchpad_pinch_events_.pop(); + } + } else { + std::queue tmp; + pending_touchpad_pinch_events_.swap(tmp); + } + } StopFlingingIfNecessary(event, ack_result); } #endif diff --git a/libcef/browser/osr/render_widget_host_view_osr.h b/libcef/browser/osr/render_widget_host_view_osr.h index d24f8c4ea..923f37c1c 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.h +++ b/libcef/browser/osr/render_widget_host_view_osr.h @@ -51,6 +51,7 @@ #endif #if BUILDFLAG(IS_OHOS) +#include #include #include "third_party/ohos_ndk/includes/ohos_adapter/adapter_base.h" #endif @@ -318,6 +319,8 @@ class CefRenderWidgetHostViewOSR void SendGestureEvent(const ui::GestureEventData& gesture); + void ScaleGestureChangeV2(int type, float scale, float originScale, float centerX, float centerY); + void SendTouchGestureEvent(blink::WebTouchEvent& touch_event); void OnVsyncReceived(); @@ -704,6 +707,7 @@ class CefRenderWidgetHostViewOSR bool scroll_enabled_ = true; int32_t node_id_ = -1; bool is_tap_down_in_cursor_update_ = false; + std::queue pending_touchpad_pinch_events_; #endif // defined(OHOS_INPUT_EVENTS) #ifdef OHOS_EX_TOPCONTROLS diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.cc b/libcef_dll/cpptoc/browser_host_cpptoc.cc index eb4bc3709..381a76053 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_host_cpptoc.cc @@ -3947,6 +3947,26 @@ browser_host_create_to_pdf(struct _cef_browser_host_t* self, settingsObj, CefPdfValueCallbackCToCpp::Wrap(callback)); } +void CEF_CALLBACK +browser_host_scale_gesture_change_v2(struct _cef_browser_host_t* self, + int type, + float scale, + float originScale, + float width, + float height) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return; + } + + // Execute + CefBrowserHostCppToC::Get(self)->ScaleGestureChangeV2(type, scale, originScale, width, height); +} + } // namespace // CONSTRUCTOR - Do not edit by hand. @@ -4172,6 +4192,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() { GetStruct()->scroll_to_with_anime = browser_host_scroll_to_with_anime; GetStruct()->scroll_by_with_anime = browser_host_scroll_by_with_anime; GetStruct()->create_to_pdf = browser_host_create_to_pdf; + GetStruct()->scale_gesture_change_v2 = browser_host_scale_gesture_change_v2; } // DESTRUCTOR - Do not edit by hand. diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index 6ef92aa98..1eb79c0aa 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -3685,6 +3685,22 @@ void CefBrowserHostCToCpp::CreateToPDF( _struct->create_to_pdf(_struct, &settings, CefPdfValueCallbackCppToC::Wrap(callback)); } + +NO_SANITIZE("cfi-icall") +void CefBrowserHostCToCpp::ScaleGestureChangeV2(int type, float scale, float originScale, float width, float height) { + shutdown_checker::AssertNotShutdown(); + + cef_browser_host_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, scale_gesture_change_v2)) { + return; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->scale_gesture_change_v2(_struct, type, scale, originScale, width, height); +} + // CONSTRUCTOR - Do not edit by hand. CefBrowserHostCToCpp::CefBrowserHostCToCpp() {} diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.h b/libcef_dll/ctocpp/browser_host_ctocpp.h index 95b09d2d9..c11051a29 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.h +++ b/libcef_dll/ctocpp/browser_host_ctocpp.h @@ -327,6 +327,7 @@ class CefBrowserHostCToCpp : public CefCToCppRefCounted