OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" |
6 | 6 |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 9 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 | 11 |
12 @implementation ShellWindowController | 12 @implementation ShellWindowController |
13 | 13 |
14 @synthesize shellWindow = shellWindow_; | 14 @synthesize shellWindow = shellWindow_; |
15 | 15 |
16 - (void)windowWillClose:(NSNotification*)notification { | 16 - (void)windowWillClose:(NSNotification*)notification { |
17 if (shellWindow_) | 17 if (shellWindow_) |
18 shellWindow_->WindowWillClose(); | 18 shellWindow_->WindowWillClose(); |
19 } | 19 } |
20 | 20 |
21 @end | 21 @end |
22 | 22 |
23 ShellWindowCocoa::ShellWindowCocoa(ExtensionHost* host) : ShellWindow(host) { | 23 ShellWindowCocoa::ShellWindowCocoa(ExtensionHost* host) : ShellWindow(host) { |
24 // TOOD(mihaip): Allow window dimensions to be specified in manifest (and | 24 // TOOD(mihaip): Restore prior window dimensions and positions on relaunch. |
25 // restore prior window dimensions and positions on relaunch). | 25 NSRect rect = NSZeroRect; |
26 NSRect rect = NSMakeRect(0, 0, 512, 384); | 26 rect.size.width = host_->extension()->launch_width(); |
27 rect.size.height = host_->extension()->launch_height(); | |
jeremy
2012/02/23 13:21:40
What if the launch_width is larger than the screen
sail
2012/02/23 19:42:34
When a window is shown it is automatically resized
| |
27 NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | | 28 NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | |
28 NSMiniaturizableWindowMask | NSResizableWindowMask; | 29 NSMiniaturizableWindowMask | NSResizableWindowMask; |
29 scoped_nsobject<NSWindow> window( | 30 scoped_nsobject<NSWindow> window( |
30 [[NSWindow alloc] initWithContentRect:rect | 31 [[NSWindow alloc] initWithContentRect:rect |
31 styleMask:styleMask | 32 styleMask:styleMask |
32 backing:NSBackingStoreBuffered | 33 backing:NSBackingStoreBuffered |
33 defer:NO]); | 34 defer:NO]); |
34 [window setTitle:base::SysUTF8ToNSString(host->extension()->name())]; | 35 [window setTitle:base::SysUTF8ToNSString(host->extension()->name())]; |
36 [window setContentMinSize: | |
37 NSMakeSize(host_->extension()->launch_min_width(), | |
38 host_->extension()->launch_min_height())]; | |
35 | 39 |
36 NSView* view = host->view()->native_view(); | 40 NSView* view = host->view()->native_view(); |
37 [view setFrame:rect]; | 41 [view setFrame:rect]; |
38 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 42 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
39 [[window contentView] addSubview:view]; | 43 [[window contentView] addSubview:view]; |
40 | 44 |
41 window_controller_.reset( | 45 window_controller_.reset( |
42 [[ShellWindowController alloc] initWithWindow:window.release()]); | 46 [[ShellWindowController alloc] initWithWindow:window.release()]); |
43 [[window_controller_ window] setDelegate:window_controller_]; | 47 [[window_controller_ window] setDelegate:window_controller_]; |
44 [window_controller_ setShellWindow:this]; | 48 [window_controller_ setShellWindow:this]; |
45 [window_controller_ showWindow:nil]; | 49 [window_controller_ showWindow:nil]; |
46 } | 50 } |
47 | 51 |
48 void ShellWindowCocoa::Close() { | 52 void ShellWindowCocoa::Close() { |
49 [[window_controller_ window] performClose:nil]; | 53 [[window_controller_ window] performClose:nil]; |
50 } | 54 } |
51 | 55 |
52 void ShellWindowCocoa::WindowWillClose() { | 56 void ShellWindowCocoa::WindowWillClose() { |
53 [window_controller_ setShellWindow:NULL]; | 57 [window_controller_ setShellWindow:NULL]; |
54 delete this; | 58 delete this; |
55 } | 59 } |
56 | 60 |
57 ShellWindowCocoa::~ShellWindowCocoa() { | 61 ShellWindowCocoa::~ShellWindowCocoa() { |
58 } | 62 } |
59 | 63 |
60 // static | 64 // static |
61 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { | 65 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { |
62 return new ShellWindowCocoa(host); | 66 return new ShellWindowCocoa(host); |
63 } | 67 } |
OLD | NEW |