| 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 |
| 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 50 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 50 BrowserWindowController* controller, | 51 BrowserWindowController* controller) |
| 51 NSWindow* window) | |
| 52 : browser_(browser), | 52 : browser_(browser), |
| 53 controller_(controller), | 53 controller_(controller), |
| 54 confirm_close_factory_(browser) { | 54 confirm_close_factory_(browser) { |
| 55 // Listen for bookmark bar visibility changes and set the initial state; we | 55 // 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. | 56 // need to listen to all profiles because of normal profile/incognito issues. |
| 57 registrar_.Add(this, | 57 registrar_.Add(this, |
| 58 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 58 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 59 NotificationService::AllBrowserContextsAndSources()); | 59 NotificationService::AllBrowserContextsAndSources()); |
| 60 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 60 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 61 Source<SidebarManager>(SidebarManager::GetInstance())); | 61 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 62 } | 62 } |
| 63 | 63 |
| 64 BrowserWindowCocoa::~BrowserWindowCocoa() { | 64 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 void BrowserWindowCocoa::Show() { | 67 void BrowserWindowCocoa::Show() { |
| 68 // The Browser associated with this browser window must become the active | 68 // 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 | 69 // browser at the time |Show()| is called. This is the natural behaviour under |
| 70 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 70 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 71 // until we return to the runloop. Therefore any calls to | 71 // until we return to the runloop. Therefore any calls to |
| 72 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return | 72 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return |
| 73 // the previous browser instead if we don't explicitly set it here. | 73 // the previous browser instead if we don't explicitly set it here. |
| 74 BrowserList::SetLastActive(browser_); | 74 BrowserList::SetLastActive(browser_); |
| 75 | 75 |
| 76 [window() makeKeyAndOrderFront:controller_]; | 76 ui::WindowShowState show_state = browser_->GetSavedWindowShowState(); |
| 77 if (show_state == ui::SHOW_STATE_MINIMIZED) { |
| 78 // Turn off swishing when restoring minimized windows. When creating |
| 79 // windows from nibs it is necessary to |orderFront:| prior to |orderOut:| |
| 80 // then |miniaturize:| when restoring windows in the minimized state. |
| 81 if ([window() respondsToSelector:@selector(setAnimationBehavior:)]) |
| 82 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; |
| 83 |
| 84 [window() makeKeyAndOrderFront:controller_]; |
| 85 |
| 86 [window() orderOut:controller_]; |
| 87 [window() miniaturize:controller_]; |
| 88 |
| 89 if ([window() respondsToSelector:@selector(setAnimationBehavior:)]) |
| 90 [window() setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow]; |
| 91 } else { |
| 92 [window() makeKeyAndOrderFront:controller_]; |
| 93 } |
| 77 } | 94 } |
| 78 | 95 |
| 79 void BrowserWindowCocoa::ShowInactive() { | 96 void BrowserWindowCocoa::ShowInactive() { |
| 80 [window() orderFront:controller_]; | 97 [window() orderFront:controller_]; |
| 81 } | 98 } |
| 82 | 99 |
| 83 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 100 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 84 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; | 101 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 85 | 102 |
| 86 SetFullscreen(false); | 103 SetFullscreen(false); |
| 87 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, | 104 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 88 real_bounds.width(), | 105 real_bounds.width(), |
| 89 real_bounds.height()); | 106 real_bounds.height()); |
| 90 // Flip coordinates based on the primary screen. | 107 // Flip coordinates based on the primary screen. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 224 } |
| 208 | 225 |
| 209 gfx::Rect BrowserWindowCocoa::GetBounds() const { | 226 gfx::Rect BrowserWindowCocoa::GetBounds() const { |
| 210 return GetRestoredBounds(); | 227 return GetRestoredBounds(); |
| 211 } | 228 } |
| 212 | 229 |
| 213 bool BrowserWindowCocoa::IsMaximized() const { | 230 bool BrowserWindowCocoa::IsMaximized() const { |
| 214 return [window() isZoomed]; | 231 return [window() isZoomed]; |
| 215 } | 232 } |
| 216 | 233 |
| 234 bool BrowserWindowCocoa::IsMinimized() const { |
| 235 return [window() isMiniaturized]; |
| 236 } |
| 237 |
| 217 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { | 238 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { |
| 218 [controller_ setFullscreen:fullscreen]; | 239 [controller_ setFullscreen:fullscreen]; |
| 219 } | 240 } |
| 220 | 241 |
| 221 bool BrowserWindowCocoa::IsFullscreen() const { | 242 bool BrowserWindowCocoa::IsFullscreen() const { |
| 222 return !![controller_ isFullscreen]; | 243 return !![controller_ isFullscreen]; |
| 223 } | 244 } |
| 224 | 245 |
| 225 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { | 246 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 226 return false; | 247 return false; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 654 |
| 634 NSWindow* BrowserWindowCocoa::window() const { | 655 NSWindow* BrowserWindowCocoa::window() const { |
| 635 return [controller_ window]; | 656 return [controller_ window]; |
| 636 } | 657 } |
| 637 | 658 |
| 638 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 659 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 639 if (tab_contents == browser_->GetSelectedTabContents()) { | 660 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 640 [controller_ updateSidebarForContents:tab_contents]; | 661 [controller_ updateSidebarForContents:tab_contents]; |
| 641 } | 662 } |
| 642 } | 663 } |
| OLD | NEW |