gfx::NativeView is no longer NSView on mac

https://chromium-review.googlesource.com/c/1270343
This commit is contained in:
Jeremy Apthorp 2019-01-09 12:25:19 -08:00
parent 70887ae21a
commit d228bdfb9e
12 changed files with 78 additions and 53 deletions

View file

@ -92,7 +92,9 @@ void ShowCertificateTrust(atom::NativeWindow* parent_window,
SecTrustRef trust = nullptr;
SecTrustCreateWithCertificates(cert_chain, sec_policy, &trust);
NSWindow* window = parent_window ? parent_window->GetNativeWindow() : nil;
NSWindow* window = parent_window
? parent_window->GetNativeWindow().GetNativeNSWindow()
: nil;
auto msg = base::SysUTF8ToNSString(message);
auto panel = [[SFCertificateTrustPanel alloc] init];

View file

@ -43,7 +43,7 @@
} else {
auto* contents = inspectableWebContentsView_->inspectable_web_contents()
->GetWebContents();
auto contentsView = contents->GetNativeView();
auto* contentsView = contents->GetNativeView().GetNativeNSView();
[contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self addSubview:contentsView];
}
@ -79,7 +79,7 @@
inspectableWebContentsView_->inspectable_web_contents();
auto* devToolsWebContents =
inspectable_web_contents->GetDevToolsWebContents();
auto devToolsView = devToolsWebContents->GetNativeView();
auto* devToolsView = devToolsWebContents->GetNativeView().GetNativeNSView();
devtools_visible_ = visible;
if (devtools_docked_) {
@ -134,7 +134,7 @@
inspectableWebContentsView_->inspectable_web_contents();
auto* devToolsWebContents =
inspectable_web_contents->GetDevToolsWebContents();
auto devToolsView = devToolsWebContents->GetNativeView();
auto devToolsView = devToolsWebContents->GetNativeView().GetNativeNSView();
auto styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
NSMiniaturizableWindowMask | NSWindowStyleMaskResizable |
@ -203,7 +203,7 @@
if (!inspectable_web_contents || inspectable_web_contents->IsGuest())
return;
auto* webContents = inspectable_web_contents->GetWebContents();
auto webContentsView = webContents->GetNativeView();
auto* webContentsView = webContents->GetNativeView().GetNativeNSView();
NSView* view = [notification object];
if ([[webContentsView subviews] containsObject:view]) {
@ -215,7 +215,7 @@
inspectable_web_contents->GetDevToolsWebContents();
if (!devToolsWebContents)
return;
auto devToolsView = devToolsWebContents->GetNativeView();
auto devToolsView = devToolsWebContents->GetNativeView().GetNativeNSView();
if ([[devToolsView subviews] containsObject:view]) {
devtools_is_first_responder_ = YES;

View file

@ -9,6 +9,7 @@
#include "atom/browser/ui/cocoa/atom_preview_item.h"
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
#include "base/mac/mac_util.h"
#include "ui/views/cocoa/bridged_native_widget_host_impl.h"
#include "ui/views/widget/native_widget_mac.h"
#include "ui/views_bridge_mac/bridged_native_widget_impl.h"
@ -21,12 +22,13 @@
// on the fly.
// TODO(zcbenz): Add interface in NativeWidgetMac to allow overriding creating
// window delegate.
auto* bridged_view = views::BridgedNativeWidgetImpl::GetFromNativeWindow(
auto* bridge_host = views::BridgedNativeWidgetHostImpl::GetFromNativeWindow(
shell->GetNativeWindow());
auto* bridged_view = bridge_host->bridge_impl();
if ((self = [super initWithBridgedNativeWidget:bridged_view])) {
shell_ = shell;
is_zooming_ = false;
level_ = [shell_->GetNativeWindow() level];
level_ = [shell_->GetNativeWindow().GetNativeNSWindow() level];
}
return self;
}
@ -138,7 +140,7 @@
}
- (void)windowWillMiniaturize:(NSNotification*)notification {
NSWindow* window = shell_->GetNativeWindow();
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
// store the current status window level to be restored in
// windowDidDeminiaturize
level_ = [window level];
@ -152,7 +154,7 @@
- (void)windowDidDeminiaturize:(NSNotification*)notification {
[super windowDidDeminiaturize:notification];
[shell_->GetNativeWindow() setLevel:level_];
[shell_->GetNativeWindow().GetNativeNSWindow() setLevel:level_];
shell_->NotifyWindowRestore();
}
@ -179,7 +181,7 @@
// artifacts.
if (@available(macOS 10.10, *)) {
if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) {
NSWindow* window = shell_->GetNativeWindow();
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
[window setToolbar:nil];
}
}
@ -192,7 +194,7 @@
// For frameless window we don't show set title for normal mode since the
// titlebar is expected to be empty, but after entering fullscreen mode we
// have to set one, because title bar is visible here.
NSWindow* window = shell_->GetNativeWindow();
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
if ((shell_->transparent() || !shell_->has_frame()) &&
// FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under
// fullscreen mode.
@ -221,7 +223,7 @@
- (void)windowWillExitFullScreen:(NSNotification*)notification {
if (@available(macOS 10.10, *)) {
// Restore the titlebar visibility.
NSWindow* window = shell_->GetNativeWindow();
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
if ((shell_->transparent() || !shell_->has_frame()) &&
(shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET ||
shell_->fullscreen_window_title())) {
@ -247,8 +249,9 @@
// Clears the delegate when window is going to be closed, since EL Capitan it
// is possible that the methods of delegate would get called after the window
// has been closed.
auto* bridged_view = views::BridgedNativeWidgetImpl::GetFromNativeWindow(
auto* bridge_host = views::BridgedNativeWidgetHostImpl::GetFromNativeWindow(
shell_->GetNativeWindow());
auto* bridged_view = bridge_host->bridge_impl();
bridged_view->OnWindowWillClose();
}

View file

@ -33,26 +33,27 @@ void DragFileItems(const std::vector<base::FilePath>& files,
// Synthesize a drag event, since we don't have access to the actual event
// that initiated a drag (possibly consumed by the Web UI, for example).
NSPoint position = [[view window] mouseLocationOutsideOfEventStream];
NSWindow* window = [view.GetNativeNSView() window];
NSPoint position = [window mouseLocationOutsideOfEventStream];
NSTimeInterval eventTime = [[NSApp currentEvent] timestamp];
NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged
location:position
modifierFlags:NSLeftMouseDraggedMask
timestamp:eventTime
windowNumber:[[view window] windowNumber]
windowNumber:[window windowNumber]
context:nil
eventNumber:0
clickCount:1
pressure:1.0];
// Run the drag operation.
[[view window] dragImage:icon.ToNSImage()
at:position
offset:NSZeroSize
event:dragEvent
pasteboard:pasteboard
source:view
slideBack:YES];
[window dragImage:icon.ToNSImage()
at:position
offset:NSZeroSize
event:dragEvent
pasteboard:pasteboard
source:view.GetNativeNSView()
slideBack:YES];
}
} // namespace atom

View file

@ -210,7 +210,8 @@ int RunModalDialog(NSSavePanel* dialog, const DialogSettings& settings) {
settings.force_detached) {
chosen = [dialog runModal];
} else {
NSWindow* window = settings.parent_window->GetNativeWindow();
NSWindow* window =
settings.parent_window->GetNativeWindow().GetNativeNSWindow();
[dialog beginSheetModalForWindow:window
completionHandler:^(NSInteger c) {
@ -328,7 +329,8 @@ void ShowOpenDialog(const DialogSettings& settings,
OpenDialogCompletion(chosen, dialog, settings, callback);
}];
} else {
NSWindow* window = settings.parent_window->GetNativeWindow();
NSWindow* window =
settings.parent_window->GetNativeWindow().GetNativeNSWindow();
[dialog beginSheetModalForWindow:window
completionHandler:^(NSInteger chosen) {
OpenDialogCompletion(chosen, dialog, settings, callback);
@ -389,7 +391,8 @@ void ShowSaveDialog(const DialogSettings& settings,
SaveDialogCompletion(chosen, dialog, settings, callback);
}];
} else {
NSWindow* window = settings.parent_window->GetNativeWindow();
NSWindow* window =
settings.parent_window->GetNativeWindow().GetNativeNSWindow();
[dialog beginSheetModalForWindow:window
completionHandler:^(NSInteger chosen) {
SaveDialogCompletion(chosen, dialog, settings, callback);

View file

@ -156,7 +156,7 @@ int ShowMessageBox(NativeWindow* parent_window,
andAlert:alert
callEndModal:true];
NSWindow* window = parent_window->GetNativeWindow();
NSWindow* window = parent_window->GetNativeWindow().GetNativeNSWindow();
[alert beginSheetModalForWindow:window
modalDelegate:delegate
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
@ -193,7 +193,9 @@ void ShowMessageBox(NativeWindow* parent_window,
andAlert:alert
callEndModal:false];
NSWindow* window = parent_window ? parent_window->GetNativeWindow() : nil;
NSWindow* window =
parent_window ? parent_window->GetNativeWindow().GetNativeNSWindow()
: nil;
[alert
beginSheetModalForWindow:window
modalDelegate:delegate