OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 | 8 |
9 #include "app/mac/scoped_nsdisable_screen_updates.h" | 9 #include "app/mac/scoped_nsdisable_screen_updates.h" |
10 #include "app/mac/nsimage_cache.h" | 10 #include "app/mac/nsimage_cache.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // prevents the browser from being able to quit <http://crbug.com/79113>. | 267 // prevents the browser from being able to quit <http://crbug.com/79113>. |
268 if ([window respondsToSelector:@selector(setRestorable:)]) | 268 if ([window respondsToSelector:@selector(setRestorable:)]) |
269 [window setRestorable:NO]; | 269 [window setRestorable:NO]; |
270 | 270 |
271 // Get the most appropriate size for the window, then enforce the | 271 // Get the most appropriate size for the window, then enforce the |
272 // minimum width and height. The window shim will handle flipping | 272 // minimum width and height. The window shim will handle flipping |
273 // the coordinates for us so we can use it to save some code. | 273 // the coordinates for us so we can use it to save some code. |
274 // Note that this may leave a significant portion of the window | 274 // Note that this may leave a significant portion of the window |
275 // offscreen, but there will always be enough window onscreen to | 275 // offscreen, but there will always be enough window onscreen to |
276 // drag the whole window back into view. | 276 // drag the whole window back into view. |
277 NSSize minSize = [[self window] minSize]; | |
278 gfx::Rect desiredContentRect = browser_->GetSavedWindowBounds(); | 277 gfx::Rect desiredContentRect = browser_->GetSavedWindowBounds(); |
279 gfx::Rect windowRect = desiredContentRect; | 278 gfx::Rect windowRect = desiredContentRect; |
280 if (windowRect.width() < minSize.width) | 279 windowRect = [self enforceMinWindowSize:windowRect]; |
281 windowRect.set_width(minSize.width); | |
282 if (windowRect.height() < minSize.height) | |
283 windowRect.set_height(minSize.height); | |
284 | 280 |
285 // When we are given x/y coordinates of 0 on a created popup window, assume | 281 // When we are given x/y coordinates of 0 on a created popup window, assume |
286 // none were given by the window.open() command. | 282 // none were given by the window.open() command. |
287 if ((browser_->is_type_popup() || browser_->is_type_panel()) && | 283 if ((browser_->is_type_popup() || browser_->is_type_panel()) && |
288 windowRect.x() == 0 && windowRect.y() == 0) { | 284 windowRect.x() == 0 && windowRect.y() == 0) { |
289 gfx::Size size = windowRect.size(); | 285 gfx::Size size = windowRect.size(); |
290 windowRect.set_origin(WindowSizer::GetDefaultPopupOrigin(size)); | 286 windowRect.set_origin(WindowSizer::GetDefaultPopupOrigin(size)); |
291 } | 287 } |
292 | 288 |
293 // Size and position the window. Note that it is not yet onscreen. Popup | 289 // Size and position the window. Note that it is not yet onscreen. Popup |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 [fullscreenButton setAction:@selector(enterFullscreen:)]; | 427 [fullscreenButton setAction:@selector(enterFullscreen:)]; |
432 [fullscreenButton setTarget:self]; | 428 [fullscreenButton setTarget:self]; |
433 } | 429 } |
434 | 430 |
435 // We are done initializing now. | 431 // We are done initializing now. |
436 initializing_ = NO; | 432 initializing_ = NO; |
437 } | 433 } |
438 return self; | 434 return self; |
439 } | 435 } |
440 | 436 |
| 437 - (void)awakeFromNib { |
| 438 // Set different minimum sizes on tabbed windows vs non-tabbed, e.g. popups. |
| 439 NSSize minSize = [self isTabbedWindow] ? |
| 440 NSMakeSize(400, 272) : NSMakeSize(100, 122); |
| 441 [[self window] setMinSize:minSize]; |
| 442 } |
| 443 |
441 - (void)dealloc { | 444 - (void)dealloc { |
442 browser_->CloseAllTabs(); | 445 browser_->CloseAllTabs(); |
443 [downloadShelfController_ exiting]; | 446 [downloadShelfController_ exiting]; |
444 | 447 |
445 // Explicitly release |fullscreenController_| here, as it may call back to | 448 // Explicitly release |fullscreenController_| here, as it may call back to |
446 // this BWC in |-dealloc|. We are required to call |-exitFullscreen| before | 449 // this BWC in |-dealloc|. We are required to call |-exitFullscreen| before |
447 // releasing the controller. | 450 // releasing the controller. |
448 [fullscreenController_ exitFullscreen]; | 451 [fullscreenController_ exitFullscreen]; |
449 fullscreenController_.reset(); | 452 fullscreenController_.reset(); |
450 | 453 |
451 // Under certain testing configurations we may not actually own the browser. | 454 // Under certain testing configurations we may not actually own the browser. |
452 if (ownsBrowser_ == NO) | 455 if (ownsBrowser_ == NO) |
453 ignore_result(browser_.release()); | 456 ignore_result(browser_.release()); |
454 | 457 |
455 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 458 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
456 | 459 |
457 [super dealloc]; | 460 [super dealloc]; |
458 } | 461 } |
459 | 462 |
| 463 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds { |
| 464 gfx::Rect checkedBounds = bounds; |
| 465 |
| 466 NSSize minSize = [[self window] minSize]; |
| 467 if (bounds.width() < minSize.width) |
| 468 checkedBounds.set_width(minSize.width); |
| 469 if (bounds.height() < minSize.height) |
| 470 checkedBounds.set_height(minSize.height); |
| 471 |
| 472 return checkedBounds; |
| 473 } |
| 474 |
460 - (BrowserWindow*)browserWindow { | 475 - (BrowserWindow*)browserWindow { |
461 return windowShim_.get(); | 476 return windowShim_.get(); |
462 } | 477 } |
463 | 478 |
464 - (ToolbarController*)toolbarController { | 479 - (ToolbarController*)toolbarController { |
465 return toolbarController_.get(); | 480 return toolbarController_.get(); |
466 } | 481 } |
467 | 482 |
468 - (TabStripController*)tabStripController { | 483 - (TabStripController*)tabStripController { |
469 return tabStripController_.get(); | 484 return tabStripController_.get(); |
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 | 2212 |
2198 - (BOOL)supportsBookmarkBar { | 2213 - (BOOL)supportsBookmarkBar { |
2199 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2214 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2200 } | 2215 } |
2201 | 2216 |
2202 - (BOOL)isTabbedWindow { | 2217 - (BOOL)isTabbedWindow { |
2203 return browser_->is_type_tabbed(); | 2218 return browser_->is_type_tabbed(); |
2204 } | 2219 } |
2205 | 2220 |
2206 @end // @implementation BrowserWindowController(WindowType) | 2221 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |