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

Side by Side Diff: components/translate/core/browser/options_menu_model.cc

Issue 284313008: Move TranslateInfoBarDelegate and OptionsMenuModel to the Translate component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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) 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/translate/options_menu_model.h" 5 #include "components/translate/core/browser/options_menu_model.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/translate/translate_infobar_delegate.h"
10 #include "components/translate/core/browser/translate_driver.h" 8 #include "components/translate/core/browser/translate_driver.h"
9 #include "components/translate/core/browser/translate_infobar_delegate.h"
11 #include "grit/component_strings.h" 10 #include "grit/component_strings.h"
12 #include "grit/locale_settings.h"
13 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
14 12
15 namespace { 13 namespace {
16 14
17 const char kAboutGoogleTranslateURL[] = 15 const char kAboutGoogleTranslateURL[] =
18 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
19 "https://support.google.com/chromeos/?p=ib_translation_bar"; 17 "https://support.google.com/chromeos/?p=ib_translation_bar";
20 #else 18 #else
21 "https://support.google.com/chrome/?p=ib_translation_bar"; 19 "https://support.google.com/chrome/?p=ib_translation_bar";
22 #endif 20 #endif
23 21
24 } // namespace 22 } // namespace
25 23
24 const int OptionsMenuModel::kOptionsAboutTranslate = 0;
25 const int OptionsMenuModel::kOptionsAlwaysTranslate = 1;
26 const int OptionsMenuModel::kOptionsNeverTranslateLanguage = 2;
27 const int OptionsMenuModel::kOptionsNeverTranslateSite = 3;
28 const int OptionsMenuModel::kOptionsReportBadDetection = 4;
Peter Kasting 2014/05/21 20:38:24 Hmm, looks like maybe these should be an enum rath
droger 2014/05/22 12:33:37 I agree, the enum was also my first idea. I used t
29
26 OptionsMenuModel::OptionsMenuModel( 30 OptionsMenuModel::OptionsMenuModel(
27 TranslateInfoBarDelegate* translate_delegate) 31 TranslateInfoBarDelegate* translate_delegate)
28 : ui::SimpleMenuModel(this), 32 : ui::SimpleMenuModel(this),
29 translate_infobar_delegate_(translate_delegate) { 33 translate_infobar_delegate_(translate_delegate) {
30 // |translate_delegate| must already be owned. 34 // |translate_delegate| must already be owned.
31 DCHECK(translate_infobar_delegate_->GetTranslateDriver()); 35 DCHECK(translate_infobar_delegate_->GetTranslateDriver());
32 36
33 base::string16 original_language = translate_delegate->language_name_at( 37 base::string16 original_language = translate_delegate->language_name_at(
34 translate_delegate->original_language_index()); 38 translate_delegate->original_language_index());
35 base::string16 target_language = translate_delegate->language_name_at( 39 base::string16 target_language = translate_delegate->language_name_at(
36 translate_delegate->target_language_index()); 40 translate_delegate->target_language_index());
37 41
38 bool autodetermined_source_language = 42 bool autodetermined_source_language =
39 translate_delegate->original_language_index() == 43 translate_delegate->original_language_index() ==
40 TranslateInfoBarDelegate::kNoIndex; 44 TranslateInfoBarDelegate::kNoIndex;
41 45
42 // Populate the menu. 46 // Populate the menu.
43 // Incognito mode does not get any preferences related items. 47 // Incognito mode does not get any preferences related items.
44 if (!translate_delegate->is_off_the_record()) { 48 if (!translate_delegate->is_off_the_record()) {
45 if (!autodetermined_source_language) { 49 if (!autodetermined_source_language) {
46 AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS, 50 AddCheckItem(kOptionsAlwaysTranslate,
47 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS, 51 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS,
48 original_language, target_language)); 52 original_language, target_language));
49 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG, 53 AddCheckItem(kOptionsNeverTranslateLanguage,
50 l10n_util::GetStringFUTF16( 54 l10n_util::GetStringFUTF16(
51 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, 55 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG,
52 original_language)); 56 original_language));
53 } 57 }
54 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE, 58 AddCheckItem(kOptionsNeverTranslateSite,
55 l10n_util::GetStringUTF16( 59 l10n_util::GetStringUTF16(
56 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE)); 60 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE));
57 AddSeparator(ui::NORMAL_SEPARATOR); 61 AddSeparator(ui::NORMAL_SEPARATOR);
58 } 62 }
59 if (!autodetermined_source_language) { 63 if (!autodetermined_source_language) {
60 AddItem(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION, 64 AddItem(kOptionsReportBadDetection,
61 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR, 65 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR,
62 original_language)); 66 original_language));
63 } 67 }
64 AddItemWithStringId(IDC_TRANSLATE_OPTIONS_ABOUT, 68 AddItemWithStringId(kOptionsAboutTranslate,
65 IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT); 69 IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT);
66 } 70 }
67 71
68 OptionsMenuModel::~OptionsMenuModel() { 72 OptionsMenuModel::~OptionsMenuModel() {
69 } 73 }
70 74
71 bool OptionsMenuModel::IsCommandIdChecked(int command_id) const { 75 bool OptionsMenuModel::IsCommandIdChecked(int command_id) const {
72 switch (command_id) { 76 switch (command_id) {
73 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: 77 case kOptionsNeverTranslateLanguage:
74 return !translate_infobar_delegate_->IsTranslatableLanguageByPrefs(); 78 return !translate_infobar_delegate_->IsTranslatableLanguageByPrefs();
75 79
76 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: 80 case kOptionsNeverTranslateSite:
77 return translate_infobar_delegate_->IsSiteBlacklisted(); 81 return translate_infobar_delegate_->IsSiteBlacklisted();
78 82
79 case IDC_TRANSLATE_OPTIONS_ALWAYS: 83 case kOptionsAlwaysTranslate:
80 return translate_infobar_delegate_->ShouldAlwaysTranslate(); 84 return translate_infobar_delegate_->ShouldAlwaysTranslate();
81 85
82 default: 86 default:
83 NOTREACHED() << "Invalid command_id from menu"; 87 NOTREACHED() << "Invalid command_id from menu";
84 break; 88 break;
85 } 89 }
86 return false; 90 return false;
87 } 91 }
88 92
89 bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const { 93 bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const {
90 switch (command_id) { 94 switch (command_id) {
91 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG : 95 case kOptionsNeverTranslateLanguage :
92 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE : 96 case kOptionsNeverTranslateSite :
93 return !translate_infobar_delegate_->ShouldAlwaysTranslate(); 97 return !translate_infobar_delegate_->ShouldAlwaysTranslate();
94 98
95 case IDC_TRANSLATE_OPTIONS_ALWAYS : 99 case kOptionsAlwaysTranslate :
96 return (translate_infobar_delegate_->IsTranslatableLanguageByPrefs() && 100 return (translate_infobar_delegate_->IsTranslatableLanguageByPrefs() &&
97 !translate_infobar_delegate_->IsSiteBlacklisted()); 101 !translate_infobar_delegate_->IsSiteBlacklisted());
98 102
99 default: 103 default:
100 break; 104 break;
101 } 105 }
102 return true; 106 return true;
103 } 107 }
104 108
105 bool OptionsMenuModel::GetAcceleratorForCommandId( 109 bool OptionsMenuModel::GetAcceleratorForCommandId(
106 int command_id, ui::Accelerator* accelerator) { 110 int command_id, ui::Accelerator* accelerator) {
107 return false; 111 return false;
108 } 112 }
109 113
110 void OptionsMenuModel::ExecuteCommand(int command_id, int event_flags) { 114 void OptionsMenuModel::ExecuteCommand(int command_id, int event_flags) {
111 switch (command_id) { 115 switch (command_id) {
112 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: 116 case kOptionsNeverTranslateLanguage:
113 translate_infobar_delegate_->ToggleTranslatableLanguageByPrefs(); 117 translate_infobar_delegate_->ToggleTranslatableLanguageByPrefs();
114 break; 118 break;
115 119
116 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: 120 case kOptionsNeverTranslateSite:
117 translate_infobar_delegate_->ToggleSiteBlacklist(); 121 translate_infobar_delegate_->ToggleSiteBlacklist();
118 break; 122 break;
119 123
120 case IDC_TRANSLATE_OPTIONS_ALWAYS: 124 case kOptionsAlwaysTranslate:
121 translate_infobar_delegate_->ToggleAlwaysTranslate(); 125 translate_infobar_delegate_->ToggleAlwaysTranslate();
122 break; 126 break;
123 127
124 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION: 128 case kOptionsReportBadDetection:
125 translate_infobar_delegate_->ReportLanguageDetectionError(); 129 translate_infobar_delegate_->ReportLanguageDetectionError();
126 break; 130 break;
127 131
128 case IDC_TRANSLATE_OPTIONS_ABOUT: { 132 case kOptionsAboutTranslate: {
129 TranslateDriver* translate_driver = 133 TranslateDriver* translate_driver =
130 translate_infobar_delegate_->GetTranslateDriver(); 134 translate_infobar_delegate_->GetTranslateDriver();
131 if (translate_driver) 135 if (translate_driver)
132 translate_driver->OpenUrlInNewTab(GURL(kAboutGoogleTranslateURL)); 136 translate_driver->OpenUrlInNewTab(GURL(kAboutGoogleTranslateURL));
133 break; 137 break;
134 } 138 }
135 139
136 default: 140 default:
137 NOTREACHED() << "Invalid command id from menu."; 141 NOTREACHED() << "Invalid command id from menu.";
138 break; 142 break;
139 } 143 }
140 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698