Add support for MimeHandlerViewInCrossProcessFrame (fixes issue #2727)

The PDF loading documentation in extension_system.cc has be updated to
describe the new code paths.

To support delivery of input events to the mime handler renderer process it is
now necessary to route events via the correct RWHV interface. For Aura-based
platforms (Windows/Linux) this means RWHVAura::On*Event and for macOS this
means RWHVMac::RouteOrProcess*Event. Since Aura uses UI event types these have
become the source of truth on Aura-based platforms with conversion to Web event
types when needed (primarily for OSR).

This change also adds a timeout for CefProcessHostMsg_GetNewBrowserInfo to
avoid a hung renderer process if the guest WebContents route is not
registered via CefMimeHandlerViewGuestDelegate::OnGuestDetached as expected
prior to CefBrowserInfoManager::OnGetNewBrowserInfo being called. This
timeout can be disabled for testing purposes by passing the
`--disable-new-browser-info-timeout` command-line flag.

The `--disable-features=MimeHandlerViewInCrossProcessFrame` command-line
flag can be used for a limited time to restore the previous implementation
based on BrowserPlugin. That implementation will be deleted starting with
the 3897 branch update.

Known issues:
- ExecuteJavaScript calls on the frame hosting the PDF extension will not
  be routed to the mime handler renderer process.
- The PDF extension will not load successfully if blocked by
  ChromePluginPlaceholder and then manually continued via the "Run this
  plugin" context menu option (see https://crbug.com/533069#c41).
This commit is contained in:
Marshall Greenblatt
2020-01-23 16:58:01 -05:00
parent f2f6ae4f29
commit a12c2ab3e1
38 changed files with 1030 additions and 917 deletions

View File

@@ -8,6 +8,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "third_party/blink/public/platform/web_mouse_event.h"
CefBrowserPlatformDelegateNative::CefBrowserPlatformDelegateNative(
const CefWindowInfo& window_info,
@@ -38,30 +39,6 @@ void CefBrowserPlatformDelegateNative::SynchronizeVisualProperties() {
host->GetWidget()->SynchronizeVisualProperties();
}
void CefBrowserPlatformDelegateNative::SendKeyEvent(
const content::NativeWebKeyboardEvent& event) {
content::RenderViewHost* host = browser_->web_contents()->GetRenderViewHost();
if (host)
host->GetWidget()->ForwardKeyboardEvent(event);
}
void CefBrowserPlatformDelegateNative::SendMouseEvent(
const blink::WebMouseEvent& event) {
content::RenderViewHost* host = browser_->web_contents()->GetRenderViewHost();
if (host)
host->GetWidget()->ForwardMouseEvent(event);
}
void CefBrowserPlatformDelegateNative::SendMouseWheelEvent(
const blink::WebMouseWheelEvent& event) {
content::RenderViewHost* host = browser_->web_contents()->GetRenderViewHost();
if (host)
host->GetWidget()->ForwardWheelEvent(event);
}
void CefBrowserPlatformDelegateNative::SendTouchEvent(
const CefTouchEvent& event) {}
bool CefBrowserPlatformDelegateNative::IsWindowless() const {
return false;
}

View File

@@ -29,25 +29,44 @@ class CefBrowserPlatformDelegateNative : public CefBrowserPlatformDelegate {
bool CanUseExternalBeginFrame() const override;
SkColor GetBackgroundColor() const override;
void SynchronizeVisualProperties() override;
void SendKeyEvent(const content::NativeWebKeyboardEvent& event) override;
void SendMouseEvent(const blink::WebMouseEvent& event) override;
void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event) override;
void SendTouchEvent(const CefTouchEvent& event) override;
bool IsWindowless() const override;
bool IsViewsHosted() const override;
// Translate CEF events to Chromium/Blink Web events.
virtual content::NativeWebKeyboardEvent TranslateWebKeyEvent(
const CefKeyEvent& key_event) const = 0;
virtual blink::WebMouseEvent TranslateWebClickEvent(
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const = 0;
virtual blink::WebMouseEvent TranslateWebMoveEvent(
const CefMouseEvent& mouse_event,
bool mouseLeave) const = 0;
virtual blink::WebMouseWheelEvent TranslateWebWheelEvent(
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const = 0;
const CefWindowInfo& window_info() const { return window_info_; }
void set_windowless_handler(WindowlessHandler* handler) {
windowless_handler_ = handler;
}
protected:
// Delegates that can wrap a native delegate.
friend class CefBrowserPlatformDelegateBackground;
friend class CefBrowserPlatformDelegateOsr;
friend class CefBrowserPlatformDelegateViews;
CefBrowserPlatformDelegateNative(const CefWindowInfo& window_info,
SkColor background_color,
bool use_shared_texture,
bool use_external_begin_frame);
// Methods used by delegates that can wrap a native delegate.
void set_windowless_handler(WindowlessHandler* handler) {
windowless_handler_ = handler;
}
void set_browser(CefBrowserHostImpl* browser) { browser_ = browser; }
CefWindowInfo window_info_;
const SkColor background_color_;
const bool use_shared_texture_;

View File

@@ -0,0 +1,232 @@
// 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"
#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"
CefBrowserPlatformDelegateNativeAura::CefBrowserPlatformDelegateNativeAura(
const CefWindowInfo& window_info,
SkColor background_color,
bool use_shared_texture,
bool use_external_begin_frame)
: CefBrowserPlatformDelegateNative(window_info,
background_color,
use_shared_texture,
use_external_begin_frame) {}
void CefBrowserPlatformDelegateNativeAura::SendKeyEvent(
const CefKeyEvent& event) {
auto view = GetHostView();
if (!view)
return;
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();
if (!view)
return;
ui::MouseEvent ui_event =
TranslateUiClickEvent(event, type, mouseUp, clickCount);
view->OnMouseEvent(&ui_event);
}
void CefBrowserPlatformDelegateNativeAura::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
auto view = GetHostView();
if (!view)
return;
ui::MouseEvent ui_event = TranslateUiMoveEvent(event, mouseLeave);
view->OnMouseEvent(&ui_event);
}
void CefBrowserPlatformDelegateNativeAura::SendMouseWheelEvent(
const CefMouseEvent& event,
int deltaX,
int deltaY) {
auto view = GetHostView();
if (!view)
return;
ui::MouseWheelEvent ui_event = TranslateUiWheelEvent(event, deltaX, deltaY);
view->OnMouseEvent(&ui_event);
}
void CefBrowserPlatformDelegateNativeAura::SendTouchEvent(
const CefTouchEvent& event) {
NOTIMPLEMENTED();
}
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);
gfx::PointF root_location(
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y)));
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);
gfx::PointF root_location(
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y)));
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);
gfx::PointF root_location(
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y)));
base::TimeTicks time_stamp = GetEventTimeStamp();
int flags = TranslateUiEventModifiers(mouse_event.modifiers);
int changed_button_flags =
TranslateUiChangedButtonFlags(mouse_event.modifiers);
return ui::MouseWheelEvent(offset, location, root_location, time_stamp, flags,
changed_button_flags);
}
gfx::Vector2d CefBrowserPlatformDelegateNativeAura::GetUiWheelEventOffset(
int deltaX,
int deltaY) const {
return gfx::Vector2d(deltaX, deltaY);
}
// static
int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers(
uint32 cef_modifiers) {
int result = 0;
// Set modifiers based on key state.
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
result |= ui::EF_SHIFT_DOWN;
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
result |= ui::EF_CONTROL_DOWN;
if (cef_modifiers & EVENTFLAG_ALT_DOWN)
result |= ui::EF_ALT_DOWN;
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
result |= ui::EF_COMMAND_DOWN;
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result |= ui::EF_LEFT_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
result |= ui::EF_RIGHT_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
result |= ui::EF_CAPS_LOCK_ON;
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
result |= ui::EF_NUM_LOCK_ON;
return result;
}
// static
int CefBrowserPlatformDelegateNativeAura::TranslateUiChangedButtonFlags(
uint32 cef_modifiers) {
int result = 0;
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result |= ui::EF_LEFT_MOUSE_BUTTON;
else if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
else if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
result |= ui::EF_RIGHT_MOUSE_BUTTON;
return result;
}
content::RenderWidgetHostViewAura*
CefBrowserPlatformDelegateNativeAura::GetHostView() const {
return static_cast<content::RenderWidgetHostViewAura*>(
browser_->web_contents()->GetRenderWidgetHostView());
}

