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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 // "preferences". | 352 // "preferences". |
353 - (TabWindowController*)mainWindowTabController { | 353 - (TabWindowController*)mainWindowTabController { |
354 NSWindowController* mainWindowController = | 354 NSWindowController* mainWindowController = |
355 [[NSApp mainWindow] windowController]; | 355 [[NSApp mainWindow] windowController]; |
356 if ([mainWindowController isKindOfClass:[TabWindowController class]]) | 356 if ([mainWindowController isKindOfClass:[TabWindowController class]]) |
357 return (TabWindowController*)mainWindowController; | 357 return (TabWindowController*)mainWindowController; |
358 | 358 |
359 return nil; | 359 return nil; |
360 } | 360 } |
361 | 361 |
362 // If the window has tabs, make "close window" be cmd-shift-w, otherwise leave | 362 // Make "close window" be cmd-shift-w. Capitalization of the key equivalent |
363 // it as the normal cmd-w. Capitalization of the key equivalent affects whether | 363 // affects whether the shift modifer is used. |
364 // the shift modifer is used. | 364 - (void)adjustCloseWindowMenuItemKeyEquivalent { |
365 - (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs { | 365 [closeWindowMenuItem_ setKeyEquivalent:@"W"]; |
Mark Mentovai
2011/06/06 16:27:15
Your change comment indicates that this is Command
shinyak (Google)
2011/06/07 03:15:57
This function is still used in fixCloseMenuItemKey
Mark Mentovai
2011/06/07 03:29:29
shinyak wrote:
shinyak (Google)
2011/06/07 03:43:04
Ah, OK. I understand your comment.
The menu items
| |
366 [closeWindowMenuItem_ setKeyEquivalent:(inHaveTabs ? @"W" : @"w")]; | |
367 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; | 366 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; |
368 } | 367 } |
369 | 368 |
370 // If the window has tabs, make "close tab" take over cmd-w, otherwise it | 369 // Make "close tab" be cmd-w. |
371 // shouldn't have any key-equivalent because it should be disabled. | 370 - (void)adjustCloseTabMenuItemKeyEquivalent { |
372 - (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)hasTabs { | 371 [closeTabMenuItem_ setKeyEquivalent:@"w"]; |
373 if (hasTabs) { | 372 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; |
374 [closeTabMenuItem_ setKeyEquivalent:@"w"]; | |
375 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; | |
376 } else { | |
377 [closeTabMenuItem_ setKeyEquivalent:@""]; | |
378 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; | |
379 } | |
380 } | 373 } |
381 | 374 |
382 // Explicitly remove any command-key equivalents from the close tab/window | 375 // Explicitly remove any command-key equivalents from the close tab/window |
383 // menus so that nothing can go haywire if we get a user action during pending | 376 // menus so that nothing can go haywire if we get a user action during pending |
384 // updates. | 377 // updates. |
385 - (void)clearCloseMenuItemKeyEquivalents { | 378 - (void)clearCloseMenuItemKeyEquivalents { |
386 [closeTabMenuItem_ setKeyEquivalent:@""]; | 379 [closeTabMenuItem_ setKeyEquivalent:@""]; |
387 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; | 380 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; |
388 [closeWindowMenuItem_ setKeyEquivalent:@""]; | 381 [closeWindowMenuItem_ setKeyEquivalent:@""]; |
389 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; | 382 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; |
390 } | 383 } |
391 | 384 |
392 // See if we have a window with tabs open, and adjust the key equivalents for | 385 // See if we have a window with tabs open, and adjust the key equivalents for |
393 // Close Tab/Close Window accordingly. | 386 // Close Tab/Close Window accordingly. |
394 - (void)fixCloseMenuItemKeyEquivalents { | 387 - (void)fixCloseMenuItemKeyEquivalents { |
395 fileMenuUpdatePending_ = NO; | 388 fileMenuUpdatePending_ = NO; |
396 TabWindowController* tabController = [self keyWindowTabController]; | 389 TabWindowController* tabController = [self keyWindowTabController]; |
397 if (!tabController && ![NSApp keyWindow]) { | 390 if (!tabController && ![NSApp keyWindow]) { |
398 // There might be a small amount of time where there is no key window, | 391 // There might be a small amount of time where there is no key window, |
399 // so just use our main browser window if there is one. | 392 // so just use our main browser window if there is one. |
400 tabController = [self mainWindowTabController]; | 393 tabController = [self mainWindowTabController]; |
401 } | 394 } |
402 BOOL windowWithMultipleTabs = | 395 |
403 (tabController && [tabController numberOfTabs] > 1); | 396 [self adjustCloseWindowMenuItemKeyEquivalent]; |
404 [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; | 397 [self adjustCloseTabMenuItemKeyEquivalent]; |
405 [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; | |
406 } | 398 } |
407 | 399 |
408 // Fix up the "close tab/close window" command-key equivalents. We do this | 400 // Fix up the "close tab/close window" command-key equivalents. We do this |
409 // after a delay to ensure that window layer state has been set by the time | 401 // after a delay to ensure that window layer state has been set by the time |
410 // we do the enabling. This should only be called on the main thread, code that | 402 // we do the enabling. This should only be called on the main thread, code that |
411 // calls this (even as a side-effect) from other threads needs to be fixed. | 403 // calls this (even as a side-effect) from other threads needs to be fixed. |
412 - (void)delayedFixCloseMenuItemKeyEquivalents { | 404 - (void)delayedFixCloseMenuItemKeyEquivalents { |
413 DCHECK([NSThread isMainThread]); | 405 DCHECK([NSThread isMainThread]); |
414 if (!fileMenuUpdatePending_) { | 406 if (!fileMenuUpdatePending_) { |
415 // The OS prefers keypresses to timers, so it's possible that a cmd-w | 407 // The OS prefers keypresses to timers, so it's possible that a cmd-w |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1190 | 1182 |
1191 } // namespace browser | 1183 } // namespace browser |
1192 | 1184 |
1193 namespace app_controller_mac { | 1185 namespace app_controller_mac { |
1194 | 1186 |
1195 bool IsOpeningNewWindow() { | 1187 bool IsOpeningNewWindow() { |
1196 return g_is_opening_new_window; | 1188 return g_is_opening_new_window; |
1197 } | 1189 } |
1198 | 1190 |
1199 } // namespace app_controller_mac | 1191 } // namespace app_controller_mac |
OLD | NEW |