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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 registrar_.Add(this, | 77 registrar_.Add(this, |
| 78 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 78 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 79 NotificationService::AllBrowserContextsAndSources()); | 79 NotificationService::AllBrowserContextsAndSources()); |
| 80 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 80 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 81 Source<SidebarManager>(SidebarManager::GetInstance())); | 81 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 82 } | 82 } |
| 83 | 83 |
| 84 BrowserWindowCocoa::~BrowserWindowCocoa() { | 84 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 85 } | 85 } |
| 86 | 86 |
| 87 void BrowserWindowCocoa::Show() { | 87 void BrowserWindowCocoa::Show(BrowserWindow::ShowContext show_context) { |
| 88 // The Browser associated with this browser window must become the active | 88 // The Browser associated with this browser window must become the active |
| 89 // browser at the time |Show()| is called. This is the natural behaviour under | 89 // browser at the time |Show()| is called. This is the natural behaviour under |
| 90 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 90 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 91 // until we return to the runloop. Therefore any calls to | 91 // until we return to the runloop. Therefore any calls to |
| 92 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return | 92 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return |
| 93 // the previous browser instead if we don't explicitly set it here. | 93 // the previous browser instead if we don't explicitly set it here. |
| 94 BrowserList::SetLastActive(browser_); | 94 BrowserList::SetLastActive(browser_); |
| 95 | 95 |
| 96 ui::WindowShowState show_state = browser_->GetSavedWindowShowState(); | 96 NSWindowAnimationBehavior savedAnimationBehavior = 0; |
|
Mark Mentovai
2011/08/31 16:20:49
Style nit: you’re supposed to use saved_animation_
dhollowa
2011/08/31 17:05:11
Done.
| |
| 97 if (show_state == ui::SHOW_STATE_MINIMIZED) { | 97 if (show_context == BrowserWindow::SHOW_CONTEXT_RESTORE) { |
| 98 // Turn off swishing when restoring minimized windows. When creating | 98 // Turn off swishing when restoring windows. |
| 99 // windows from nibs it is necessary to |orderFront:| prior to |orderOut:| | |
| 100 // then |miniaturize:| when restoring windows in the minimized state. | |
| 101 NSWindowAnimationBehavior savedAnimationBehavior = 0; | |
| 102 if ([window() respondsToSelector:@selector(animationBehavior)] && | 99 if ([window() respondsToSelector:@selector(animationBehavior)] && |
|
Mark Mentovai
2011/08/31 16:20:49
Fold these conditions into the same |if| that encl
dhollowa
2011/08/31 17:05:11
Done.
| |
| 103 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { | 100 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 104 savedAnimationBehavior = [window() animationBehavior]; | 101 savedAnimationBehavior = [window() animationBehavior]; |
| 105 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; | 102 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; |
| 106 } | 103 } |
| 104 } | |
| 107 | 105 |
| 108 [window() makeKeyAndOrderFront:controller_]; | 106 [window() makeKeyAndOrderFront:controller_]; |
| 109 | 107 |
| 108 // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:| | |
| 109 // prior to |orderOut:| then |miniaturize:| when restoring windows in the | |
| 110 // minimized state. | |
| 111 if (browser_->GetSavedWindowShowState() == ui::SHOW_STATE_MINIMIZED) { | |
| 110 [window() orderOut:controller_]; | 112 [window() orderOut:controller_]; |
| 111 [window() miniaturize:controller_]; | 113 [window() miniaturize:controller_]; |
| 114 } | |
| 112 | 115 |
| 116 if (show_context == BrowserWindow::SHOW_CONTEXT_RESTORE) { | |
| 113 // Restore window animation behavior. | 117 // Restore window animation behavior. |
| 114 if ([window() respondsToSelector:@selector(animationBehavior)] && | 118 if ([window() respondsToSelector:@selector(animationBehavior)] && |
|
Mark Mentovai
2011/08/31 16:20:49
Rather than doing this check, and maybe the one th
dhollowa
2011/08/31 17:05:11
Done. Nice, yes. And I've done the same in drag-
| |
| 115 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { | 119 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 116 [window() setAnimationBehavior:savedAnimationBehavior]; | 120 [window() setAnimationBehavior:savedAnimationBehavior]; |
| 117 } | 121 } |
| 118 } else { | |
| 119 [window() makeKeyAndOrderFront:controller_]; | |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 | 124 |
| 123 void BrowserWindowCocoa::ShowInactive() { | 125 void BrowserWindowCocoa::ShowInactive() { |
| 124 [window() orderFront:controller_]; | 126 [window() orderFront:controller_]; |
| 125 } | 127 } |
| 126 | 128 |
| 127 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 129 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 128 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; | 130 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 129 | 131 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 | 580 |
| 579 NSWindow* BrowserWindowCocoa::window() const { | 581 NSWindow* BrowserWindowCocoa::window() const { |
| 580 return [controller_ window]; | 582 return [controller_ window]; |
| 581 } | 583 } |
| 582 | 584 |
| 583 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 585 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 584 if (tab_contents == browser_->GetSelectedTabContents()) { | 586 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 585 [controller_ updateSidebarForContents:tab_contents]; | 587 [controller_ updateSidebarForContents:tab_contents]; |
| 586 } | 588 } |
| 587 } | 589 } |
| OLD | NEW |