Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / shell / browser / shell_native_app_window_mac.mm
blob2b879e89147b3e8263519f3a1a86cc945f70e12c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "extensions/shell/browser/shell_native_app_window_mac.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "content/public/browser/web_contents.h"
13 #import "ui/gfx/mac/coordinate_conversion.h"
15 @implementation ShellNativeAppWindowController
17 @synthesize appWindow = appWindow_;
19 - (void)windowWillClose:(NSNotification*)notification {
20   if (appWindow_)
21     appWindow_->WindowWillClose();
24 @end
26 // TODO(yoz): Do we need to handle commands (keyboard shortcuts)?
27 // Do we need need ChromeEventProcessingWindow or UnderlayOpenGLHostingWindow?
28 @interface ShellNSWindow : NSWindow
29 @end
31 @implementation ShellNSWindow
33 - (BOOL)_isTitleHidden {
34   return YES;
37 @end
39 namespace extensions {
41 ShellNativeAppWindowMac::ShellNativeAppWindowMac(
42     AppWindow* app_window,
43     const AppWindow::CreateParams& params)
44     : ShellNativeAppWindow(app_window, params) {
45   base::scoped_nsobject<NSWindow> shell_window;
46   NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask;
48   NSRect cocoa_bounds = gfx::ScreenRectToNSRect(
49       params.GetInitialWindowBounds(gfx::Insets()));
51   shell_window.reset(
52       [[ShellNSWindow alloc] initWithContentRect:cocoa_bounds
53                                        styleMask:style_mask
54                                          backing:NSBackingStoreBuffered
55                                            defer:NO]);
56   [shell_window setReleasedWhenClosed:NO];
58   window_controller_.reset([[ShellNativeAppWindowController alloc]
59                             initWithWindow:shell_window]);
61   [[window_controller_ window] setDelegate:window_controller_];
62   [window_controller_ setAppWindow:this];
64   NSView* view = app_window->web_contents()->GetNativeView();
65   NSView* frameView = [window() contentView];
66   [view setFrame:[frameView bounds]];
67   [frameView addSubview:view];
70 ShellNativeAppWindowMac::~ShellNativeAppWindowMac() {
71   [window() setDelegate:nil];
72   [window() close];
75 bool ShellNativeAppWindowMac::IsActive() const {
76   return [window() isKeyWindow];
79 gfx::NativeWindow ShellNativeAppWindowMac::GetNativeWindow() const {
80   return window();
83 gfx::Rect ShellNativeAppWindowMac::GetBounds() const {
84   return gfx::ScreenRectFromNSRect([window() frame]);
87 void ShellNativeAppWindowMac::Show() {
88   [window_controller_ showWindow:nil];
91 void ShellNativeAppWindowMac::Hide() {
92   NOTIMPLEMENTED();
95 void ShellNativeAppWindowMac::Activate() {
96   // TODO(yoz): Activate in front of other applications.
97   [[window_controller_ window] makeKeyAndOrderFront:window_controller_];
100 void ShellNativeAppWindowMac::Deactivate() {
101   // See crbug.com/51364.
102   NOTIMPLEMENTED();
105 void ShellNativeAppWindowMac::SetBounds(const gfx::Rect& bounds) {
106   // TODO(yoz): Windows should be fullscreen.
107   NOTIMPLEMENTED();
110 void ShellNativeAppWindowMac::WindowWillClose() {
111   [window_controller_ setAppWindow:NULL];
112   app_window()->OnNativeWindowChanged();
113   app_window()->OnNativeClose();
116 ShellNSWindow* ShellNativeAppWindowMac::window() const {
117   return base::mac::ObjCCastStrict<ShellNSWindow>([window_controller_ window]);
120 }  // namespace extensions