OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "apps/app_shim/app_shim_mac.h" | 7 #include "apps/app_shim/app_shim_mac.h" |
8 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 8 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 | 99 |
100 namespace { | 100 namespace { |
101 | 101 |
102 // Declare notification names from the 10.7 SDK. | 102 // Declare notification names from the 10.7 SDK. |
103 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 103 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
104 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 104 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
105 NSString* NSPopoverDidShowNotification = @"NSPopoverDidShowNotification"; | 105 NSString* NSPopoverDidShowNotification = @"NSPopoverDidShowNotification"; |
106 NSString* NSPopoverDidCloseNotification = @"NSPopoverDidCloseNotification"; | 106 NSString* NSPopoverDidCloseNotification = @"NSPopoverDidCloseNotification"; |
107 #endif | 107 #endif |
108 | 108 |
109 // How long we allow a workspace change notification to wait to be | |
110 // associated with a dock activation. The animation lasts 250ms. See | |
111 // applicationShouldHandleReopen:hasVisibleWindows:. | |
112 static const int kWorkspaceChangeTimeoutMs = 500; | |
113 | |
109 // True while AppController is calling chrome::NewEmptyWindow(). We need a | 114 // True while AppController is calling chrome::NewEmptyWindow(). We need a |
110 // global flag here, analogue to StartupBrowserCreator::InProcessStartup() | 115 // global flag here, analogue to StartupBrowserCreator::InProcessStartup() |
111 // because otherwise the SessionService will try to restore sessions when we | 116 // because otherwise the SessionService will try to restore sessions when we |
112 // make a new window while there are no other active windows. | 117 // make a new window while there are no other active windows. |
113 bool g_is_opening_new_window = false; | 118 bool g_is_opening_new_window = false; |
114 | 119 |
115 // Activates a browser window having the given profile (the last one active) if | 120 // Activates a browser window having the given profile (the last one active) if |
116 // possible and returns a pointer to the activate |Browser| or NULL if this was | 121 // possible and returns a pointer to the activate |Browser| or NULL if this was |
117 // not possible. If the last active browser is minimized (in particular, if | 122 // not possible. If the last active browser is minimized (in particular, if |
118 // there are only minimized windows), it will unminimize it. | 123 // there are only minimized windows), it will unminimize it. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 @interface AppController (Private) | 194 @interface AppController (Private) |
190 - (void)initMenuState; | 195 - (void)initMenuState; |
191 - (void)initProfileMenu; | 196 - (void)initProfileMenu; |
192 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 197 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
193 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 198 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
194 - (void)openUrls:(const std::vector<GURL>&)urls; | 199 - (void)openUrls:(const std::vector<GURL>&)urls; |
195 - (void)getUrl:(NSAppleEventDescriptor*)event | 200 - (void)getUrl:(NSAppleEventDescriptor*)event |
196 withReply:(NSAppleEventDescriptor*)reply; | 201 withReply:(NSAppleEventDescriptor*)reply; |
197 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | 202 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; |
198 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 203 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
204 - (void)activeSpaceDidChange:(NSNotification*)inNotification; | |
199 - (void)windowChangedToProfile:(Profile*)profile; | 205 - (void)windowChangedToProfile:(Profile*)profile; |
200 - (void)checkForAnyKeyWindows; | 206 - (void)checkForAnyKeyWindows; |
201 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 207 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
202 - (BOOL)shouldQuitWithInProgressDownloads; | 208 - (BOOL)shouldQuitWithInProgressDownloads; |
203 - (void)executeApplication:(id)sender; | 209 - (void)executeApplication:(id)sender; |
204 - (void)profileWasRemoved:(const base::FilePath&)profilePath; | 210 - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
205 @end | 211 @end |
206 | 212 |
207 class AppControllerProfileObserver : public ProfileInfoCacheObserver { | 213 class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
208 public: | 214 public: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 selector:@selector(popoverDidShow:) | 313 selector:@selector(popoverDidShow:) |
308 name:NSPopoverDidShowNotification | 314 name:NSPopoverDidShowNotification |
309 object:nil]; | 315 object:nil]; |
310 [notificationCenter | 316 [notificationCenter |
311 addObserver:self | 317 addObserver:self |
312 selector:@selector(popoverDidClose:) | 318 selector:@selector(popoverDidClose:) |
313 name:NSPopoverDidCloseNotification | 319 name:NSPopoverDidCloseNotification |
314 object:nil]; | 320 object:nil]; |
315 } | 321 } |
316 | 322 |
323 // Register for space change notifications. | |
324 [[[NSWorkspace sharedWorkspace] notificationCenter] | |
325 addObserver:self | |
326 selector:@selector(activeSpaceDidChange:) | |
327 name:NSWorkspaceActiveSpaceDidChangeNotification | |
328 object:nil]; | |
329 | |
317 // Set up the command updater for when there are no windows open | 330 // Set up the command updater for when there are no windows open |
318 [self initMenuState]; | 331 [self initMenuState]; |
319 | 332 |
320 // Initialize the Profile menu. | 333 // Initialize the Profile menu. |
321 [self initProfileMenu]; | 334 [self initProfileMenu]; |
322 } | 335 } |
323 | 336 |
324 - (void)unregisterEventHandlers { | 337 - (void)unregisterEventHandlers { |
325 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 338 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
326 [em removeEventHandlerForEventClass:kInternetEventClass | 339 [em removeEventHandlerForEventClass:kInternetEventClass |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 [windowController isKindOfClass:[BrowserWindowController class]]) { | 562 [windowController isKindOfClass:[BrowserWindowController class]]) { |
550 // If the profile is incognito, use the original profile. | 563 // If the profile is incognito, use the original profile. |
551 Profile* newProfile = [windowController profile]->GetOriginalProfile(); | 564 Profile* newProfile = [windowController profile]->GetOriginalProfile(); |
552 [self windowChangedToProfile:newProfile]; | 565 [self windowChangedToProfile:newProfile]; |
553 } else if (chrome::GetTotalBrowserCount() == 0) { | 566 } else if (chrome::GetTotalBrowserCount() == 0) { |
554 [self windowChangedToProfile: | 567 [self windowChangedToProfile: |
555 g_browser_process->profile_manager()->GetLastUsedProfile()]; | 568 g_browser_process->profile_manager()->GetLastUsedProfile()]; |
556 } | 569 } |
557 } | 570 } |
558 | 571 |
572 - (void)activeSpaceDidChange:(NSNotification*)notify { | |
573 if (reopenTime_.is_null() || | |
574 ![NSApp isActive] || | |
575 (base::TimeTicks::Now() - reopenTime_).InMilliseconds() > | |
576 kWorkspaceChangeTimeoutMs) { | |
577 return; | |
578 } | |
579 | |
580 // The last applicationShouldHandleReopen:hasVisibleWindows: call | |
581 // happened during a space change. Now that the change has | |
582 // completed, raise browser windows. | |
583 reopenTime_ = base::TimeTicks(); | |
584 std::set<NSWindow*> browserWindows; | |
585 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { | |
586 Browser* browser = *iter; | |
587 browserWindows.insert(browser->window()->GetNativeWindow()); | |
588 } | |
589 if (!browserWindows.empty()) { | |
590 ui::FocusWindowSet(browserWindows, false); | |
591 } | |
592 } | |
593 | |
559 // Called on Lion and later when a popover (e.g. dictionary) is shown. | 594 // Called on Lion and later when a popover (e.g. dictionary) is shown. |
560 - (void)popoverDidShow:(NSNotification*)notify { | 595 - (void)popoverDidShow:(NSNotification*)notify { |
561 hasPopover_ = YES; | 596 hasPopover_ = YES; |
562 [self fixCloseMenuItemKeyEquivalents]; | 597 [self fixCloseMenuItemKeyEquivalents]; |
563 } | 598 } |
564 | 599 |
565 // Called on Lion and later when a popover (e.g. dictionary) is closed. | 600 // Called on Lion and later when a popover (e.g. dictionary) is closed. |
566 - (void)popoverDidClose:(NSNotification*)notify { | 601 - (void)popoverDidClose:(NSNotification*)notify { |
567 hasPopover_ = NO; | 602 hasPopover_ = NO; |
568 [self fixCloseMenuItemKeyEquivalents]; | 603 [self fixCloseMenuItemKeyEquivalents]; |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 // recently minimized window if no windows in the set are visible. | 1110 // recently minimized window if no windows in the set are visible. |
1076 // If there are any, return here. Otherwise, the windows are panels or | 1111 // If there are any, return here. Otherwise, the windows are panels or |
1077 // notifications so we still need to open a new window. | 1112 // notifications so we still need to open a new window. |
1078 if (hasVisibleWindows) { | 1113 if (hasVisibleWindows) { |
1079 std::set<NSWindow*> browserWindows; | 1114 std::set<NSWindow*> browserWindows; |
1080 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { | 1115 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
1081 Browser* browser = *iter; | 1116 Browser* browser = *iter; |
1082 browserWindows.insert(browser->window()->GetNativeWindow()); | 1117 browserWindows.insert(browser->window()->GetNativeWindow()); |
1083 } | 1118 } |
1084 if (!browserWindows.empty()) { | 1119 if (!browserWindows.empty()) { |
1085 ui::FocusWindowSet(browserWindows, false); | 1120 NSWindow* keyWindow = [NSApp keyWindow]; |
1086 // Return NO; we've done the unminimize, so AppKit shouldn't do | 1121 if (keyWindow && ![keyWindow isOnActiveSpace]) { |
1087 // anything. | 1122 // The key window is not on the active space. We must be |
1123 // mid-animation for a space change triggered by the | |
1124 // dock. Delay the call to ui::FocusWindowSet until the change | |
1125 // completes. | |
1126 reopenTime_ = base::TimeTicks::Now(); | |
davidben
2013/10/23 16:04:45
Not calling FocusWindowSet here is apparently nece
| |
1127 } else { | |
1128 ui::FocusWindowSet(browserWindows, false); | |
1129 } | |
1130 // Return NO; we've done (or soon will do) the deminiaturize, so | |
1131 // AppKit shouldn't do anything. | |
1088 return NO; | 1132 return NO; |
1089 } | 1133 } |
1090 } | 1134 } |
1091 | 1135 |
1092 // If launched as a hidden login item (due to installation of a persistent app | 1136 // If launched as a hidden login item (due to installation of a persistent app |
1093 // or by the user, for example in System Preferences->Accounts->Login Items), | 1137 // or by the user, for example in System Preferences->Accounts->Login Items), |
1094 // allow session to be restored first time the user clicks on a Dock icon. | 1138 // allow session to be restored first time the user clicks on a Dock icon. |
1095 // Normally, it'd just open a new empty page. | 1139 // Normally, it'd just open a new empty page. |
1096 { | 1140 { |
1097 static BOOL doneOnce = NO; | 1141 static BOOL doneOnce = NO; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 | 1466 |
1423 //--------------------------------------------------------------------------- | 1467 //--------------------------------------------------------------------------- |
1424 | 1468 |
1425 namespace app_controller_mac { | 1469 namespace app_controller_mac { |
1426 | 1470 |
1427 bool IsOpeningNewWindow() { | 1471 bool IsOpeningNewWindow() { |
1428 return g_is_opening_new_window; | 1472 return g_is_opening_new_window; |
1429 } | 1473 } |
1430 | 1474 |
1431 } // namespace app_controller_mac | 1475 } // namespace app_controller_mac |
OLD | NEW |