Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 7065054: Removed the code that checks the tab number. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
363 // it as the normal cmd-w. Capitalization of the key equivalent affects whether 363 // Capitalization of the key equivalent affects whether the shift modifer is
Robert Sesek 2011/06/03 15:46:51 Rewrap this comment to the previous line.
364 // the shift modifer is used. 364 // used.
365 - (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs { 365 - (void)adjustCloseWindowMenuItemKeyEquivalent {
366 [closeWindowMenuItem_ setKeyEquivalent:(inHaveTabs ? @"W" : @"w")]; 366 [closeWindowMenuItem_ setKeyEquivalent:@"W"];
367 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; 367 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
368 } 368 }
369 369
370 // If the window has tabs, make "close tab" take over cmd-w, otherwise it 370 // Make "close tab" be cmd-w.
371 // shouldn't have any key-equivalent because it should be disabled. 371 - (void)adjustCloseTabMenuItemKeyEquivalent {
372 - (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)hasTabs { 372 [closeTabMenuItem_ setKeyEquivalent:@"w"];
373 if (hasTabs) { 373 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
374 [closeTabMenuItem_ setKeyEquivalent:@"w"];
375 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
376 } else {
377 [closeTabMenuItem_ setKeyEquivalent:@""];
378 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
379 }
380 } 374 }
381 375
382 // Explicitly remove any command-key equivalents from the close tab/window 376 // 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 377 // menus so that nothing can go haywire if we get a user action during pending
384 // updates. 378 // updates.
385 - (void)clearCloseMenuItemKeyEquivalents { 379 - (void)clearCloseMenuItemKeyEquivalents {
386 [closeTabMenuItem_ setKeyEquivalent:@""]; 380 [closeTabMenuItem_ setKeyEquivalent:@""];
387 [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; 381 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
388 [closeWindowMenuItem_ setKeyEquivalent:@""]; 382 [closeWindowMenuItem_ setKeyEquivalent:@""];
389 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; 383 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0];
390 } 384 }
391 385
392 // See if we have a window with tabs open, and adjust the key equivalents for 386 // See if we have a window with tabs open, and adjust the key equivalents for
393 // Close Tab/Close Window accordingly. 387 // Close Tab/Close Window accordingly.
394 - (void)fixCloseMenuItemKeyEquivalents { 388 - (void)fixCloseMenuItemKeyEquivalents {
395 fileMenuUpdatePending_ = NO; 389 fileMenuUpdatePending_ = NO;
396 TabWindowController* tabController = [self keyWindowTabController]; 390 TabWindowController* tabController = [self keyWindowTabController];
397 if (!tabController && ![NSApp keyWindow]) { 391 if (!tabController && ![NSApp keyWindow]) {
398 // There might be a small amount of time where there is no key window, 392 // 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. 393 // so just use our main browser window if there is one.
400 tabController = [self mainWindowTabController]; 394 tabController = [self mainWindowTabController];
401 } 395 }
402 BOOL windowWithMultipleTabs = 396
403 (tabController && [tabController numberOfTabs] > 1); 397 [self adjustCloseWindowMenuItemKeyEquivalent];
404 [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; 398 [self adjustCloseTabMenuItemKeyEquivalent];
405 [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs];
406 } 399 }
407 400
408 // Fix up the "close tab/close window" command-key equivalents. We do this 401 // 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 402 // 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 403 // 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. 404 // calls this (even as a side-effect) from other threads needs to be fixed.
412 - (void)delayedFixCloseMenuItemKeyEquivalents { 405 - (void)delayedFixCloseMenuItemKeyEquivalents {
413 DCHECK([NSThread isMainThread]); 406 DCHECK([NSThread isMainThread]);
414 if (!fileMenuUpdatePending_) { 407 if (!fileMenuUpdatePending_) {
415 // The OS prefers keypresses to timers, so it's possible that a cmd-w 408 // 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
1190 1183
1191 } // namespace browser 1184 } // namespace browser
1192 1185
1193 namespace app_controller_mac { 1186 namespace app_controller_mac {
1194 1187
1195 bool IsOpeningNewWindow() { 1188 bool IsOpeningNewWindow() {
1196 return g_is_opening_new_window; 1189 return g_is_opening_new_window;
1197 } 1190 }
1198 1191
1199 } // namespace app_controller_mac 1192 } // namespace app_controller_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698