| 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 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 51 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 52 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 53 |
| 54 enum { |
| 55 NSWindowAnimationBehaviorDefault = 0, |
| 56 NSWindowAnimationBehaviorNone = 2, |
| 57 NSWindowAnimationBehaviorDocumentWindow = 3, |
| 58 NSWindowAnimationBehaviorUtilityWindow = 4, |
| 59 NSWindowAnimationBehaviorAlertPanel = 5 |
| 60 }; |
| 61 typedef NSInteger NSWindowAnimationBehavior; |
| 62 |
| 63 @interface NSWindow (LionSDKDeclarations) |
| 64 - (NSWindowAnimationBehavior)animationBehavior; |
| 65 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; |
| 66 @end |
| 67 |
| 68 #endif // MAC_OS_X_VERSION_10_7 |
| 69 |
| 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 70 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 50 BrowserWindowController* controller, | 71 BrowserWindowController* controller) |
| 51 NSWindow* window) | |
| 52 : browser_(browser), | 72 : browser_(browser), |
| 53 controller_(controller), | 73 controller_(controller), |
| 54 confirm_close_factory_(browser) { | 74 confirm_close_factory_(browser) { |
| 55 // Listen for bookmark bar visibility changes and set the initial state; we | 75 // 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. | 76 // need to listen to all profiles because of normal profile/incognito issues. |
| 57 registrar_.Add(this, | 77 registrar_.Add(this, |
| 58 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 78 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 59 NotificationService::AllBrowserContextsAndSources()); | 79 NotificationService::AllBrowserContextsAndSources()); |
| 60 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 80 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 61 Source<SidebarManager>(SidebarManager::GetInstance())); | 81 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 62 } | 82 } |
| 63 | 83 |
| 64 BrowserWindowCocoa::~BrowserWindowCocoa() { | 84 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 65 } | 85 } |
| 66 | 86 |
| 67 void BrowserWindowCocoa::Show() { | 87 void BrowserWindowCocoa::Show() { |
| 68 // The Browser associated with this browser window must become the active | 88 // 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 | 89 // browser at the time |Show()| is called. This is the natural behaviour under |
| 70 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 90 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 71 // until we return to the runloop. Therefore any calls to | 91 // until we return to the runloop. Therefore any calls to |
| 72 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return | 92 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return |
| 73 // 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. |
| 74 BrowserList::SetLastActive(browser_); | 94 BrowserList::SetLastActive(browser_); |
| 75 | 95 |
| 76 [window() makeKeyAndOrderFront:controller_]; | 96 ui::WindowShowState show_state = browser_->GetSavedWindowShowState(); |
| 97 if (show_state == ui::SHOW_STATE_MINIMIZED) { |
| 98 // Turn off swishing when restoring minimized windows. When creating |
| 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)] && |
| 103 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 104 savedAnimationBehavior = [window() animationBehavior]; |
| 105 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; |
| 106 } |
| 107 |
| 108 [window() makeKeyAndOrderFront:controller_]; |
| 109 |
| 110 [window() orderOut:controller_]; |
| 111 [window() miniaturize:controller_]; |
| 112 |
| 113 // Restore window animation behavior. |
| 114 if ([window() respondsToSelector:@selector(animationBehavior)] && |
| 115 [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 116 [window() setAnimationBehavior:savedAnimationBehavior]; |
| 117 } |
| 118 } else { |
| 119 [window() makeKeyAndOrderFront:controller_]; |
| 120 } |
| 77 } | 121 } |
| 78 | 122 |
| 79 void BrowserWindowCocoa::ShowInactive() { | 123 void BrowserWindowCocoa::ShowInactive() { |
| 80 [window() orderFront:controller_]; | 124 [window() orderFront:controller_]; |
| 81 } | 125 } |
| 82 | 126 |
| 83 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 127 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 84 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; | 128 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 85 | 129 |
| 86 SetFullscreen(false); | 130 SetFullscreen(false); |
| 87 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, | 131 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 88 real_bounds.width(), | 132 real_bounds.width(), |
| 89 real_bounds.height()); | 133 real_bounds.height()); |
| 90 // Flip coordinates based on the primary screen. | 134 // Flip coordinates based on the primary screen. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 251 } |
| 208 | 252 |
| 209 gfx::Rect BrowserWindowCocoa::GetBounds() const { | 253 gfx::Rect BrowserWindowCocoa::GetBounds() const { |
| 210 return GetRestoredBounds(); | 254 return GetRestoredBounds(); |
| 211 } | 255 } |
| 212 | 256 |
| 213 bool BrowserWindowCocoa::IsMaximized() const { | 257 bool BrowserWindowCocoa::IsMaximized() const { |
| 214 return [window() isZoomed]; | 258 return [window() isZoomed]; |
| 215 } | 259 } |
| 216 | 260 |
| 261 bool BrowserWindowCocoa::IsMinimized() const { |
| 262 return [window() isMiniaturized]; |
| 263 } |
| 264 |
| 217 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { | 265 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { |
| 218 [controller_ setFullscreen:fullscreen]; | 266 [controller_ setFullscreen:fullscreen]; |
| 219 } | 267 } |
| 220 | 268 |
| 221 bool BrowserWindowCocoa::IsFullscreen() const { | 269 bool BrowserWindowCocoa::IsFullscreen() const { |
| 222 return !![controller_ isFullscreen]; | 270 return !![controller_ isFullscreen]; |
| 223 } | 271 } |
| 224 | 272 |
| 225 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { | 273 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 226 return false; | 274 return false; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 681 |
| 634 NSWindow* BrowserWindowCocoa::window() const { | 682 NSWindow* BrowserWindowCocoa::window() const { |
| 635 return [controller_ window]; | 683 return [controller_ window]; |
| 636 } | 684 } |
| 637 | 685 |
| 638 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 686 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 639 if (tab_contents == browser_->GetSelectedTabContents()) { | 687 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 640 [controller_ updateSidebarForContents:tab_contents]; | 688 [controller_ updateSidebarForContents:tab_contents]; |
| 641 } | 689 } |
| 642 } | 690 } |
| OLD | NEW |