OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #import "extensions/shell/browser/shell_native_app_window_mac.h" | |
6 | |
7 #import <Cocoa/Cocoa.h> | |
8 | |
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" | |
14 | |
15 @implementation ShellNativeAppWindowController | |
16 | |
17 @synthesize appWindow = appWindow_; | |
18 | |
19 - (void)windowWillClose:(NSNotification*)notification { | |
20 if (appWindow_) | |
21 appWindow_->WindowWillClose(); | |
22 } | |
23 | |
24 @end | |
25 | |
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 | |
30 | |
31 @implementation ShellNSWindow | |
32 | |
33 - (BOOL)_isTitleHidden { | |
34 return YES; | |
35 } | |
36 | |
37 @end | |
38 | |
39 namespace extensions { | |
40 | |
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; | |
47 | |
48 NSRect cocoa_bounds = gfx::ScreenRectToNSRect( | |
49 params.GetInitialWindowBounds(gfx::Insets())); | |
50 | |
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]; | |
57 | |
58 window_controller_.reset([[ShellNativeAppWindowController alloc] | |
59 initWithWindow:shell_window.release()]); | |
tapted
2014/12/18 03:30:55
It's now properly owned by the scoped_nsobject, so
Yoyo Zhou
2014/12/18 22:42:07
Done.
| |
60 | |
61 [[window_controller_ window] setDelegate:window_controller_]; | |
62 [window_controller_ setAppWindow:this]; | |
63 | |
64 NSView* view = app_window->web_contents()->GetNativeView(); | |
65 NSView* frameView = [window() contentView]; | |
66 [view setFrame:[frameView bounds]]; | |
67 [frameView addSubview:view]; | |
68 } | |
69 | |
70 ShellNativeAppWindowMac::~ShellNativeAppWindowMac() { | |
71 [window() setDelegate:nil]; | |
72 [window() close]; | |
73 } | |
74 | |
75 bool ShellNativeAppWindowMac::IsActive() const { | |
76 return [window() isKeyWindow]; | |
77 } | |
78 | |
79 gfx::NativeWindow ShellNativeAppWindowMac::GetNativeWindow() const { | |
80 return window(); | |
81 } | |
82 | |
83 gfx::Rect ShellNativeAppWindowMac::GetBounds() const { | |
84 return gfx::ScreenRectFromNSRect([window() frame]); | |
85 } | |
86 | |
87 void ShellNativeAppWindowMac::Show() { | |
88 [window_controller_ showWindow:nil]; | |
89 } | |
90 | |
91 void ShellNativeAppWindowMac::Hide() { | |
92 NOTIMPLEMENTED(); | |
93 } | |
94 | |
95 void ShellNativeAppWindowMac::Activate() { | |
96 // TODO(yoz): Activate in front of other applications. | |
97 [[window_controller_ window] makeKeyAndOrderFront:window_controller_]; | |
98 } | |
99 | |
100 void ShellNativeAppWindowMac::Deactivate() { | |
101 // See crbug.com/51364. | |
102 NOTIMPLEMENTED(); | |
103 } | |
104 | |
105 void ShellNativeAppWindowMac::SetBounds(const gfx::Rect& bounds) { | |
106 // TODO(yoz): Windows should be fullscreen. | |
107 NOTIMPLEMENTED(); | |
108 } | |
109 | |
110 void ShellNativeAppWindowMac::WindowWillClose() { | |
111 [window_controller_ setAppWindow:NULL]; | |
112 app_window()->OnNativeWindowChanged(); | |
113 app_window()->OnNativeClose(); | |
114 } | |
115 | |
116 ShellNSWindow* ShellNativeAppWindowMac::window() const { | |
117 return base::mac::ObjCCastStrict<ShellNSWindow>([window_controller_ window]); | |
118 } | |
119 | |
120 } // namespace extensions | |
OLD | NEW |