2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
|
2014-05-22 23:01:22 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_linux.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/menu_runner_linux.h"
|
|
|
|
#include "libcef/browser/native/window_delegate_view.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
#include "base/no_destructor.h"
|
2014-10-29 19:14:47 +01:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
2014-10-29 19:14:47 +01:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
|
2016-07-06 21:34:09 +02:00
|
|
|
#include "ui/events/keycodes/dom/dom_key.h"
|
|
|
|
#include "ui/events/keycodes/dom/keycode_converter.h"
|
|
|
|
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
|
|
|
|
#include "ui/events/keycodes/keyboard_code_conversion_xkb.h"
|
|
|
|
#include "ui/events/keycodes/keysym_to_unicode.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "ui/gfx/font_render_params.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
|
|
|
#include "libcef/browser/native/window_x11.h"
|
|
|
|
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
|
|
|
|
#endif
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Returns the number of seconds since system boot.
|
|
|
|
long GetSystemUptime() {
|
|
|
|
struct sysinfo info;
|
|
|
|
if (sysinfo(&info) == 0)
|
|
|
|
return info.uptime;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
} // namespace
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserPlatformDelegateNativeLinux::CefBrowserPlatformDelegateNativeLinux(
|
2017-04-20 21:28:17 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2019-03-18 22:07:02 +01:00
|
|
|
SkColor background_color,
|
|
|
|
bool use_external_begin_frame)
|
2018-07-03 02:46:03 +02:00
|
|
|
: CefBrowserPlatformDelegateNative(window_info,
|
|
|
|
background_color,
|
|
|
|
false,
|
2019-03-18 22:07:02 +01:00
|
|
|
use_external_begin_frame),
|
2015-11-17 19:20:13 +01:00
|
|
|
host_window_created_(false),
|
2019-04-23 19:00:14 +02:00
|
|
|
window_widget_(nullptr) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::BrowserDestroyed(
|
|
|
|
CefBrowserHostImpl* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
if (host_window_created_) {
|
|
|
|
// Release the reference added in CreateHostWindow().
|
|
|
|
browser->Release();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() {
|
2014-05-22 23:01:22 +02:00
|
|
|
DCHECK(!window_widget_);
|
|
|
|
|
|
|
|
if (window_info_.width == 0)
|
|
|
|
window_info_.width = 800;
|
|
|
|
if (window_info_.height == 0)
|
|
|
|
window_info_.height = 600;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
gfx::Rect rect(window_info_.x, window_info_.y, window_info_.width,
|
|
|
|
window_info_.height);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
|
|
|
DCHECK(!window_x11_);
|
2014-05-22 23:01:22 +02:00
|
|
|
// Create a new window object. It will delete itself when the associated X11
|
|
|
|
// window is destroyed.
|
2019-04-24 04:50:25 +02:00
|
|
|
window_x11_ =
|
|
|
|
new CefWindowX11(browser_, window_info_.parent_window, rect,
|
|
|
|
CefString(&window_info_.window_name).ToString());
|
2014-05-22 23:01:22 +02:00
|
|
|
window_info_.window = window_x11_->xwindow();
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
host_window_created_ = true;
|
|
|
|
|
|
|
|
// Add a reference that will be released in BrowserDestroyed().
|
|
|
|
browser_->AddRef();
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2018-02-28 05:47:36 +01:00
|
|
|
CefWindowDelegateView* delegate_view = new CefWindowDelegateView(
|
|
|
|
GetBackgroundColor(), window_x11_->TopLevelAlwaysOnTop());
|
2017-05-17 11:29:28 +02:00
|
|
|
delegate_view->Init(window_info_.window, browser_->web_contents(),
|
2014-05-22 23:01:22 +02:00
|
|
|
gfx::Rect(gfx::Point(), rect.size()));
|
|
|
|
|
|
|
|
window_widget_ = delegate_view->GetWidget();
|
|
|
|
window_widget_->Show();
|
|
|
|
|
|
|
|
window_x11_->Show();
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
// As an additional requirement on Linux, we must set the colors for the
|
|
|
|
// render widgets in webkit.
|
2019-02-21 01:42:36 +01:00
|
|
|
blink::mojom::RendererPreferences* prefs =
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_->web_contents()->GetMutableRendererPrefs();
|
2014-05-22 23:01:22 +02:00
|
|
|
prefs->focus_ring_color = SkColorSetARGB(255, 229, 151, 0);
|
|
|
|
|
|
|
|
prefs->active_selection_bg_color = SkColorSetRGB(30, 144, 255);
|
|
|
|
prefs->active_selection_fg_color = SK_ColorWHITE;
|
|
|
|
prefs->inactive_selection_bg_color = SkColorSetRGB(200, 200, 200);
|
|
|
|
prefs->inactive_selection_fg_color = SkColorSetRGB(50, 50, 50);
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Set font-related attributes.
|
2018-11-03 02:15:09 +01:00
|
|
|
static const base::NoDestructor<gfx::FontRenderParams> params(
|
|
|
|
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr));
|
|
|
|
prefs->should_antialias_text = params->antialiasing;
|
|
|
|
prefs->use_subpixel_positioning = params->subpixel_positioning;
|
|
|
|
prefs->hinting = params->hinting;
|
|
|
|
prefs->use_autohinter = params->autohinter;
|
|
|
|
prefs->use_bitmaps = params->use_bitmaps;
|
|
|
|
prefs->subpixel_rendering = params->subpixel_rendering;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
browser_->web_contents()->GetRenderViewHost()->SyncRendererPrefs();
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::CloseHostWindow() {
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2014-05-22 23:01:22 +02:00
|
|
|
if (window_x11_)
|
|
|
|
window_x11_->Close();
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateNativeLinux::GetHostWindowHandle()
|
|
|
|
const {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (windowless_handler_)
|
|
|
|
return windowless_handler_->GetParentWindowHandle();
|
|
|
|
return window_info_.window;
|
|
|
|
}
|
|
|
|
|
|
|
|
views::Widget* CefBrowserPlatformDelegateNativeLinux::GetWindowWidget() const {
|
|
|
|
return window_widget_;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::SendFocusEvent(bool setFocus) {
|
|
|
|
if (!setFocus)
|
2014-06-06 21:04:21 +02:00
|
|
|
return;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
if (browser_->web_contents()) {
|
2014-06-06 21:04:21 +02:00
|
|
|
// Give logical focus to the RenderWidgetHostViewAura in the views
|
|
|
|
// hierarchy. This does not change the native keyboard focus.
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_->web_contents()->Focus();
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2014-06-06 21:04:21 +02:00
|
|
|
if (window_x11_) {
|
|
|
|
// Give native focus to the DesktopNativeWidgetAura for the root window.
|
|
|
|
// Needs to be done via the ::Window so that keyboard focus is assigned
|
|
|
|
// correctly.
|
|
|
|
window_x11_->Focus();
|
|
|
|
}
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::NotifyMoveOrResizeStarted() {
|
|
|
|
// Call the parent method to dismiss any existing popups.
|
|
|
|
CefBrowserPlatformDelegate::NotifyMoveOrResizeStarted();
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!window_x11_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
views::DesktopWindowTreeHostX11* tree_host = window_x11_->GetHost();
|
|
|
|
if (!tree_host)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Explicitly set the screen bounds so that WindowTreeHost::*Screen()
|
|
|
|
// methods return the correct results.
|
|
|
|
const gfx::Rect& bounds = window_x11_->GetBoundsInScreen();
|
|
|
|
tree_host->set_screen_bounds(bounds);
|
|
|
|
|
|
|
|
// Send updated screen rectangle information to the renderer process so that
|
|
|
|
// popups are displayed in the correct location.
|
|
|
|
content::RenderWidgetHostImpl::From(
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_->web_contents()->GetRenderViewHost()->GetWidget())
|
|
|
|
->SendScreenRects();
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeLinux::SizeTo(int width, int height) {
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
if (window_x11_) {
|
|
|
|
window_x11_->SetBounds(
|
|
|
|
gfx::Rect(window_x11_->bounds().origin(), gfx::Size(width, height)));
|
|
|
|
}
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
gfx::Point CefBrowserPlatformDelegateNativeLinux::GetScreenPoint(
|
|
|
|
const gfx::Point& view) const {
|
|
|
|
if (windowless_handler_)
|
|
|
|
return windowless_handler_->GetParentScreenPoint(view);
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!window_x11_)
|
|
|
|
return view;
|
|
|
|
|
|
|
|
// We can't use aura::Window::GetBoundsInScreen on Linux because it will
|
|
|
|
// return bounds from DesktopWindowTreeHostX11 which in our case is relative
|
|
|
|
// to the parent window instead of the root window (screen).
|
|
|
|
const gfx::Rect& bounds_in_screen = window_x11_->GetBoundsInScreen();
|
|
|
|
return gfx::Point(bounds_in_screen.x() + view.x(),
|
|
|
|
bounds_in_screen.y() + view.y());
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
|
|
|
return gfx::Point();
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::ViewText(const std::string& text) {
|
2014-05-22 23:01:22 +02:00
|
|
|
char buff[] = "/tmp/CEFSourceXXXXXX";
|
|
|
|
int fd = mkstemp(buff);
|
|
|
|
|
|
|
|
if (fd == -1)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
FILE* srcOutput = fdopen(fd, "w+");
|
|
|
|
if (!srcOutput)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
if (fputs(text.c_str(), srcOutput) < 0) {
|
|
|
|
fclose(srcOutput);
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(srcOutput);
|
|
|
|
|
|
|
|
std::string newName(buff);
|
|
|
|
newName.append(".txt");
|
|
|
|
if (rename(buff, newName.c_str()) != 0)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
std::string openCommand("xdg-open ");
|
|
|
|
openCommand += newName;
|
|
|
|
|
2016-06-03 17:33:06 +02:00
|
|
|
int result = system(openCommand.c_str());
|
|
|
|
ALLOW_UNUSED_LOCAL(result);
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
bool CefBrowserPlatformDelegateNativeLinux::HandleKeyboardEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
// TODO(cef): Is something required here to handle shortcut keys?
|
2018-11-03 02:15:09 +01:00
|
|
|
return false;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// static
|
|
|
|
void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {}
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::TranslateKeyEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
content::NativeWebKeyboardEvent& result,
|
2015-11-17 19:20:13 +01:00
|
|
|
const CefKeyEvent& key_event) const {
|
2017-04-20 21:28:17 +02:00
|
|
|
result.windows_key_code = key_event.windows_key_code;
|
|
|
|
result.native_key_code = key_event.native_key_code;
|
|
|
|
result.is_system_key = key_event.is_system_key ? 1 : 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
switch (key_event.type) {
|
2017-05-17 11:29:28 +02:00
|
|
|
case KEYEVENT_RAWKEYDOWN:
|
|
|
|
case KEYEVENT_KEYDOWN:
|
|
|
|
result.SetType(blink::WebInputEvent::kRawKeyDown);
|
|
|
|
break;
|
|
|
|
case KEYEVENT_KEYUP:
|
|
|
|
result.SetType(blink::WebInputEvent::kKeyUp);
|
|
|
|
break;
|
|
|
|
case KEYEVENT_CHAR:
|
|
|
|
result.SetType(blink::WebInputEvent::kChar);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2016-07-06 21:34:09 +02:00
|
|
|
// Populate DOM values that will be passed to JavaScript handlers via
|
|
|
|
// KeyboardEvent.
|
2017-05-17 11:29:28 +02:00
|
|
|
result.dom_code = static_cast<int>(
|
|
|
|
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code));
|
2016-07-06 21:34:09 +02:00
|
|
|
int keysym = ui::XKeysymForWindowsKeyCode(
|
|
|
|
static_cast<ui::KeyboardCode>(key_event.windows_key_code),
|
|
|
|
!!(key_event.modifiers & EVENTFLAG_SHIFT_DOWN));
|
|
|
|
base::char16 ch = ui::GetUnicodeCharacterFromXKeySym(keysym);
|
2017-04-20 21:28:17 +02:00
|
|
|
result.dom_key = static_cast<int>(ui::XKeySymToDomKey(keysym, ch));
|
2016-07-06 21:34:09 +02:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
result.text[0] = key_event.character;
|
2017-04-20 21:28:17 +02:00
|
|
|
result.unmodified_text[0] = key_event.unmodified_character;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
result.SetModifiers(result.GetModifiers() |
|
|
|
|
TranslateModifiers(key_event.modifiers));
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::TranslateClickEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserHost::MouseButtonType type,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) const {
|
2015-11-17 19:20:13 +01:00
|
|
|
TranslateMouseEvent(result, mouse_event);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
switch (type) {
|
2017-05-17 11:29:28 +02:00
|
|
|
case MBT_LEFT:
|
|
|
|
result.SetType(mouseUp ? blink::WebInputEvent::kMouseUp
|
|
|
|
: blink::WebInputEvent::kMouseDown);
|
|
|
|
result.button = blink::WebMouseEvent::Button::kLeft;
|
|
|
|
break;
|
|
|
|
case MBT_MIDDLE:
|
|
|
|
result.SetType(mouseUp ? blink::WebInputEvent::kMouseUp
|
|
|
|
: blink::WebInputEvent::kMouseDown);
|
|
|
|
result.button = blink::WebMouseEvent::Button::kMiddle;
|
|
|
|
break;
|
|
|
|
case MBT_RIGHT:
|
|
|
|
result.SetType(mouseUp ? blink::WebInputEvent::kMouseUp
|
|
|
|
: blink::WebInputEvent::kMouseDown);
|
|
|
|
result.button = blink::WebMouseEvent::Button::kRight;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.click_count = clickCount;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::TranslateMoveEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool mouseLeave) const {
|
|
|
|
TranslateMouseEvent(result, mouse_event);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
if (!mouseLeave) {
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseMove);
|
2014-05-22 23:01:22 +02:00
|
|
|
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kLeft;
|
2014-05-22 23:01:22 +02:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kMiddle;
|
2014-05-22 23:01:22 +02:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kRight;
|
2014-05-22 23:01:22 +02:00
|
|
|
else
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2014-05-22 23:01:22 +02:00
|
|
|
} else {
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseLeave);
|
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.click_count = 0;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateNativeLinux::TranslateWheelEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
blink::WebMouseWheelEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
2017-05-17 11:29:28 +02:00
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
2014-05-22 23:01:22 +02:00
|
|
|
result = blink::WebMouseWheelEvent();
|
2015-11-17 19:20:13 +01:00
|
|
|
TranslateMouseEvent(result, mouse_event);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseWheel);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
static const double scrollbarPixelsPerGtkTick = 40.0;
|
2017-04-20 21:28:17 +02:00
|
|
|
result.delta_x = deltaX;
|
|
|
|
result.delta_y = deltaY;
|
|
|
|
result.wheel_ticks_x = deltaX / scrollbarPixelsPerGtkTick;
|
|
|
|
result.wheel_ticks_y = deltaY / scrollbarPixelsPerGtkTick;
|
|
|
|
result.has_precise_scrolling_deltas = true;
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kLeft;
|
2014-05-22 23:01:22 +02:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kMiddle;
|
2014-05-22 23:01:22 +02:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kRight;
|
2014-05-22 23:01:22 +02:00
|
|
|
else
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefEventHandle CefBrowserPlatformDelegateNativeLinux::GetEventHandle(
|
|
|
|
const content::NativeWebKeyboardEvent& event) const {
|
|
|
|
if (!event.os_event)
|
|
|
|
return NULL;
|
2019-04-23 19:00:14 +02:00
|
|
|
return const_cast<CefEventHandle>(
|
|
|
|
static_cast<CefEventHandle>(event.os_event->native_event()));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefMenuRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateNativeLinux::CreateMenuRunner() {
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new CefMenuRunnerLinux);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeLinux::TranslateMouseEvent(
|
2014-05-22 23:01:22 +02:00
|
|
|
blink::WebMouseEvent& result,
|
2015-11-17 19:20:13 +01:00
|
|
|
const CefMouseEvent& mouse_event) const {
|
2014-05-22 23:01:22 +02:00
|
|
|
// position
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetPositionInWidget(mouse_event.x, mouse_event.y);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const gfx::Point& screen_pt =
|
|
|
|
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y));
|
|
|
|
result.SetPositionInScreen(screen_pt.x(), screen_pt.y());
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
// modifiers
|
2017-05-17 11:29:28 +02:00
|
|
|
result.SetModifiers(result.GetModifiers() |
|
|
|
|
TranslateModifiers(mouse_event.modifiers));
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
// timestamp
|
2018-05-17 10:58:21 +02:00
|
|
|
result.SetTimeStamp(base::TimeTicks() +
|
|
|
|
base::TimeDelta::FromSeconds(GetSystemUptime()));
|
2018-02-22 18:09:28 +01:00
|
|
|
|
|
|
|
result.pointer_type = blink::WebPointerProperties::PointerType::kMouse;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|