alloy: views: mac: Add three-finger-swipe navigation gesture support
This adds support for the three-finger-swipe navigation gesture with Alloy/Views. The default implementation matches the Chrome runtime and navigates the browser back/forward. We also add an Alloy/Views- specific client callback in CefBrowserViewDelegate for optional custom handling of the gesture event.
This commit is contained in:
parent
8ff65ec09f
commit
f3083218af
|
@ -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
|
||||
|
|
|
@ -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 "1b74f24b87efbeddb08fb75d41827ccb19b84f77"
|
||||
#define CEF_API_HASH_UNIVERSAL "eb6257d3e4894dd51617d20588b7f0c3c8717301"
|
||||
#if defined(OS_WIN)
|
||||
#define CEF_API_HASH_PLATFORM "b36fe9fcbae0d8691bb9124f6ec18daf6abd7da5"
|
||||
#define CEF_API_HASH_PLATFORM "3c99a150153b982d4d8b1a19e33b66a1d93fec21"
|
||||
#elif defined(OS_MAC)
|
||||
#define CEF_API_HASH_PLATFORM "1af96f9fcc63d812b95d4be22f66f78e4a9b03a4"
|
||||
#define CEF_API_HASH_PLATFORM "b63aacf68a1fda1164948c24bab4f74abe046137"
|
||||
#elif defined(OS_LINUX)
|
||||
#define CEF_API_HASH_PLATFORM "5016f4b78232c528ba78c9ee656d85d4a6fe910a"
|
||||
#define CEF_API_HASH_PLATFORM "b12c839a3ea0dcb9705e543fc17fd3c1d9fa1e7c"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -3605,6 +3605,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
|
||||
|
|
|
@ -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<CefBrowserView> browser_view,
|
||||
cef_gesture_command_t gesture_command) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_VIEWS_CEF_BROWSER_VIEW_DELEGATE_H_
|
||||
|
|
|
@ -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<CefBrowserViewDelegate> delegate)
|
||||
: ParentClass(delegate), weak_ptr_factory_(this) {}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,8 +4,28 @@
|
|||
|
||||
#include "libcef/browser/views/browser_view_view.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "libcef/browser/views/browser_view_impl.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::optional<cef_gesture_command_t> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<CefBrowserView> 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<CefView> view) {
|
||||
|
|
|
@ -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<CefBrowserView> popup_browser_view,
|
||||
bool is_devtools) override;
|
||||
ChromeToolbarType GetChromeToolbarType() override;
|
||||
bool OnGestureCommand(CefRefPtr<CefBrowserView> browser_view,
|
||||
cef_gesture_command_t gesture_command) override;
|
||||
|
||||
// CefViewDelegate methods.
|
||||
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
|
||||
|
|
Loading…
Reference in New Issue