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

Side by Side Diff: chrome/browser/ui/toolbar/wrench_menu_model.cc

Issue 1289413003: Switch global error menu icon to vectorized MD asset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: kick signin error service on mac Created 5 years, 3 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
OLDNEW
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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; 359 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS;
360 } 360 }
361 361
362 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { 362 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const {
363 return command_id == IDC_ZOOM_PERCENT_DISPLAY || 363 return command_id == IDC_ZOOM_PERCENT_DISPLAY ||
364 #if defined(OS_MACOSX) 364 #if defined(OS_MACOSX)
365 command_id == IDC_FULLSCREEN || 365 command_id == IDC_FULLSCREEN ||
366 #elif defined(OS_WIN) 366 #elif defined(OS_WIN)
367 command_id == IDC_PIN_TO_START_SCREEN || 367 command_id == IDC_PIN_TO_START_SCREEN ||
368 #endif 368 #endif
369 command_id == IDC_UPGRADE_DIALOG || 369 command_id == IDC_UPGRADE_DIALOG;
370 (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN);
371 } 370 }
372 371
373 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { 372 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
374 switch (command_id) { 373 switch (command_id) {
375 case IDC_ZOOM_PERCENT_DISPLAY: 374 case IDC_ZOOM_PERCENT_DISPLAY:
376 return zoom_label_; 375 return zoom_label_;
377 #if defined(OS_MACOSX) 376 #if defined(OS_MACOSX)
378 case IDC_FULLSCREEN: { 377 case IDC_FULLSCREEN: {
379 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. 378 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter.
380 // Note: On startup, |window()| may be NULL. 379 // Note: On startup, |window()| may be NULL.
381 if (browser_->window() && browser_->window()->IsFullscreen()) 380 if (browser_->window() && browser_->window()->IsFullscreen())
382 string_id = IDS_EXIT_FULLSCREEN_MAC; 381 string_id = IDS_EXIT_FULLSCREEN_MAC;
383 return l10n_util::GetStringUTF16(string_id); 382 return l10n_util::GetStringUTF16(string_id);
384 } 383 }
385 #elif defined(OS_WIN) 384 #elif defined(OS_WIN)
386 case IDC_PIN_TO_START_SCREEN: { 385 case IDC_PIN_TO_START_SCREEN: {
387 int string_id = IDS_PIN_TO_START_SCREEN; 386 int string_id = IDS_PIN_TO_START_SCREEN;
388 WebContents* web_contents = 387 WebContents* web_contents =
389 browser_->tab_strip_model()->GetActiveWebContents(); 388 browser_->tab_strip_model()->GetActiveWebContents();
390 MetroPinTabHelper* tab_helper = 389 MetroPinTabHelper* tab_helper =
391 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) 390 web_contents ? MetroPinTabHelper::FromWebContents(web_contents)
392 : NULL; 391 : NULL;
393 if (tab_helper && tab_helper->IsPinned()) 392 if (tab_helper && tab_helper->IsPinned())
394 string_id = IDS_UNPIN_FROM_START_SCREEN; 393 string_id = IDS_UNPIN_FROM_START_SCREEN;
395 return l10n_util::GetStringUTF16(string_id); 394 return l10n_util::GetStringUTF16(string_id);
396 } 395 }
397 #endif 396 #endif
398 case IDC_UPGRADE_DIALOG: 397 case IDC_UPGRADE_DIALOG:
399 return GetUpgradeDialogMenuItemName(); 398 return GetUpgradeDialogMenuItemName();
400 case IDC_SHOW_SIGNIN:
401 DCHECK(!switches::IsNewAvatarMenu());
402 return signin_ui_util::GetSigninMenuLabel(
403 browser_->profile()->GetOriginalProfile());
404 default: 399 default:
405 NOTREACHED(); 400 NOTREACHED();
406 return base::string16(); 401 return base::string16();
407 } 402 }
408 } 403 }
409 404
410 bool WrenchMenuModel::GetIconForCommandId(int command_id, 405 bool WrenchMenuModel::GetIconForCommandId(int command_id,
411 gfx::Image* icon) const { 406 gfx::Image* icon) const {
412 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 407 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
413 switch (command_id) { 408 switch (command_id) {
414 case IDC_UPGRADE_DIALOG: { 409 case IDC_UPGRADE_DIALOG: {
415 if (UpgradeDetector::GetInstance()->notify_upgrade()) { 410 if (UpgradeDetector::GetInstance()->notify_upgrade()) {
416 *icon = rb.GetNativeImageNamed( 411 *icon = rb.GetNativeImageNamed(
417 UpgradeDetector::GetInstance()->GetIconResourceID()); 412 UpgradeDetector::GetInstance()->GetIconResourceID());
418 return true; 413 return true;
419 } 414 }
420 return false; 415 return false;
421 } 416 }
422 case IDC_SHOW_SIGNIN: {
423 DCHECK(!switches::IsNewAvatarMenu());
424 GlobalError* error = signin_ui_util::GetSignedInServiceError(
425 browser_->profile()->GetOriginalProfile());
426 if (error) {
427 int icon_id = error->MenuItemIconResourceID();
428 if (icon_id) {
429 *icon = rb.GetNativeImageNamed(icon_id);
430 return true;
431 }
432 }
433 return false;
434 }
435 default: 417 default:
436 break; 418 break;
437 } 419 }
438 return false; 420 return false;
439 } 421 }
440 422
441 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { 423 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) {
442 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( 424 GlobalError* error = GlobalErrorServiceFactory::GetForProfile(
443 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); 425 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id);
444 if (error) { 426 if (error) {
445 error->ExecuteMenuItem(browser_); 427 error->ExecuteMenuItem(browser_);
446 return; 428 return;
447 } 429 }
448 430
449 if (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN) {
450 // If a custom error message is being shown, handle it.
451 GlobalError* error = signin_ui_util::GetSignedInServiceError(
452 browser_->profile()->GetOriginalProfile());
453 if (error) {
454 error->ExecuteMenuItem(browser_);
455 return;
456 }
457 }
458
459 LogMenuMetrics(command_id); 431 LogMenuMetrics(command_id);
460 chrome::ExecuteCommand(browser_, command_id); 432 chrome::ExecuteCommand(browser_, command_id);
461 } 433 }
462 434
463 void WrenchMenuModel::LogMenuMetrics(int command_id) { 435 void WrenchMenuModel::LogMenuMetrics(int command_id) {
464 base::TimeDelta delta = timer_.Elapsed(); 436 base::TimeDelta delta = timer_.Elapsed();
465 437
466 switch (command_id) { 438 switch (command_id) {
467 case IDC_NEW_TAB: 439 case IDC_NEW_TAB:
468 if (!uma_action_recorded_) 440 if (!uma_action_recorded_)
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 switches::kEnableDomDistiller)) 895 switches::kEnableDomDistiller))
924 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE); 896 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE);
925 tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); 897 tools_menu_model_.reset(new ToolsMenuModel(this, browser_));
926 AddSubMenuWithStringId( 898 AddSubMenuWithStringId(
927 IDC_MORE_TOOLS_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get()); 899 IDC_MORE_TOOLS_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get());
928 // Append the full menu including separators. The final separator only gets 900 // Append the full menu including separators. The final separator only gets
929 // appended when this is a touch menu - otherwise it would get added twice. 901 // appended when this is a touch menu - otherwise it would get added twice.
930 CreateCutCopyPasteMenu(); 902 CreateCutCopyPasteMenu();
931 903
932 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); 904 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS);
933 #if !defined(OS_CHROMEOS)
934 if (!switches::IsNewAvatarMenu()) {
935 // No "Sign in to Chromium..." menu item on ChromeOS.
936 SigninManager* signin = SigninManagerFactory::GetForProfile(
937 browser_->profile()->GetOriginalProfile());
938 if (signin && signin->IsSigninAllowed() &&
939 signin_ui_util::GetSignedInServiceErrors(
940 browser_->profile()->GetOriginalProfile()).empty()) {
941 AddItem(IDC_SHOW_SYNC_SETUP,
942 l10n_util::GetStringFUTF16(
943 IDS_SYNC_MENU_PRE_SYNCED_LABEL,
944 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
945 }
946 }
947 #endif
948 // The help submenu is only displayed on official Chrome builds. As the 905 // The help submenu is only displayed on official Chrome builds. As the
949 // 'About' item has been moved to this submenu, it's reinstated here for 906 // 'About' item has been moved to this submenu, it's reinstated here for
950 // Chromium builds. 907 // Chromium builds.
951 #if defined(GOOGLE_CHROME_BUILD) 908 #if defined(GOOGLE_CHROME_BUILD)
952 help_menu_model_.reset(new HelpMenuModel(this, browser_)); 909 help_menu_model_.reset(new HelpMenuModel(this, browser_));
953 AddSubMenuWithStringId(IDC_HELP_MENU, IDS_HELP_MENU, 910 AddSubMenuWithStringId(IDC_HELP_MENU, IDS_HELP_MENU,
954 help_menu_model_.get()); 911 help_menu_model_.get());
955 #else 912 #else
956 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT)); 913 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT));
957 #endif 914 #endif
(...skipping 24 matching lines...) Expand all
982 AddItemWithStringId(IDC_EXIT, IDS_EXIT); 939 AddItemWithStringId(IDC_EXIT, IDS_EXIT);
983 } 940 }
984 uma_action_recorded_ = false; 941 uma_action_recorded_ = false;
985 } 942 }
986 943
987 bool WrenchMenuModel::AddGlobalErrorMenuItems() { 944 bool WrenchMenuModel::AddGlobalErrorMenuItems() {
988 // TODO(sail): Currently we only build the wrench menu once per browser 945 // TODO(sail): Currently we only build the wrench menu once per browser
989 // window. This means that if a new error is added after the menu is built 946 // window. This means that if a new error is added after the menu is built
990 // it won't show in the existing wrench menu. To fix this we need to some 947 // it won't show in the existing wrench menu. To fix this we need to some
991 // how update the menu if new errors are added. 948 // how update the menu if new errors are added.
992 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
993 // GetSignedInServiceErrors() can modify the global error list, so call it
994 // before iterating through that list below.
995 std::vector<GlobalError*> signin_errors;
996 signin_errors = signin_ui_util::GetSignedInServiceErrors(
997 browser_->profile()->GetOriginalProfile());
998 const GlobalErrorService::GlobalErrorList& errors = 949 const GlobalErrorService::GlobalErrorList& errors =
999 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); 950 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors();
1000 bool menu_items_added = false; 951 bool menu_items_added = false;
1001 for (GlobalErrorService::GlobalErrorList::const_iterator 952 for (GlobalErrorService::GlobalErrorList::const_iterator
1002 it = errors.begin(); it != errors.end(); ++it) { 953 it = errors.begin(); it != errors.end(); ++it) {
1003 GlobalError* error = *it; 954 GlobalError* error = *it;
1004 DCHECK(error); 955 DCHECK(error);
1005 if (error->HasMenuItem()) { 956 if (error->HasMenuItem()) {
1006 #if !defined(OS_CHROMEOS)
1007 // Don't add a signin error if it's already being displayed elsewhere.
1008 if (std::find(signin_errors.begin(), signin_errors.end(), error) !=
1009 signin_errors.end()) {
1010 MenuModel* model = this;
1011 int index = 0;
1012 if (MenuModel::GetModelAndIndexForCommandId(
1013 IDC_SHOW_SIGNIN, &model, &index)) {
1014 continue;
1015 }
1016 }
1017 #endif
1018
1019 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); 957 AddItem(error->MenuItemCommandID(), error->MenuItemLabel());
1020 int icon_id = error->MenuItemIconResourceID(); 958 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()),
1021 if (icon_id) { 959 error->MenuItemIcon());
1022 const gfx::Image& image = rb.GetNativeImageNamed(icon_id);
1023 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()),
1024 image);
1025 }
1026 menu_items_added = true; 960 menu_items_added = true;
1027 } 961 }
1028 } 962 }
1029 return menu_items_added; 963 return menu_items_added;
1030 } 964 }
1031 965
1032 void WrenchMenuModel::CreateActionToolbarOverflowMenu() { 966 void WrenchMenuModel::CreateActionToolbarOverflowMenu() {
1033 // We only add the extensions overflow container if there are any icons that 967 // We only add the extensions overflow container if there are any icons that
1034 // aren't shown in the main container. 968 // aren't shown in the main container.
1035 if (!ToolbarActionsModel::Get(browser_->profile())->all_icons_visible()) { 969 if (!ToolbarActionsModel::Get(browser_->profile())->all_icons_visible()) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 ->GetZoomPercent(); 1024 ->GetZoomPercent();
1091 } 1025 }
1092 zoom_label_ = l10n_util::GetStringFUTF16( 1026 zoom_label_ = l10n_util::GetStringFUTF16(
1093 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); 1027 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent));
1094 } 1028 }
1095 1029
1096 void WrenchMenuModel::OnZoomLevelChanged( 1030 void WrenchMenuModel::OnZoomLevelChanged(
1097 const content::HostZoomMap::ZoomLevelChange& change) { 1031 const content::HostZoomMap::ZoomLevelChange& change) {
1098 UpdateZoomControls(); 1032 UpdateZoomControls();
1099 } 1033 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698