diff --git a/include/capi/views/cef_browser_view_delegate_capi.h b/include/capi/views/cef_browser_view_delegate_capi.h index 25fc074ff..2b4e20e4f 100644 --- a/include/capi/views/cef_browser_view_delegate_capi.h +++ b/include/capi/views/cef_browser_view_delegate_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=e38c41a553d518abcd1b912d32281e99b93c4fd7$ +// $hash=94e93810316b74e54eb315d97c6fc6f1cc0c9cc5$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_DELEGATE_CAPI_H_ @@ -120,6 +120,18 @@ typedef struct _cef_browser_view_delegate_t { /// cef_chrome_toolbar_type_t(CEF_CALLBACK* get_chrome_toolbar_type)( struct _cef_browser_view_delegate_t* self); + + /// + /// Called when |browser_view| receives a gesture command. Return true (1) to + /// handle (or disable) a |gesture_command| or false (0) to propagate the + /// gesture to the browser for default handling. This function will only be + /// called with the Alloy runtime. To handle these commands with the Chrome + /// runtime implement cef_command_handler_t::OnChromeCommand instead. + /// + int(CEF_CALLBACK* on_gesture_command)( + struct _cef_browser_view_delegate_t* self, + struct _cef_browser_view_t* browser_view, + cef_gesture_command_t gesture_command); } cef_browser_view_delegate_t; #ifdef __cplusplus diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 4ac85e3df..c47ece1e6 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "ffa07abf4b1f2e4bb228a0ec6b8959b6923236ba" +#define CEF_API_HASH_UNIVERSAL "61103000223ad380e5538c1c57862166d0882752" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "25327dfd50f3fd5aefd523622c42297ff5a02382" +#define CEF_API_HASH_PLATFORM "f6cd8cea55b2198ff51b8a1e47239050f23b5a9e" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "f021e371a8edb71ca9158cffa8c3ada1db2d9955" +#define CEF_API_HASH_PLATFORM "af3e1ed369344bc2d40b5d4da10e582309d14e06" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "f8a8b9758a53e7ba8b259151176b54edefea5471" +#define CEF_API_HASH_PLATFORM "58a17b28e55e61dee2f39a7a05a8cac49d37d031" #endif #ifdef __cplusplus diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 77a0c53c2..ca0900c85 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -3606,6 +3606,14 @@ typedef enum { CEF_DOWNLOAD_INTERRUPT_REASON_CRASH = 50, } cef_download_interrupt_reason_t; +/// +/// Specifies the gesture commands. +/// +typedef enum { + CEF_GESTURE_COMMAND_BACK, + CEF_GESTURE_COMMAND_FORWARD, +} cef_gesture_command_t; + #ifdef __cplusplus } #endif diff --git a/include/views/cef_browser_view_delegate.h b/include/views/cef_browser_view_delegate.h index 262c14521..ec2623a7f 100644 --- a/include/views/cef_browser_view_delegate.h +++ b/include/views/cef_browser_view_delegate.h @@ -114,6 +114,19 @@ class CefBrowserViewDelegate : public CefViewDelegate { /// /*--cef(default_retval=CEF_CTT_NONE)--*/ virtual ChromeToolbarType GetChromeToolbarType() { return CEF_CTT_NONE; } + + /// + /// Called when |browser_view| receives a gesture command. Return true to + /// handle (or disable) a |gesture_command| or false to propagate the gesture + /// to the browser for default handling. This method will only be called with + /// the Alloy runtime. To handle these commands with the Chrome runtime + /// implement CefCommandHandler::OnChromeCommand instead. + /// + /*--cef()--*/ + virtual bool OnGestureCommand(CefRefPtr browser_view, + cef_gesture_command_t gesture_command) { + return false; + } }; #endif // CEF_INCLUDE_VIEWS_CEF_BROWSER_VIEW_DELEGATE_H_ diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index 74ccef214..b0ab586c8 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -218,6 +218,23 @@ void CefBrowserViewImpl::OnBoundsChanged() { } } +void CefBrowserViewImpl::OnGestureCommand(cef_gesture_command_t command) { + if (delegate()->OnGestureCommand(this, command)) { + return; + } + + if (browser_) { + switch (command) { + case CEF_GESTURE_COMMAND_BACK: + browser_->GoBack(); + break; + case CEF_GESTURE_COMMAND_FORWARD: + browser_->GoForward(); + break; + } + } +} + CefBrowserViewImpl::CefBrowserViewImpl( CefRefPtr delegate) : ParentClass(delegate), weak_ptr_factory_(this) {} diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index 90033d581..5acb7e48a 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -74,6 +74,7 @@ class CefBrowserViewImpl // CefBrowserViewView::Delegate methods: void OnBrowserViewAdded() override; void OnBoundsChanged() override; + void OnGestureCommand(cef_gesture_command_t command) override; // Return the WebView representation of this object. views::WebView* web_view() const; diff --git a/libcef/browser/views/browser_view_view.cc b/libcef/browser/views/browser_view_view.cc index 70ee77201..548c2edff 100644 --- a/libcef/browser/views/browser_view_view.cc +++ b/libcef/browser/views/browser_view_view.cc @@ -4,8 +4,28 @@ #include "libcef/browser/views/browser_view_view.h" +#include + #include "libcef/browser/views/browser_view_impl.h" +namespace { + +std::optional GetGestureCommand( + ui::GestureEvent* event) { +#if defined(OS_MAC) + if (event->details().type() == ui::ET_GESTURE_SWIPE) { + if (event->details().swipe_left()) { + return cef_gesture_command_t::CEF_GESTURE_COMMAND_BACK; + } else if (event->details().swipe_right()) { + return cef_gesture_command_t::CEF_GESTURE_COMMAND_FORWARD; + } + } +#endif + return std::nullopt; +} + +} // namespace + CefBrowserViewView::CefBrowserViewView(CefBrowserViewDelegate* cef_delegate, Delegate* browser_view_delegate) : ParentClass(cef_delegate), browser_view_delegate_(browser_view_delegate) { @@ -38,3 +58,9 @@ void CefBrowserViewView::OnBoundsChanged(const gfx::Rect& previous_bounds) { ParentClass::OnBoundsChanged(previous_bounds); browser_view_delegate_->OnBoundsChanged(); } + +void CefBrowserViewView::OnGestureEvent(ui::GestureEvent* event) { + if (auto command = GetGestureCommand(event)) { + browser_view_delegate_->OnGestureCommand(*command); + } +} diff --git a/libcef/browser/views/browser_view_view.h b/libcef/browser/views/browser_view_view.h index bd47b9e0a..06e3e28bc 100644 --- a/libcef/browser/views/browser_view_view.h +++ b/libcef/browser/views/browser_view_view.h @@ -41,6 +41,9 @@ class CefBrowserViewView // Called when the BrowserView bounds have changed. virtual void OnBoundsChanged() = 0; + // Called when the BrowserView receives a gesture command. + virtual void OnGestureCommand(cef_gesture_command_t command) = 0; + protected: virtual ~Delegate() {} }; @@ -54,6 +57,7 @@ class CefBrowserViewView void ViewHierarchyChanged( const views::ViewHierarchyChangedDetails& details) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override; + void OnGestureEvent(ui::GestureEvent* event) override; private: // Not owned by this object. diff --git a/libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.cc b/libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.cc index 4d4aa9336..03df391ab 100644 --- a/libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.cc +++ b/libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=1b695e1b06a8ba626073b4a610d47c5a931a4735$ +// $hash=4bffd98075025b4d02063698dbec87e9b9a31597$ // #include "libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.h" @@ -184,6 +184,32 @@ browser_view_delegate_get_chrome_toolbar_type( return _retval; } +int CEF_CALLBACK browser_view_delegate_on_gesture_command( + struct _cef_browser_view_delegate_t* self, + cef_browser_view_t* browser_view, + cef_gesture_command_t gesture_command) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + // Verify param: browser_view; type: refptr_diff + DCHECK(browser_view); + if (!browser_view) { + return 0; + } + + // Execute + bool _retval = CefBrowserViewDelegateCppToC::Get(self)->OnGestureCommand( + CefBrowserViewCToCpp::Wrap(browser_view), gesture_command); + + // Return type: bool + return _retval; +} + cef_size_t CEF_CALLBACK browser_view_delegate_get_preferred_size(struct _cef_view_delegate_t* self, cef_view_t* view) { @@ -467,6 +493,7 @@ CefBrowserViewDelegateCppToC::CefBrowserViewDelegateCppToC() { browser_view_delegate_on_popup_browser_view_created; GetStruct()->get_chrome_toolbar_type = browser_view_delegate_get_chrome_toolbar_type; + GetStruct()->on_gesture_command = browser_view_delegate_on_gesture_command; GetStruct()->base.get_preferred_size = browser_view_delegate_get_preferred_size; GetStruct()->base.get_minimum_size = browser_view_delegate_get_minimum_size; diff --git a/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.cc b/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.cc index de4e70f2f..9d10dc134 100644 --- a/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.cc +++ b/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=2b3486a52f25be7c189ca58fa5af1e12dc73299f$ +// $hash=bff0bff161e504deec6aef910ebf5d8962bd7c85$ // #include "libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h" @@ -166,6 +166,33 @@ CefBrowserViewDelegateCToCpp::GetChromeToolbarType() { return _retval; } +NO_SANITIZE("cfi-icall") +bool CefBrowserViewDelegateCToCpp::OnGestureCommand( + CefRefPtr browser_view, + cef_gesture_command_t gesture_command) { + shutdown_checker::AssertNotShutdown(); + + cef_browser_view_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, on_gesture_command)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser_view; type: refptr_diff + DCHECK(browser_view.get()); + if (!browser_view.get()) { + return false; + } + + // Execute + int _retval = _struct->on_gesture_command( + _struct, CefBrowserViewCppToC::Wrap(browser_view), gesture_command); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") CefSize CefBrowserViewDelegateCToCpp::GetPreferredSize( CefRefPtr view) { diff --git a/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h b/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h index bc1abf588..b92183201 100644 --- a/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h +++ b/libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=ae219b09b69d7a49f48878a5d2f94b25c9b4150b$ +// $hash=15c0d7230887344fa77279c76ff377b3f2d9ee1d$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_BROWSER_VIEW_DELEGATE_CTOCPP_H_ @@ -52,6 +52,8 @@ class CefBrowserViewDelegateCToCpp CefRefPtr popup_browser_view, bool is_devtools) override; ChromeToolbarType GetChromeToolbarType() override; + bool OnGestureCommand(CefRefPtr browser_view, + cef_gesture_command_t gesture_command) override; // CefViewDelegate methods. CefSize GetPreferredSize(CefRefPtr view) override;