2015-01-30 19:07:13 +01:00
|
|
|
// Copyright (c) 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.
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/browser_window_osr_mac.h"
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#import <AppKit/NSAccessibility.h>
|
2015-01-30 19:07:13 +01:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2014-07-01 00:30:29 +02:00
|
|
|
#include <OpenGL/gl.h>
|
2017-05-17 11:29:28 +02:00
|
|
|
#import <objc/runtime.h>
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
#include "include/base/cef_logging.h"
|
2015-04-09 16:59:34 +02:00
|
|
|
#include "include/cef_parser.h"
|
2015-01-30 19:07:13 +01:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/bytes_write_handler.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "tests/cefclient/browser/osr_accessibility_helper.h"
|
|
|
|
#include "tests/cefclient/browser/osr_accessibility_node.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/text_input_client_osr_mac.h"
|
|
|
|
#include "tests/shared/browser/geometry_util.h"
|
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2016-10-28 18:11:24 +02:00
|
|
|
|
2023-07-24 18:57:37 +02:00
|
|
|
// Begin disable NSOpenGL deprecation warnings.
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
@interface BrowserOpenGLView
|
2019-02-25 22:17:28 +01:00
|
|
|
: NSOpenGLView <NSDraggingSource, NSDraggingDestination, NSAccessibility> {
|
2015-01-30 19:07:13 +01:00
|
|
|
@private
|
|
|
|
NSTrackingArea* tracking_area_;
|
|
|
|
client::BrowserWindowOsrMac* browser_window_;
|
|
|
|
client::OsrRenderer* renderer_;
|
|
|
|
NSPoint last_mouse_pos_;
|
|
|
|
NSPoint cur_mouse_pos_;
|
|
|
|
bool rotating_;
|
|
|
|
|
|
|
|
bool was_last_mouse_down_on_view_;
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
float device_scale_factor_;
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
// Drag and drop.
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefDragData> current_drag_data_;
|
|
|
|
NSDragOperation current_drag_op_;
|
|
|
|
NSDragOperation current_allowed_ops_;
|
|
|
|
NSPasteboard* pasteboard_;
|
2019-04-23 19:17:56 +02:00
|
|
|
NSString* fileUTI_;
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
// For intreacting with IME.
|
|
|
|
NSTextInputContext* text_input_context_osr_mac_;
|
2019-04-23 19:17:56 +02:00
|
|
|
CefTextInputClientOSRMac* text_input_client_;
|
2016-10-28 18:11:24 +02:00
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
// Manages Accessibility Tree
|
|
|
|
client::OsrAccessibilityHelper* accessibility_helper_;
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
// Event monitor for scroll wheel end event.
|
|
|
|
id endWheelMonitor_;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
@end // @interface BrowserOpenGLView
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2014-12-02 12:23:57 +01:00
|
|
|
namespace {
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
NSString* const kCEFDragDummyPboardType = @"org.CEF.drag-dummy-type";
|
|
|
|
NSString* const kNSURLTitlePboardType = @"public.url-name";
|
|
|
|
|
2014-12-02 12:23:57 +01:00
|
|
|
class ScopedGLContext {
|
|
|
|
public:
|
2015-01-30 19:07:13 +01:00
|
|
|
ScopedGLContext(BrowserOpenGLView* view, bool swap_buffers)
|
2017-05-17 11:29:28 +02:00
|
|
|
: swap_buffers_(swap_buffers) {
|
2014-12-02 12:23:57 +01:00
|
|
|
context_ = [view openGLContext];
|
|
|
|
[context_ makeCurrentContext];
|
|
|
|
}
|
|
|
|
~ScopedGLContext() {
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (swap_buffers_) {
|
2014-12-02 12:23:57 +01:00
|
|
|
[context_ flushBuffer];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-12-02 12:23:57 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2024-03-08 13:44:56 +01:00
|
|
|
NSOpenGLContext* context() const { return context_; }
|
|
|
|
|
2014-12-02 12:23:57 +01:00
|
|
|
private:
|
|
|
|
NSOpenGLContext* context_;
|
|
|
|
const bool swap_buffers_;
|
|
|
|
};
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
|
|
|
|
NSRect point_rect = NSMakeRect(point.x, point.y, 0, 0);
|
|
|
|
return [window convertRectToScreen:point_rect].origin;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
} // namespace
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
@implementation BrowserOpenGLView
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (id)initWithFrame:(NSRect)frame
|
2017-05-17 11:29:28 +02:00
|
|
|
andBrowserWindow:(client::BrowserWindowOsrMac*)browser_window
|
|
|
|
andRenderer:(client::OsrRenderer*)renderer {
|
|
|
|
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes:(NSOpenGLPixelFormatAttribute[]){
|
|
|
|
NSOpenGLPFADoubleBuffer, NSOpenGLPFADepthSize, 32,
|
|
|
|
0}];
|
2019-04-23 19:17:56 +02:00
|
|
|
#if !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
[pixelFormat autorelease];
|
2019-04-23 19:17:56 +02:00
|
|
|
#endif // !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
if (self = [super initWithFrame:frame pixelFormat:pixelFormat]) {
|
|
|
|
browser_window_ = browser_window;
|
|
|
|
renderer_ = renderer;
|
2014-07-01 00:30:29 +02:00
|
|
|
rotating_ = false;
|
|
|
|
endWheelMonitor_ = nil;
|
2015-08-10 22:49:45 +02:00
|
|
|
device_scale_factor_ = 1.0f;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
tracking_area_ = [[NSTrackingArea alloc]
|
|
|
|
initWithRect:frame
|
|
|
|
options:NSTrackingMouseMoved | NSTrackingActiveInActiveApp |
|
|
|
|
NSTrackingInVisibleRect
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
2014-07-01 00:30:29 +02:00
|
|
|
[self addTrackingArea:tracking_area_];
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
// enable HiDPI buffer
|
|
|
|
[self setWantsBestResolutionOpenGLSurface:YES];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
[self resetDragDrop];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2023-07-24 18:57:37 +02:00
|
|
|
NSArray* types = [NSArray arrayWithObjects:kCEFDragDummyPboardType,
|
|
|
|
NSPasteboardTypeFileURL,
|
|
|
|
NSPasteboardTypeString, nil];
|
2015-01-30 19:07:13 +01:00
|
|
|
[self registerForDraggedTypes:types];
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2016-04-29 18:42:09 +02:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
removeObserver:self
|
|
|
|
name:NSWindowDidChangeBackingPropertiesNotification
|
|
|
|
object:nil];
|
2019-04-23 19:17:56 +02:00
|
|
|
#if !__has_feature(objc_arc)
|
2017-04-26 21:05:12 +02:00
|
|
|
if (text_input_context_osr_mac_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[text_input_client_ release];
|
2017-04-26 21:05:12 +02:00
|
|
|
[text_input_context_osr_mac_ release];
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
[super dealloc];
|
2019-04-23 19:17:56 +02:00
|
|
|
#endif // !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)detach {
|
2021-06-17 22:08:01 +02:00
|
|
|
renderer_ = nullptr;
|
|
|
|
browser_window_ = nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (text_input_client_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[text_input_client_ detach];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
- (CefRefPtr<CefBrowser>)getBrowser {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_window_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return browser_window_->GetBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-06-17 22:08:01 +02:00
|
|
|
return nullptr;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFrame:(NSRect)frameRect {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
[super setFrame:frameRect];
|
|
|
|
browser->GetHost()->WasResized();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (void)sendMouseClick:(NSEvent*)event
|
|
|
|
button:(CefBrowserHost::MouseButtonType)type
|
|
|
|
isUp:(bool)isUp {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
CefMouseEvent mouseEvent;
|
2015-08-10 22:49:45 +02:00
|
|
|
[self getMouseEvent:mouseEvent forEvent:event];
|
|
|
|
|
|
|
|
// |point| is in OS X view coordinates.
|
2014-07-01 00:30:29 +02:00
|
|
|
NSPoint point = [self getClickPointForEvent:event];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Convert to device coordinates.
|
|
|
|
point = [self convertPointToBackingInternal:point];
|
|
|
|
|
|
|
|
if (!isUp) {
|
2019-02-25 22:17:28 +01:00
|
|
|
was_last_mouse_down_on_view_ = ![self isOverPopupWidgetX:point.x
|
|
|
|
andY:point.y];
|
2015-08-10 22:49:45 +02:00
|
|
|
} else if (was_last_mouse_down_on_view_ &&
|
|
|
|
[self isOverPopupWidgetX:point.x andY:point.y] &&
|
|
|
|
([self getPopupXOffset] || [self getPopupYOffset])) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
browser->GetHost()->SendMouseClickEvent(mouseEvent, type, isUp,
|
2023-01-04 20:23:52 +01:00
|
|
|
static_cast<int>([event clickCount]));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseDown:(NSEvent*)event {
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_LEFT isUp:false];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)rightMouseDown:(NSEvent*)event {
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event modifierFlags] & NSEventModifierFlagShift) {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Start rotation effect.
|
|
|
|
last_mouse_pos_ = cur_mouse_pos_ = [self getClickPointForEvent:event];
|
|
|
|
rotating_ = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_RIGHT isUp:false];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)otherMouseDown:(NSEvent*)event {
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_MIDDLE isUp:false];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseUp:(NSEvent*)event {
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_LEFT isUp:true];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)rightMouseUp:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (rotating_) {
|
|
|
|
// End rotation effect.
|
|
|
|
renderer_->SetSpin(0, 0);
|
|
|
|
rotating_ = false;
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
return;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_RIGHT isUp:true];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)otherMouseUp:(NSEvent*)event {
|
2017-05-17 11:29:28 +02:00
|
|
|
[self sendMouseClick:event button:MBT_MIDDLE isUp:true];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseMoved:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
if (rotating_) {
|
|
|
|
// Apply rotation effect.
|
2017-05-17 11:29:28 +02:00
|
|
|
cur_mouse_pos_ = [self getClickPointForEvent:event];
|
|
|
|
;
|
2014-07-01 00:30:29 +02:00
|
|
|
renderer_->IncrementSpin((cur_mouse_pos_.x - last_mouse_pos_.x),
|
|
|
|
(cur_mouse_pos_.y - last_mouse_pos_.y));
|
|
|
|
last_mouse_pos_ = cur_mouse_pos_;
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefMouseEvent mouseEvent;
|
2015-08-10 22:49:45 +02:00
|
|
|
[self getMouseEvent:mouseEvent forEvent:event];
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetHost()->SendMouseMoveEvent(mouseEvent, false);
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseDragged:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)rightMouseDragged:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)otherMouseDragged:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseEntered:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)mouseExited:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
CefMouseEvent mouseEvent;
|
2015-08-10 22:49:45 +02:00
|
|
|
[self getMouseEvent:mouseEvent forEvent:event];
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetHost()->SendMouseMoveEvent(mouseEvent, true);
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)keyDown:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get() || !text_input_context_osr_mac_) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event type] != NSEventTypeFlagsChanged) {
|
2019-04-23 19:17:56 +02:00
|
|
|
if (text_input_client_) {
|
|
|
|
[text_input_client_ HandleKeyEventBeforeTextInputClient:event];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
// The return value of this method seems to always be set to YES, thus we
|
|
|
|
// ignore it and ask the host view whether IME is active or not.
|
|
|
|
[text_input_context_osr_mac_ handleEvent:event];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
CefKeyEvent keyEvent;
|
|
|
|
[self getKeyEvent:keyEvent forEvent:event];
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
[text_input_client_ HandleKeyEventAfterTextInputClient:keyEvent];
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
|
|
|
|
// Check for Caps lock and Toggle Touch Emulation
|
2023-01-02 23:59:03 +01:00
|
|
|
if (client::MainContext::Get()->TouchEventsEnabled()) {
|
2019-02-25 22:17:28 +01:00
|
|
|
[self toggleTouchEmulation:event];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OSX does not have touch screens, so we emulate it by mapping multitouch
|
|
|
|
// events on TrackPad to Touch Events on Screen. To ensure it does not
|
|
|
|
// interfere with other Trackpad events, this mapping is only enabled if
|
|
|
|
// touch-events=enabled commandline is passed and caps lock key is on.
|
|
|
|
- (void)toggleTouchEmulation:(NSEvent*)event {
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event type] == NSEventTypeFlagsChanged && [event keyCode] == 0x39) {
|
2019-02-25 22:17:28 +01:00
|
|
|
NSUInteger flags = [event modifierFlags];
|
2022-06-17 15:28:55 +02:00
|
|
|
BOOL touch_enabled = flags & NSEventModifierFlagCapsLock ? YES : NO;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (touch_enabled) {
|
2022-06-17 15:28:55 +02:00
|
|
|
self.allowedTouchTypes |= NSTouchTypeMaskDirect;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2022-06-17 15:28:55 +02:00
|
|
|
self.allowedTouchTypes &= ~NSTouchTypeMaskDirect;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (cef_touch_event_type_t)getTouchPhase:(NSTouchPhase)phase {
|
|
|
|
cef_touch_event_type_t event_type = CEF_TET_RELEASED;
|
|
|
|
switch (phase) {
|
|
|
|
case NSTouchPhaseBegan:
|
|
|
|
event_type = CEF_TET_PRESSED;
|
|
|
|
break;
|
|
|
|
case NSTouchPhaseMoved:
|
|
|
|
event_type = CEF_TET_MOVED;
|
|
|
|
break;
|
|
|
|
case NSTouchPhaseEnded:
|
|
|
|
event_type = CEF_TET_RELEASED;
|
|
|
|
break;
|
|
|
|
case NSTouchPhaseCancelled:
|
|
|
|
event_type = CEF_TET_CANCELLED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return event_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translate NSTouch events to CefTouchEvents and send to browser.
|
|
|
|
- (void)sendTouchEvent:(NSEvent*)event touchPhase:(NSTouchPhase)phase {
|
|
|
|
int modifiers = [self getModifiersForEvent:event];
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
|
|
|
|
|
|
|
NSSet* touches = [event touchesMatchingPhase:phase inView:self];
|
|
|
|
|
|
|
|
for (NSTouch* touch in touches) {
|
|
|
|
// Convert NSTouch to CefTouchEvent.
|
|
|
|
CefTouchEvent touch_event;
|
|
|
|
|
|
|
|
// NSTouch.identity is unique during the life of the touch
|
2023-01-04 20:23:52 +01:00
|
|
|
touch_event.id = static_cast<int>(touch.identity.hash);
|
2019-02-25 22:17:28 +01:00
|
|
|
touch_event.type = [self getTouchPhase:phase];
|
|
|
|
|
|
|
|
NSPoint scaled_pos = [touch normalizedPosition];
|
|
|
|
NSSize view_size = [self bounds].size;
|
|
|
|
|
|
|
|
// Map point on Touch Device to View coordinates.
|
|
|
|
NSPoint touch_point = NSMakePoint(scaled_pos.x * view_size.width,
|
|
|
|
scaled_pos.y * view_size.height);
|
|
|
|
|
|
|
|
NSPoint contentLocal = [self convertPoint:touch_point fromView:nil];
|
|
|
|
NSPoint point;
|
|
|
|
point.x = contentLocal.x;
|
|
|
|
point.y = [self frame].size.height - contentLocal.y; // Flip y.
|
|
|
|
|
|
|
|
// Convert to device coordinates.
|
|
|
|
point = [self convertPointToBackingInternal:point];
|
|
|
|
|
|
|
|
int device_x = point.x;
|
|
|
|
int device_y = point.y;
|
|
|
|
|
|
|
|
const float device_scale_factor = [self getDeviceScaleFactor];
|
|
|
|
// Convert to browser view coordinates.
|
|
|
|
touch_event.x = client::DeviceToLogical(device_x, device_scale_factor);
|
|
|
|
touch_event.y = client::DeviceToLogical(device_y, device_scale_factor);
|
|
|
|
|
|
|
|
touch_event.radius_x = 0;
|
|
|
|
touch_event.radius_y = 0;
|
|
|
|
|
|
|
|
touch_event.rotation_angle = 0;
|
|
|
|
touch_event.pressure = 0;
|
|
|
|
|
|
|
|
touch_event.modifiers = modifiers;
|
|
|
|
|
|
|
|
// Notify the browser of touch event.
|
|
|
|
browser->GetHost()->SendTouchEvent(touch_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesBeganWithEvent:(NSEvent*)event {
|
|
|
|
[self sendTouchEvent:event touchPhase:NSTouchPhaseBegan];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesMovedWithEvent:(NSEvent*)event {
|
|
|
|
[self sendTouchEvent:event touchPhase:NSTouchPhaseMoved];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesEndedWithEvent:(NSEvent*)event {
|
|
|
|
[self sendTouchEvent:event touchPhase:NSTouchPhaseEnded];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesCancelledWithEvent:(NSEvent*)event {
|
|
|
|
[self sendTouchEvent:event touchPhase:NSTouchPhaseCancelled];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)keyUp:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
CefKeyEvent keyEvent;
|
|
|
|
[self getKeyEvent:keyEvent forEvent:event];
|
|
|
|
|
|
|
|
keyEvent.type = KEYEVENT_KEYUP;
|
|
|
|
browser->GetHost()->SendKeyEvent(keyEvent);
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)flagsChanged:(NSEvent*)event {
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([self isKeyUpEvent:event]) {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self keyUp:event];
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2014-07-01 00:30:29 +02:00
|
|
|
[self keyDown:event];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)shortCircuitScrollWheelEvent:(NSEvent*)event {
|
|
|
|
if ([event phase] != NSEventPhaseEnded &&
|
2023-01-02 23:59:03 +01:00
|
|
|
[event phase] != NSEventPhaseCancelled) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
[self sendScrollWheelEvet:event];
|
|
|
|
|
|
|
|
if (endWheelMonitor_) {
|
|
|
|
[NSEvent removeMonitor:endWheelMonitor_];
|
|
|
|
endWheelMonitor_ = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)scrollWheel:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Use an NSEvent monitor to listen for the wheel-end end. This ensures that
|
|
|
|
// the event is received even when the mouse cursor is no longer over the
|
|
|
|
// view when the scrolling ends. Also it avoids sending duplicate scroll
|
|
|
|
// events to the renderer.
|
2016-04-27 22:38:52 +02:00
|
|
|
if ([event phase] == NSEventPhaseBegan && !endWheelMonitor_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
endWheelMonitor_ = [NSEvent
|
2022-06-17 15:28:55 +02:00
|
|
|
addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel
|
2017-05-17 11:29:28 +02:00
|
|
|
handler:^(NSEvent* blockEvent) {
|
|
|
|
[self shortCircuitScrollWheelEvent:
|
|
|
|
blockEvent];
|
|
|
|
return blockEvent;
|
|
|
|
}];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[self sendScrollWheelEvet:event];
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)sendScrollWheelEvet:(NSEvent*)event {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
CGEventRef cgEvent = [event CGEvent];
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(cgEvent);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2023-01-04 20:23:52 +01:00
|
|
|
int deltaX = static_cast<int>(
|
|
|
|
CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis2));
|
|
|
|
int deltaY = static_cast<int>(
|
|
|
|
CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1));
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
CefMouseEvent mouseEvent;
|
2015-08-10 22:49:45 +02:00
|
|
|
[self getMouseEvent:mouseEvent forEvent:event];
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetHost()->SendMouseWheelEvent(mouseEvent, deltaX, deltaY);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyView {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2021-06-17 22:08:01 +02:00
|
|
|
return (browser.get() != nullptr);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2021-06-17 22:08:01 +02:00
|
|
|
return (browser.get() != nullptr);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)becomeFirstResponder {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2015-01-30 19:07:13 +01:00
|
|
|
if (browser.get()) {
|
2021-09-27 09:50:07 +02:00
|
|
|
browser->GetHost()->SetFocus(true);
|
2014-07-01 00:30:29 +02:00
|
|
|
return [super becomeFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)resignFirstResponder {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2015-01-30 19:07:13 +01:00
|
|
|
if (browser.get()) {
|
2021-09-27 09:50:07 +02:00
|
|
|
browser->GetHost()->SetFocus(false);
|
2014-07-01 00:30:29 +02:00
|
|
|
return [super resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)undo:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Undo();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)redo:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Redo();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cut:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Cut();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)copy:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Copy();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)paste:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Paste();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
- (void)delete:(id)sender {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->Delete();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectAll:(id)sender {
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser->GetFocusedFrame()->SelectAll();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPoint)getClickPointForEvent:(NSEvent*)event {
|
|
|
|
NSPoint windowLocal = [event locationInWindow];
|
|
|
|
NSPoint contentLocal = [self convertPoint:windowLocal fromView:nil];
|
|
|
|
|
|
|
|
NSPoint point;
|
|
|
|
point.x = contentLocal.x;
|
|
|
|
point.y = [self frame].size.height - contentLocal.y; // Flip y.
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (void)getKeyEvent:(CefKeyEvent&)keyEvent forEvent:(NSEvent*)event {
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event type] == NSEventTypeKeyDown || [event type] == NSEventTypeKeyUp) {
|
2014-07-01 00:30:29 +02:00
|
|
|
NSString* s = [event characters];
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([s length] > 0) {
|
2014-07-01 00:30:29 +02:00
|
|
|
keyEvent.character = [s characterAtIndex:0];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
s = [event charactersIgnoringModifiers];
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([s length] > 0) {
|
2014-07-01 00:30:29 +02:00
|
|
|
keyEvent.unmodified_character = [s characterAtIndex:0];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event type] == NSEventTypeFlagsChanged) {
|
2014-07-01 00:30:29 +02:00
|
|
|
keyEvent.character = 0;
|
|
|
|
keyEvent.unmodified_character = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyEvent.native_key_code = [event keyCode];
|
|
|
|
|
|
|
|
keyEvent.modifiers = [self getModifiersForEvent:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTextInputContext*)inputContext {
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!text_input_context_osr_mac_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
text_input_client_ =
|
|
|
|
[[CefTextInputClientOSRMac alloc] initWithBrowser:[self getBrowser]];
|
2017-05-17 11:29:28 +02:00
|
|
|
text_input_context_osr_mac_ =
|
2019-04-23 19:17:56 +02:00
|
|
|
[[NSTextInputContext alloc] initWithClient:text_input_client_];
|
|
|
|
#if !__has_feature(objc_arc)
|
|
|
|
[text_input_client_ retain];
|
|
|
|
[text_input_context_osr_mac_ retain];
|
|
|
|
#endif // !__has_feature(objc_arc)
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return text_input_context_osr_mac_;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)getMouseEvent:(CefMouseEvent&)mouseEvent forEvent:(NSEvent*)event {
|
2015-08-10 22:49:45 +02:00
|
|
|
const float device_scale_factor = [self getDeviceScaleFactor];
|
|
|
|
|
|
|
|
// |point| is in OS X view coordinates.
|
2014-07-01 00:30:29 +02:00
|
|
|
NSPoint point = [self getClickPointForEvent:event];
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Convert to device coordinates.
|
|
|
|
point = [self convertPointToBackingInternal:point];
|
|
|
|
|
|
|
|
int device_x = point.x;
|
|
|
|
int device_y = point.y;
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([self isOverPopupWidgetX:device_x andY:device_y]) {
|
2015-08-10 22:49:45 +02:00
|
|
|
[self applyPopupOffsetToX:device_x andY:device_y];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Convert to browser view coordinates.
|
|
|
|
mouseEvent.x = client::DeviceToLogical(device_x, device_scale_factor);
|
|
|
|
mouseEvent.y = client::DeviceToLogical(device_y, device_scale_factor);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
mouseEvent.modifiers = [self getModifiersForEvent:event];
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (void)getMouseEvent:(CefMouseEvent&)mouseEvent
|
|
|
|
forDragInfo:(id<NSDraggingInfo>)info {
|
|
|
|
const float device_scale_factor = [self getDeviceScaleFactor];
|
|
|
|
|
|
|
|
// |point| is in OS X view coordinates.
|
|
|
|
NSPoint windowPoint = [info draggingLocation];
|
|
|
|
NSPoint point = [self flipWindowPointToView:windowPoint];
|
|
|
|
|
|
|
|
// Convert to device coordinates.
|
|
|
|
point = [self convertPointToBackingInternal:point];
|
|
|
|
|
|
|
|
// Convert to browser view coordinates.
|
|
|
|
mouseEvent.x = client::DeviceToLogical(point.x, device_scale_factor);
|
|
|
|
mouseEvent.y = client::DeviceToLogical(point.y, device_scale_factor);
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
mouseEvent.modifiers = static_cast<uint32_t>([NSEvent modifierFlags]);
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
- (int)getModifiersForEvent:(NSEvent*)event {
|
|
|
|
int modifiers = 0;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([event modifierFlags] & NSEventModifierFlagControl) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_CONTROL_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if ([event modifierFlags] & NSEventModifierFlagShift) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_SHIFT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if ([event modifierFlags] & NSEventModifierFlagOption) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_ALT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if ([event modifierFlags] & NSEventModifierFlagCommand) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_COMMAND_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if ([event modifierFlags] & NSEventModifierFlagCapsLock) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_CAPS_LOCK_ON;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
if ([event type] == NSEventTypeKeyUp || [event type] == NSEventTypeKeyDown ||
|
|
|
|
[event type] == NSEventTypeFlagsChanged) {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Only perform this check for key events
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([self isKeyPadEvent:event]) {
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_IS_KEY_PAD;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// OS X does not have a modifier for NumLock, so I'm not entirely sure how to
|
|
|
|
// set EVENTFLAG_NUM_LOCK_ON;
|
|
|
|
//
|
|
|
|
// There is no EVENTFLAG for the function key either.
|
|
|
|
|
|
|
|
// Mouse buttons
|
|
|
|
switch ([event type]) {
|
2022-06-17 15:28:55 +02:00
|
|
|
case NSEventTypeLeftMouseDragged:
|
|
|
|
case NSEventTypeLeftMouseDown:
|
|
|
|
case NSEventTypeLeftMouseUp:
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON;
|
2017-05-17 11:29:28 +02:00
|
|
|
break;
|
2022-06-17 15:28:55 +02:00
|
|
|
case NSEventTypeRightMouseDragged:
|
|
|
|
case NSEventTypeRightMouseDown:
|
|
|
|
case NSEventTypeRightMouseUp:
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
2017-05-17 11:29:28 +02:00
|
|
|
break;
|
2022-06-17 15:28:55 +02:00
|
|
|
case NSEventTypeOtherMouseDragged:
|
|
|
|
case NSEventTypeOtherMouseDown:
|
|
|
|
case NSEventTypeOtherMouseUp:
|
2014-07-01 00:30:29 +02:00
|
|
|
modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
2017-05-17 11:29:28 +02:00
|
|
|
break;
|
2015-08-26 22:38:43 +02:00
|
|
|
default:
|
2017-05-17 11:29:28 +02:00
|
|
|
break;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isKeyUpEvent:(NSEvent*)event {
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([event type] != NSEventTypeFlagsChanged) {
|
2022-06-17 15:28:55 +02:00
|
|
|
return [event type] == NSEventTypeKeyUp;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
// FIXME: This logic fails if the user presses both Shift keys at once, for
|
|
|
|
// example: we treat releasing one of them as keyDown.
|
|
|
|
switch ([event keyCode]) {
|
2017-05-17 11:29:28 +02:00
|
|
|
case 54: // Right Command
|
|
|
|
case 55: // Left Command
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagCommand) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
case 57: // Capslock
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagCapsLock) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
case 56: // Left Shift
|
|
|
|
case 60: // Right Shift
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagShift) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
case 58: // Left Alt
|
|
|
|
case 61: // Right Alt
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagOption) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
case 59: // Left Ctrl
|
|
|
|
case 62: // Right Ctrl
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagControl) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
case 63: // Function
|
2022-06-17 15:28:55 +02:00
|
|
|
return ([event modifierFlags] & NSEventModifierFlagFunction) == 0;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isKeyPadEvent:(NSEvent*)event {
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([event modifierFlags] & NSEventModifierFlagNumericPad) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
switch ([event keyCode]) {
|
2017-05-17 11:29:28 +02:00
|
|
|
case 71: // Clear
|
|
|
|
case 81: // =
|
|
|
|
case 75: // /
|
|
|
|
case 67: // *
|
|
|
|
case 78: // -
|
|
|
|
case 69: // +
|
|
|
|
case 76: // Enter
|
|
|
|
case 65: // .
|
|
|
|
case 82: // 0
|
|
|
|
case 83: // 1
|
|
|
|
case 84: // 2
|
|
|
|
case 85: // 3
|
|
|
|
case 86: // 4
|
|
|
|
case 87: // 5
|
|
|
|
case 88: // 6
|
|
|
|
case 89: // 7
|
|
|
|
case 91: // 8
|
|
|
|
case 92: // 9
|
2014-07-01 00:30:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification*)notification {
|
|
|
|
// This delegate method is only called on 10.7 and later, so don't worry about
|
|
|
|
// other backing changes calling it on 10.6 or earlier
|
2015-08-10 22:49:45 +02:00
|
|
|
[self resetDeviceScaleFactor];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (void)drawRect:(NSRect)dirtyRect {
|
2015-04-09 16:59:34 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
|
|
|
if ([self inLiveResize] || !browser.get()) {
|
|
|
|
// Fill with the background color.
|
2017-04-20 21:28:17 +02:00
|
|
|
const cef_color_t background_color =
|
|
|
|
client::MainContext::Get()->GetBackgroundColor();
|
2017-05-17 11:29:28 +02:00
|
|
|
NSColor* color = [NSColor
|
|
|
|
colorWithCalibratedRed:float(CefColorGetR(background_color)) / 255.0f
|
|
|
|
green:float(CefColorGetG(background_color)) / 255.0f
|
|
|
|
blue:float(CefColorGetB(background_color)) / 255.0f
|
|
|
|
alpha:1.f];
|
2015-04-09 16:59:34 +02:00
|
|
|
[color setFill];
|
|
|
|
NSRectFill(dirtyRect);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2015-04-09 16:59:34 +02:00
|
|
|
|
|
|
|
// The Invalidate below fixes flicker when resizing.
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([self inLiveResize] && browser.get()) {
|
2015-04-09 16:59:34 +02:00
|
|
|
browser->GetHost()->Invalidate(PET_VIEW);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Drag and drop
|
|
|
|
|
|
|
|
- (BOOL)startDragging:(CefRefPtr<CefDragData>)drag_data
|
2015-01-30 19:07:13 +01:00
|
|
|
allowedOps:(NSDragOperation)ops
|
2014-07-01 00:30:29 +02:00
|
|
|
point:(NSPoint)position {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(!pasteboard_);
|
|
|
|
DCHECK(!fileUTI_);
|
|
|
|
DCHECK(!current_drag_data_.get());
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
[self resetDragDrop];
|
|
|
|
|
|
|
|
current_allowed_ops_ = ops;
|
|
|
|
current_drag_data_ = drag_data;
|
|
|
|
|
|
|
|
[self fillPasteboard];
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
NSEvent* currentEvent = [[NSApplication sharedApplication] currentEvent];
|
2014-07-01 00:30:29 +02:00
|
|
|
NSWindow* window = [self window];
|
|
|
|
NSTimeInterval eventTime = [currentEvent timestamp];
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
NSEvent* dragEvent = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDragged
|
2014-07-01 00:30:29 +02:00
|
|
|
location:position
|
2022-06-17 15:28:55 +02:00
|
|
|
modifierFlags:NSEventMaskLeftMouseDragged
|
2014-07-01 00:30:29 +02:00
|
|
|
timestamp:eventTime
|
|
|
|
windowNumber:[window windowNumber]
|
|
|
|
context:nil
|
|
|
|
eventNumber:0
|
|
|
|
clickCount:1
|
|
|
|
pressure:1.0];
|
|
|
|
|
2015-12-08 18:59:24 +01:00
|
|
|
// TODO(cef): Pass a non-nil value to dragImage (see issue #1715). For now
|
|
|
|
// work around the "callee requires a non-null argument" error that occurs
|
|
|
|
// when building with the 10.11 SDK.
|
|
|
|
id nilArg = nil;
|
|
|
|
[window dragImage:nilArg
|
2014-07-01 00:30:29 +02:00
|
|
|
at:position
|
|
|
|
offset:NSZeroSize
|
|
|
|
event:dragEvent
|
|
|
|
pasteboard:pasteboard_
|
|
|
|
source:self
|
|
|
|
slideBack:YES];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)setCurrentDragOp:(NSDragOperation)op {
|
|
|
|
current_drag_op_ = op;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
// NSDraggingSource Protocol
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (NSDragOperation)draggingSession:(NSDraggingSession*)session
|
2014-07-01 00:30:29 +02:00
|
|
|
sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
|
2017-05-17 11:29:28 +02:00
|
|
|
switch (context) {
|
2014-07-01 00:30:29 +02:00
|
|
|
case NSDraggingContextOutsideApplication:
|
|
|
|
return current_allowed_ops_;
|
|
|
|
|
|
|
|
case NSDraggingContextWithinApplication:
|
|
|
|
default:
|
|
|
|
return current_allowed_ops_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)namesOfPromisedFilesDroppedAtDestination:(NSURL*)dropDest {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (![dropDest isFileURL]) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return nil;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!current_drag_data_) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return nil;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
size_t expected_size = current_drag_data_->GetFileContents(nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (expected_size == 0) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return nil;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
std::string path = [[dropDest path] UTF8String];
|
|
|
|
path.append("/");
|
|
|
|
path.append(current_drag_data_->GetFileName().ToString());
|
|
|
|
|
|
|
|
CefRefPtr<CefStreamWriter> writer = CefStreamWriter::CreateForFile(path);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!writer) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return nil;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (current_drag_data_->GetFileContents(writer) != expected_size) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return nil;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
return @[ [NSString stringWithUTF8String:path.c_str()] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)draggedImage:(NSImage*)anImage
|
|
|
|
endedAt:(NSPoint)screenPoint
|
|
|
|
operation:(NSDragOperation)operation {
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (operation == (NSDragOperationMove | NSDragOperationCopy)) {
|
2014-07-01 00:30:29 +02:00
|
|
|
operation &= ~NSDragOperationMove;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
NSPoint windowPoint = [[self window] convertScreenToBase:screenPoint];
|
2014-07-01 00:30:29 +02:00
|
|
|
NSPoint pt = [self flipWindowPointToView:windowPoint];
|
|
|
|
CefRenderHandler::DragOperation op =
|
|
|
|
static_cast<CefRenderHandler::DragOperation>(operation);
|
2015-01-30 19:07:13 +01:00
|
|
|
browser->GetHost()->DragSourceEndedAt(pt.x, pt.y, op);
|
|
|
|
browser->GetHost()->DragSourceSystemDragEnded();
|
2014-07-01 00:30:29 +02:00
|
|
|
[self resetDragDrop];
|
|
|
|
}
|
|
|
|
|
|
|
|
// NSDraggingDestination Protocol
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return NSDragOperationNone;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefDragData> drag_data;
|
|
|
|
if (!current_drag_data_) {
|
|
|
|
drag_data = CefDragData::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
[self populateDropData:drag_data fromPasteboard:[info draggingPasteboard]];
|
2014-07-01 00:30:29 +02:00
|
|
|
} else {
|
|
|
|
drag_data = current_drag_data_->Clone();
|
|
|
|
drag_data->ResetFileContents();
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
CefMouseEvent mouseEvent;
|
|
|
|
[self getMouseEvent:mouseEvent forDragInfo:info];
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
NSDragOperation mask = [info draggingSourceOperationMask];
|
|
|
|
CefBrowserHost::DragOperationsMask allowed_ops =
|
|
|
|
static_cast<CefBrowserHost::DragOperationsMask>(mask);
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
browser->GetHost()->DragTargetDragEnter(drag_data, mouseEvent, allowed_ops);
|
|
|
|
browser->GetHost()->DragTargetDragOver(mouseEvent, allowed_ops);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
current_drag_op_ = NSDragOperationCopy;
|
|
|
|
return current_drag_op_;
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (void)draggingExited:(id<NSDraggingInfo>)sender {
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
browser->GetHost()->DragTargetDragLeave();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)info {
|
2014-07-01 00:30:29 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return NO;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
CefMouseEvent mouseEvent;
|
|
|
|
[self getMouseEvent:mouseEvent forDragInfo:info];
|
|
|
|
|
|
|
|
browser->GetHost()->DragTargetDrop(mouseEvent);
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info {
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return NSDragOperationNone;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
CefMouseEvent mouseEvent;
|
|
|
|
[self getMouseEvent:mouseEvent forDragInfo:info];
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
NSDragOperation mask = [info draggingSourceOperationMask];
|
|
|
|
CefBrowserHost::DragOperationsMask allowed_ops =
|
2015-08-10 22:49:45 +02:00
|
|
|
static_cast<CefBrowserHost::DragOperationsMask>(mask);
|
|
|
|
|
|
|
|
browser->GetHost()->DragTargetDragOver(mouseEvent, allowed_ops);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
return current_drag_op_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NSPasteboardOwner Protocol
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (void)pasteboard:(NSPasteboard*)pboard provideDataForType:(NSString*)type {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!current_drag_data_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// URL.
|
2023-07-24 18:57:37 +02:00
|
|
|
if ([type isEqualToString:NSPasteboardTypeURL]) {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(current_drag_data_->IsLink());
|
2017-05-17 11:29:28 +02:00
|
|
|
NSString* strUrl =
|
|
|
|
[NSString stringWithUTF8String:current_drag_data_->GetLinkURL()
|
|
|
|
.ToString()
|
|
|
|
.c_str()];
|
2014-07-01 00:30:29 +02:00
|
|
|
NSURL* url = [NSURL URLWithString:strUrl];
|
|
|
|
[url writeToPasteboard:pboard];
|
2017-05-17 11:29:28 +02:00
|
|
|
// URL title.
|
2014-07-01 00:30:29 +02:00
|
|
|
} else if ([type isEqualToString:kNSURLTitlePboardType]) {
|
2017-05-17 11:29:28 +02:00
|
|
|
NSString* strTitle =
|
|
|
|
[NSString stringWithUTF8String:current_drag_data_->GetLinkTitle()
|
|
|
|
.ToString()
|
|
|
|
.c_str()];
|
2014-07-01 00:30:29 +02:00
|
|
|
[pboard setString:strTitle forType:kNSURLTitlePboardType];
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
// File contents.
|
2019-04-23 19:17:56 +02:00
|
|
|
} else if ([type isEqualToString:fileUTI_]) {
|
2021-06-17 22:08:01 +02:00
|
|
|
size_t size = current_drag_data_->GetFileContents(nullptr);
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK_GT(size, 0U);
|
2015-01-23 20:09:34 +01:00
|
|
|
CefRefPtr<client::BytesWriteHandler> handler =
|
|
|
|
new client::BytesWriteHandler(size);
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefStreamWriter> writer =
|
|
|
|
CefStreamWriter::CreateForHandler(handler.get());
|
|
|
|
current_drag_data_->GetFileContents(writer);
|
2023-06-01 16:06:15 +02:00
|
|
|
DCHECK_EQ(handler->GetDataSize(), static_cast<int64_t>(size));
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
[pboard setData:[NSData dataWithBytes:handler->GetData()
|
|
|
|
length:handler->GetDataSize()]
|
2019-04-23 19:17:56 +02:00
|
|
|
forType:fileUTI_];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
// Plain text.
|
2023-07-24 18:57:37 +02:00
|
|
|
} else if ([type isEqualToString:NSPasteboardTypeString]) {
|
2017-05-17 11:29:28 +02:00
|
|
|
NSString* strTitle =
|
|
|
|
[NSString stringWithUTF8String:current_drag_data_->GetFragmentText()
|
|
|
|
.ToString()
|
|
|
|
.c_str()];
|
2023-07-24 18:57:37 +02:00
|
|
|
[pboard setString:strTitle forType:NSPasteboardTypeString];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
} else if ([type isEqualToString:kCEFDragDummyPboardType]) {
|
|
|
|
// The dummy type _was_ promised and someone decided to call the bluff.
|
2017-05-17 11:29:28 +02:00
|
|
|
[pboard setData:[NSData data] forType:kCEFDragDummyPboardType];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
// NSAccessibility Protocol implementation.
|
|
|
|
- (BOOL)accessibilityIsIgnored {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!accessibility_helper_) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return YES;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2017-05-12 20:28:25 +02:00
|
|
|
return NO;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!accessibility_helper_) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return [super accessibilityAttributeValue:attribute];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
|
|
|
|
return NSAccessibilityGroupRole;
|
|
|
|
} else if ([attribute isEqualToString:NSAccessibilityDescriptionAttribute]) {
|
|
|
|
client::OsrAXNode* node = accessibility_helper_->GetRootNode();
|
2017-05-17 11:29:28 +02:00
|
|
|
std::string desc = node ? node->AxDescription() : "";
|
2017-05-12 20:28:25 +02:00
|
|
|
return [NSString stringWithUTF8String:desc.c_str()];
|
|
|
|
} else if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
|
|
|
client::OsrAXNode* node = accessibility_helper_->GetRootNode();
|
2017-05-17 11:29:28 +02:00
|
|
|
std::string desc = node ? node->AxValue() : "";
|
2017-05-12 20:28:25 +02:00
|
|
|
return [NSString stringWithUTF8String:desc.c_str()];
|
2017-05-17 11:29:28 +02:00
|
|
|
} else if ([attribute
|
|
|
|
isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return NSAccessibilityRoleDescriptionForUIElement(self);
|
|
|
|
} else if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
|
|
|
|
client::OsrAXNode* node = accessibility_helper_->GetRootNode();
|
|
|
|
// Add Root as first Kid
|
|
|
|
NSMutableArray* kids = [NSMutableArray arrayWithCapacity:1];
|
2019-04-23 19:17:56 +02:00
|
|
|
NSObject* child = CAST_CEF_NATIVE_ACCESSIBLE_TO_NSOBJECT(
|
2021-06-17 22:08:01 +02:00
|
|
|
node->GetNativeAccessibleObject(nullptr));
|
2017-05-17 11:29:28 +02:00
|
|
|
[kids addObject:child];
|
2017-05-12 20:28:25 +02:00
|
|
|
return NSAccessibilityUnignoredChildren(kids);
|
|
|
|
} else {
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityFocusedUIElement {
|
|
|
|
if (accessibility_helper_) {
|
|
|
|
client::OsrAXNode* node = accessibility_helper_->GetFocusedNode();
|
2019-04-23 19:17:56 +02:00
|
|
|
return node ? CAST_CEF_NATIVE_ACCESSIBLE_TO_NSOBJECT(
|
2021-06-17 22:08:01 +02:00
|
|
|
node->GetNativeAccessibleObject(nullptr))
|
2019-04-23 19:17:56 +02:00
|
|
|
: nil;
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
// Utility methods.
|
2014-07-01 00:30:29 +02:00
|
|
|
- (void)resetDragDrop {
|
|
|
|
current_drag_op_ = NSDragOperationNone;
|
|
|
|
current_allowed_ops_ = NSDragOperationNone;
|
2021-06-17 22:08:01 +02:00
|
|
|
current_drag_data_ = nullptr;
|
2014-07-01 00:30:29 +02:00
|
|
|
if (fileUTI_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
#if !__has_feature(objc_arc)
|
|
|
|
[fileUTI_ release];
|
|
|
|
#endif // !__has_feature(objc_arc)
|
|
|
|
fileUTI_ = nil;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
if (pasteboard_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
#if !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
[pasteboard_ release];
|
2019-04-23 19:17:56 +02:00
|
|
|
#endif // !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
pasteboard_ = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)fillPasteboard {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(!pasteboard_);
|
2022-06-17 15:28:55 +02:00
|
|
|
pasteboard_ = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag];
|
2019-04-23 19:17:56 +02:00
|
|
|
#if !__has_feature(objc_arc)
|
|
|
|
[pasteboard_ retain];
|
|
|
|
#endif // !__has_feature(objc_arc)
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
[pasteboard_ declareTypes:@[ kCEFDragDummyPboardType ] owner:self];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
// URL (and title).
|
|
|
|
if (current_drag_data_->IsLink()) {
|
2023-07-24 18:57:37 +02:00
|
|
|
[pasteboard_ addTypes:@[ NSPasteboardTypeURL, kNSURLTitlePboardType ]
|
2014-07-01 00:30:29 +02:00
|
|
|
owner:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
// MIME type.
|
|
|
|
CefString mimeType;
|
2021-06-17 22:08:01 +02:00
|
|
|
size_t contents_size = current_drag_data_->GetFileContents(nullptr);
|
2014-07-01 00:30:29 +02:00
|
|
|
CefString download_metadata = current_drag_data_->GetLinkMetadata();
|
|
|
|
|
|
|
|
// File.
|
|
|
|
if (contents_size > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
std::string file_name = current_drag_data_->GetFileName().ToString();
|
|
|
|
size_t sep = file_name.find_last_of(".");
|
|
|
|
CefString extension = file_name.substr(sep + 1);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
mimeType = CefGetMimeType(extension);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
if (!mimeType.empty()) {
|
|
|
|
CFStringRef mimeTypeCF;
|
|
|
|
mimeTypeCF = CFStringCreateWithCString(kCFAllocatorDefault,
|
2017-05-17 11:29:28 +02:00
|
|
|
mimeType.ToString().c_str(),
|
|
|
|
kCFStringEncodingUTF8);
|
2019-04-23 19:17:56 +02:00
|
|
|
fileUTI_ = (__bridge NSString*)UTTypeCreatePreferredIdentifierForTag(
|
2021-06-17 22:08:01 +02:00
|
|
|
kUTTagClassMIMEType, mimeTypeCF, nullptr);
|
2014-07-01 00:30:29 +02:00
|
|
|
CFRelease(mimeTypeCF);
|
|
|
|
// File (HFS) promise.
|
2019-04-23 19:17:56 +02:00
|
|
|
NSArray* fileUTIList = @[ fileUTI_ ];
|
2023-07-24 18:57:37 +02:00
|
|
|
NSString* NSPasteboardTypeFileURLPromise =
|
|
|
|
#if __has_feature(objc_arc)
|
|
|
|
(__bridge NSString*)kPasteboardTypeFileURLPromise;
|
|
|
|
#else
|
|
|
|
(NSString*)kPasteboardTypeFileURLPromise;
|
|
|
|
#endif
|
|
|
|
[pasteboard_ addTypes:@[ NSPasteboardTypeFileURLPromise ] owner:self];
|
2014-07-01 00:30:29 +02:00
|
|
|
[pasteboard_ setPropertyList:fileUTIList
|
2023-07-24 18:57:37 +02:00
|
|
|
forType:NSPasteboardTypeFileURLPromise];
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
[pasteboard_ addTypes:fileUTIList owner:self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plain text.
|
|
|
|
if (!current_drag_data_->GetFragmentText().empty()) {
|
2023-07-24 18:57:37 +02:00
|
|
|
[pasteboard_ addTypes:@[ NSPasteboardTypeString ] owner:self];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)populateDropData:(CefRefPtr<CefDragData>)data
|
|
|
|
fromPasteboard:(NSPasteboard*)pboard {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(data);
|
|
|
|
DCHECK(pboard);
|
|
|
|
DCHECK(data && !data->IsReadOnly());
|
2014-07-01 00:30:29 +02:00
|
|
|
NSArray* types = [pboard types];
|
|
|
|
|
|
|
|
// Get plain text.
|
2023-07-24 18:57:37 +02:00
|
|
|
if ([types containsObject:NSPasteboardTypeString]) {
|
2014-07-01 00:30:29 +02:00
|
|
|
data->SetFragmentText(
|
2023-07-24 18:57:37 +02:00
|
|
|
[[pboard stringForType:NSPasteboardTypeString] UTF8String]);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get files.
|
2023-07-24 18:57:37 +02:00
|
|
|
if ([types containsObject:NSPasteboardTypeFileURL]) {
|
|
|
|
NSArray* files = [pboard propertyListForType:NSPasteboardTypeFileURL];
|
2014-07-01 00:30:29 +02:00
|
|
|
if ([files isKindOfClass:[NSArray class]] && [files count]) {
|
|
|
|
for (NSUInteger i = 0; i < [files count]; i++) {
|
|
|
|
NSString* filename = [files objectAtIndex:i];
|
2017-05-17 11:29:28 +02:00
|
|
|
BOOL exists =
|
|
|
|
[[NSFileManager defaultManager] fileExistsAtPath:filename];
|
2014-07-01 00:30:29 +02:00
|
|
|
if (exists) {
|
|
|
|
data->AddFile([filename UTF8String], CefString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint {
|
2017-05-17 11:29:28 +02:00
|
|
|
NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil];
|
2014-07-01 00:30:29 +02:00
|
|
|
NSRect viewFrame = [self frame];
|
|
|
|
viewPoint.y = viewFrame.size.height - viewPoint.y;
|
|
|
|
return viewPoint;
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (void)resetDeviceScaleFactor {
|
|
|
|
float device_scale_factor = 1.0f;
|
2014-07-01 00:30:29 +02:00
|
|
|
NSWindow* window = [self window];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window) {
|
2016-04-27 22:38:52 +02:00
|
|
|
device_scale_factor = [window backingScaleFactor];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
[self setDeviceScaleFactor:device_scale_factor];
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
- (void)setDeviceScaleFactor:(float)device_scale_factor {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device_scale_factor == device_scale_factor_) {
|
2015-08-10 22:49:45 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Apply some sanity checks.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f) {
|
2015-08-10 22:49:45 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
device_scale_factor_ = device_scale_factor;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
|
|
|
if (browser) {
|
|
|
|
browser->GetHost()->NotifyScreenInfoChanged();
|
|
|
|
browser->GetHost()->WasResized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)getDeviceScaleFactor {
|
|
|
|
return device_scale_factor_;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-12-03 21:22:44 +01:00
|
|
|
- (void)viewDidChangeBackingProperties {
|
2023-01-12 17:47:19 +01:00
|
|
|
[super viewDidChangeBackingProperties];
|
2015-12-03 21:22:44 +01:00
|
|
|
const CGFloat device_scale_factor = [self getDeviceScaleFactor];
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device_scale_factor == device_scale_factor_) {
|
2015-12-03 21:22:44 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-03 21:22:44 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> browser = [self getBrowser];
|
|
|
|
if (browser) {
|
|
|
|
browser->GetHost()->NotifyScreenInfoChanged();
|
|
|
|
browser->GetHost()->WasResized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (bool)isOverPopupWidgetX:(int)x andY:(int)y {
|
2015-08-10 22:49:45 +02:00
|
|
|
CefRect rc = renderer_->popup_rect();
|
2014-07-01 00:30:29 +02:00
|
|
|
int popup_right = rc.x + rc.width;
|
|
|
|
int popup_bottom = rc.y + rc.height;
|
2017-05-17 11:29:28 +02:00
|
|
|
return (x >= rc.x) && (x < popup_right) && (y >= rc.y) && (y < popup_bottom);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (int)getPopupXOffset {
|
2015-08-10 22:49:45 +02:00
|
|
|
return renderer_->original_popup_rect().x - renderer_->popup_rect().x;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (int)getPopupYOffset {
|
2015-08-10 22:49:45 +02:00
|
|
|
return renderer_->original_popup_rect().y - renderer_->popup_rect().y;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
- (void)applyPopupOffsetToX:(int&)x andY:(int&)y {
|
2014-07-01 00:30:29 +02:00
|
|
|
if ([self isOverPopupWidgetX:x andY:y]) {
|
|
|
|
x += [self getPopupXOffset];
|
|
|
|
y += [self getPopupYOffset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Convert from scaled coordinates to view coordinates.
|
|
|
|
- (NSPoint)convertPointFromBackingInternal:(NSPoint)aPoint {
|
2016-04-27 22:38:52 +02:00
|
|
|
return [self convertPointFromBacking:aPoint];
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Convert from view coordinates to scaled coordinates.
|
|
|
|
- (NSPoint)convertPointToBackingInternal:(NSPoint)aPoint {
|
2016-04-27 22:38:52 +02:00
|
|
|
return [self convertPointToBacking:aPoint];
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Convert from scaled coordinates to view coordinates.
|
|
|
|
- (NSRect)convertRectFromBackingInternal:(NSRect)aRect {
|
2016-04-27 22:38:52 +02:00
|
|
|
return [self convertRectFromBacking:aRect];
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Convert from view coordinates to scaled coordinates.
|
|
|
|
- (NSRect)convertRectToBackingInternal:(NSRect)aRect {
|
2016-04-27 22:38:52 +02:00
|
|
|
return [self convertRectToBacking:aRect];
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
- (void)ChangeCompositionRange:(CefRange)range
|
2017-05-17 11:29:28 +02:00
|
|
|
character_bounds:(const CefRenderHandler::RectList&)bounds {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (text_input_client_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[text_input_client_ ChangeCompositionRange:range character_bounds:bounds];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
- (void)UpdateAccessibilityTree:(CefRefPtr<CefValue>)value {
|
|
|
|
if (!accessibility_helper_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
accessibility_helper_ =
|
|
|
|
new client::OsrAccessibilityHelper(value, [self getBrowser]);
|
2017-05-12 20:28:25 +02:00
|
|
|
} else {
|
|
|
|
accessibility_helper_->UpdateAccessibilityTree(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accessibility_helper_) {
|
|
|
|
NSAccessibilityPostNotification(self,
|
|
|
|
NSAccessibilityValueChangedNotification);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-03-21 17:56:06 +01:00
|
|
|
|
|
|
|
- (void)UpdateAccessibilityLocation:(CefRefPtr<CefValue>)value {
|
|
|
|
if (accessibility_helper_) {
|
|
|
|
accessibility_helper_->UpdateAccessibilityLocation(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accessibility_helper_) {
|
|
|
|
NSAccessibilityPostNotification(self,
|
|
|
|
NSAccessibilityValueChangedNotification);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
@end
|
|
|
|
|
2015-01-23 18:37:23 +01:00
|
|
|
namespace client {
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
class BrowserWindowOsrMacImpl {
|
|
|
|
public:
|
|
|
|
BrowserWindowOsrMacImpl(BrowserWindow::Delegate* delegate,
|
|
|
|
const std::string& startup_url,
|
|
|
|
const OsrRendererSettings& settings,
|
|
|
|
BrowserWindowOsrMac& browser_window);
|
|
|
|
~BrowserWindowOsrMacImpl();
|
|
|
|
|
|
|
|
// BrowserWindow methods.
|
|
|
|
void CreateBrowser(ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-05-18 14:23:17 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2019-04-23 19:17:56 +02:00
|
|
|
CefRefPtr<CefRequestContext> request_context);
|
|
|
|
void GetPopupConfig(CefWindowHandle temp_handle,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings);
|
|
|
|
void ShowPopup(ClientWindowHandle parent_handle,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height);
|
|
|
|
void Show();
|
|
|
|
void Hide();
|
|
|
|
void SetBounds(int x, int y, size_t width, size_t height);
|
|
|
|
void SetFocus(bool focus);
|
|
|
|
void SetDeviceScaleFactor(float device_scale_factor);
|
|
|
|
float GetDeviceScaleFactor() const;
|
|
|
|
ClientWindowHandle GetWindowHandle() const;
|
|
|
|
|
|
|
|
// ClientHandlerOsr::OsrDelegate methods.
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser);
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser);
|
|
|
|
bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect);
|
|
|
|
void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect);
|
|
|
|
bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY);
|
|
|
|
bool GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info);
|
|
|
|
void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show);
|
|
|
|
void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect);
|
|
|
|
void OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height);
|
2024-03-08 13:44:56 +01:00
|
|
|
void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const CefAcceleratedPaintInfo& info);
|
2019-04-23 19:17:56 +02:00
|
|
|
void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_type_t type,
|
2019-04-23 19:17:56 +02:00
|
|
|
const CefCursorInfo& custom_cursor_info);
|
|
|
|
bool StartDragging(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
|
|
|
int x,
|
|
|
|
int y);
|
|
|
|
void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation);
|
|
|
|
void OnImeCompositionRangeChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRange& selection_range,
|
|
|
|
const CefRenderHandler::RectList& character_bounds);
|
|
|
|
|
|
|
|
void UpdateAccessibilityTree(CefRefPtr<CefValue> value);
|
|
|
|
void UpdateAccessibilityLocation(CefRefPtr<CefValue> value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Create the NSView.
|
|
|
|
void Create(ClientWindowHandle parent_handle, const CefRect& rect);
|
|
|
|
|
|
|
|
BrowserWindowOsrMac& browser_window_;
|
|
|
|
// The below members will only be accessed on the main thread which should be
|
|
|
|
// the same as the CEF UI thread.
|
|
|
|
OsrRenderer renderer_;
|
|
|
|
BrowserOpenGLView* native_browser_view_;
|
|
|
|
bool hidden_;
|
|
|
|
bool painting_popup_;
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowserWindowOsrMacImpl::BrowserWindowOsrMacImpl(
|
|
|
|
BrowserWindow::Delegate* delegate,
|
|
|
|
const std::string& startup_url,
|
|
|
|
const OsrRendererSettings& settings,
|
|
|
|
BrowserWindowOsrMac& browser_window)
|
|
|
|
: browser_window_(browser_window),
|
2015-04-09 16:59:34 +02:00
|
|
|
renderer_(settings),
|
2019-04-23 19:17:56 +02:00
|
|
|
native_browser_view_(nil),
|
2015-01-30 19:07:13 +01:00
|
|
|
hidden_(false),
|
2019-04-23 19:17:56 +02:00
|
|
|
painting_popup_(false) {}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
BrowserWindowOsrMacImpl::~BrowserWindowOsrMacImpl() {
|
|
|
|
if (native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
// Disassociate the view with |this|.
|
2019-04-23 19:17:56 +02:00
|
|
|
[native_browser_view_ detach];
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::CreateBrowser(
|
2015-02-14 00:17:08 +01:00
|
|
|
ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2015-02-14 00:17:08 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
// Create the native NSView.
|
|
|
|
Create(parent_handle, rect);
|
|
|
|
|
|
|
|
CefWindowInfo window_info;
|
2019-04-23 19:17:56 +02:00
|
|
|
window_info.SetAsWindowless(
|
|
|
|
CAST_NSVIEW_TO_CEF_WINDOW_HANDLE(native_browser_view_));
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2024-03-08 13:44:56 +01:00
|
|
|
window_info.shared_texture_enabled =
|
|
|
|
renderer_.settings().shared_texture_enabled;
|
|
|
|
window_info.external_begin_frame_enabled =
|
|
|
|
renderer_.settings().external_begin_frame_enabled;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Windowless rendering requires Alloy style.
|
|
|
|
DCHECK_EQ(CEF_RUNTIME_STYLE_ALLOY, window_info.runtime_style);
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
// Create the browser asynchronously.
|
2019-04-23 19:17:56 +02:00
|
|
|
CefBrowserHost::CreateBrowser(window_info, browser_window_.client_handler_,
|
|
|
|
browser_window_.client_handler_->startup_url(),
|
2019-03-19 10:42:54 +01:00
|
|
|
settings, extra_info, request_context);
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::GetPopupConfig(CefWindowHandle temp_handle,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
windowInfo.SetAsWindowless(temp_handle);
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
// Windowless rendering requires Alloy style.
|
|
|
|
DCHECK_EQ(CEF_RUNTIME_STYLE_ALLOY, windowInfo.runtime_style);
|
|
|
|
|
2024-03-08 13:44:56 +01:00
|
|
|
windowInfo.shared_texture_enabled =
|
|
|
|
renderer_.settings().shared_texture_enabled;
|
|
|
|
windowInfo.external_begin_frame_enabled =
|
|
|
|
renderer_.settings().external_begin_frame_enabled;
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
client = browser_window_.client_handler_;
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::ShowPopup(ClientWindowHandle parent_handle,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2019-04-23 19:17:56 +02:00
|
|
|
DCHECK(browser_window_.browser_.get());
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
// Create the native NSView.
|
|
|
|
Create(parent_handle,
|
|
|
|
CefRect(x, y, static_cast<int>(width), static_cast<int>(height)));
|
|
|
|
|
|
|
|
// Send resize notification so the compositor is assigned the correct
|
|
|
|
// viewport size and begins rendering.
|
2019-04-23 19:17:56 +02:00
|
|
|
browser_window_.browser_->GetHost()->WasResized();
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::Show() {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
if (hidden_) {
|
|
|
|
// Set the browser as visible.
|
2019-04-23 19:17:56 +02:00
|
|
|
browser_window_.browser_->GetHost()->WasHidden(false);
|
2015-01-30 19:07:13 +01:00
|
|
|
hidden_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give focus to the browser.
|
2021-09-27 09:50:07 +02:00
|
|
|
browser_window_.browser_->GetHost()->SetFocus(true);
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::Hide() {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_window_.browser_.get()) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
// Remove focus from the browser.
|
2021-09-27 09:50:07 +02:00
|
|
|
browser_window_.browser_->GetHost()->SetFocus(false);
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
if (!hidden_) {
|
|
|
|
// Set the browser as hidden.
|
2019-04-23 19:17:56 +02:00
|
|
|
browser_window_.browser_->GetHost()->WasHidden(true);
|
2015-01-30 19:07:13 +01:00
|
|
|
hidden_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::SetBounds(int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
// Nothing to do here. GTK will take care of positioning in the container.
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::SetFocus(bool focus) {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (native_browser_view_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[native_browser_view_.window makeFirstResponder:native_browser_view_];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::SetDeviceScaleFactor(float device_scale_factor) {
|
2015-08-10 22:49:45 +02:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (native_browser_view_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[native_browser_view_ setDeviceScaleFactor:device_scale_factor];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
float BrowserWindowOsrMacImpl::GetDeviceScaleFactor() const {
|
2015-08-10 22:49:45 +02:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (native_browser_view_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
return [native_browser_view_ getDeviceScaleFactor];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
ClientWindowHandle BrowserWindowOsrMacImpl::GetWindowHandle() const {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2019-04-23 19:17:56 +02:00
|
|
|
return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE(native_browser_view_);
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
// Detach |this| from the ClientHandlerOsr.
|
2024-08-06 00:30:39 +02:00
|
|
|
auto handler =
|
|
|
|
ClientHandlerOsr::GetForClient(browser_window_.client_handler_);
|
|
|
|
CHECK(handler);
|
|
|
|
handler->DetachOsrDelegate();
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
bool BrowserWindowOsrMacImpl::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::GetViewRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2018-09-25 15:40:02 +02:00
|
|
|
rect.x = rect.y = 0;
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
if (!native_browser_view_) {
|
2018-09-25 15:40:02 +02:00
|
|
|
// Never return an empty rectangle.
|
|
|
|
rect.width = rect.height = 1;
|
|
|
|
return;
|
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
const float device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// |bounds| is in OS X view coordinates.
|
2019-04-23 19:17:56 +02:00
|
|
|
NSRect bounds = native_browser_view_.bounds;
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Convert to device coordinates.
|
2019-04-23 19:17:56 +02:00
|
|
|
bounds = [native_browser_view_ convertRectToBackingInternal:bounds];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Convert to browser view coordinates.
|
|
|
|
rect.width = DeviceToLogical(bounds.size.width, device_scale_factor);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (rect.width == 0) {
|
2018-09-26 15:09:46 +02:00
|
|
|
rect.width = 1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
rect.height = DeviceToLogical(bounds.size.height, device_scale_factor);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (rect.height == 0) {
|
2018-09-26 15:09:46 +02:00
|
|
|
rect.height = 1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
bool BrowserWindowOsrMacImpl::GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
const float device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// (viewX, viewX) is in browser view coordinates.
|
|
|
|
// Convert to device coordinates.
|
2017-05-17 11:29:28 +02:00
|
|
|
NSPoint view_pt = NSMakePoint(LogicalToDevice(viewX, device_scale_factor),
|
|
|
|
LogicalToDevice(viewY, device_scale_factor));
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Convert to OS X view coordinates.
|
2019-04-23 19:17:56 +02:00
|
|
|
view_pt = [native_browser_view_ convertPointFromBackingInternal:view_pt];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Reverse the Y component.
|
2019-04-23 19:17:56 +02:00
|
|
|
const NSRect bounds = native_browser_view_.bounds;
|
2015-08-10 22:49:45 +02:00
|
|
|
view_pt.y = bounds.size.height - view_pt.y;
|
|
|
|
|
|
|
|
// Convert to screen coordinates.
|
2019-04-23 19:17:56 +02:00
|
|
|
NSPoint window_pt = [native_browser_view_ convertPoint:view_pt toView:nil];
|
2016-04-27 22:38:52 +02:00
|
|
|
NSPoint screen_pt =
|
2019-04-23 19:17:56 +02:00
|
|
|
ConvertPointFromWindowToScreen(native_browser_view_.window, window_pt);
|
2015-08-10 22:49:45 +02:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
screenX = screen_pt.x;
|
|
|
|
screenY = screen_pt.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
bool BrowserWindowOsrMacImpl::GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefScreenInfo& screen_info) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
CefRect view_rect;
|
|
|
|
GetViewRect(browser, view_rect);
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
screen_info.device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// The screen info rectangles are used by the renderer to create and position
|
|
|
|
// popups. Keep popups inside the view rectangle.
|
|
|
|
screen_info.rect = view_rect;
|
|
|
|
screen_info.available_rect = view_rect;
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnPopupShow(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool show) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
renderer_.ClearPopupRects();
|
|
|
|
browser->GetHost()->Invalidate(PET_VIEW);
|
|
|
|
}
|
|
|
|
renderer_.OnPopupShow(browser, show);
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnPopupSize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRect& rect) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
const float device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// |rect| is in browser view coordinates. Convert to device coordinates.
|
|
|
|
CefRect device_rect = LogicalToDevice(rect, device_scale_factor);
|
|
|
|
|
|
|
|
renderer_.OnPopupSize(browser, device_rect);
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnPaint(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
if (width <= 2 && height <= 2) {
|
|
|
|
// Ignore really small buffer sizes while the widget is starting up.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (painting_popup_) {
|
|
|
|
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
ScopedGLContext scoped_gl_context(native_browser_view_, true);
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
|
|
|
|
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
|
|
|
|
painting_popup_ = true;
|
|
|
|
browser->GetHost()->Invalidate(PET_POPUP);
|
|
|
|
painting_popup_ = false;
|
|
|
|
}
|
|
|
|
renderer_.Render();
|
|
|
|
}
|
|
|
|
|
2024-03-08 13:44:56 +01:00
|
|
|
void BrowserWindowOsrMacImpl::OnAcceleratedPaint(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const CefAcceleratedPaintInfo& info) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
if (!native_browser_view_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedGLContext scoped_gl_context(native_browser_view_, true);
|
|
|
|
|
|
|
|
IOSurfaceRef io_surface = (IOSurfaceRef)info.shared_texture_io_surface;
|
|
|
|
|
|
|
|
GLuint rectTexture;
|
|
|
|
glGenTextures(1, &rectTexture);
|
|
|
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, rectTexture);
|
|
|
|
|
|
|
|
CGLContextObj cgl_context = CGLGetCurrentContext();
|
|
|
|
|
|
|
|
GLsizei width = (GLsizei)IOSurfaceGetWidth(io_surface);
|
|
|
|
GLsizei height = (GLsizei)IOSurfaceGetHeight(io_surface);
|
|
|
|
|
|
|
|
CGLTexImageIOSurface2D(cgl_context, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA8, width,
|
|
|
|
height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
|
|
|
|
io_surface, 0);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
|
|
|
|
|
|
|
renderer_.OnAcceleratedPaint(browser, type, dirtyRects, rectTexture, width,
|
|
|
|
height);
|
|
|
|
renderer_.Render();
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnCursorChange(
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_type_t type,
|
2015-01-30 19:07:13 +01:00
|
|
|
const CefCursorInfo& custom_cursor_info) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
[CAST_CEF_CURSOR_HANDLE_TO_NSCURSOR(cursor) set];
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
bool BrowserWindowOsrMacImpl::StartDragging(
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y) {
|
2015-01-30 19:07:13 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_browser_view_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
static float device_scale_factor =
|
|
|
|
[native_browser_view_ getDeviceScaleFactor];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// |point| is in browser view coordinates.
|
|
|
|
NSPoint point = NSMakePoint(x, y);
|
|
|
|
|
|
|
|
// Convert to device coordinates.
|
|
|
|
point.x = LogicalToDevice(point.x, device_scale_factor);
|
|
|
|
point.y = LogicalToDevice(point.y, device_scale_factor);
|
|
|
|
|
|
|
|
// Convert to OS X view coordinates.
|
2019-04-23 19:17:56 +02:00
|
|
|
point = [native_browser_view_ convertPointFromBackingInternal:point];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
return [native_browser_view_
|
|
|
|
startDragging:drag_data
|
|
|
|
allowedOps:static_cast<NSDragOperation>(allowed_ops)
|
|
|
|
point:point];
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::UpdateDragCursor(
|
2015-01-30 19:07:13 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (native_browser_view_) {
|
2019-04-23 19:17:56 +02:00
|
|
|
[native_browser_view_ setCurrentDragOp:operation];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:07:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::OnImeCompositionRangeChanged(
|
2016-10-28 18:11:24 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRange& selection_range,
|
|
|
|
const CefRenderHandler::RectList& bounds) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
if (native_browser_view_) {
|
|
|
|
[native_browser_view_ ChangeCompositionRange:selection_range
|
|
|
|
character_bounds:bounds];
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::UpdateAccessibilityTree(
|
|
|
|
CefRefPtr<CefValue> value) {
|
2017-05-12 20:28:25 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
if (native_browser_view_) {
|
|
|
|
[native_browser_view_ UpdateAccessibilityTree:value];
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::UpdateAccessibilityLocation(
|
|
|
|
CefRefPtr<CefValue> value) {
|
2019-03-26 15:13:55 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
if (native_browser_view_) {
|
|
|
|
[native_browser_view_ UpdateAccessibilityLocation:value];
|
2019-03-26 15:13:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMacImpl::Create(ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect) {
|
2015-01-30 19:07:13 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2019-04-23 19:17:56 +02:00
|
|
|
DCHECK(!native_browser_view_);
|
2015-01-30 19:07:13 +01:00
|
|
|
|
|
|
|
NSRect window_rect = NSMakeRect(rect.x, rect.y, rect.width, rect.height);
|
2019-04-23 19:17:56 +02:00
|
|
|
native_browser_view_ =
|
|
|
|
[[BrowserOpenGLView alloc] initWithFrame:window_rect
|
|
|
|
andBrowserWindow:&browser_window_
|
|
|
|
andRenderer:&renderer_];
|
|
|
|
native_browser_view_.autoresizingMask =
|
|
|
|
(NSViewWidthSizable | NSViewHeightSizable);
|
|
|
|
native_browser_view_.autoresizesSubviews = YES;
|
|
|
|
[CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(parent_handle)
|
|
|
|
addSubview:native_browser_view_];
|
2015-01-30 19:07:13 +01:00
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Determine the default scale factor.
|
2019-04-23 19:17:56 +02:00
|
|
|
[native_browser_view_ resetDeviceScaleFactor];
|
2015-08-10 22:49:45 +02:00
|
|
|
|
2016-04-29 18:42:09 +02:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
2019-04-23 19:17:56 +02:00
|
|
|
addObserver:native_browser_view_
|
2017-05-17 11:29:28 +02:00
|
|
|
selector:@selector(windowDidChangeBackingProperties:)
|
|
|
|
name:NSWindowDidChangeBackingPropertiesNotification
|
2019-04-23 19:17:56 +02:00
|
|
|
object:native_browser_view_.window];
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWindowOsrMac::BrowserWindowOsrMac(BrowserWindow::Delegate* delegate,
|
2022-03-22 19:31:30 +01:00
|
|
|
bool with_controls,
|
2019-04-23 19:17:56 +02:00
|
|
|
const std::string& startup_url,
|
|
|
|
const OsrRendererSettings& settings)
|
|
|
|
: BrowserWindow(delegate) {
|
2022-03-22 19:31:30 +01:00
|
|
|
client_handler_ =
|
|
|
|
new ClientHandlerOsr(this, this, with_controls, startup_url);
|
2019-04-23 19:17:56 +02:00
|
|
|
impl_.reset(
|
|
|
|
new BrowserWindowOsrMacImpl(delegate, startup_url, settings, *this));
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWindowOsrMac::~BrowserWindowOsrMac() {}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::CreateBrowser(
|
|
|
|
ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-05-18 14:23:17 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2019-04-23 19:17:56 +02:00
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
2019-05-18 14:23:17 +02:00
|
|
|
impl_->CreateBrowser(parent_handle, rect, settings, extra_info,
|
|
|
|
request_context);
|
2019-04-23 19:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::GetPopupConfig(CefWindowHandle temp_handle,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
|
|
|
impl_->GetPopupConfig(temp_handle, windowInfo, client, settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::ShowPopup(ClientWindowHandle parent_handle,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
|
|
|
impl_->ShowPopup(parent_handle, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::Show() {
|
|
|
|
impl_->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::Hide() {
|
|
|
|
impl_->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::SetBounds(int x, int y, size_t width, size_t height) {
|
|
|
|
impl_->SetBounds(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::SetFocus(bool focus) {
|
|
|
|
impl_->SetFocus(focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::SetDeviceScaleFactor(float device_scale_factor) {
|
|
|
|
impl_->SetDeviceScaleFactor(device_scale_factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
float BrowserWindowOsrMac::GetDeviceScaleFactor() const {
|
|
|
|
return impl_->GetDeviceScaleFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientWindowHandle BrowserWindowOsrMac::GetWindowHandle() const {
|
|
|
|
return impl_->GetWindowHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
impl_->OnAfterCreated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
|
|
|
impl_->OnBeforeClose(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWindowOsrMac::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) {
|
|
|
|
return impl_->GetRootScreenRect(browser, rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::GetViewRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) {
|
|
|
|
impl_->GetViewRect(browser, rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWindowOsrMac::GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY) {
|
|
|
|
return impl_->GetScreenPoint(browser, viewX, viewY, screenX, screenY);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWindowOsrMac::GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefScreenInfo& screen_info) {
|
|
|
|
return impl_->GetScreenInfo(browser, screen_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnPopupShow(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool show) {
|
|
|
|
impl_->OnPopupShow(browser, show);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnPopupSize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRect& rect) {
|
|
|
|
impl_->OnPopupSize(browser, rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height) {
|
|
|
|
impl_->OnPaint(browser, type, dirtyRects, buffer, width, height);
|
|
|
|
}
|
|
|
|
|
2024-03-08 13:44:56 +01:00
|
|
|
void BrowserWindowOsrMac::OnAcceleratedPaint(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const CefAcceleratedPaintInfo& info) {
|
|
|
|
impl_->OnAcceleratedPaint(browser, type, dirtyRects, info);
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:17:56 +02:00
|
|
|
void BrowserWindowOsrMac::OnCursorChange(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_type_t type,
|
2019-04-23 19:17:56 +02:00
|
|
|
const CefCursorInfo& custom_cursor_info) {
|
|
|
|
impl_->OnCursorChange(browser, cursor, type, custom_cursor_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWindowOsrMac::StartDragging(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
|
|
|
int x,
|
|
|
|
int y) {
|
|
|
|
return impl_->StartDragging(browser, drag_data, allowed_ops, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::UpdateDragCursor(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation) {
|
|
|
|
impl_->UpdateDragCursor(browser, operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::OnImeCompositionRangeChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRange& selection_range,
|
|
|
|
const CefRenderHandler::RectList& character_bounds) {
|
|
|
|
impl_->OnImeCompositionRangeChanged(browser, selection_range,
|
|
|
|
character_bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::UpdateAccessibilityTree(CefRefPtr<CefValue> value) {
|
|
|
|
impl_->UpdateAccessibilityTree(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrMac::UpdateAccessibilityLocation(
|
|
|
|
CefRefPtr<CefValue> value) {
|
|
|
|
impl_->UpdateAccessibilityLocation(value);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2015-01-23 18:37:23 +01:00
|
|
|
|
|
|
|
} // namespace client
|
2024-03-08 13:44:56 +01:00
|
|
|
|
|
|
|
// End disable NSOpenGL deprecation warnings.
|
|
|
|
#pragma clang diagnostic pop
|