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/app_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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); | 226 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); |
227 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); | 227 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); |
228 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); | 228 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); |
229 } | 229 } |
230 | 230 |
231 //////////////////////////////////////////////////////////////////////////////// | 231 //////////////////////////////////////////////////////////////////////////////// |
232 // HelpMenuModel | 232 // HelpMenuModel |
233 | 233 |
234 #if defined(GOOGLE_CHROME_BUILD) | 234 #if defined(GOOGLE_CHROME_BUILD) |
235 | 235 |
236 class WrenchMenuModel::HelpMenuModel : public ui::SimpleMenuModel { | 236 class AppMenuModel::HelpMenuModel : public ui::SimpleMenuModel { |
237 public: | 237 public: |
238 HelpMenuModel(ui::SimpleMenuModel::Delegate* delegate, | 238 HelpMenuModel(ui::SimpleMenuModel::Delegate* delegate, |
239 Browser* browser) | 239 Browser* browser) |
240 : SimpleMenuModel(delegate) { | 240 : SimpleMenuModel(delegate) { |
241 Build(browser); | 241 Build(browser); |
242 } | 242 } |
243 | 243 |
244 private: | 244 private: |
245 void Build(Browser* browser) { | 245 void Build(Browser* browser) { |
246 #if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD) | 246 #if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 AddSeparator(ui::NORMAL_SEPARATOR); | 328 AddSeparator(ui::NORMAL_SEPARATOR); |
329 AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS); | 329 AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS); |
330 | 330 |
331 #if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 331 #if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
332 AddSeparator(ui::NORMAL_SEPARATOR); | 332 AddSeparator(ui::NORMAL_SEPARATOR); |
333 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED); | 333 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED); |
334 #endif | 334 #endif |
335 } | 335 } |
336 | 336 |
337 //////////////////////////////////////////////////////////////////////////////// | 337 //////////////////////////////////////////////////////////////////////////////// |
338 // WrenchMenuModel | 338 // AppMenuModel |
339 | 339 |
340 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 340 AppMenuModel::AppMenuModel(ui::AcceleratorProvider* provider, Browser* browser) |
341 Browser* browser) | |
342 : ui::SimpleMenuModel(this), | 341 : ui::SimpleMenuModel(this), |
343 uma_action_recorded_(false), | 342 uma_action_recorded_(false), |
344 provider_(provider), | 343 provider_(provider), |
345 browser_(browser) { | 344 browser_(browser) { |
346 Build(); | 345 Build(); |
347 UpdateZoomControls(); | 346 UpdateZoomControls(); |
348 | 347 |
349 browser_zoom_subscription_ = | 348 browser_zoom_subscription_ = |
350 ui_zoom::ZoomEventManager::GetForBrowserContext(browser->profile()) | 349 ui_zoom::ZoomEventManager::GetForBrowserContext(browser->profile()) |
351 ->AddZoomLevelChangedCallback(base::Bind( | 350 ->AddZoomLevelChangedCallback(base::Bind( |
352 &WrenchMenuModel::OnZoomLevelChanged, base::Unretained(this))); | 351 &AppMenuModel::OnZoomLevelChanged, base::Unretained(this))); |
353 | 352 |
354 browser_->tab_strip_model()->AddObserver(this); | 353 browser_->tab_strip_model()->AddObserver(this); |
355 | 354 |
356 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 355 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
357 content::NotificationService::AllSources()); | 356 content::NotificationService::AllSources()); |
358 } | 357 } |
359 | 358 |
360 WrenchMenuModel::~WrenchMenuModel() { | 359 AppMenuModel::~AppMenuModel() { |
361 if (browser_) // Null in tests. | 360 if (browser_) // Null in tests. |
362 browser_->tab_strip_model()->RemoveObserver(this); | 361 browser_->tab_strip_model()->RemoveObserver(this); |
363 } | 362 } |
364 | 363 |
365 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 364 bool AppMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
366 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 365 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
367 } | 366 } |
368 | 367 |
369 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 368 bool AppMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
370 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 369 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
371 #if defined(OS_MACOSX) | 370 #if defined(OS_MACOSX) |
372 command_id == IDC_FULLSCREEN || | 371 command_id == IDC_FULLSCREEN || |
373 #elif defined(OS_WIN) | 372 #elif defined(OS_WIN) |
374 command_id == IDC_PIN_TO_START_SCREEN || | 373 command_id == IDC_PIN_TO_START_SCREEN || |
375 #endif | 374 #endif |
376 command_id == IDC_UPGRADE_DIALOG; | 375 command_id == IDC_UPGRADE_DIALOG; |
377 } | 376 } |
378 | 377 |
379 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { | 378 base::string16 AppMenuModel::GetLabelForCommandId(int command_id) const { |
380 switch (command_id) { | 379 switch (command_id) { |
381 case IDC_ZOOM_PERCENT_DISPLAY: | 380 case IDC_ZOOM_PERCENT_DISPLAY: |
382 return zoom_label_; | 381 return zoom_label_; |
383 #if defined(OS_MACOSX) | 382 #if defined(OS_MACOSX) |
384 case IDC_FULLSCREEN: { | 383 case IDC_FULLSCREEN: { |
385 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. | 384 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
386 // Note: On startup, |window()| may be NULL. | 385 // Note: On startup, |window()| may be NULL. |
387 if (browser_->window() && browser_->window()->IsFullscreen()) | 386 if (browser_->window() && browser_->window()->IsFullscreen()) |
388 string_id = IDS_EXIT_FULLSCREEN_MAC; | 387 string_id = IDS_EXIT_FULLSCREEN_MAC; |
389 return l10n_util::GetStringUTF16(string_id); | 388 return l10n_util::GetStringUTF16(string_id); |
(...skipping 12 matching lines...) Expand all Loading... |
402 } | 401 } |
403 #endif | 402 #endif |
404 case IDC_UPGRADE_DIALOG: | 403 case IDC_UPGRADE_DIALOG: |
405 return GetUpgradeDialogMenuItemName(); | 404 return GetUpgradeDialogMenuItemName(); |
406 default: | 405 default: |
407 NOTREACHED(); | 406 NOTREACHED(); |
408 return base::string16(); | 407 return base::string16(); |
409 } | 408 } |
410 } | 409 } |
411 | 410 |
412 bool WrenchMenuModel::GetIconForCommandId(int command_id, | 411 bool AppMenuModel::GetIconForCommandId(int command_id, gfx::Image* icon) const { |
413 gfx::Image* icon) const { | |
414 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 412 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
415 switch (command_id) { | 413 switch (command_id) { |
416 case IDC_UPGRADE_DIALOG: { | 414 case IDC_UPGRADE_DIALOG: { |
417 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 415 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
418 *icon = rb.GetNativeImageNamed( | 416 *icon = rb.GetNativeImageNamed( |
419 UpgradeDetector::GetInstance()->GetIconResourceID()); | 417 UpgradeDetector::GetInstance()->GetIconResourceID()); |
420 return true; | 418 return true; |
421 } | 419 } |
422 return false; | 420 return false; |
423 } | 421 } |
424 default: | 422 default: |
425 break; | 423 break; |
426 } | 424 } |
427 return false; | 425 return false; |
428 } | 426 } |
429 | 427 |
430 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { | 428 void AppMenuModel::ExecuteCommand(int command_id, int event_flags) { |
431 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( | 429 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( |
432 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); | 430 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); |
433 if (error) { | 431 if (error) { |
434 error->ExecuteMenuItem(browser_); | 432 error->ExecuteMenuItem(browser_); |
435 return; | 433 return; |
436 } | 434 } |
437 | 435 |
438 LogMenuMetrics(command_id); | 436 LogMenuMetrics(command_id); |
439 chrome::ExecuteCommand(browser_, command_id); | 437 chrome::ExecuteCommand(browser_, command_id); |
440 } | 438 } |
441 | 439 |
442 void WrenchMenuModel::LogMenuMetrics(int command_id) { | 440 void AppMenuModel::LogMenuMetrics(int command_id) { |
443 base::TimeDelta delta = timer_.Elapsed(); | 441 base::TimeDelta delta = timer_.Elapsed(); |
444 | 442 |
445 switch (command_id) { | 443 switch (command_id) { |
446 case IDC_NEW_TAB: | 444 case IDC_NEW_TAB: |
447 if (!uma_action_recorded_) | 445 if (!uma_action_recorded_) |
448 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.NewTab", delta); | 446 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.NewTab", delta); |
449 LogMenuAction(MENU_ACTION_NEW_TAB); | 447 LogMenuAction(MENU_ACTION_NEW_TAB); |
450 break; | 448 break; |
451 case IDC_NEW_WINDOW: | 449 case IDC_NEW_WINDOW: |
452 if (!uma_action_recorded_) | 450 if (!uma_action_recorded_) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 LogMenuAction(MENU_ACTION_EXIT); | 724 LogMenuAction(MENU_ACTION_EXIT); |
727 break; | 725 break; |
728 } | 726 } |
729 | 727 |
730 if (!uma_action_recorded_) { | 728 if (!uma_action_recorded_) { |
731 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction", delta); | 729 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction", delta); |
732 uma_action_recorded_ = true; | 730 uma_action_recorded_ = true; |
733 } | 731 } |
734 } | 732 } |
735 | 733 |
736 void WrenchMenuModel::LogMenuAction(int action_id) { | 734 void AppMenuModel::LogMenuAction(int action_id) { |
737 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.MenuAction", action_id, | 735 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.MenuAction", action_id, |
738 LIMIT_MENU_ACTION); | 736 LIMIT_MENU_ACTION); |
739 } | 737 } |
740 | 738 |
741 bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { | 739 bool AppMenuModel::IsCommandIdChecked(int command_id) const { |
742 if (command_id == IDC_SHOW_BOOKMARK_BAR) { | 740 if (command_id == IDC_SHOW_BOOKMARK_BAR) { |
743 return browser_->profile()->GetPrefs()->GetBoolean( | 741 return browser_->profile()->GetPrefs()->GetBoolean( |
744 bookmarks::prefs::kShowBookmarkBar); | 742 bookmarks::prefs::kShowBookmarkBar); |
745 } else if (command_id == IDC_PROFILING_ENABLED) { | 743 } else if (command_id == IDC_PROFILING_ENABLED) { |
746 return Profiling::BeingProfiled(); | 744 return Profiling::BeingProfiled(); |
747 } else if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) { | 745 } else if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) { |
748 return chrome::IsRequestingTabletSite(browser_); | 746 return chrome::IsRequestingTabletSite(browser_); |
749 } | 747 } |
750 | 748 |
751 return false; | 749 return false; |
752 } | 750 } |
753 | 751 |
754 bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { | 752 bool AppMenuModel::IsCommandIdEnabled(int command_id) const { |
755 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( | 753 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( |
756 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); | 754 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); |
757 if (error) | 755 if (error) |
758 return true; | 756 return true; |
759 | 757 |
760 return chrome::IsCommandEnabled(browser_, command_id); | 758 return chrome::IsCommandEnabled(browser_, command_id); |
761 } | 759 } |
762 | 760 |
763 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { | 761 bool AppMenuModel::IsCommandIdVisible(int command_id) const { |
764 switch (command_id) { | 762 switch (command_id) { |
765 #if defined(OS_MACOSX) | 763 #if defined(OS_MACOSX) |
766 case kEmptyMenuItemCommand: | 764 case kEmptyMenuItemCommand: |
767 return false; // Always hidden (see CreateActionToolbarOverflowMenu). | 765 return false; // Always hidden (see CreateActionToolbarOverflowMenu). |
768 #endif | 766 #endif |
769 #if defined(OS_WIN) | 767 #if defined(OS_WIN) |
770 case IDC_VIEW_INCOMPATIBILITIES: { | 768 case IDC_VIEW_INCOMPATIBILITIES: { |
771 EnumerateModulesModel* loaded_modules = | 769 EnumerateModulesModel* loaded_modules = |
772 EnumerateModulesModel::GetInstance(); | 770 EnumerateModulesModel::GetInstance(); |
773 if (loaded_modules->confirmed_bad_modules_detected() <= 0) | 771 if (loaded_modules->confirmed_bad_modules_detected() <= 0) |
774 return false; | 772 return false; |
775 // We'll leave the wrench adornment on until the user clicks the link. | 773 // We'll leave the app menu adornment on until the user clicks the link. |
776 if (loaded_modules->modules_to_notify_about() <= 0) | 774 if (loaded_modules->modules_to_notify_about() <= 0) |
777 loaded_modules->AcknowledgeConflictNotification(); | 775 loaded_modules->AcknowledgeConflictNotification(); |
778 return true; | 776 return true; |
779 } | 777 } |
780 case IDC_PIN_TO_START_SCREEN: | 778 case IDC_PIN_TO_START_SCREEN: |
781 return base::win::IsMetroProcess(); | 779 return base::win::IsMetroProcess(); |
782 #else | 780 #else |
783 case IDC_VIEW_INCOMPATIBILITIES: | 781 case IDC_VIEW_INCOMPATIBILITIES: |
784 case IDC_PIN_TO_START_SCREEN: | 782 case IDC_PIN_TO_START_SCREEN: |
785 return false; | 783 return false; |
786 #endif | 784 #endif |
787 case IDC_UPGRADE_DIALOG: | 785 case IDC_UPGRADE_DIALOG: |
788 return browser_defaults::kShowUpgradeMenuItem && | 786 return browser_defaults::kShowUpgradeMenuItem && |
789 UpgradeDetector::GetInstance()->notify_upgrade(); | 787 UpgradeDetector::GetInstance()->notify_upgrade(); |
790 #if !defined(OS_LINUX) || defined(USE_AURA) | 788 #if !defined(OS_LINUX) || defined(USE_AURA) |
791 case IDC_BOOKMARK_PAGE: | 789 case IDC_BOOKMARK_PAGE: |
792 return !chrome::ShouldRemoveBookmarkThisPageUI(browser_->profile()); | 790 return !chrome::ShouldRemoveBookmarkThisPageUI(browser_->profile()); |
793 case IDC_BOOKMARK_ALL_TABS: | 791 case IDC_BOOKMARK_ALL_TABS: |
794 return !chrome::ShouldRemoveBookmarkOpenPagesUI(browser_->profile()); | 792 return !chrome::ShouldRemoveBookmarkOpenPagesUI(browser_->profile()); |
795 #endif | 793 #endif |
796 default: | 794 default: |
797 return true; | 795 return true; |
798 } | 796 } |
799 } | 797 } |
800 | 798 |
801 bool WrenchMenuModel::GetAcceleratorForCommandId( | 799 bool AppMenuModel::GetAcceleratorForCommandId(int command_id, |
802 int command_id, | 800 ui::Accelerator* accelerator) { |
803 ui::Accelerator* accelerator) { | |
804 return provider_->GetAcceleratorForCommandId(command_id, accelerator); | 801 return provider_->GetAcceleratorForCommandId(command_id, accelerator); |
805 } | 802 } |
806 | 803 |
807 void WrenchMenuModel::ActiveTabChanged(WebContents* old_contents, | 804 void AppMenuModel::ActiveTabChanged(WebContents* old_contents, |
808 WebContents* new_contents, | 805 WebContents* new_contents, |
809 int index, | 806 int index, |
810 int reason) { | 807 int reason) { |
811 // The user has switched between tabs and the new tab may have a different | 808 // The user has switched between tabs and the new tab may have a different |
812 // zoom setting. | 809 // zoom setting. |
813 UpdateZoomControls(); | 810 UpdateZoomControls(); |
814 } | 811 } |
815 | 812 |
816 void WrenchMenuModel::TabReplacedAt(TabStripModel* tab_strip_model, | 813 void AppMenuModel::TabReplacedAt(TabStripModel* tab_strip_model, |
817 WebContents* old_contents, | 814 WebContents* old_contents, |
818 WebContents* new_contents, | 815 WebContents* new_contents, |
819 int index) { | 816 int index) { |
820 UpdateZoomControls(); | 817 UpdateZoomControls(); |
821 } | 818 } |
822 | 819 |
823 void WrenchMenuModel::Observe(int type, | 820 void AppMenuModel::Observe(int type, |
824 const content::NotificationSource& source, | 821 const content::NotificationSource& source, |
825 const content::NotificationDetails& details) { | 822 const content::NotificationDetails& details) { |
826 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 823 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
827 UpdateZoomControls(); | 824 UpdateZoomControls(); |
828 } | 825 } |
829 | 826 |
830 // For testing. | 827 // For testing. |
831 WrenchMenuModel::WrenchMenuModel() | 828 AppMenuModel::AppMenuModel() |
832 : ui::SimpleMenuModel(this), | 829 : ui::SimpleMenuModel(this), |
833 uma_action_recorded_(false), | 830 uma_action_recorded_(false), |
834 provider_(nullptr), | 831 provider_(nullptr), |
835 browser_(nullptr) {} | 832 browser_(nullptr) {} |
836 | 833 |
837 bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() { | 834 bool AppMenuModel::ShouldShowNewIncognitoWindowMenuItem() { |
838 if (browser_->profile()->IsGuestSession()) | 835 if (browser_->profile()->IsGuestSession()) |
839 return false; | 836 return false; |
840 | 837 |
841 return IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 838 return IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
842 IncognitoModePrefs::DISABLED; | 839 IncognitoModePrefs::DISABLED; |
843 } | 840 } |
844 | 841 |
845 // Note: When adding new menu items please place under an appropriate section. | 842 // Note: When adding new menu items please place under an appropriate section. |
846 // Menu is organised as follows: | 843 // Menu is organised as follows: |
847 // - Extension toolbar overflow. | 844 // - Extension toolbar overflow. |
848 // - Global browser errors and warnings. | 845 // - Global browser errors and warnings. |
849 // - Tabs and windows. | 846 // - Tabs and windows. |
850 // - Places previously been e.g. History, bookmarks, recent tabs. | 847 // - Places previously been e.g. History, bookmarks, recent tabs. |
851 // - Page actions e.g. zoom, edit, find, print. | 848 // - Page actions e.g. zoom, edit, find, print. |
852 // - Learn about the browser and global customisation e.g. settings, help. | 849 // - Learn about the browser and global customisation e.g. settings, help. |
853 // - Browser relaunch, quit. | 850 // - Browser relaunch, quit. |
854 void WrenchMenuModel::Build() { | 851 void AppMenuModel::Build() { |
855 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) | 852 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
856 CreateActionToolbarOverflowMenu(); | 853 CreateActionToolbarOverflowMenu(); |
857 | 854 |
858 AddItem(IDC_VIEW_INCOMPATIBILITIES, | 855 AddItem(IDC_VIEW_INCOMPATIBILITIES, |
859 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); | 856 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); |
860 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), | 857 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), |
861 ui::ResourceBundle::GetSharedInstance(). | 858 ui::ResourceBundle::GetSharedInstance(). |
862 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); | 859 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); |
863 if (IsCommandIdVisible(IDC_UPGRADE_DIALOG)) | 860 if (IsCommandIdVisible(IDC_UPGRADE_DIALOG)) |
864 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); | 861 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 932 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
936 show_exit_menu = false; | 933 show_exit_menu = false; |
937 #endif | 934 #endif |
938 if (show_exit_menu) { | 935 if (show_exit_menu) { |
939 AddSeparator(ui::NORMAL_SEPARATOR); | 936 AddSeparator(ui::NORMAL_SEPARATOR); |
940 AddItemWithStringId(IDC_EXIT, IDS_EXIT); | 937 AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
941 } | 938 } |
942 uma_action_recorded_ = false; | 939 uma_action_recorded_ = false; |
943 } | 940 } |
944 | 941 |
945 bool WrenchMenuModel::AddGlobalErrorMenuItems() { | 942 bool AppMenuModel::AddGlobalErrorMenuItems() { |
946 // TODO(sail): Currently we only build the wrench menu once per browser | 943 // TODO(sail): Currently we only build the app menu once per browser |
947 // window. This means that if a new error is added after the menu is built | 944 // window. This means that if a new error is added after the menu is built |
948 // it won't show in the existing wrench menu. To fix this we need to some | 945 // it won't show in the existing app menu. To fix this we need to some |
949 // how update the menu if new errors are added. | 946 // how update the menu if new errors are added. |
950 const GlobalErrorService::GlobalErrorList& errors = | 947 const GlobalErrorService::GlobalErrorList& errors = |
951 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); | 948 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); |
952 bool menu_items_added = false; | 949 bool menu_items_added = false; |
953 for (GlobalErrorService::GlobalErrorList::const_iterator | 950 for (GlobalErrorService::GlobalErrorList::const_iterator |
954 it = errors.begin(); it != errors.end(); ++it) { | 951 it = errors.begin(); it != errors.end(); ++it) { |
955 GlobalError* error = *it; | 952 GlobalError* error = *it; |
956 DCHECK(error); | 953 DCHECK(error); |
957 if (error->HasMenuItem()) { | 954 if (error->HasMenuItem()) { |
958 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); | 955 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); |
959 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), | 956 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), |
960 error->MenuItemIcon()); | 957 error->MenuItemIcon()); |
961 menu_items_added = true; | 958 menu_items_added = true; |
962 } | 959 } |
963 } | 960 } |
964 return menu_items_added; | 961 return menu_items_added; |
965 } | 962 } |
966 | 963 |
967 void WrenchMenuModel::CreateActionToolbarOverflowMenu() { | 964 void AppMenuModel::CreateActionToolbarOverflowMenu() { |
968 // We only add the extensions overflow container if there are any icons that | 965 // We only add the extensions overflow container if there are any icons that |
969 // aren't shown in the main container. | 966 // aren't shown in the main container. |
970 // browser_->window() can return null during startup. | 967 // browser_->window() can return null during startup. |
971 if (browser_->window() && | 968 if (browser_->window() && |
972 browser_->window()->GetToolbarActionsBar()->NeedsOverflow()) { | 969 browser_->window()->GetToolbarActionsBar()->NeedsOverflow()) { |
973 #if defined(OS_MACOSX) | 970 #if defined(OS_MACOSX) |
974 // There's a bug in AppKit menus, where if a menu item with a custom view | 971 // There's a bug in AppKit menus, where if a menu item with a custom view |
975 // (like the extensions overflow menu) is the first menu item, it is not | 972 // (like the extensions overflow menu) is the first menu item, it is not |
976 // highlightable or keyboard-selectable. | 973 // highlightable or keyboard-selectable. |
977 // Adding any menu item before it (even one which is never visible) prevents | 974 // Adding any menu item before it (even one which is never visible) prevents |
978 // it, so add a bogus item here that will always be hidden. | 975 // it, so add a bogus item here that will always be hidden. |
979 AddItem(kEmptyMenuItemCommand, base::string16()); | 976 AddItem(kEmptyMenuItemCommand, base::string16()); |
980 #endif | 977 #endif |
981 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); | 978 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); |
982 AddSeparator(ui::UPPER_SEPARATOR); | 979 AddSeparator(ui::UPPER_SEPARATOR); |
983 } | 980 } |
984 } | 981 } |
985 | 982 |
986 void WrenchMenuModel::CreateCutCopyPasteMenu() { | 983 void AppMenuModel::CreateCutCopyPasteMenu() { |
987 AddSeparator(ui::LOWER_SEPARATOR); | 984 AddSeparator(ui::LOWER_SEPARATOR); |
988 | 985 |
989 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the | 986 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the |
990 // layout for this menu item in WrenchMenu.xib. It does, however, use the | 987 // layout for this menu item in WrenchMenu.xib. It does, however, use the |
991 // command_id value from AddButtonItem() to identify this special item. | 988 // command_id value from AddButtonItem() to identify this special item. |
992 edit_menu_item_model_.reset(new ui::ButtonMenuItemModel(IDS_EDIT, this)); | 989 edit_menu_item_model_.reset(new ui::ButtonMenuItemModel(IDS_EDIT, this)); |
993 edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); | 990 edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); |
994 edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); | 991 edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); |
995 edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); | 992 edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); |
996 AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get()); | 993 AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get()); |
997 | 994 |
998 AddSeparator(ui::UPPER_SEPARATOR); | 995 AddSeparator(ui::UPPER_SEPARATOR); |
999 } | 996 } |
1000 | 997 |
1001 void WrenchMenuModel::CreateZoomMenu() { | 998 void AppMenuModel::CreateZoomMenu() { |
1002 // This menu needs to be enclosed by separators. | 999 // This menu needs to be enclosed by separators. |
1003 AddSeparator(ui::LOWER_SEPARATOR); | 1000 AddSeparator(ui::LOWER_SEPARATOR); |
1004 | 1001 |
1005 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the | 1002 // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the |
1006 // layout for this menu item in WrenchMenu.xib. It does, however, use the | 1003 // layout for this menu item in WrenchMenu.xib. It does, however, use the |
1007 // command_id value from AddButtonItem() to identify this special item. | 1004 // command_id value from AddButtonItem() to identify this special item. |
1008 zoom_menu_item_model_.reset( | 1005 zoom_menu_item_model_.reset( |
1009 new ui::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); | 1006 new ui::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); |
1010 zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_MINUS, | 1007 zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_MINUS, |
1011 IDS_ZOOM_MINUS2); | 1008 IDS_ZOOM_MINUS2); |
1012 zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_PLUS, | 1009 zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_PLUS, |
1013 IDS_ZOOM_PLUS2); | 1010 IDS_ZOOM_PLUS2); |
1014 zoom_menu_item_model_->AddItemWithImage(IDC_FULLSCREEN, | 1011 zoom_menu_item_model_->AddItemWithImage(IDC_FULLSCREEN, |
1015 IDR_FULLSCREEN_MENU_BUTTON); | 1012 IDR_FULLSCREEN_MENU_BUTTON); |
1016 AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get()); | 1013 AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get()); |
1017 | 1014 |
1018 AddSeparator(ui::UPPER_SEPARATOR); | 1015 AddSeparator(ui::UPPER_SEPARATOR); |
1019 } | 1016 } |
1020 | 1017 |
1021 void WrenchMenuModel::UpdateZoomControls() { | 1018 void AppMenuModel::UpdateZoomControls() { |
1022 int zoom_percent = 100; | 1019 int zoom_percent = 100; |
1023 if (browser_->tab_strip_model() && | 1020 if (browser_->tab_strip_model() && |
1024 browser_->tab_strip_model()->GetActiveWebContents()) { | 1021 browser_->tab_strip_model()->GetActiveWebContents()) { |
1025 zoom_percent = ui_zoom::ZoomController::FromWebContents( | 1022 zoom_percent = ui_zoom::ZoomController::FromWebContents( |
1026 browser_->tab_strip_model()->GetActiveWebContents()) | 1023 browser_->tab_strip_model()->GetActiveWebContents()) |
1027 ->GetZoomPercent(); | 1024 ->GetZoomPercent(); |
1028 } | 1025 } |
1029 zoom_label_ = l10n_util::GetStringFUTF16( | 1026 zoom_label_ = l10n_util::GetStringFUTF16( |
1030 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 1027 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
1031 } | 1028 } |
1032 | 1029 |
1033 void WrenchMenuModel::OnZoomLevelChanged( | 1030 void AppMenuModel::OnZoomLevelChanged( |
1034 const content::HostZoomMap::ZoomLevelChange& change) { | 1031 const content::HostZoomMap::ZoomLevelChange& change) { |
1035 UpdateZoomControls(); | 1032 UpdateZoomControls(); |
1036 } | 1033 } |
OLD | NEW |