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
29b5999fd7
commit
eb63f9e7ae
|
@ -33,7 +33,7 @@
|
||||||
// by hand. See the translator.README.txt file in the tools directory for
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
// more information.
|
// more information.
|
||||||
//
|
//
|
||||||
// $hash=e38c41a553d518abcd1b912d32281e99b93c4fd7$
|
// $hash=94e93810316b74e54eb315d97c6fc6f1cc0c9cc5$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_DELEGATE_CAPI_H_
|
#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)(
|
cef_chrome_toolbar_type_t(CEF_CALLBACK* get_chrome_toolbar_type)(
|
||||||
struct _cef_browser_view_delegate_t* self);
|
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;
|
} cef_browser_view_delegate_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -42,13 +42,13 @@
|
||||||
// way that may cause binary incompatibility with other builds. The universal
|
// way that may cause binary incompatibility with other builds. The universal
|
||||||
// hash value will change if any platform is affected whereas the platform hash
|
// hash value will change if any platform is affected whereas the platform hash
|
||||||
// values will change only if that particular platform is affected.
|
// 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)
|
#if defined(OS_WIN)
|
||||||
#define CEF_API_HASH_PLATFORM "25327dfd50f3fd5aefd523622c42297ff5a02382"
|
#define CEF_API_HASH_PLATFORM "f6cd8cea55b2198ff51b8a1e47239050f23b5a9e"
|
||||||
#elif defined(OS_MAC)
|
#elif defined(OS_MAC)
|
||||||
#define CEF_API_HASH_PLATFORM "f021e371a8edb71ca9158cffa8c3ada1db2d9955"
|
#define CEF_API_HASH_PLATFORM "af3e1ed369344bc2d40b5d4da10e582309d14e06"
|
||||||
#elif defined(OS_LINUX)
|
#elif defined(OS_LINUX)
|
||||||
#define CEF_API_HASH_PLATFORM "f8a8b9758a53e7ba8b259151176b54edefea5471"
|
#define CEF_API_HASH_PLATFORM "58a17b28e55e61dee2f39a7a05a8cac49d37d031"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -3606,6 +3606,14 @@ typedef enum {
|
||||||
CEF_DOWNLOAD_INTERRUPT_REASON_CRASH = 50,
|
CEF_DOWNLOAD_INTERRUPT_REASON_CRASH = 50,
|
||||||
} cef_download_interrupt_reason_t;
|
} 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,6 +114,19 @@ class CefBrowserViewDelegate : public CefViewDelegate {
|
||||||
///
|
///
|
||||||
/*--cef(default_retval=CEF_CTT_NONE)--*/
|
/*--cef(default_retval=CEF_CTT_NONE)--*/
|
||||||
virtual ChromeToolbarType GetChromeToolbarType() { return 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_
|
#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(
|
CefBrowserViewImpl::CefBrowserViewImpl(
|
||||||
CefRefPtr<CefBrowserViewDelegate> delegate)
|
CefRefPtr<CefBrowserViewDelegate> delegate)
|
||||||
: ParentClass(delegate), weak_ptr_factory_(this) {}
|
: ParentClass(delegate), weak_ptr_factory_(this) {}
|
||||||
|
|
|
@ -74,6 +74,7 @@ class CefBrowserViewImpl
|
||||||
// CefBrowserViewView::Delegate methods:
|
// CefBrowserViewView::Delegate methods:
|
||||||
void OnBrowserViewAdded() override;
|
void OnBrowserViewAdded() override;
|
||||||
void OnBoundsChanged() override;
|
void OnBoundsChanged() override;
|
||||||
|
void OnGestureCommand(cef_gesture_command_t command) override;
|
||||||
|
|
||||||
// Return the WebView representation of this object.
|
// Return the WebView representation of this object.
|
||||||
views::WebView* web_view() const;
|
views::WebView* web_view() const;
|
||||||
|
|
|
@ -4,8 +4,28 @@
|
||||||
|
|
||||||
#include "libcef/browser/views/browser_view_view.h"
|
#include "libcef/browser/views/browser_view_view.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "libcef/browser/views/browser_view_impl.h"
|
#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,
|
CefBrowserViewView::CefBrowserViewView(CefBrowserViewDelegate* cef_delegate,
|
||||||
Delegate* browser_view_delegate)
|
Delegate* browser_view_delegate)
|
||||||
: ParentClass(cef_delegate), browser_view_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);
|
ParentClass::OnBoundsChanged(previous_bounds);
|
||||||
browser_view_delegate_->OnBoundsChanged();
|
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.
|
// Called when the BrowserView bounds have changed.
|
||||||
virtual void OnBoundsChanged() = 0;
|
virtual void OnBoundsChanged() = 0;
|
||||||
|
|
||||||
|
// Called when the BrowserView receives a gesture command.
|
||||||
|
virtual void OnGestureCommand(cef_gesture_command_t command) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~Delegate() {}
|
virtual ~Delegate() {}
|
||||||
};
|
};
|
||||||
|
@ -54,6 +57,7 @@ class CefBrowserViewView
|
||||||
void ViewHierarchyChanged(
|
void ViewHierarchyChanged(
|
||||||
const views::ViewHierarchyChangedDetails& details) override;
|
const views::ViewHierarchyChangedDetails& details) override;
|
||||||
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
|
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
|
||||||
|
void OnGestureEvent(ui::GestureEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Not owned by this object.
|
// Not owned by this object.
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=1b695e1b06a8ba626073b4a610d47c5a931a4735$
|
// $hash=4bffd98075025b4d02063698dbec87e9b9a31597$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.h"
|
#include "libcef_dll/cpptoc/views/browser_view_delegate_cpptoc.h"
|
||||||
|
@ -184,6 +184,32 @@ browser_view_delegate_get_chrome_toolbar_type(
|
||||||
return _retval;
|
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
|
cef_size_t CEF_CALLBACK
|
||||||
browser_view_delegate_get_preferred_size(struct _cef_view_delegate_t* self,
|
browser_view_delegate_get_preferred_size(struct _cef_view_delegate_t* self,
|
||||||
cef_view_t* view) {
|
cef_view_t* view) {
|
||||||
|
@ -467,6 +493,7 @@ CefBrowserViewDelegateCppToC::CefBrowserViewDelegateCppToC() {
|
||||||
browser_view_delegate_on_popup_browser_view_created;
|
browser_view_delegate_on_popup_browser_view_created;
|
||||||
GetStruct()->get_chrome_toolbar_type =
|
GetStruct()->get_chrome_toolbar_type =
|
||||||
browser_view_delegate_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 =
|
GetStruct()->base.get_preferred_size =
|
||||||
browser_view_delegate_get_preferred_size;
|
browser_view_delegate_get_preferred_size;
|
||||||
GetStruct()->base.get_minimum_size = browser_view_delegate_get_minimum_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
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=2b3486a52f25be7c189ca58fa5af1e12dc73299f$
|
// $hash=bff0bff161e504deec6aef910ebf5d8962bd7c85$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h"
|
#include "libcef_dll/ctocpp/views/browser_view_delegate_ctocpp.h"
|
||||||
|
@ -166,6 +166,33 @@ CefBrowserViewDelegateCToCpp::GetChromeToolbarType() {
|
||||||
return _retval;
|
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")
|
NO_SANITIZE("cfi-icall")
|
||||||
CefSize CefBrowserViewDelegateCToCpp::GetPreferredSize(
|
CefSize CefBrowserViewDelegateCToCpp::GetPreferredSize(
|
||||||
CefRefPtr<CefView> view) {
|
CefRefPtr<CefView> view) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=ae219b09b69d7a49f48878a5d2f94b25c9b4150b$
|
// $hash=15c0d7230887344fa77279c76ff377b3f2d9ee1d$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_BROWSER_VIEW_DELEGATE_CTOCPP_H_
|
#ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_BROWSER_VIEW_DELEGATE_CTOCPP_H_
|
||||||
|
@ -52,6 +52,8 @@ class CefBrowserViewDelegateCToCpp
|
||||||
CefRefPtr<CefBrowserView> popup_browser_view,
|
CefRefPtr<CefBrowserView> popup_browser_view,
|
||||||
bool is_devtools) override;
|
bool is_devtools) override;
|
||||||
ChromeToolbarType GetChromeToolbarType() override;
|
ChromeToolbarType GetChromeToolbarType() override;
|
||||||
|
bool OnGestureCommand(CefRefPtr<CefBrowserView> browser_view,
|
||||||
|
cef_gesture_command_t gesture_command) override;
|
||||||
|
|
||||||
// CefViewDelegate methods.
|
// CefViewDelegate methods.
|
||||||
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
|
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
|
||||||
|
|
Loading…
Reference in New Issue