2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2015 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_mac.h"
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#import <CoreServices/CoreServices.h>
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
|
|
#include "libcef/browser/context.h"
|
|
|
|
#include "libcef/browser/native/file_dialog_runner_mac.h"
|
|
|
|
#include "libcef/browser/native/javascript_dialog_runner_mac.h"
|
|
|
|
#include "libcef/browser/native/menu_runner_mac.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/mac/scoped_nsautorelease_pool.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "base/threading/thread_restrictions.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"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_input_event.h"
|
|
|
|
#include "third_party/blink/public/platform/web_mouse_event.h"
|
|
|
|
#include "third_party/blink/public/platform/web_mouse_wheel_event.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#import "ui/base/cocoa/cocoa_base_utils.h"
|
|
|
|
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "ui/events/keycodes/keyboard_codes_posix.h"
|
|
|
|
#include "ui/gfx/geometry/rect.h"
|
|
|
|
|
|
|
|
// Wrapper NSView for the native view. Necessary to destroy the browser when
|
|
|
|
// the view is deleted.
|
|
|
|
@interface CefBrowserHostView : NSView {
|
|
|
|
@private
|
|
|
|
CefBrowserHostImpl* browser_; // weak
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
@property(nonatomic, assign) CefBrowserHostImpl* browser;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CefBrowserHostView
|
|
|
|
|
|
|
|
@synthesize browser = browser_;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (void)dealloc {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (browser_) {
|
|
|
|
// Force the browser to be destroyed and release the reference added in
|
|
|
|
// PlatformCreateWindow().
|
|
|
|
browser_->WindowDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Receives notifications from the browser window. Will delete itself when done.
|
2017-05-17 11:29:28 +02:00
|
|
|
@interface CefWindowDelegate : NSObject<NSWindowDelegate> {
|
2015-11-17 19:20:13 +01:00
|
|
|
@private
|
|
|
|
CefBrowserHostImpl* browser_; // weak
|
|
|
|
NSWindow* window_;
|
|
|
|
}
|
|
|
|
- (id)initWithWindow:(NSWindow*)window andBrowser:(CefBrowserHostImpl*)browser;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CefWindowDelegate
|
|
|
|
|
|
|
|
- (id)initWithWindow:(NSWindow*)window andBrowser:(CefBrowserHostImpl*)browser {
|
|
|
|
if (self = [super init]) {
|
|
|
|
window_ = window;
|
|
|
|
browser_ = browser;
|
|
|
|
|
|
|
|
[window_ setDelegate:self];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)window {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (browser_ && !browser_->TryCloseBrowser()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
// Cancel the close.
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean ourselves up after clearing the stack of anything that might have the
|
|
|
|
// window on it.
|
|
|
|
[self performSelectorOnMainThread:@selector(cleanup:)
|
|
|
|
withObject:window
|
|
|
|
waitUntilDone:NO];
|
|
|
|
|
|
|
|
// Allow the close.
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cleanup:(id)window {
|
|
|
|
[self release];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
NSTimeInterval currentEventTimestamp() {
|
|
|
|
NSEvent* currentEvent = [NSApp currentEvent];
|
|
|
|
if (currentEvent)
|
|
|
|
return [currentEvent timestamp];
|
|
|
|
else {
|
|
|
|
// FIXME(API): In case there is no current event, the timestamp could be
|
|
|
|
// obtained by getting the time since the application started. This involves
|
|
|
|
// taking some more static functions from Chromium code.
|
|
|
|
// Another option is to have the timestamp as a field in CefEvent structures
|
|
|
|
// and let the client provide it.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSUInteger NativeModifiers(int cef_modifiers) {
|
|
|
|
NSUInteger native_modifiers = 0;
|
|
|
|
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
|
|
|
|
native_modifiers |= NSShiftKeyMask;
|
|
|
|
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
|
|
|
|
native_modifiers |= NSControlKeyMask;
|
|
|
|
if (cef_modifiers & EVENTFLAG_ALT_DOWN)
|
|
|
|
native_modifiers |= NSAlternateKeyMask;
|
|
|
|
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
|
|
|
|
native_modifiers |= NSCommandKeyMask;
|
|
|
|
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
|
|
|
|
native_modifiers |= NSAlphaShiftKeyMask;
|
|
|
|
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
|
|
|
|
native_modifiers |= NSNumericPadKeyMask;
|
|
|
|
|
|
|
|
return native_modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefBrowserPlatformDelegateNativeMac::CefBrowserPlatformDelegateNativeMac(
|
2017-04-20 21:28:17 +02:00
|
|
|
const CefWindowInfo& window_info,
|
|
|
|
SkColor background_color)
|
|
|
|
: CefBrowserPlatformDelegateNative(window_info, background_color),
|
2017-05-17 11:29:28 +02:00
|
|
|
host_window_created_(false) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::BrowserDestroyed(
|
|
|
|
CefBrowserHostImpl* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
|
|
|
|
|
|
|
if (host_window_created_) {
|
|
|
|
// Release the reference added in CreateHostWindow().
|
|
|
|
browser->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateNativeMac::CreateHostWindow() {
|
|
|
|
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
|
|
|
|
|
|
|
NSWindow* newWnd = nil;
|
|
|
|
|
|
|
|
NSView* parentView = window_info_.parent_view;
|
|
|
|
NSRect contentRect = {{window_info_.x, window_info_.y},
|
|
|
|
{window_info_.width, window_info_.height}};
|
|
|
|
if (parentView == nil) {
|
|
|
|
// Create a new window.
|
|
|
|
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
2017-05-17 11:29:28 +02:00
|
|
|
NSRect window_rect = {
|
|
|
|
{window_info_.x, screen_rect.size.height - window_info_.y},
|
|
|
|
{window_info_.width, window_info_.height}};
|
2015-11-17 19:20:13 +01:00
|
|
|
if (window_rect.size.width == 0)
|
|
|
|
window_rect.size.width = 750;
|
|
|
|
if (window_rect.size.height == 0)
|
|
|
|
window_rect.size.height = 750;
|
|
|
|
|
|
|
|
contentRect.origin.x = 0;
|
|
|
|
contentRect.origin.y = 0;
|
|
|
|
contentRect.size.width = window_rect.size.width;
|
|
|
|
contentRect.size.height = window_rect.size.height;
|
|
|
|
|
|
|
|
newWnd = [[UnderlayOpenGLHostingWindow alloc]
|
2017-05-17 11:29:28 +02:00
|
|
|
initWithContentRect:window_rect
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask |
|
|
|
|
NSResizableWindowMask |
|
|
|
|
NSUnifiedTitleAndToolbarWindowMask)
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Create the delegate for control and browser window events.
|
|
|
|
[[CefWindowDelegate alloc] initWithWindow:newWnd andBrowser:browser_];
|
|
|
|
|
|
|
|
parentView = [newWnd contentView];
|
|
|
|
window_info_.parent_view = parentView;
|
|
|
|
|
2016-06-09 20:48:38 +02:00
|
|
|
// Make the content view for the window have a layer. This will make all
|
|
|
|
// sub-views have layers. This is necessary to ensure correct layer
|
|
|
|
// ordering of all child views and their layers.
|
|
|
|
[parentView setWantsLayer:YES];
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
host_window_created_ = true;
|
|
|
|
|
|
|
|
// Add a reference that will be released in BrowserDestroyed().
|
|
|
|
browser_->AddRef();
|
|
|
|
|
|
|
|
// Create the browser view.
|
|
|
|
CefBrowserHostView* browser_view =
|
|
|
|
[[CefBrowserHostView alloc] initWithFrame:contentRect];
|
|
|
|
browser_view.browser = browser_;
|
|
|
|
[parentView addSubview:browser_view];
|
|
|
|
[browser_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
|
|
|
|
[browser_view setNeedsDisplay:YES];
|
|
|
|
[browser_view release];
|
|
|
|
|
|
|
|
// Parent the TabContents to the browser view.
|
|
|
|
const NSRect bounds = [browser_view bounds];
|
|
|
|
NSView* native_view = browser_->web_contents()->GetNativeView();
|
|
|
|
[browser_view addSubview:native_view];
|
|
|
|
[native_view setFrame:bounds];
|
|
|
|
[native_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
|
|
|
|
[native_view setNeedsDisplay:YES];
|
|
|
|
|
|
|
|
window_info_.view = browser_view;
|
|
|
|
|
|
|
|
if (newWnd != nil && !window_info_.hidden) {
|
|
|
|
// Show the window.
|
2017-05-17 11:29:28 +02:00
|
|
|
[newWnd makeKeyAndOrderFront:nil];
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::CloseHostWindow() {
|
|
|
|
if (window_info_.view != nil) {
|
|
|
|
[[window_info_.view window]
|
|
|
|
performSelectorOnMainThread:@selector(performClose:)
|
|
|
|
withObject:nil
|
|
|
|
waitUntilDone:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateNativeMac::GetHostWindowHandle()
|
|
|
|
const {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (windowless_handler_)
|
|
|
|
return windowless_handler_->GetParentWindowHandle();
|
|
|
|
return window_info_.view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::SendFocusEvent(bool setFocus) {
|
|
|
|
content::RenderWidgetHostView* view =
|
|
|
|
browser_->web_contents()->GetRenderWidgetHostView();
|
|
|
|
if (view) {
|
|
|
|
view->SetActive(setFocus);
|
|
|
|
|
|
|
|
if (setFocus) {
|
|
|
|
// Give keyboard focus to the native view.
|
|
|
|
NSView* view = browser_->web_contents()->GetContentNativeView();
|
|
|
|
DCHECK([view canBecomeKeyView]);
|
|
|
|
[[view window] makeFirstResponder:view];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateNativeMac::GetScreenPoint(
|
|
|
|
const gfx::Point& view) const {
|
|
|
|
if (windowless_handler_)
|
|
|
|
return windowless_handler_->GetParentScreenPoint(view);
|
|
|
|
|
|
|
|
NSView* nsview = window_info_.parent_view;
|
|
|
|
if (nsview) {
|
|
|
|
NSRect bounds = [nsview bounds];
|
|
|
|
NSPoint view_pt = {view.x(), bounds.size.height - view.y()};
|
|
|
|
NSPoint window_pt = [nsview convertPoint:view_pt toView:nil];
|
2016-04-27 22:38:52 +02:00
|
|
|
NSPoint screen_pt =
|
|
|
|
ui::ConvertPointFromWindowToScreen([nsview window], window_pt);
|
2015-11-17 19:20:13 +01:00
|
|
|
return gfx::Point(screen_pt.x, screen_pt.y);
|
|
|
|
}
|
|
|
|
return gfx::Point();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::ViewText(const std::string& text) {
|
|
|
|
// TODO(cef): Implement this functionality.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::HandleKeyboardEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
// Give the top level menu equivalents a chance to handle the event.
|
|
|
|
if ([event.os_event type] == NSKeyDown)
|
|
|
|
[[NSApp mainMenu] performKeyEquivalent:event.os_event];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::HandleExternalProtocol(
|
2017-05-17 11:29:28 +02:00
|
|
|
const GURL& url) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::TranslateKeyEvent(
|
|
|
|
content::NativeWebKeyboardEvent& result,
|
|
|
|
const CefKeyEvent& key_event) const {
|
|
|
|
// 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
|
|
|
|
// if this was a NSFlagsChanged event.
|
|
|
|
// A dead key will have an empty character, but a non-empty unmodified
|
|
|
|
// character
|
|
|
|
event_type = NSFlagsChanged;
|
|
|
|
} else {
|
|
|
|
switch (key_event.type) {
|
|
|
|
case KEYEVENT_RAWKEYDOWN:
|
|
|
|
case KEYEVENT_KEYDOWN:
|
|
|
|
case KEYEVENT_CHAR:
|
|
|
|
event_type = NSKeyDown;
|
|
|
|
break;
|
|
|
|
case KEYEVENT_KEYUP:
|
|
|
|
event_type = NSKeyUp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
NSString* charactersIgnoringModifiers =
|
|
|
|
[[[NSString alloc] initWithCharacters:&key_event.unmodified_character
|
|
|
|
length:1] autorelease];
|
|
|
|
NSString* characters =
|
|
|
|
[[[NSString alloc] initWithCharacters:&key_event.character length:1]
|
|
|
|
autorelease];
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
NSEvent* synthetic_event =
|
2017-05-17 11:29:28 +02:00
|
|
|
[NSEvent keyEventWithType:event_type
|
|
|
|
location:NSMakePoint(0, 0)
|
|
|
|
modifierFlags:NativeModifiers(key_event.modifiers)
|
|
|
|
timestamp:currentEventTimestamp()
|
|
|
|
windowNumber:0
|
|
|
|
context:nil
|
|
|
|
characters:characters
|
|
|
|
charactersIgnoringModifiers:charactersIgnoringModifiers
|
|
|
|
isARepeat:NO
|
|
|
|
keyCode:key_event.native_key_code];
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
result = content::NativeWebKeyboardEvent(synthetic_event);
|
|
|
|
if (key_event.type == KEYEVENT_CHAR)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kChar);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.is_system_key = key_event.is_system_key;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::TranslateClickEvent(
|
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
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);
|
|
|
|
|
|
|
|
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();
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.click_count = clickCount;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::TranslateMoveEvent(
|
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
bool mouseLeave) const {
|
|
|
|
TranslateMouseEvent(result, mouse_event);
|
|
|
|
|
|
|
|
if (!mouseLeave) {
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseMove);
|
2015-11-17 19:20:13 +01:00
|
|
|
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kLeft;
|
2015-11-17 19:20:13 +01:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kMiddle;
|
2015-11-17 19:20:13 +01:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kRight;
|
2015-11-17 19:20:13 +01:00
|
|
|
else
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseLeave);
|
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.click_count = 0;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::TranslateWheelEvent(
|
|
|
|
blink::WebMouseWheelEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
2017-05-17 11:29:28 +02:00
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
2015-11-17 19:20:13 +01:00
|
|
|
result = blink::WebMouseWheelEvent();
|
|
|
|
TranslateMouseEvent(result, mouse_event);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
result.SetType(blink::WebInputEvent::kMouseWheel);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
static const double scrollbarPixelsPerCocoaTick = 40.0;
|
2017-09-13 18:47:43 +02:00
|
|
|
result.delta_x = deltaX;
|
2017-04-20 21:28:17 +02:00
|
|
|
result.delta_y = deltaY;
|
|
|
|
result.wheel_ticks_x = deltaX / scrollbarPixelsPerCocoaTick;
|
|
|
|
result.wheel_ticks_y = deltaY / scrollbarPixelsPerCocoaTick;
|
|
|
|
result.has_precise_scrolling_deltas = true;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kLeft;
|
2015-11-17 19:20:13 +01:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kMiddle;
|
2015-11-17 19:20:13 +01:00
|
|
|
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kRight;
|
2015-11-17 19:20:13 +01:00
|
|
|
else
|
2017-04-20 21:28:17 +02:00
|
|
|
result.button = blink::WebMouseEvent::Button::kNoButton;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefEventHandle CefBrowserPlatformDelegateNativeMac::GetEventHandle(
|
|
|
|
const content::NativeWebKeyboardEvent& event) const {
|
|
|
|
return event.os_event;
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefFileDialogRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateNativeMac::CreateFileDialogRunner() {
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new CefFileDialogRunnerMac);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefJavaScriptDialogRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateNativeMac::CreateJavaScriptDialogRunner() {
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new CefJavaScriptDialogRunnerMac);
|
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
|
|
|
CefBrowserPlatformDelegateNativeMac::CreateMenuRunner() {
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new CefMenuRunnerMac);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateNativeMac::TranslateMouseEvent(
|
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event) const {
|
|
|
|
// 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());
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// modifiers
|
2017-05-17 11:29:28 +02:00
|
|
|
result.SetModifiers(result.GetModifiers() |
|
|
|
|
TranslateModifiers(mouse_event.modifiers));
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// timestamp - Mac OSX specific
|
2018-05-17 10:58:21 +02:00
|
|
|
result.SetTimeStamp(base::TimeTicks() +
|
|
|
|
base::TimeDelta::FromSeconds(currentEventTimestamp()));
|
2018-02-22 18:09:28 +01:00
|
|
|
|
|
|
|
result.pointer_type = blink::WebPointerProperties::PointerType::kMouse;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|