Chromium Code Reviews| 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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 37 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 39 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
| 40 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 41 #include "content/browser/tab_contents/tab_contents.h" | 41 #include "content/browser/tab_contents/tab_contents.h" |
| 42 #include "content/common/native_web_keyboard_event.h" | 42 #include "content/common/native_web_keyboard_event.h" |
| 43 #include "content/common/notification_service.h" | 43 #include "content/common/notification_service.h" |
| 44 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
| 45 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 46 #include "ui/base/l10n/l10n_util_mac.h" | 46 #include "ui/base/l10n/l10n_util_mac.h" |
| 47 #include "ui/base/ui_base_types.h" | |
| 47 #include "ui/gfx/rect.h" | 48 #include "ui/gfx/rect.h" |
| 48 | 49 |
| 50 // Provide the forward-declarations of new 10.7 SDK symbols so they can be | |
|
Mark Mentovai
2011/08/19 19:17:27
People keep copying and pasting this comment, but
dhollowa
2011/08/19 20:38:16
Done. And I've fixed it in the other copy/paste s
| |
| 51 // called when building with the 10.5 SDK. | |
| 52 #if !defined(MAC_OS_X_VERSION_10_7) || \ | |
| 53 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | |
| 54 | |
| 55 enum { | |
| 56 NSWindowAnimationBehaviorDefault = 0, | |
| 57 NSWindowAnimationBehaviorNone = 2, | |
| 58 NSWindowAnimationBehaviorDocumentWindow = 3, | |
| 59 NSWindowAnimationBehaviorUtilityWindow = 4, | |
| 60 NSWindowAnimationBehaviorAlertPanel = 5 | |
| 61 }; | |
| 62 typedef NSInteger NSWindowAnimationBehavior; | |
| 63 | |
| 64 @interface NSWindow (LionSDKDeclarations) | |
| 65 - (NSWindowAnimationBehavior)animationBehavior; | |
| 66 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; | |
| 67 @end | |
| 68 | |
| 69 #endif // MAC_OS_X_VERSION_10_7 | |
| 70 | |
| 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 71 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 50 BrowserWindowController* controller, | 72 BrowserWindowController* controller) |
| 51 NSWindow* window) | |
| 52 : browser_(browser), | 73 : browser_(browser), |
| 53 controller_(controller), | 74 controller_(controller), |
| 54 confirm_close_factory_(browser) { | 75 confirm_close_factory_(browser) { |
| 55 // Listen for bookmark bar visibility changes and set the initial state; we | 76 // Listen for bookmark bar visibility changes and set the initial state; we |
| 56 // need to listen to all profiles because of normal profile/incognito issues. | 77 // need to listen to all profiles because of normal profile/incognito issues. |
| 57 registrar_.Add(this, | 78 registrar_.Add(this, |
| 58 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 79 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 59 NotificationService::AllBrowserContextsAndSources()); | 80 NotificationService::AllBrowserContextsAndSources()); |
| 60 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 81 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 61 Source<SidebarManager>(SidebarManager::GetInstance())); | 82 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 62 } | 83 } |
| 63 | 84 |
| 64 BrowserWindowCocoa::~BrowserWindowCocoa() { | 85 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 65 } | 86 } |
| 66 | 87 |
| 67 void BrowserWindowCocoa::Show() { | 88 void BrowserWindowCocoa::Show() { |
| 68 // The Browser associated with this browser window must become the active | 89 // The Browser associated with this browser window must become the active |
| 69 // browser at the time |Show()| is called. This is the natural behaviour under | 90 // browser at the time |Show()| is called. This is the natural behaviour under |
| 70 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 91 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 71 // until we return to the runloop. Therefore any calls to | 92 // until we return to the runloop. Therefore any calls to |
| 72 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return | 93 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return |
| 73 // the previous browser instead if we don't explicitly set it here. | 94 // the previous browser instead if we don't explicitly set it here. |
| 74 BrowserList::SetLastActive(browser_); | 95 BrowserList::SetLastActive(browser_); |
| 75 | 96 |
| 76 [window() makeKeyAndOrderFront:controller_]; | 97 ui::WindowShowState show_state = browser_->GetSavedWindowShowState(); |
| 98 if (show_state == ui::SHOW_STATE_MINIMIZED) { | |
| 99 // Turn off swishing when restoring minimized windows. When creating | |
| 100 // windows from nibs it is necessary to |orderFront:| prior to |orderOut:| | |
| 101 // then |miniaturize:| when restoring windows in the minimized state. | |
|
Mark Mentovai
2011/08/19 19:17:27
Glad you figured this out.
dhollowa
2011/08/19 20:38:16
Me too!
On 2011/08/19 19:17:27, Mark Mentovai wro
| |
| 102 NSWindowAnimationBehavior savedAnimationBehavior = 0; | |
| 103 if ([window() respondsToSelector:@selector(animationBehavior)] && | |
| 104 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { | |
| 105 savedAnimationBehavior = [window() animationBehavior]; | |
| 106 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; | |
| 107 } | |
| 108 | |
| 109 [window() makeKeyAndOrderFront:controller_]; | |
| 110 | |
| 111 [window() orderOut:controller_]; | |
| 112 [window() miniaturize:controller_]; | |
| 113 | |
| 114 // Restore window animation behavior. | |
| 115 if ([window() respondsToSelector:@selector(animationBehavior)] && | |
| 116 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { | |
| 117 [window() setAnimationBehavior:savedAnimationBehavior]; | |
| 118 } | |
| 119 } else { | |
| 120 [window() makeKeyAndOrderFront:controller_]; | |
| 121 } | |
| 77 } | 122 } |
| 78 | 123 |
| 79 void BrowserWindowCocoa::ShowInactive() { | 124 void BrowserWindowCocoa::ShowInactive() { |
| 80 [window() orderFront:controller_]; | 125 [window() orderFront:controller_]; |
| 81 } | 126 } |
| 82 | 127 |
| 83 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 128 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 84 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; | 129 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 85 | 130 |
| 86 SetFullscreen(false); | 131 SetFullscreen(false); |
| 87 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, | 132 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 88 real_bounds.width(), | 133 real_bounds.width(), |
| 89 real_bounds.height()); | 134 real_bounds.height()); |
| 90 // Flip coordinates based on the primary screen. | 135 // Flip coordinates based on the primary screen. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 } | 252 } |
| 208 | 253 |
| 209 gfx::Rect BrowserWindowCocoa::GetBounds() const { | 254 gfx::Rect BrowserWindowCocoa::GetBounds() const { |
| 210 return GetRestoredBounds(); | 255 return GetRestoredBounds(); |
| 211 } | 256 } |
| 212 | 257 |
| 213 bool BrowserWindowCocoa::IsMaximized() const { | 258 bool BrowserWindowCocoa::IsMaximized() const { |
| 214 return [window() isZoomed]; | 259 return [window() isZoomed]; |
| 215 } | 260 } |
| 216 | 261 |
| 262 bool BrowserWindowCocoa::IsMinimized() const { | |
| 263 return [window() isMiniaturized]; | |
| 264 } | |
| 265 | |
| 217 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { | 266 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { |
| 218 [controller_ setFullscreen:fullscreen]; | 267 [controller_ setFullscreen:fullscreen]; |
| 219 } | 268 } |
| 220 | 269 |
| 221 bool BrowserWindowCocoa::IsFullscreen() const { | 270 bool BrowserWindowCocoa::IsFullscreen() const { |
| 222 return !![controller_ isFullscreen]; | 271 return !![controller_ isFullscreen]; |
| 223 } | 272 } |
| 224 | 273 |
| 225 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { | 274 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 226 return false; | 275 return false; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 | 682 |
| 634 NSWindow* BrowserWindowCocoa::window() const { | 683 NSWindow* BrowserWindowCocoa::window() const { |
| 635 return [controller_ window]; | 684 return [controller_ window]; |
| 636 } | 685 } |
| 637 | 686 |
| 638 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 687 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 639 if (tab_contents == browser_->GetSelectedTabContents()) { | 688 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 640 [controller_ updateSidebarForContents:tab_contents]; | 689 [controller_ updateSidebarForContents:tab_contents]; |
| 641 } | 690 } |
| 642 } | 691 } |
| OLD | NEW |