2020-01-23 22:58:01 +01:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_aura.h"
|
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
#include "libcef/browser/native/menu_runner_views_aura.h"
|
|
|
|
#include "libcef/browser/views/view_util.h"
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "content/public/browser/render_widget_host.h"
|
|
|
|
#include "ui/events/blink/blink_event_util.h"
|
|
|
|
#include "ui/events/blink/web_input_event.h"
|
|
|
|
#include "ui/gfx/geometry/vector2d.h"
|
2022-05-13 13:38:41 +02:00
|
|
|
#include "ui/views/widget/widget.h"
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
CefBrowserPlatformDelegateNativeAura::CefBrowserPlatformDelegateNativeAura(
|
|
|
|
const CefWindowInfo& window_info,
|
2020-07-04 20:21:34 +02:00
|
|
|
SkColor background_color)
|
|
|
|
: CefBrowserPlatformDelegateNative(window_info, background_color) {}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeAura::SendKeyEvent(
|
|
|
|
const CefKeyEvent& event) {
|
|
|
|
auto view = GetHostView();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view) {
|
2020-01-23 22:58:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
ui::KeyEvent ui_event = TranslateUiKeyEvent(event);
|
|
|
|
view->OnKeyEvent(&ui_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeAura::SendMouseClickEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) {
|
|
|
|
auto view = GetHostView();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view) {
|
2020-01-23 22:58:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
ui::MouseEvent ui_event =
|
|
|
|
TranslateUiClickEvent(event, type, mouseUp, clickCount);
|
|
|
|
view->OnMouseEvent(&ui_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeAura::SendMouseMoveEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
bool mouseLeave) {
|
|
|
|
auto view = GetHostView();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view) {
|
2020-01-23 22:58:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
ui::MouseEvent ui_event = TranslateUiMoveEvent(event, mouseLeave);
|
|
|
|
view->OnMouseEvent(&ui_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeAura::SendMouseWheelEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) {
|
|
|
|
auto view = GetHostView();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view) {
|
2020-01-23 22:58:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
ui::MouseWheelEvent ui_event = TranslateUiWheelEvent(event, deltaX, deltaY);
|
|
|
|
view->OnMouseEvent(&ui_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeAura::SendTouchEvent(
|
|
|
|
const CefTouchEvent& event) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
std::unique_ptr<CefMenuRunner>
|
|
|
|
CefBrowserPlatformDelegateNativeAura::CreateMenuRunner() {
|
|
|
|
return base::WrapUnique(new CefMenuRunnerViewsAura);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateNativeAura::GetScreenPoint(
|
|
|
|
const gfx::Point& view,
|
|
|
|
bool want_dip_coords) const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (windowless_handler_) {
|
2022-05-13 13:38:41 +02:00
|
|
|
return windowless_handler_->GetParentScreenPoint(view, want_dip_coords);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-05-13 13:38:41 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_widget_) {
|
2022-05-13 13:38:41 +02:00
|
|
|
return view;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-05-13 13:38:41 +02:00
|
|
|
|
|
|
|
gfx::Point screen_pt(view);
|
|
|
|
if (!view_util::ConvertPointToScreen(
|
|
|
|
window_widget_->GetRootView(), &screen_pt,
|
|
|
|
/*output_pixel_coords=*/!want_dip_coords)) {
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return screen_pt;
|
|
|
|
}
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
content::NativeWebKeyboardEvent
|
|
|
|
CefBrowserPlatformDelegateNativeAura::TranslateWebKeyEvent(
|
|
|
|
const CefKeyEvent& key_event) const {
|
|
|
|
return content::NativeWebKeyboardEvent(TranslateUiKeyEvent(key_event));
|
|
|
|
}
|
|
|
|
|
|
|
|
blink::WebMouseEvent
|
|
|
|
CefBrowserPlatformDelegateNativeAura::TranslateWebClickEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) const {
|
|
|
|
return ui::MakeWebMouseEvent(
|
|
|
|
TranslateUiClickEvent(mouse_event, type, mouseUp, clickCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
blink::WebMouseEvent
|
|
|
|
CefBrowserPlatformDelegateNativeAura::TranslateWebMoveEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
bool mouseLeave) const {
|
|
|
|
return ui::MakeWebMouseEvent(TranslateUiMoveEvent(mouse_event, mouseLeave));
|
|
|
|
}
|
|
|
|
|
|
|
|
blink::WebMouseWheelEvent
|
|
|
|
CefBrowserPlatformDelegateNativeAura::TranslateWebWheelEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
|
|
|
return ui::MakeWebMouseWheelEvent(
|
|
|
|
TranslateUiWheelEvent(mouse_event, deltaX, deltaY));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseEvent CefBrowserPlatformDelegateNativeAura::TranslateUiClickEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) const {
|
|
|
|
DCHECK_GE(clickCount, 1);
|
|
|
|
|
|
|
|
ui::EventType event_type =
|
|
|
|
mouseUp ? ui::ET_MOUSE_RELEASED : ui::ET_MOUSE_PRESSED;
|
|
|
|
gfx::PointF location(mouse_event.x, mouse_event.y);
|
2022-05-13 13:38:41 +02:00
|
|
|
gfx::PointF root_location(GetScreenPoint(
|
|
|
|
gfx::Point(mouse_event.x, mouse_event.y), /*want_dip_coords=*/false));
|
2020-01-23 22:58:01 +01:00
|
|
|
base::TimeTicks time_stamp = GetEventTimeStamp();
|
|
|
|
int flags = TranslateUiEventModifiers(mouse_event.modifiers);
|
|
|
|
|
|
|
|
int changed_button_flags = 0;
|
|
|
|
switch (type) {
|
|
|
|
case MBT_LEFT:
|
|
|
|
changed_button_flags |= ui::EF_LEFT_MOUSE_BUTTON;
|
|
|
|
break;
|
|
|
|
case MBT_MIDDLE:
|
|
|
|
changed_button_flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
|
|
|
|
break;
|
|
|
|
case MBT_RIGHT:
|
|
|
|
changed_button_flags |= ui::EF_RIGHT_MOUSE_BUTTON;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseEvent result(event_type, location, root_location, time_stamp, flags,
|
|
|
|
changed_button_flags);
|
|
|
|
result.SetClickCount(clickCount);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseEvent CefBrowserPlatformDelegateNativeAura::TranslateUiMoveEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
bool mouseLeave) const {
|
|
|
|
ui::EventType event_type =
|
|
|
|
mouseLeave ? ui::ET_MOUSE_EXITED : ui::ET_MOUSE_MOVED;
|
|
|
|
gfx::PointF location(mouse_event.x, mouse_event.y);
|
2022-05-13 13:38:41 +02:00
|
|
|
gfx::PointF root_location(GetScreenPoint(
|
|
|
|
gfx::Point(mouse_event.x, mouse_event.y), /*want_dip_coords=*/false));
|
2020-01-23 22:58:01 +01:00
|
|
|
base::TimeTicks time_stamp = GetEventTimeStamp();
|
|
|
|
int flags = TranslateUiEventModifiers(mouse_event.modifiers);
|
|
|
|
|
|
|
|
int changed_button_flags = 0;
|
|
|
|
if (!mouseLeave) {
|
|
|
|
changed_button_flags = TranslateUiChangedButtonFlags(mouse_event.modifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ui::MouseEvent(event_type, location, root_location, time_stamp, flags,
|
|
|
|
changed_button_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseWheelEvent CefBrowserPlatformDelegateNativeAura::TranslateUiWheelEvent(
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
|
|
|
gfx::Vector2d offset(GetUiWheelEventOffset(deltaX, deltaY));
|
|
|
|
DCHECK(!offset.IsZero());
|
|
|
|
|
|
|
|
gfx::PointF location(mouse_event.x, mouse_event.y);
|
2022-05-13 13:38:41 +02:00
|
|
|
gfx::PointF root_location(GetScreenPoint(
|
|
|
|
gfx::Point(mouse_event.x, mouse_event.y), /*want_dip_coords=*/false));
|
2020-01-23 22:58:01 +01:00
|
|
|
base::TimeTicks time_stamp = GetEventTimeStamp();
|
|
|
|
int flags = TranslateUiEventModifiers(mouse_event.modifiers);
|
|
|
|
int changed_button_flags =
|
|
|
|
TranslateUiChangedButtonFlags(mouse_event.modifiers);
|
|
|
|
|
2020-04-02 22:59:26 +02:00
|
|
|
return ui::MouseWheelEvent(offset, location, root_location, time_stamp,
|
|
|
|
(ui::EF_PRECISION_SCROLLING_DELTA | flags),
|
2020-01-23 22:58:01 +01:00
|
|
|
changed_button_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Vector2d CefBrowserPlatformDelegateNativeAura::GetUiWheelEventOffset(
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
|
|
|
return gfx::Vector2d(deltaX, deltaY);
|
|
|
|
}
|
|
|
|
|
2023-02-07 00:43:00 +01:00
|
|
|
base::OnceClosure
|
|
|
|
CefBrowserPlatformDelegateNativeAura::GetWidgetDeleteCallback() {
|
|
|
|
return base::BindOnce(&CefBrowserPlatformDelegateNativeAura::WidgetDeleted,
|
|
|
|
weak_ptr_factory_.GetWeakPtr());
|
|
|
|
}
|
|
|
|
|
2021-06-07 21:34:24 +02:00
|
|
|
// static
|
|
|
|
base::TimeTicks CefBrowserPlatformDelegateNativeAura::GetEventTimeStamp() {
|
|
|
|
return base::TimeTicks::Now();
|
|
|
|
}
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
// static
|
|
|
|
int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers(
|
|
|
|
uint32 cef_modifiers) {
|
|
|
|
int result = 0;
|
|
|
|
// Set modifiers based on key state.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON) {
|
2021-07-19 17:52:36 +02:00
|
|
|
result |= ui::EF_CAPS_LOCK_ON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_SHIFT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_CONTROL_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_ALT_DOWN) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_ALT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_LEFT_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_RIGHT_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN) {
|
2021-07-19 17:52:36 +02:00
|
|
|
result |= ui::EF_COMMAND_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_NUM_LOCK_ON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_IS_KEY_PAD) {
|
2021-07-19 17:52:36 +02:00
|
|
|
result |= ui::EF_IS_EXTENDED_KEY;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN) {
|
2020-04-08 17:43:39 +02:00
|
|
|
result |= ui::EF_ALTGR_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_modifiers & EVENTFLAG_IS_REPEAT) {
|
2021-07-19 17:52:36 +02:00
|
|
|
result |= ui::EF_IS_REPEAT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
int CefBrowserPlatformDelegateNativeAura::TranslateUiChangedButtonFlags(
|
|
|
|
uint32 cef_modifiers) {
|
|
|
|
int result = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_LEFT_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
|
2020-01-23 22:58:01 +01:00
|
|
|
result |= ui::EF_RIGHT_MOUSE_BUTTON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-02-07 00:43:00 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeAura::WidgetDeleted() {
|
|
|
|
DCHECK(window_widget_);
|
|
|
|
window_widget_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
content::RenderWidgetHostViewAura*
|
|
|
|
CefBrowserPlatformDelegateNativeAura::GetHostView() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents_) {
|
2020-09-15 17:03:38 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
return static_cast<content::RenderWidgetHostViewAura*>(
|
2020-07-08 19:23:29 +02:00
|
|
|
web_contents_->GetRenderWidgetHostView());
|
2020-01-23 22:58:01 +01:00
|
|
|
}
|