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 #import "chrome/browser/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #include "chrome/browser/sync/sync_ui_util.h" | 37 #include "chrome/browser/sync/sync_ui_util.h" |
38 #include "chrome/browser/sync/sync_ui_util_mac.h" | 38 #include "chrome/browser/sync/sync_ui_util_mac.h" |
39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/browser_init.h" | 40 #include "chrome/browser/ui/browser_init.h" |
41 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
42 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
43 #import "chrome/browser/ui/cocoa/about_window_controller.h" | 43 #import "chrome/browser/ui/cocoa/about_window_controller.h" |
44 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 44 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
45 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 45 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
46 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 46 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
47 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | |
47 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 48 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
48 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 49 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
49 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 50 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
50 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" | 51 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
51 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 52 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
52 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 53 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
53 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 54 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
54 #include "chrome/common/chrome_notification_types.h" | 55 #include "chrome/common/chrome_notification_types.h" |
55 #include "chrome/common/chrome_paths_internal.h" | 56 #include "chrome/common/chrome_paths_internal.h" |
56 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 // As we're shutting down, we need to nuke the TabRestoreService, which | 347 // As we're shutting down, we need to nuke the TabRestoreService, which |
347 // will start the shutdown of the NavigationControllers and allow for | 348 // will start the shutdown of the NavigationControllers and allow for |
348 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, | 349 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, |
349 // and may end up crashing when some thread tries to use the IO thread (or | 350 // and may end up crashing when some thread tries to use the IO thread (or |
350 // another thread) that is no longer valid. | 351 // another thread) that is no longer valid. |
351 TabRestoreServiceFactory::ResetForProfile([self lastProfile]); | 352 TabRestoreServiceFactory::ResetForProfile([self lastProfile]); |
352 } | 353 } |
353 } | 354 } |
354 | 355 |
355 // Helper routine to get the window controller if the key window is a tabbed | 356 // Helper routine to get the window controller if the key window is a tabbed |
356 // window, or nil if not. Examples of non-tabbed windows are "about" or | 357 // window, or nil if not. For example, the "about" window is non-tabbed. |
357 // "preferences". | |
358 - (TabWindowController*)keyWindowTabController { | 358 - (TabWindowController*)keyWindowTabController { |
359 NSWindowController* keyWindowController = | 359 NSWindowController* keyWindowController = |
360 [[NSApp keyWindow] windowController]; | 360 [[NSApp keyWindow] windowController]; |
361 if ([keyWindowController isKindOfClass:[TabWindowController class]]) | 361 if ([keyWindowController isKindOfClass:[TabWindowController class]]) |
362 return (TabWindowController*)keyWindowController; | 362 return (TabWindowController*)keyWindowController; |
363 | 363 |
364 return nil; | 364 return nil; |
365 } | 365 } |
366 | 366 |
367 // Helper routine to get the window controller if the main window is a tabbed | 367 // Helper routine to get the window controller if the main window is a tabbed |
368 // window, or nil if not. Examples of non-tabbed windows are "about" or | 368 // window, or nil if not. For example, the "about" window is non-tabbed. |
369 // "preferences". | |
370 - (TabWindowController*)mainWindowTabController { | 369 - (TabWindowController*)mainWindowTabController { |
371 NSWindowController* mainWindowController = | 370 NSWindowController* mainWindowController = |
372 [[NSApp mainWindow] windowController]; | 371 [[NSApp mainWindow] windowController]; |
373 if ([mainWindowController isKindOfClass:[TabWindowController class]]) | 372 if ([mainWindowController isKindOfClass:[TabWindowController class]]) |
374 return (TabWindowController*)mainWindowController; | 373 return (TabWindowController*)mainWindowController; |
375 | 374 |
376 return nil; | 375 return nil; |
377 } | 376 } |
378 | 377 |
379 // If the window has a tab controller, make "close window" be cmd-shift-w, | 378 // If the window has a tab controller, make "close window" be cmd-shift-w, |
(...skipping 24 matching lines...) Expand all Loading... | |
404 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; | 403 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; |
405 [closeWindowMenuItem_ setKeyEquivalent:@""]; | 404 [closeWindowMenuItem_ setKeyEquivalent:@""]; |
406 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; | 405 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; |
407 } | 406 } |
408 | 407 |
409 // See if we have a window with tabs open, and adjust the key equivalents for | 408 // See if we have a window with tabs open, and adjust the key equivalents for |
410 // Close Tab/Close Window accordingly. | 409 // Close Tab/Close Window accordingly. |
411 - (void)fixCloseMenuItemKeyEquivalents:(NSWindow*)window { | 410 - (void)fixCloseMenuItemKeyEquivalents:(NSWindow*)window { |
412 fileMenuUpdatePending_ = NO; | 411 fileMenuUpdatePending_ = NO; |
413 TabWindowController* tabController = [self keyWindowTabController]; | 412 TabWindowController* tabController = [self keyWindowTabController]; |
414 if (!tabController && ![NSApp keyWindow]) { | 413 if (!tabController && |
415 // There might be a small amount of time where there is no key window, | 414 (![NSApp keyWindow] || |
416 // so just use our main browser window if there is one. | 415 [[NSApp keyWindow] isKindOfClass:[ChromeEventProcessingWindow class]])) { |
Ilya Sherman
2011/10/15 04:31:38
This seems a little hacky, but I wasn't sure of a
Scott Hess - ex-Googler
2011/10/19 02:43:41
I agree - I think that this is EXACTLY the kind of
| |
416 // If the key window is a |ChromeEventProcessingWindow| (i.e. a bubble), the | |
417 // window that should handle the close menu item action is the main window. | |
418 // Also, there might be a small amount of time where there is no key window; | |
419 // in that case as well, just use our main browser window if there is one. | |
417 tabController = [self mainWindowTabController]; | 420 tabController = [self mainWindowTabController]; |
Scott Hess - ex-Googler
2011/10/19 02:43:41
Wow, this whole thing seems hokey. AFAICT, the on
| |
418 } | 421 } |
419 BOOL hasTabs = !!tabController; | 422 BOOL hasTabs = !!tabController; |
420 | 423 |
421 [self adjustCloseWindowMenuItemKeyEquivalent:hasTabs]; | 424 [self adjustCloseWindowMenuItemKeyEquivalent:hasTabs]; |
422 [self adjustCloseTabMenuItemKeyEquivalent:hasTabs]; | 425 [self adjustCloseTabMenuItemKeyEquivalent:hasTabs]; |
423 } | 426 } |
424 | 427 |
425 // Fix up the "close tab/close window" command-key equivalents. We do this | 428 // Fix up the "close tab/close window" command-key equivalents. We do this |
426 // after a delay to ensure that window layer state has been set by the time | 429 // after a delay to ensure that window layer state has been set by the time |
427 // we do the enabling. This should only be called on the main thread, code that | 430 // we do the enabling. This should only be called on the main thread, code that |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 | 1285 |
1283 } // namespace browser | 1286 } // namespace browser |
1284 | 1287 |
1285 namespace app_controller_mac { | 1288 namespace app_controller_mac { |
1286 | 1289 |
1287 bool IsOpeningNewWindow() { | 1290 bool IsOpeningNewWindow() { |
1288 return g_is_opening_new_window; | 1291 return g_is_opening_new_window; |
1289 } | 1292 } |
1290 | 1293 |
1291 } // namespace app_controller_mac | 1294 } // namespace app_controller_mac |
OLD | NEW |