chrome: Add support for CefBrowserViewDelegate::OnGestureCommand
This commit is contained in:
parent
f4ecc23213
commit
f808926fbd
|
@ -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,
|
||||
|
|
|
@ -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<CefBrowserView> browser_view,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<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
|
||||
CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
||||
CefRefPtr<CefClient> 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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,28 +4,8 @@
|
|||
|
||||
#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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
|
Loading…
Reference in New Issue