diff --git a/include/capi/views/cef_browser_view_delegate_capi.h b/include/capi/views/cef_browser_view_delegate_capi.h index 2b4e20e4f..105c21f99 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=94e93810316b74e54eb315d97c6fc6f1cc0c9cc5$ +// $hash=d49d6b19e52e8a0496c69ec5cbd00750f7ac4740$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_DELEGATE_CAPI_H_ @@ -124,9 +124,8 @@ typedef struct _cef_browser_view_delegate_t { /// /// 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. + /// gesture to the browser for default handling. With the Chrome runtime these + /// commands can also be handled via cef_command_handler_t::OnChromeCommand. /// int(CEF_CALLBACK* on_gesture_command)( struct _cef_browser_view_delegate_t* self, diff --git a/include/views/cef_browser_view_delegate.h b/include/views/cef_browser_view_delegate.h index ec2623a7f..fcfb01f83 100644 --- a/include/views/cef_browser_view_delegate.h +++ b/include/views/cef_browser_view_delegate.h @@ -118,9 +118,8 @@ class CefBrowserViewDelegate : public CefViewDelegate { /// /// 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. + /// to the browser for default handling. With the Chrome runtime these + /// commands can also be handled via CefCommandHandler::OnChromeCommand. /// /*--cef()--*/ virtual bool OnGestureCommand(CefRefPtr browser_view, diff --git a/libcef/browser/chrome/views/chrome_browser_view.cc b/libcef/browser/chrome/views/chrome_browser_view.cc index b7c94a648..41a549012 100644 --- a/libcef/browser/chrome/views/chrome_browser_view.cc +++ b/libcef/browser/chrome/views/chrome_browser_view.cc @@ -70,6 +70,13 @@ void ChromeBrowserView::OnBoundsChanged(const gfx::Rect& previous_bounds) { browser_view_delegate_->OnBoundsChanged(); } +void ChromeBrowserView::OnGestureEvent(ui::GestureEvent* event) { + if (browser_view_delegate_->OnGestureEvent(event)) { + return; + } + ParentClass::OnGestureEvent(event); +} + ToolbarView* ChromeBrowserView::OverrideCreateToolbar( Browser* browser, BrowserView* browser_view) { diff --git a/libcef/browser/chrome/views/chrome_browser_view.h b/libcef/browser/chrome/views/chrome_browser_view.h index 930774667..f0ebc174f 100644 --- a/libcef/browser/chrome/views/chrome_browser_view.h +++ b/libcef/browser/chrome/views/chrome_browser_view.h @@ -45,6 +45,7 @@ class ChromeBrowserView const views::ViewHierarchyChangedDetails& details) override; void AddedToWidget() override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override; + void OnGestureEvent(ui::GestureEvent* event) override; // BrowserView methods: ToolbarView* OverrideCreateToolbar(Browser* browser, diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index b0ab586c8..046f3b037 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -13,8 +13,27 @@ #include "libcef/browser/views/window_impl.h" #include "content/public/browser/native_web_keyboard_event.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/content_accelerators/accelerator_util.h" +namespace { + +absl::optional GetGestureCommand( + ui::GestureEvent* event) { +#if BUILDFLAG(IS_MAC) + if (event->details().type() == ui::ET_GESTURE_SWIPE) { + if (event->details().swipe_left()) { + return CEF_GESTURE_COMMAND_BACK; + } else if (event->details().swipe_right()) { + return CEF_GESTURE_COMMAND_FORWARD; + } + } +#endif + return absl::nullopt; +} + +} // namespace + // static CefRefPtr CefBrowserView::CreateBrowserView( CefRefPtr client, @@ -218,21 +237,27 @@ void CefBrowserViewImpl::OnBoundsChanged() { } } -void CefBrowserViewImpl::OnGestureCommand(cef_gesture_command_t command) { - if (delegate()->OnGestureCommand(this, command)) { - return; - } +bool CefBrowserViewImpl::OnGestureEvent(ui::GestureEvent* event) { + if (auto command = GetGestureCommand(event)) { + if (delegate() && delegate()->OnGestureCommand(this, *command)) { + return true; + } - if (browser_) { - switch (command) { - case CEF_GESTURE_COMMAND_BACK: - browser_->GoBack(); - break; - case CEF_GESTURE_COMMAND_FORWARD: - browser_->GoForward(); - break; + if (!cef::IsChromeRuntimeEnabled() && browser_) { + // Default handling for the Alloy runtime. + switch (*command) { + case CEF_GESTURE_COMMAND_BACK: + browser_->GoBack(); + break; + case CEF_GESTURE_COMMAND_FORWARD: + browser_->GoForward(); + break; + } + return true; } } + + return false; } CefBrowserViewImpl::CefBrowserViewImpl( diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index 5acb7e48a..b0d1338e4 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -74,7 +74,7 @@ class CefBrowserViewImpl // CefBrowserViewView::Delegate methods: void OnBrowserViewAdded() override; void OnBoundsChanged() override; - void OnGestureCommand(cef_gesture_command_t command) override; + bool OnGestureEvent(ui::GestureEvent* event) 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 548c2edff..2de10aee2 100644 --- a/libcef/browser/views/browser_view_view.cc +++ b/libcef/browser/views/browser_view_view.cc @@ -4,28 +4,8 @@ #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) { @@ -60,7 +40,8 @@ void CefBrowserViewView::OnBoundsChanged(const gfx::Rect& previous_bounds) { } void CefBrowserViewView::OnGestureEvent(ui::GestureEvent* event) { - if (auto command = GetGestureCommand(event)) { - browser_view_delegate_->OnGestureCommand(*command); + if (browser_view_delegate_->OnGestureEvent(event)) { + return; } + ParentClass::OnGestureEvent(event); } diff --git a/libcef/browser/views/browser_view_view.h b/libcef/browser/views/browser_view_view.h index 06e3e28bc..ba0a51ae5 100644 --- a/libcef/browser/views/browser_view_view.h +++ b/libcef/browser/views/browser_view_view.h @@ -41,8 +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; + // Called when the BrowserView receives a gesture event. + // Returns true if the gesture was handled. + virtual bool OnGestureEvent(ui::GestureEvent* event) = 0; protected: virtual ~Delegate() {}