View File

@@ -0,0 +1,81 @@
// 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.
#ifndef CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_AURA_H_
#define CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_AURA_H_
#include "libcef/browser/native/browser_platform_delegate_native.h"
#include "ui/events/event.h"
namespace content {
class RenderWidgetHostViewAura;
}
namespace gfx {
class Vector2d;
}
// Windowed browser implementation for Aura platforms.
class CefBrowserPlatformDelegateNativeAura
: public CefBrowserPlatformDelegateNative {
public:
CefBrowserPlatformDelegateNativeAura(const CefWindowInfo& window_info,
SkColor background_color,
bool use_shared_texture,
bool use_external_begin_frame);
// CefBrowserPlatformDelegate methods:
void SendKeyEvent(const CefKeyEvent& event) override;
void SendMouseClickEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) override;
void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override;
void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) override;
void SendTouchEvent(const CefTouchEvent& event) override;
// CefBrowserPlatformDelegateNative methods:
content::NativeWebKeyboardEvent TranslateWebKeyEvent(
const CefKeyEvent& key_event) const override;
blink::WebMouseEvent TranslateWebClickEvent(
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const override;
blink::WebMouseEvent TranslateWebMoveEvent(const CefMouseEvent& mouse_event,
bool mouseLeave) const override;
blink::WebMouseWheelEvent TranslateWebWheelEvent(
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const override;
// Translate CEF events to Chromium UI events.
virtual ui::KeyEvent TranslateUiKeyEvent(
const CefKeyEvent& key_event) const = 0;
virtual ui::MouseEvent TranslateUiClickEvent(
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const;
virtual ui::MouseEvent TranslateUiMoveEvent(const CefMouseEvent& mouse_event,
bool mouseLeave) const;
virtual ui::MouseWheelEvent TranslateUiWheelEvent(
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const;
virtual gfx::Vector2d GetUiWheelEventOffset(int deltaX, int deltaY) const;
virtual base::TimeTicks GetEventTimeStamp() const = 0;
protected:
static int TranslateUiEventModifiers(uint32 cef_modifiers);
static int TranslateUiChangedButtonFlags(uint32 cef_modifiers);
private:
content::RenderWidgetHostViewAura* GetHostView() const;
};
#endif // CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_AURA_H_

View File

@@ -46,10 +46,10 @@ CefBrowserPlatformDelegateNativeLinux::CefBrowserPlatformDelegateNativeLinux(
const CefWindowInfo& window_info,
SkColor background_color,
bool use_external_begin_frame)
: CefBrowserPlatformDelegateNative(window_info,
background_color,
false,
use_external_begin_frame),
: CefBrowserPlatformDelegateNativeAura(window_info,
background_color,
false,
use_external_begin_frame),
host_window_created_(false),
window_widget_(nullptr) {}
@@ -256,129 +256,6 @@ bool CefBrowserPlatformDelegateNativeLinux::HandleKeyboardEvent(
// static
void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {}
void CefBrowserPlatformDelegateNativeLinux::TranslateKeyEvent(
content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const {
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;
switch (key_event.type) {
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();
}
#if defined(USE_X11)
// Populate DOM values that will be passed to JavaScript handlers via
// KeyboardEvent.
result.dom_code = static_cast<int>(
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code));
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);
result.dom_key = static_cast<int>(ui::XKeySymToDomKey(keysym, ch));
result.text[0] = key_event.character;
result.unmodified_text[0] = key_event.unmodified_character;
result.SetModifiers(result.GetModifiers() |
TranslateModifiers(key_event.modifiers));
#endif // defined(USE_X11)
}
void CefBrowserPlatformDelegateNativeLinux::TranslateClickEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const {
TranslateMouseEvent(result, mouse_event);
switch (type) {
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();
}
result.click_count = clickCount;
}
void CefBrowserPlatformDelegateNativeLinux::TranslateMoveEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const {
TranslateMouseEvent(result, mouse_event);
if (!mouseLeave) {
result.SetType(blink::WebInputEvent::kMouseMove);
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kLeft;
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kMiddle;
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kRight;
else
result.button = blink::WebMouseEvent::Button::kNoButton;
} else {
result.SetType(blink::WebInputEvent::kMouseLeave);
result.button = blink::WebMouseEvent::Button::kNoButton;
}
result.click_count = 0;
}
void CefBrowserPlatformDelegateNativeLinux::TranslateWheelEvent(
blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const {
result = blink::WebMouseWheelEvent();
TranslateMouseEvent(result, mouse_event);
result.SetType(blink::WebInputEvent::kMouseWheel);
static const double scrollbarPixelsPerGtkTick = 40.0;
result.delta_x = deltaX;
result.delta_y = deltaY;
result.wheel_ticks_x = deltaX / scrollbarPixelsPerGtkTick;
result.wheel_ticks_y = deltaY / scrollbarPixelsPerGtkTick;
result.delta_units =
ui::input_types::ScrollGranularity::kScrollByPrecisePixel;
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kLeft;
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kMiddle;
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kRight;
else
result.button = blink::WebMouseEvent::Button::kNoButton;
}
CefEventHandle CefBrowserPlatformDelegateNativeLinux::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
if (!event.os_event)
@@ -392,27 +269,6 @@ CefBrowserPlatformDelegateNativeLinux::CreateMenuRunner() {
return base::WrapUnique(new CefMenuRunnerLinux);
}
void CefBrowserPlatformDelegateNativeLinux::TranslateMouseEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const {
// position
result.SetPositionInWidget(mouse_event.x, mouse_event.y);
const gfx::Point& screen_pt =
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y));
result.SetPositionInScreen(screen_pt.x(), screen_pt.y());
// modifiers
result.SetModifiers(result.GetModifiers() |
TranslateModifiers(mouse_event.modifiers));
// timestamp
result.SetTimeStamp(base::TimeTicks() +
base::TimeDelta::FromSeconds(GetSystemUptime()));
result.pointer_type = blink::WebPointerProperties::PointerType::kMouse;
}
gfx::Point CefBrowserPlatformDelegateNativeLinux::GetDialogPosition(
const gfx::Size& size) {
const gfx::Size& max_size = GetMaximumDialogSize();
@@ -423,3 +279,41 @@ gfx::Point CefBrowserPlatformDelegateNativeLinux::GetDialogPosition(
gfx::Size CefBrowserPlatformDelegateNativeLinux::GetMaximumDialogSize() {
return GetWindowWidget()->GetWindowBoundsInScreen().size();
}
ui::KeyEvent CefBrowserPlatformDelegateNativeLinux::TranslateUiKeyEvent(
const CefKeyEvent& key_event) const {
int flags = TranslateUiEventModifiers(key_event.modifiers);
ui::KeyboardCode key_code =
static_cast<ui::KeyboardCode>(key_event.windows_key_code);
ui::DomCode dom_code =
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code);
int keysym = ui::XKeysymForWindowsKeyCode(
key_code, !!(key_event.modifiers & EVENTFLAG_SHIFT_DOWN));
base::char16 character = ui::GetUnicodeCharacterFromXKeySym(keysym);
base::TimeTicks time_stamp = GetEventTimeStamp();
if (key_event.type == KEYEVENT_CHAR) {
return ui::KeyEvent(character, key_code, dom_code, flags, time_stamp);
}
ui::EventType type = ui::ET_UNKNOWN;
switch (key_event.type) {
case KEYEVENT_RAWKEYDOWN:
case KEYEVENT_KEYDOWN:
type = ui::ET_KEY_PRESSED;
break;
case KEYEVENT_KEYUP:
type = ui::ET_KEY_RELEASED;
break;
default:
NOTREACHED();
}
ui::DomKey dom_key = ui::XKeySymToDomKey(keysym, character);
return ui::KeyEvent(type, key_code, dom_code, flags, dom_key, time_stamp);
}
base::TimeTicks CefBrowserPlatformDelegateNativeLinux::GetEventTimeStamp()
const {
return base::TimeTicks() + base::TimeDelta::FromSeconds(GetSystemUptime());
}

View File

@@ -5,7 +5,7 @@
#ifndef CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_LINUX_H_
#define CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_LINUX_H_
#include "libcef/browser/native/browser_platform_delegate_native.h"
#include "libcef/browser/native/browser_platform_delegate_native_aura.h"
#if defined(USE_X11)
class CefWindowX11;
@@ -13,7 +13,7 @@ class CefWindowX11;
// Windowed browser implementation for Linux.
class CefBrowserPlatformDelegateNativeLinux
: public CefBrowserPlatformDelegateNative {
: public CefBrowserPlatformDelegateNativeAura {
public:
CefBrowserPlatformDelegateNativeLinux(const CefWindowInfo& window_info,
SkColor background_color,
@@ -32,30 +32,17 @@ class CefBrowserPlatformDelegateNativeLinux
void ViewText(const std::string& text) override;
bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) override;
void TranslateKeyEvent(content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const override;
void TranslateClickEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const override;
void TranslateMoveEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const override;
void TranslateWheelEvent(blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const override;
CefEventHandle GetEventHandle(
const content::NativeWebKeyboardEvent& event) const override;
std::unique_ptr<CefMenuRunner> CreateMenuRunner() override;
gfx::Point GetDialogPosition(const gfx::Size& size) override;
gfx::Size GetMaximumDialogSize() override;
private:
void TranslateMouseEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const;
// CefBrowserPlatformDelegateNativeAura methods:
ui::KeyEvent TranslateUiKeyEvent(const CefKeyEvent& key_event) const override;
base::TimeTicks GetEventTimeStamp() const override;
private:
// True if the host window has been created.
bool host_window_created_;

View File

@@ -7,6 +7,10 @@
#include "libcef/browser/native/browser_platform_delegate_native.h"
namespace content {
class RenderWidgetHostViewMac;
}
// Windowed browser implementation for Mac OS X.
class CefBrowserPlatformDelegateNativeMac
: public CefBrowserPlatformDelegateNative {
@@ -19,25 +23,21 @@ class CefBrowserPlatformDelegateNativeMac
bool CreateHostWindow() override;
void CloseHostWindow() override;
CefWindowHandle GetHostWindowHandle() const override;
void SendKeyEvent(const CefKeyEvent& event) override;
void SendMouseClickEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) override;
void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override;
void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) override;
void SendTouchEvent(const CefTouchEvent& event) override;
void SendFocusEvent(bool setFocus) override;
gfx::Point GetScreenPoint(const gfx::Point& view) const override;
void ViewText(const std::string& text) override;
bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) override;
void TranslateKeyEvent(content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const override;
void TranslateClickEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const override;
void TranslateMoveEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const override;
void TranslateWheelEvent(blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const override;
CefEventHandle GetEventHandle(
const content::NativeWebKeyboardEvent& event) const override;
std::unique_ptr<CefFileDialogRunner> CreateFileDialogRunner() override;
@@ -47,9 +47,26 @@ class CefBrowserPlatformDelegateNativeMac
gfx::Point GetDialogPosition(const gfx::Size& size) override;
gfx::Size GetMaximumDialogSize() override;
// CefBrowserPlatformDelegateNative methods:
content::NativeWebKeyboardEvent TranslateWebKeyEvent(
const CefKeyEvent& key_event) const override;
blink::WebMouseEvent TranslateWebClickEvent(
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const override;
blink::WebMouseEvent TranslateWebMoveEvent(const CefMouseEvent& mouse_event,
bool mouseLeave) const override;
blink::WebMouseWheelEvent TranslateWebWheelEvent(
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const override;
private:
void TranslateMouseEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const;
void TranslateWebMouseEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const;
content::RenderWidgetHostViewMac* GetHostView() const;
// True if the host window has been created.
bool host_window_created_;

View File

@@ -17,6 +17,7 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/ptr_util.h"
#include "base/threading/thread_restrictions.h"
#include "content/browser/renderer_host/render_widget_host_view_mac.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
@@ -25,6 +26,7 @@
#include "third_party/blink/public/platform/web_mouse_wheel_event.h"
#import "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
#include "ui/gfx/geometry/rect.h"
@@ -255,9 +257,61 @@ CefWindowHandle CefBrowserPlatformDelegateNativeMac::GetHostWindowHandle()
return window_info_.view;
}
void CefBrowserPlatformDelegateNativeMac::SendKeyEvent(
const CefKeyEvent& event) {
auto view = GetHostView();
if (!view)
return;
content::NativeWebKeyboardEvent web_event = TranslateWebKeyEvent(event);
view->ForwardKeyboardEvent(web_event, ui::LatencyInfo());
}
void CefBrowserPlatformDelegateNativeMac::SendMouseClickEvent(
const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) {
auto view = GetHostView();
if (!view)
return;
blink::WebMouseEvent web_event =
TranslateWebClickEvent(event, type, mouseUp, clickCount);
view->RouteOrProcessMouseEvent(web_event);
}
void CefBrowserPlatformDelegateNativeMac::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
auto view = GetHostView();
if (!view)
return;
blink::WebMouseEvent web_event = TranslateWebMoveEvent(event, mouseLeave);
view->RouteOrProcessMouseEvent(web_event);
}
void CefBrowserPlatformDelegateNativeMac::SendMouseWheelEvent(
const CefMouseEvent& event,
int deltaX,
int deltaY) {
auto view = GetHostView();
if (!view)
return;
blink::WebMouseWheelEvent web_event =
TranslateWebWheelEvent(event, deltaX, deltaY);
view->RouteOrProcessMouseEvent(web_event);
}
void CefBrowserPlatformDelegateNativeMac::SendTouchEvent(
const CefTouchEvent& event) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegateNativeMac::SendFocusEvent(bool setFocus) {
content::RenderWidgetHostView* view =
browser_->web_contents()->GetRenderWidgetHostView();
auto view = GetHostView();
if (view) {
view->SetActive(setFocus);
@@ -304,15 +358,51 @@ bool CefBrowserPlatformDelegateNativeMac::HandleKeyboardEvent(
// static
void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {}
void CefBrowserPlatformDelegateNativeMac::TranslateKeyEvent(
content::NativeWebKeyboardEvent& result,
CefEventHandle CefBrowserPlatformDelegateNativeMac::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
return event.os_event;
}
std::unique_ptr<CefFileDialogRunner>
CefBrowserPlatformDelegateNativeMac::CreateFileDialogRunner() {
return base::WrapUnique(new CefFileDialogRunnerMac);
}
std::unique_ptr<CefJavaScriptDialogRunner>
CefBrowserPlatformDelegateNativeMac::CreateJavaScriptDialogRunner() {
return base::WrapUnique(new CefJavaScriptDialogRunnerMac);
}
std::unique_ptr<CefMenuRunner>
CefBrowserPlatformDelegateNativeMac::CreateMenuRunner() {
return base::WrapUnique(new CefMenuRunnerMac);
}
gfx::Point CefBrowserPlatformDelegateNativeMac::GetDialogPosition(
const gfx::Size& size) {
// Dialogs are always re-positioned by the constrained window sheet controller
// so nothing interesting to return yet.
return gfx::Point();
}
gfx::Size CefBrowserPlatformDelegateNativeMac::GetMaximumDialogSize() {
// The dialog should try to fit within the overlay for the web contents.
// Note that, for things like print preview, this is just a suggested maximum.
return browser_->web_contents()->GetContainerBounds().size();
}
content::NativeWebKeyboardEvent
CefBrowserPlatformDelegateNativeMac::TranslateWebKeyEvent(
const CefKeyEvent& key_event) const {
content::NativeWebKeyboardEvent result(blink::WebInputEvent::kUndefined,
blink::WebInputEvent::kNoModifiers,
ui::EventTimeForNow());
// Use a synthetic NSEvent in order to obtain the windowsKeyCode member from
// the NativeWebKeyboardEvent constructor. This is the only member which can
// not be easily translated (without hardcoding keyCodes)
// Determining whether a modifier key is left or right seems to be done
// through the key code as well.
NSEventType event_type;
if (key_event.character == 0 && key_event.unmodified_character == 0) {
// Check if both character and unmodified_characther are empty to determine
@@ -357,15 +447,18 @@ void CefBrowserPlatformDelegateNativeMac::TranslateKeyEvent(
result.SetType(blink::WebInputEvent::kChar);
result.is_system_key = key_event.is_system_key;
return result;
}
void CefBrowserPlatformDelegateNativeMac::TranslateClickEvent(
blink::WebMouseEvent& result,
blink::WebMouseEvent
CefBrowserPlatformDelegateNativeMac::TranslateWebClickEvent(
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const {
TranslateMouseEvent(result, mouse_event);
blink::WebMouseEvent result;
TranslateWebMouseEvent(result, mouse_event);
switch (type) {
case MBT_LEFT:
@@ -388,13 +481,15 @@ void CefBrowserPlatformDelegateNativeMac::TranslateClickEvent(
}
result.click_count = clickCount;
return result;
}
void CefBrowserPlatformDelegateNativeMac::TranslateMoveEvent(
blink::WebMouseEvent& result,
blink::WebMouseEvent CefBrowserPlatformDelegateNativeMac::TranslateWebMoveEvent(
const CefMouseEvent& mouse_event,
bool mouseLeave) const {
TranslateMouseEvent(result, mouse_event);
blink::WebMouseEvent result;
TranslateWebMouseEvent(result, mouse_event);
if (!mouseLeave) {
result.SetType(blink::WebInputEvent::kMouseMove);
@@ -412,15 +507,17 @@ void CefBrowserPlatformDelegateNativeMac::TranslateMoveEvent(
}
result.click_count = 0;
return result;
}
void CefBrowserPlatformDelegateNativeMac::TranslateWheelEvent(
blink::WebMouseWheelEvent& result,
blink::WebMouseWheelEvent
CefBrowserPlatformDelegateNativeMac::TranslateWebWheelEvent(
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const {
result = blink::WebMouseWheelEvent();
TranslateMouseEvent(result, mouse_event);
blink::WebMouseWheelEvent result;
TranslateWebMouseEvent(result, mouse_event);
result.SetType(blink::WebInputEvent::kMouseWheel);
@@ -429,7 +526,8 @@ void CefBrowserPlatformDelegateNativeMac::TranslateWheelEvent(
result.delta_y = deltaY;
result.wheel_ticks_x = deltaX / scrollbarPixelsPerCocoaTick;
result.wheel_ticks_y = deltaY / scrollbarPixelsPerCocoaTick;
result.delta_units = ui::input_types::ScrollGranularity::kScrollByPrecisePixel;
result.delta_units =
ui::input_types::ScrollGranularity::kScrollByPrecisePixel;
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kLeft;
@@ -439,29 +537,11 @@ void CefBrowserPlatformDelegateNativeMac::TranslateWheelEvent(
result.button = blink::WebMouseEvent::Button::kRight;
else
result.button = blink::WebMouseEvent::Button::kNoButton;
return result;
}
CefEventHandle CefBrowserPlatformDelegateNativeMac::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
return event.os_event;
}
std::unique_ptr<CefFileDialogRunner>
CefBrowserPlatformDelegateNativeMac::CreateFileDialogRunner() {
return base::WrapUnique(new CefFileDialogRunnerMac);
}
std::unique_ptr<CefJavaScriptDialogRunner>
CefBrowserPlatformDelegateNativeMac::CreateJavaScriptDialogRunner() {
return base::WrapUnique(new CefJavaScriptDialogRunnerMac);
}
std::unique_ptr<CefMenuRunner>
CefBrowserPlatformDelegateNativeMac::CreateMenuRunner() {
return base::WrapUnique(new CefMenuRunnerMac);
}
void CefBrowserPlatformDelegateNativeMac::TranslateMouseEvent(
void CefBrowserPlatformDelegateNativeMac::TranslateWebMouseEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const {
// position
@@ -473,24 +553,17 @@ void CefBrowserPlatformDelegateNativeMac::TranslateMouseEvent(
// modifiers
result.SetModifiers(result.GetModifiers() |
TranslateModifiers(mouse_event.modifiers));
TranslateWebEventModifiers(mouse_event.modifiers));
// timestamp - Mac OSX specific
// timestamp
result.SetTimeStamp(base::TimeTicks() +
base::TimeDelta::FromSeconds(currentEventTimestamp()));
result.pointer_type = blink::WebPointerProperties::PointerType::kMouse;
}
gfx::Point CefBrowserPlatformDelegateNativeMac::GetDialogPosition(
const gfx::Size& size) {
// Dialogs are always re-positioned by the constrained window sheet controller
// so nothing interesting to return yet.
return gfx::Point();
}
gfx::Size CefBrowserPlatformDelegateNativeMac::GetMaximumDialogSize() {
// The dialog should try to fit within the overlay for the web contents.
// Note that, for things like print preview, this is just a suggested maximum.
return browser_->web_contents()->GetContainerBounds().size();
content::RenderWidgetHostViewMac*
CefBrowserPlatformDelegateNativeMac::GetHostView() const {
return static_cast<content::RenderWidgetHostViewMac*>(
browser_->web_contents()->GetRenderWidgetHostView());
}

View File

@@ -32,6 +32,7 @@
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/events/keycodes/platform_key_map_win.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/win/hwnd_util.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#include "ui/views/widget/widget.h"
@@ -128,10 +129,10 @@ CefBrowserPlatformDelegateNativeWin::CefBrowserPlatformDelegateNativeWin(
SkColor background_color,
bool use_shared_texture,
bool use_external_begin_frame)
: CefBrowserPlatformDelegateNative(window_info,
background_color,
use_shared_texture,
use_external_begin_frame),
: CefBrowserPlatformDelegateNativeAura(window_info,
background_color,
use_shared_texture,
use_external_begin_frame),
host_window_created_(false),
window_widget_(nullptr) {}
@@ -404,153 +405,6 @@ void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {
CEF_POST_USER_VISIBLE_TASK(base::Bind(ExecuteExternalProtocol, url));
}
void CefBrowserPlatformDelegateNativeWin::TranslateKeyEvent(
content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const {
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;
switch (key_event.type) {
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();
}
// Populate DOM values that will be passed to JavaScript handlers via
// KeyboardEvent.
result.dom_code = static_cast<int>(
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code));
if (result.GetType() == blink::WebInputEvent::kChar) {
result.dom_key = ui::DomKey::FromCharacter(key_event.windows_key_code);
} else {
// TODO(cef): CefKeyEvent does not currently pass extended key status (see
// WM_KEYDOWN docs) which would be necessary to pass EF_IS_EXTENDED_KEY as
// the |flags| parameter to DomKeyFromKeyboardCode().
int flags = 0;
result.dom_key = ui::PlatformKeyMap::DomKeyFromKeyboardCode(
ui::KeyboardCodeForWindowsKeyCode(key_event.windows_key_code), &flags);
}
if (result.GetType() == blink::WebInputEvent::kChar ||
result.GetType() == blink::WebInputEvent::kRawKeyDown) {
result.text[0] = result.windows_key_code;
result.unmodified_text[0] = result.windows_key_code;
}
result.SetModifiers(result.GetModifiers() |
TranslateModifiers(key_event.modifiers));
}
void CefBrowserPlatformDelegateNativeWin::TranslateClickEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const {
TranslateMouseEvent(result, mouse_event);
switch (type) {
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();
}
result.click_count = clickCount;
}
void CefBrowserPlatformDelegateNativeWin::TranslateMoveEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const {
TranslateMouseEvent(result, mouse_event);
if (!mouseLeave) {
result.SetType(blink::WebInputEvent::kMouseMove);
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kLeft;
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kMiddle;
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
result.button = blink::WebMouseEvent::Button::kRight;
else
result.button = blink::WebMouseEvent::Button::kNoButton;
} else {
result.SetType(blink::WebInputEvent::kMouseLeave);
result.button = blink::WebMouseEvent::Button::kNoButton;
}
result.click_count = 0;
}
void CefBrowserPlatformDelegateNativeWin::TranslateWheelEvent(
blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const {
TranslateMouseEvent(result, mouse_event);
result.SetType(blink::WebInputEvent::kMouseWheel);
result.button = blink::WebMouseEvent::Button::kNoButton;
float wheelDelta;
bool horizontalScroll = false;
wheelDelta = static_cast<float>(deltaY ? deltaY : deltaX);
horizontalScroll = (deltaY == 0);
static const ULONG defaultScrollCharsPerWheelDelta = 1;
static const FLOAT scrollbarPixelsPerLine = 100.0f / 3.0f;
static const ULONG defaultScrollLinesPerWheelDelta = 3;
wheelDelta /= WHEEL_DELTA;
float scrollDelta = wheelDelta;
if (horizontalScroll) {
ULONG scrollChars = defaultScrollCharsPerWheelDelta;
SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0);
scrollDelta *= static_cast<FLOAT>(scrollChars) * scrollbarPixelsPerLine;
} else {
ULONG scrollLines = defaultScrollLinesPerWheelDelta;
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
if (scrollLines == WHEEL_PAGESCROLL)
result.delta_units = ui::input_types::ScrollGranularity::kScrollByPage;
if (result.delta_units != ui::input_types::ScrollGranularity::kScrollByPage)
scrollDelta *= static_cast<FLOAT>(scrollLines) * scrollbarPixelsPerLine;
}
// Set scroll amount based on above calculations. WebKit expects positive
// deltaY to mean "scroll up" and positive deltaX to mean "scroll left".
if (horizontalScroll) {
result.delta_x = scrollDelta;
result.wheel_ticks_x = wheelDelta;
} else {
result.delta_y = scrollDelta;
result.wheel_ticks_y = wheelDelta;
}
}
CefEventHandle CefBrowserPlatformDelegateNativeWin::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
if (!event.os_event)
@@ -573,27 +427,6 @@ CefBrowserPlatformDelegateNativeWin::CreateMenuRunner() {
return base::WrapUnique(new CefMenuRunnerWin);
}
void CefBrowserPlatformDelegateNativeWin::TranslateMouseEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const {
// position
result.SetPositionInWidget(mouse_event.x, mouse_event.y);
const gfx::Point& screen_pt =
GetScreenPoint(gfx::Point(mouse_event.x, mouse_event.y));
result.SetPositionInScreen(screen_pt.x(), screen_pt.y());
// modifiers
result.SetModifiers(result.GetModifiers() |
TranslateModifiers(mouse_event.modifiers));
// timestamp
result.SetTimeStamp(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(GetMessageTime()));
result.pointer_type = blink::WebPointerProperties::PointerType::kMouse;
}
gfx::Point CefBrowserPlatformDelegateNativeWin::GetDialogPosition(
const gfx::Size& size) {
const gfx::Size& max_size = GetMaximumDialogSize();
@@ -605,6 +438,66 @@ gfx::Size CefBrowserPlatformDelegateNativeWin::GetMaximumDialogSize() {
return GetWindowWidget()->GetWindowBoundsInScreen().size();
}
ui::KeyEvent CefBrowserPlatformDelegateNativeWin::TranslateUiKeyEvent(
const CefKeyEvent& key_event) const {
int flags = TranslateUiEventModifiers(key_event.modifiers);
ui::KeyboardCode key_code =
ui::KeyboardCodeForWindowsKeyCode(key_event.windows_key_code);
ui::DomCode dom_code =
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code);
base::TimeTicks time_stamp = GetEventTimeStamp();
if (key_event.type == KEYEVENT_CHAR) {
return ui::KeyEvent(key_event.windows_key_code /* character */, key_code,
dom_code, flags, time_stamp);
}
ui::EventType type = ui::ET_UNKNOWN;
switch (key_event.type) {
case KEYEVENT_RAWKEYDOWN:
case KEYEVENT_KEYDOWN:
type = ui::ET_KEY_PRESSED;
break;
case KEYEVENT_KEYUP:
type = ui::ET_KEY_RELEASED;
break;
default:
NOTREACHED();
}
ui::DomKey dom_key =
ui::PlatformKeyMap::DomKeyFromKeyboardCode(key_code, &flags);
return ui::KeyEvent(type, key_code, dom_code, flags, dom_key, time_stamp);
}
gfx::Vector2d CefBrowserPlatformDelegateNativeWin::GetUiWheelEventOffset(
int deltaX,
int deltaY) const {
static const ULONG defaultScrollCharsPerWheelDelta = 1;
static const FLOAT scrollbarPixelsPerLine = 100.0f / 3.0f;
static const ULONG defaultScrollLinesPerWheelDelta = 3;
float wheelDeltaX = float(deltaX) / WHEEL_DELTA;
float wheelDeltaY = float(deltaY) / WHEEL_DELTA;
float scrollDeltaX = wheelDeltaX;
float scrollDeltaY = wheelDeltaY;
ULONG scrollChars = defaultScrollCharsPerWheelDelta;
SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0);
scrollDeltaX *= static_cast<FLOAT>(scrollChars) * scrollbarPixelsPerLine;
ULONG scrollLines = defaultScrollLinesPerWheelDelta;
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
scrollDeltaY *= static_cast<FLOAT>(scrollLines) * scrollbarPixelsPerLine;
return gfx::Vector2d(scrollDeltaX, scrollDeltaY);
}
base::TimeTicks CefBrowserPlatformDelegateNativeWin::GetEventTimeStamp() const {
return base::TimeTicks() +
base::TimeDelta::FromMilliseconds(GetMessageTime());
}
// static
void CefBrowserPlatformDelegateNativeWin::RegisterWindowClass() {
static bool registered = false;

View File

@@ -7,11 +7,11 @@
#include <windows.h>
#include "libcef/browser/native/browser_platform_delegate_native.h"
#include "libcef/browser/native/browser_platform_delegate_native_aura.h"
// Windowed browser implementation for Windows.
class CefBrowserPlatformDelegateNativeWin
: public CefBrowserPlatformDelegateNative {
: public CefBrowserPlatformDelegateNativeAura {
public:
CefBrowserPlatformDelegateNativeWin(const CefWindowInfo& window_info,
SkColor background_color,
@@ -31,20 +31,6 @@ class CefBrowserPlatformDelegateNativeWin
void ViewText(const std::string& text) override;
bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) override;
void TranslateKeyEvent(content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const override;
void TranslateClickEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) const override;
void TranslateMoveEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const override;
void TranslateWheelEvent(blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX,
int deltaY) const override;
CefEventHandle GetEventHandle(
const content::NativeWebKeyboardEvent& event) const override;
std::unique_ptr<CefFileDialogRunner> CreateFileDialogRunner() override;
@@ -54,10 +40,12 @@ class CefBrowserPlatformDelegateNativeWin
gfx::Point GetDialogPosition(const gfx::Size& size) override;
gfx::Size GetMaximumDialogSize() override;
private:
void TranslateMouseEvent(blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event) const;
// CefBrowserPlatformDelegateNativeAura methods:
ui::KeyEvent TranslateUiKeyEvent(const CefKeyEvent& key_event) const override;
gfx::Vector2d GetUiWheelEventOffset(int deltaX, int deltaY) const override;
base::TimeTicks GetEventTimeStamp() const override;
private:
static void RegisterWindowClass();
static LPCTSTR GetWndClass();
static LRESULT CALLBACK WndProc(HWND hwnd,