chrome: Add support for CefBrowserViewDelegate::OnGestureCommand
This commit is contained in:
parent
f38f362349
commit
c6a20bc586
|
@ -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=94e93810316b74e54eb315d97c6fc6f1cc0c9cc5$
|
// $hash=d49d6b19e52e8a0496c69ec5cbd00750f7ac4740$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_DELEGATE_CAPI_H_
|
#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
|
/// Called when |browser_view| receives a gesture command. Return true (1) to
|
||||||
/// handle (or disable) a |gesture_command| or false (0) to propagate the
|
/// handle (or disable) a |gesture_command| or false (0) to propagate the
|
||||||
/// gesture to the browser for default handling. This function will only be
|
/// gesture to the browser for default handling. With the Chrome runtime these
|
||||||
/// called with the Alloy runtime. To handle these commands with the Chrome
|
/// commands can also be handled via cef_command_handler_t::OnChromeCommand.
|
||||||
/// runtime implement cef_command_handler_t::OnChromeCommand instead.
|
|
||||||
///
|
///
|
||||||
int(CEF_CALLBACK* on_gesture_command)(
|
int(CEF_CALLBACK* on_gesture_command)(
|
||||||
struct _cef_browser_view_delegate_t* self,
|
struct _cef_browser_view_delegate_t* self,
|
||||||
|
|
|
@ -118,9 +118,8 @@ class CefBrowserViewDelegate : public CefViewDelegate {
|
||||||
///
|
///
|
||||||
/// Called when |browser_view| receives a gesture command. Return true to
|
/// Called when |browser_view| receives a gesture command. Return true to
|
||||||
/// handle (or disable) a |gesture_command| or false to propagate the gesture
|
/// 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
|
/// to the browser for default handling. With the Chrome runtime these
|
||||||
/// the Alloy runtime. To handle these commands with the Chrome runtime
|
/// commands can also be handled via CefCommandHandler::OnChromeCommand.
|
||||||
/// implement CefCommandHandler::OnChromeCommand instead.
|
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual bool OnGestureCommand(CefRefPtr<CefBrowserView> browser_view,
|
virtual bool OnGestureCommand(CefRefPtr<CefBrowserView> browser_view,
|
||||||
|
|
|
@ -70,6 +70,13 @@ void ChromeBrowserView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
|
||||||
browser_view_delegate_->OnBoundsChanged();
|
browser_view_delegate_->OnBoundsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChromeBrowserView::OnGestureEvent(ui::GestureEvent* event) {
|
||||||
|
if (browser_view_delegate_->OnGestureEvent(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParentClass::OnGestureEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
ToolbarView* ChromeBrowserView::OverrideCreateToolbar(
|
ToolbarView* ChromeBrowserView::OverrideCreateToolbar(
|
||||||
Browser* browser,
|
Browser* browser,
|
||||||
BrowserView* browser_view) {
|
BrowserView* browser_view) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ class ChromeBrowserView
|
||||||
const views::ViewHierarchyChangedDetails& details) override;
|
const views::ViewHierarchyChangedDetails& details) override;
|
||||||
void AddedToWidget() override;
|
void AddedToWidget() override;
|
||||||
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
|
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
|
||||||
|
void OnGestureEvent(ui::GestureEvent* event) override;
|
||||||
|
|
||||||
// BrowserView methods:
|
// BrowserView methods:
|
||||||
ToolbarView* OverrideCreateToolbar(Browser* browser,
|
ToolbarView* OverrideCreateToolbar(Browser* browser,
|
||||||
|
|
|
@ -13,8 +13,27 @@
|
||||||
#include "libcef/browser/views/window_impl.h"
|
#include "libcef/browser/views/window_impl.h"
|
||||||
|
|
||||||
#include "content/public/browser/native_web_keyboard_event.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"
|
#include "ui/content_accelerators/accelerator_util.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
absl::optional<cef_gesture_command_t> 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
|
// static
|
||||||
CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
||||||
CefRefPtr<CefClient> client,
|
CefRefPtr<CefClient> client,
|
||||||
|
@ -218,21 +237,27 @@ void CefBrowserViewImpl::OnBoundsChanged() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefBrowserViewImpl::OnGestureCommand(cef_gesture_command_t command) {
|
bool CefBrowserViewImpl::OnGestureEvent(ui::GestureEvent* event) {
|
||||||
if (delegate()->OnGestureCommand(this, command)) {
|
if (auto command = GetGestureCommand(event)) {
|
||||||
return;
|
if (delegate() && delegate()->OnGestureCommand(this, *command)) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (browser_) {
|
if (!cef::IsChromeRuntimeEnabled() && browser_) {
|
||||||
switch (command) {
|
// Default handling for the Alloy runtime.
|
||||||
case CEF_GESTURE_COMMAND_BACK:
|
switch (*command) {
|
||||||
browser_->GoBack();
|
case CEF_GESTURE_COMMAND_BACK:
|
||||||
break;
|
browser_->GoBack();
|
||||||
case CEF_GESTURE_COMMAND_FORWARD:
|
break;
|
||||||
browser_->GoForward();
|
case CEF_GESTURE_COMMAND_FORWARD:
|
||||||
break;
|
browser_->GoForward();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CefBrowserViewImpl::CefBrowserViewImpl(
|
CefBrowserViewImpl::CefBrowserViewImpl(
|
||||||
|
|
|
@ -74,7 +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;
|
bool OnGestureEvent(ui::GestureEvent* event) 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,28 +4,8 @@
|
||||||
|
|
||||||
#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) {
|
||||||
|
@ -60,7 +40,8 @@ void CefBrowserViewView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefBrowserViewView::OnGestureEvent(ui::GestureEvent* event) {
|
void CefBrowserViewView::OnGestureEvent(ui::GestureEvent* event) {
|
||||||
if (auto command = GetGestureCommand(event)) {
|
if (browser_view_delegate_->OnGestureEvent(event)) {
|
||||||
browser_view_delegate_->OnGestureCommand(*command);
|
return;
|
||||||
}
|
}
|
||||||
|
ParentClass::OnGestureEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +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.
|
// Called when the BrowserView receives a gesture event.
|
||||||
virtual void OnGestureCommand(cef_gesture_command_t command) = 0;
|
// Returns true if the gesture was handled.
|
||||||
|
virtual bool OnGestureEvent(ui::GestureEvent* event) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~Delegate() {}
|
virtual ~Delegate() {}
|
||||||
|
|
Loading…
Reference in New Issue