| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 567 } |
| 568 | 568 |
| 569 // Called to determine if we should enable the "restore tab" menu item. | 569 // Called to determine if we should enable the "restore tab" menu item. |
| 570 // Checks with the TabRestoreService to see if there's anything there to | 570 // Checks with the TabRestoreService to see if there's anything there to |
| 571 // restore and returns YES if so. | 571 // restore and returns YES if so. |
| 572 - (BOOL)canRestoreTab { | 572 - (BOOL)canRestoreTab { |
| 573 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService(); | 573 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService(); |
| 574 return service && !service->entries().empty(); | 574 return service && !service->entries().empty(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 // Returns true if there is no browser window, or if the active window is | 577 // Returns true if there is not a modal window (either window- or application- |
| 578 // blocked by a modal dialog. | 578 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
| 579 - (BOOL)keyWindowIsMissingOrBlocked { | 579 // sheets) will not count as blocking the browser. But things like open/save |
| 580 // dialogs that are window modal will block the browser. |
| 581 - (BOOL)keyWindowIsNotModal { |
| 580 Browser* browser = BrowserList::GetLastActive(); | 582 Browser* browser = BrowserList::GetLastActive(); |
| 581 return browser == NULL || | 583 return [NSApp modalWindow] == nil && (browser && |
| 582 ![[browser->window()->GetNativeHandle() attachedSheet] | 584 ![[browser->window()->GetNativeHandle() attachedSheet] |
| 583 isKindOfClass:[NSWindow class]]; | 585 isKindOfClass:[NSWindow class]]); |
| 584 } | 586 } |
| 585 | 587 |
| 586 // Called to validate menu items when there are no key windows. All the | 588 // Called to validate menu items when there are no key windows. All the |
| 587 // items we care about have been set with the |commandDispatch:| action and | 589 // items we care about have been set with the |commandDispatch:| action and |
| 588 // a target of FirstResponder in IB. If it's not one of those, let it | 590 // a target of FirstResponder in IB. If it's not one of those, let it |
| 589 // continue up the responder chain to be handled elsewhere. We pull out the | 591 // continue up the responder chain to be handled elsewhere. We pull out the |
| 590 // tag as the cross-platform constant to differentiate and dispatch the | 592 // tag as the cross-platform constant to differentiate and dispatch the |
| 591 // various commands. | 593 // various commands. |
| 592 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 594 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 593 SEL action = [item action]; | 595 SEL action = [item action]; |
| 594 BOOL enable = NO; | 596 BOOL enable = NO; |
| 595 if (action == @selector(commandDispatch:)) { | 597 if (action == @selector(commandDispatch:)) { |
| 596 NSInteger tag = [item tag]; | 598 NSInteger tag = [item tag]; |
| 597 if (menuState_->SupportsCommand(tag)) { | 599 if (menuState_->SupportsCommand(tag)) { |
| 598 switch (tag) { | 600 switch (tag) { |
| 599 // The File Menu commands are not automatically disabled by Cocoa when a | 601 // The File Menu commands are not automatically disabled by Cocoa when a |
| 600 // dialog sheet obscures the browser window, so we disable several of | 602 // dialog sheet obscures the browser window, so we disable several of |
| 601 // them here. We don't need to include IDC_CLOSE_WINDOW, because | 603 // them here. We don't need to include IDC_CLOSE_WINDOW, because |
| 602 // app_controller is only activated when there are no key windows (see | 604 // app_controller is only activated when there are no key windows (see |
| 603 // function comment). | 605 // function comment). |
| 604 case IDC_RESTORE_TAB: | 606 case IDC_RESTORE_TAB: |
| 605 enable = [self keyWindowIsMissingOrBlocked] && [self canRestoreTab]; | 607 enable = [self keyWindowIsNotModal] && [self canRestoreTab]; |
| 606 break; | 608 break; |
| 609 // Browser-level items that open in new tabs should not open if there's |
| 610 // a window- or app-modal dialog. |
| 607 case IDC_OPEN_FILE: | 611 case IDC_OPEN_FILE: |
| 608 case IDC_NEW_TAB: | 612 case IDC_NEW_TAB: |
| 609 enable = [self keyWindowIsMissingOrBlocked]; | 613 case IDC_SHOW_HISTORY: |
| 614 case IDC_SHOW_BOOKMARK_MANAGER: |
| 615 enable = [self keyWindowIsNotModal]; |
| 616 break; |
| 617 // Browser-level items that open in new windows. |
| 618 case IDC_NEW_WINDOW: |
| 619 case IDC_TASK_MANAGER: |
| 620 // Allow the user to open a new window if there's a window-modal |
| 621 // dialog. |
| 622 enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil); |
| 610 break; | 623 break; |
| 611 case IDC_SYNC_BOOKMARKS: { | 624 case IDC_SYNC_BOOKMARKS: { |
| 612 Profile* defaultProfile = [self defaultProfile]; | 625 Profile* defaultProfile = [self defaultProfile]; |
| 613 // The profile may be NULL during shutdown -- see | 626 // The profile may be NULL during shutdown -- see |
| 614 // http://code.google.com/p/chromium/issues/detail?id=43048 . | 627 // http://code.google.com/p/chromium/issues/detail?id=43048 . |
| 615 // | 628 // |
| 616 // TODO(akalin,viettrungluu): Figure out whether this method | 629 // TODO(akalin,viettrungluu): Figure out whether this method |
| 617 // can be prevented from being called if defaultProfile is | 630 // can be prevented from being called if defaultProfile is |
| 618 // NULL. | 631 // NULL. |
| 619 if (!defaultProfile) { | 632 if (!defaultProfile) { |
| 620 LOG(WARNING) | 633 LOG(WARNING) |
| 621 << "NULL defaultProfile detected -- not doing anything"; | 634 << "NULL defaultProfile detected -- not doing anything"; |
| 622 break; | 635 break; |
| 623 } | 636 } |
| 624 enable = ProfileSyncService::IsSyncEnabled(); | 637 enable = ProfileSyncService::IsSyncEnabled() && |
| 638 [self keyWindowIsNotModal]; |
| 625 sync_ui_util::UpdateSyncItem(item, enable, defaultProfile); | 639 sync_ui_util::UpdateSyncItem(item, enable, defaultProfile); |
| 626 break; | 640 break; |
| 627 } | 641 } |
| 628 default: | 642 default: |
| 629 enable = menuState_->IsCommandEnabled(tag) ? YES : NO; | 643 enable = menuState_->IsCommandEnabled(tag) ? |
| 644 [self keyWindowIsNotModal] : NO; |
| 630 } | 645 } |
| 631 } | 646 } |
| 632 } else if (action == @selector(terminate:)) { | 647 } else if (action == @selector(terminate:)) { |
| 633 enable = YES; | 648 enable = YES; |
| 634 } else if (action == @selector(showPreferences:)) { | 649 } else if (action == @selector(showPreferences:)) { |
| 635 enable = YES; | 650 enable = YES; |
| 636 } else if (action == @selector(orderFrontStandardAboutPanel:)) { | 651 } else if (action == @selector(orderFrontStandardAboutPanel:)) { |
| 637 enable = YES; | 652 enable = YES; |
| 638 } else if (action == @selector(newWindowFromDock:)) { | 653 } else if (action == @selector(newWindowFromDock:)) { |
| 639 enable = YES; | 654 enable = YES; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 [appController showPreferencesWindow:nil page:page profile:profile]; | 1030 [appController showPreferencesWindow:nil page:page profile:profile]; |
| 1016 } | 1031 } |
| 1017 | 1032 |
| 1018 namespace app_controller_mac { | 1033 namespace app_controller_mac { |
| 1019 | 1034 |
| 1020 bool IsOpeningNewWindow() { | 1035 bool IsOpeningNewWindow() { |
| 1021 return g_is_opening_new_window; | 1036 return g_is_opening_new_window; |
| 1022 } | 1037 } |
| 1023 | 1038 |
| 1024 } // namespace app_controller_mac | 1039 } // namespace app_controller_mac |
| OLD | NEW |