Chromium Code Reviews| Index: extensions/shell/browser/shell_native_app_window_mac.mm |
| diff --git a/extensions/shell/browser/shell_native_app_window_mac.mm b/extensions/shell/browser/shell_native_app_window_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2e74c3ef4b8b3d202104fdbe72887cb757e3cdd |
| --- /dev/null |
| +++ b/extensions/shell/browser/shell_native_app_window_mac.mm |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/shell/browser/shell_native_app_window_mac.h" |
|
tapted
2014/12/17 08:05:16
nit: import
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +@implementation ShellNativeAppWindowController |
| + |
| +@synthesize appWindow = appWindow_; |
| + |
| +- (void)windowWillClose:(NSNotification*)notification { |
| + if (appWindow_) |
| + appWindow_->WindowWillClose(); |
| +} |
| + |
| +@end |
| + |
| +// TODO(yoz): Do we need to handle commands (keyboard shortcuts)? |
| +// Do we need need ChromeEventProcessingWindow or UnderlayOpenGLHostingWindow? |
| +@interface ShellNSWindow : NSWindow |
| +@end |
| + |
| +@implementation ShellNSWindow |
| + |
| +- (BOOL)_isTitleHidden { |
| + return YES; |
| +} |
| + |
| +@end |
| + |
| +namespace extensions { |
| + |
| +ShellNativeAppWindowMac::ShellNativeAppWindowMac( |
| + AppWindow* app_window, |
| + const AppWindow::CreateParams& params) |
| + : ShellNativeAppWindow(app_window, params) { |
| + base::scoped_nsobject<NSWindow> shell_window; |
| + NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask; |
| + |
| + NSRect cocoa_bounds = params.GetInitialWindowBounds(gfx::Insets()).ToCGRect(); |
| + // TODO(yoz): Flip coordinates here? |
|
tapted
2014/12/17 08:05:16
you could use gfx::ScreenRectToNSRect from #import
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + |
| + shell_window.reset( |
| + [[ShellNSWindow alloc] initWithContentRect:cocoa_bounds |
| + styleMask:style_mask |
| + backing:NSBackingStoreBuffered |
| + defer:NO]); |
| + |
| + window_controller_.reset([[ShellNativeAppWindowController alloc] |
| + initWithWindow:shell_window.release()]); |
|
tapted
2014/12/17 08:05:16
The release() looks a bit like a leak, but it's ne
Yoyo Zhou
2014/12/18 02:38:34
This looks more complicated right now; I was hopin
tapted
2014/12/18 03:30:55
Corect - the releases are not the same. But NSWind
|
| + |
| + [[window_controller_ window] setDelegate:window_controller_]; |
| + [window_controller_ setAppWindow:this]; |
| + |
| + NSView* view = app_window->web_contents()->GetNativeView(); |
| + NSView* frameView = [window() contentView]; |
| + [view setFrame:[frameView bounds]]; |
| + [frameView addSubview:view]; |
| +} |
| + |
| +ShellNativeAppWindowMac::~ShellNativeAppWindowMac() { |
| +} |
|
tapted
2014/12/17 08:05:16
this should call [window() setDelegate:nil]; (the
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + |
| +bool ShellNativeAppWindowMac::IsActive() const { |
| + NOTIMPLEMENTED(); |
|
tapted
2014/12/17 08:05:16
if you feel like it now.. [window() isKeyWindow] s
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + return false; |
| +} |
| + |
| +gfx::NativeWindow ShellNativeAppWindowMac::GetNativeWindow() const { |
| + return window(); |
| +} |
| + |
| +gfx::Rect ShellNativeAppWindowMac::GetBounds() const { |
| + // Flip coordinates based on the primary screen. |
|
tapted
2014/12/17 08:05:16
return gfx::ScreenRectFromNSRect([window() frame])
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| + NSRect frame = [[window_controller_ window] frame]; |
| + return gfx::Rect(frame.origin.x, NSHeight([screen frame]) - NSMaxY(frame), |
| + NSWidth(frame), NSHeight(frame)); |
| +} |
| + |
| +void ShellNativeAppWindowMac::Show() { |
| + [window_controller_ showWindow:nil]; |
| +} |
| + |
| +void ShellNativeAppWindowMac::Hide() { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ShellNativeAppWindowMac::Activate() { |
| + // TODO(yoz): Activate in front of other applications. |
| + [[window_controller_ window] makeKeyAndOrderFront:window_controller_]; |
| +} |
| + |
| +void ShellNativeAppWindowMac::Deactivate() { |
| + // See crbug.com/51364. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ShellNativeAppWindowMac::SetBounds(const gfx::Rect& bounds) { |
| + // TODO(yoz): Windows should be fullscreen. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ShellNativeAppWindowMac::WindowWillClose() { |
| + [window_controller_ setAppWindow:NULL]; |
| + app_window()->OnNativeWindowChanged(); |
| + app_window()->OnNativeClose(); |
| +} |
| + |
| +ShellNSWindow* ShellNativeAppWindowMac::window() const { |
| + NSWindow* window = [window_controller_ window]; |
| + CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
|
tapted
2014/12/17 08:05:16
maybe, from base/mac/foundation_util.h
return b
Yoyo Zhou
2014/12/18 02:38:34
Done.
|
| + return static_cast<ShellNSWindow*>(window); |
| +} |
| + |
| +} // namespace extensions |