| 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 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 #if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 270 #if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 271 AddSeparator(ui::NORMAL_SEPARATOR); | 271 AddSeparator(ui::NORMAL_SEPARATOR); |
| 272 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED); | 272 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED); |
| 273 #endif | 273 #endif |
| 274 } | 274 } |
| 275 | 275 |
| 276 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
| 277 // WrenchMenuModel | 277 // WrenchMenuModel |
| 278 | 278 |
| 279 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 279 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, |
| 280 Browser* browser, | 280 Browser* browser) |
| 281 bool is_new_menu) | |
| 282 : ui::SimpleMenuModel(this), | 281 : ui::SimpleMenuModel(this), |
| 283 provider_(provider), | 282 provider_(provider), |
| 284 browser_(browser), | 283 browser_(browser), |
| 285 tab_strip_model_(browser_->tab_strip_model()) { | 284 tab_strip_model_(browser_->tab_strip_model()) { |
| 286 Build(is_new_menu); | 285 Build(); |
| 287 UpdateZoomControls(); | 286 UpdateZoomControls(); |
| 288 | 287 |
| 289 content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( | 288 content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( |
| 290 browser->profile())->AddZoomLevelChangedCallback( | 289 browser->profile())->AddZoomLevelChangedCallback( |
| 291 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, | 290 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 292 base::Unretained(this))); | 291 base::Unretained(this))); |
| 293 | 292 |
| 294 browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext( | 293 browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext( |
| 295 browser->profile())->AddZoomLevelChangedCallback( | 294 browser->profile())->AddZoomLevelChangedCallback( |
| 296 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, | 295 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 tab_strip_model_(NULL) { | 518 tab_strip_model_(NULL) { |
| 520 } | 519 } |
| 521 | 520 |
| 522 bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() { | 521 bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() { |
| 523 if (browser_->profile()->IsSupervised()) | 522 if (browser_->profile()->IsSupervised()) |
| 524 return false; | 523 return false; |
| 525 | 524 |
| 526 return !browser_->profile()->IsGuestSession(); | 525 return !browser_->profile()->IsGuestSession(); |
| 527 } | 526 } |
| 528 | 527 |
| 529 void WrenchMenuModel::Build(bool is_new_menu) { | 528 void WrenchMenuModel::Build() { |
| 530 #if defined(OS_WIN) | 529 #if defined(OS_WIN) |
| 531 AddItem(IDC_VIEW_INCOMPATIBILITIES, | 530 AddItem(IDC_VIEW_INCOMPATIBILITIES, |
| 532 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); | 531 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); |
| 533 EnumerateModulesModel* model = | 532 EnumerateModulesModel* model = |
| 534 EnumerateModulesModel::GetInstance(); | 533 EnumerateModulesModel::GetInstance(); |
| 535 if (model->modules_to_notify_about() > 0 || | 534 if (model->modules_to_notify_about() > 0 || |
| 536 model->confirmed_bad_modules_detected() > 0) | 535 model->confirmed_bad_modules_detected() > 0) |
| 537 AddSeparator(ui::NORMAL_SEPARATOR); | 536 AddSeparator(ui::NORMAL_SEPARATOR); |
| 538 #endif | 537 #endif |
| 539 | 538 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 // In Windows 8 desktop, add the 'Relaunch Chrome in Windows 8 mode'. | 590 // In Windows 8 desktop, add the 'Relaunch Chrome in Windows 8 mode'. |
| 592 AddSeparator(ui::NORMAL_SEPARATOR); | 591 AddSeparator(ui::NORMAL_SEPARATOR); |
| 593 AddItemWithStringId(IDC_WIN8_METRO_RESTART, IDS_WIN8_METRO_RESTART); | 592 AddItemWithStringId(IDC_WIN8_METRO_RESTART, IDS_WIN8_METRO_RESTART); |
| 594 } | 593 } |
| 595 #endif | 594 #endif |
| 596 | 595 |
| 597 #endif | 596 #endif |
| 598 | 597 |
| 599 // Append the full menu including separators. The final separator only gets | 598 // Append the full menu including separators. The final separator only gets |
| 600 // appended when this is a touch menu - otherwise it would get added twice. | 599 // appended when this is a touch menu - otherwise it would get added twice. |
| 601 CreateCutCopyPasteMenu(is_new_menu); | 600 CreateCutCopyPasteMenu(); |
| 602 | |
| 603 if (!is_new_menu) | |
| 604 CreateZoomMenu(is_new_menu); | |
| 605 | 601 |
| 606 if (CommandLine::ForCurrentProcess()->HasSwitch( | 602 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 607 switches::kEnableDomDistiller)) { | 603 switches::kEnableDomDistiller)) { |
| 608 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE); | 604 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE); |
| 609 } | 605 } |
| 610 | 606 |
| 611 AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); | 607 AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); |
| 612 AddItemWithStringId(IDC_FIND, IDS_FIND); | 608 AddItemWithStringId(IDC_FIND, IDS_FIND); |
| 613 AddItemWithStringId(IDC_PRINT, IDS_PRINT); | 609 AddItemWithStringId(IDC_PRINT, IDS_PRINT); |
| 614 | 610 |
| 615 tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); | 611 tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); |
| 616 // In case of touch this is the last item. | 612 CreateZoomMenu(); |
| 617 if (!is_new_menu) { | |
| 618 AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU, | |
| 619 tools_menu_model_.get()); | |
| 620 } | |
| 621 | |
| 622 if (is_new_menu) | |
| 623 CreateZoomMenu(is_new_menu); | |
| 624 else | |
| 625 AddSeparator(ui::NORMAL_SEPARATOR); | |
| 626 | 613 |
| 627 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); | 614 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); |
| 628 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); | 615 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); |
| 629 AddSeparator(ui::NORMAL_SEPARATOR); | 616 AddSeparator(ui::NORMAL_SEPARATOR); |
| 630 | 617 |
| 631 #if !defined(OS_CHROMEOS) | 618 #if !defined(OS_CHROMEOS) |
| 632 if (!switches::IsNewAvatarMenu()) { | 619 if (!switches::IsNewAvatarMenu()) { |
| 633 // No "Sign in to Chromium..." menu item on ChromeOS. | 620 // No "Sign in to Chromium..." menu item on ChromeOS. |
| 634 SigninManager* signin = SigninManagerFactory::GetForProfile( | 621 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 635 browser_->profile()->GetOriginalProfile()); | 622 browser_->profile()->GetOriginalProfile()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); | 654 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); |
| 668 | 655 |
| 669 #if defined(OS_WIN) | 656 #if defined(OS_WIN) |
| 670 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), | 657 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), |
| 671 ui::ResourceBundle::GetSharedInstance(). | 658 ui::ResourceBundle::GetSharedInstance(). |
| 672 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); | 659 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); |
| 673 #endif | 660 #endif |
| 674 | 661 |
| 675 AddGlobalErrorMenuItems(); | 662 AddGlobalErrorMenuItems(); |
| 676 | 663 |
| 677 if (is_new_menu) { | 664 AddSeparator(ui::NORMAL_SEPARATOR); |
| 678 AddSeparator(ui::NORMAL_SEPARATOR); | 665 AddSubMenuWithStringId( |
| 679 AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU, | 666 IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get()); |
| 680 tools_menu_model_.get()); | |
| 681 } | |
| 682 | 667 |
| 683 bool show_exit_menu = browser_defaults::kShowExitMenuItem; | 668 bool show_exit_menu = browser_defaults::kShowExitMenuItem; |
| 684 #if defined(OS_WIN) | 669 #if defined(OS_WIN) |
| 685 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 670 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 686 show_exit_menu = false; | 671 show_exit_menu = false; |
| 687 #endif | 672 #endif |
| 688 | 673 |
| 689 if (show_exit_menu) { | 674 if (show_exit_menu) { |
| 690 AddSeparator(ui::NORMAL_SEPARATOR); | 675 AddSeparator(ui::NORMAL_SEPARATOR); |
| 691 AddItemWithStringId(IDC_EXIT, IDS_EXIT); | 676 AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); | 728 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); |
| 744 // We only add the separator if there are > 0 items to show in the overflow. | 729 // We only add the separator if there are > 0 items to show in the overflow. |
| 745 extensions::ExtensionToolbarModel* toolbar_model = | 730 extensions::ExtensionToolbarModel* toolbar_model = |
| 746 extensions::ExtensionToolbarModel::Get(browser_->profile()); | 731 extensions::ExtensionToolbarModel::Get(browser_->profile()); |
| 747 // A count of -1 means all actions are visible. | 732 // A count of -1 means all actions are visible. |
| 748 if (toolbar_model->GetVisibleIconCount() != -1) | 733 if (toolbar_model->GetVisibleIconCount() != -1) |
| 749 AddSeparator(ui::UPPER_SEPARATOR); | 734 AddSeparator(ui::UPPER_SEPARATOR); |
| 750 #endif // defined(TOOLKIT_VIEWS) | 735 #endif // defined(TOOLKIT_VIEWS) |
| 751 } | 736 } |
| 752 | 737 |
| 753 void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) { | 738 void WrenchMenuModel::CreateCutCopyPasteMenu() { |
| 754 AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR); | 739 AddSeparator(ui::LOWER_SEPARATOR); |
| 755 | 740 |
| 756 #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) | 741 #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) |
| 757 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the | 742 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the |
| 758 // layout for this menu item in Toolbar.xib. It does, however, use the | 743 // layout for this menu item in Toolbar.xib. It does, however, use the |
| 759 // command_id value from AddButtonItem() to identify this special item. | 744 // command_id value from AddButtonItem() to identify this special item. |
| 760 edit_menu_item_model_.reset(new ui::ButtonMenuItemModel(IDS_EDIT, this)); | 745 edit_menu_item_model_.reset(new ui::ButtonMenuItemModel(IDS_EDIT, this)); |
| 761 edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); | 746 edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); |
| 762 edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); | 747 edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); |
| 763 edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); | 748 edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); |
| 764 AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get()); | 749 AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get()); |
| 765 #else | 750 #else |
| 766 // WARNING: views/wrench_menu assumes these items are added in this order. If | 751 // WARNING: views/wrench_menu assumes these items are added in this order. If |
| 767 // you change the order you'll need to update wrench_menu as well. | 752 // you change the order you'll need to update wrench_menu as well. |
| 768 AddItemWithStringId(IDC_CUT, IDS_CUT); | 753 AddItemWithStringId(IDC_CUT, IDS_CUT); |
| 769 AddItemWithStringId(IDC_COPY, IDS_COPY); | 754 AddItemWithStringId(IDC_COPY, IDS_COPY); |
| 770 AddItemWithStringId(IDC_PASTE, IDS_PASTE); | 755 AddItemWithStringId(IDC_PASTE, IDS_PASTE); |
| 771 #endif | 756 #endif |
| 772 | 757 |
| 773 if (new_menu) | 758 AddSeparator(ui::UPPER_SEPARATOR); |
| 774 AddSeparator(ui::UPPER_SEPARATOR); | |
| 775 } | 759 } |
| 776 | 760 |
| 777 void WrenchMenuModel::CreateZoomMenu(bool new_menu) { | 761 void WrenchMenuModel::CreateZoomMenu() { |
| 778 // This menu needs to be enclosed by separators. | 762 // This menu needs to be enclosed by separators. |
| 779 AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR); | 763 AddSeparator(ui::LOWER_SEPARATOR); |
| 780 | 764 |
| 781 #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) | 765 #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) |
| 782 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the | 766 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the |
| 783 // layout for this menu item in Toolbar.xib. It does, however, use the | 767 // layout for this menu item in Toolbar.xib. It does, however, use the |
| 784 // command_id value from AddButtonItem() to identify this special item. | 768 // command_id value from AddButtonItem() to identify this special item. |
| 785 zoom_menu_item_model_.reset( | 769 zoom_menu_item_model_.reset( |
| 786 new ui::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); | 770 new ui::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); |
| 787 zoom_menu_item_model_->AddGroupItemWithStringId( | 771 zoom_menu_item_model_->AddGroupItemWithStringId( |
| 788 IDC_ZOOM_MINUS, IDS_ZOOM_MINUS2); | 772 IDC_ZOOM_MINUS, IDS_ZOOM_MINUS2); |
| 789 zoom_menu_item_model_->AddButtonLabel(IDC_ZOOM_PERCENT_DISPLAY, | 773 zoom_menu_item_model_->AddButtonLabel(IDC_ZOOM_PERCENT_DISPLAY, |
| 790 IDS_ZOOM_PLUS2); | 774 IDS_ZOOM_PLUS2); |
| 791 zoom_menu_item_model_->AddGroupItemWithStringId( | 775 zoom_menu_item_model_->AddGroupItemWithStringId( |
| 792 IDC_ZOOM_PLUS, IDS_ZOOM_PLUS2); | 776 IDC_ZOOM_PLUS, IDS_ZOOM_PLUS2); |
| 793 zoom_menu_item_model_->AddSpace(); | 777 zoom_menu_item_model_->AddSpace(); |
| 794 zoom_menu_item_model_->AddItemWithImage( | 778 zoom_menu_item_model_->AddItemWithImage( |
| 795 IDC_FULLSCREEN, IDR_FULLSCREEN_MENU_BUTTON); | 779 IDC_FULLSCREEN, IDR_FULLSCREEN_MENU_BUTTON); |
| 796 AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get()); | 780 AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get()); |
| 797 #else | 781 #else |
| 798 // WARNING: views/wrench_menu assumes these items are added in this order. If | 782 // WARNING: views/wrench_menu assumes these items are added in this order. If |
| 799 // you change the order you'll need to update wrench_menu as well. | 783 // you change the order you'll need to update wrench_menu as well. |
| 800 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); | 784 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); |
| 801 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); | 785 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); |
| 802 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); | 786 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); |
| 803 #endif | 787 #endif |
| 804 | 788 |
| 805 AddSeparator(new_menu ? ui::UPPER_SEPARATOR : ui::NORMAL_SEPARATOR); | 789 AddSeparator(ui::UPPER_SEPARATOR); |
| 806 } | 790 } |
| 807 | 791 |
| 808 void WrenchMenuModel::UpdateZoomControls() { | 792 void WrenchMenuModel::UpdateZoomControls() { |
| 809 int zoom_percent = 100; | 793 int zoom_percent = 100; |
| 810 if (browser_->tab_strip_model()->GetActiveWebContents()) { | 794 if (browser_->tab_strip_model()->GetActiveWebContents()) { |
| 811 zoom_percent = ZoomController::FromWebContents( | 795 zoom_percent = ZoomController::FromWebContents( |
| 812 browser_->tab_strip_model()->GetActiveWebContents()) | 796 browser_->tab_strip_model()->GetActiveWebContents()) |
| 813 ->GetZoomPercent(); | 797 ->GetZoomPercent(); |
| 814 } | 798 } |
| 815 zoom_label_ = l10n_util::GetStringFUTF16( | 799 zoom_label_ = l10n_util::GetStringFUTF16( |
| 816 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 800 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
| 817 } | 801 } |
| 818 | 802 |
| 819 void WrenchMenuModel::OnZoomLevelChanged( | 803 void WrenchMenuModel::OnZoomLevelChanged( |
| 820 const content::HostZoomMap::ZoomLevelChange& change) { | 804 const content::HostZoomMap::ZoomLevelChange& change) { |
| 821 UpdateZoomControls(); | 805 UpdateZoomControls(); |
| 822 } | 806 } |
| OLD | NEW |