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

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 + review comments Created 6 years, 6 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/components_strings.h" 10 #include "grit/components_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
26 OptionsMenuModel::OptionsMenuModel( 24 OptionsMenuModel::OptionsMenuModel(TranslateInfoBarDelegate* translate_delegate)
27 TranslateInfoBarDelegate* translate_delegate)
28 : ui::SimpleMenuModel(this), 25 : ui::SimpleMenuModel(this),
29 translate_infobar_delegate_(translate_delegate) { 26 translate_infobar_delegate_(translate_delegate) {
30 // |translate_delegate| must already be owned. 27 // |translate_delegate| must already be owned.
31 DCHECK(translate_infobar_delegate_->GetTranslateDriver()); 28 DCHECK(translate_infobar_delegate_->GetTranslateDriver());
32 29
33 base::string16 original_language = translate_delegate->language_name_at( 30 base::string16 original_language = translate_delegate->language_name_at(
34 translate_delegate->original_language_index()); 31 translate_delegate->original_language_index());
35 base::string16 target_language = translate_delegate->language_name_at( 32 base::string16 target_language = translate_delegate->language_name_at(
36 translate_delegate->target_language_index()); 33 translate_delegate->target_language_index());
37 34
38 bool autodetermined_source_language = 35 bool autodetermined_source_language =
39 translate_delegate->original_language_index() == 36 translate_delegate->original_language_index() ==
40 TranslateInfoBarDelegate::kNoIndex; 37 TranslateInfoBarDelegate::kNoIndex;
41 38
42 // Populate the menu. 39 // Populate the menu.
43 // Incognito mode does not get any preferences related items. 40 // Incognito mode does not get any preferences related items.
44 if (!translate_delegate->is_off_the_record()) { 41 if (!translate_delegate->is_off_the_record()) {
45 if (!autodetermined_source_language) { 42 if (!autodetermined_source_language) {
46 AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS, 43 AddCheckItem(ALWAYS_TRANSLATE,
47 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS, 44 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS,
48 original_language, target_language)); 45 original_language, target_language));
49 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG, 46 AddCheckItem(NEVER_TRANSLATE_LANGUAGE,
50 l10n_util::GetStringFUTF16( 47 l10n_util::GetStringFUTF16(
51 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, 48 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG,
52 original_language)); 49 original_language));
53 } 50 }
54 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE, 51 AddCheckItem(NEVER_TRANSLATE_SITE,
55 l10n_util::GetStringUTF16( 52 l10n_util::GetStringUTF16(
56 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE)); 53 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE));
57 AddSeparator(ui::NORMAL_SEPARATOR); 54 AddSeparator(ui::NORMAL_SEPARATOR);
58 } 55 }
59 if (!autodetermined_source_language) { 56 if (!autodetermined_source_language) {
60 AddItem(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION, 57 AddItem(REPORT_BAD_DETECTION,
61 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR, 58 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR,
62 original_language)); 59 original_language));
63 } 60 }
64 AddItemWithStringId(IDC_TRANSLATE_OPTIONS_ABOUT, 61 AddItemWithStringId(ABOUT_TRANSLATE, IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT);
65 IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT);
66 } 62 }
67 63
68 OptionsMenuModel::~OptionsMenuModel() { 64 OptionsMenuModel::~OptionsMenuModel() {
69 } 65 }
70 66
71 bool OptionsMenuModel::IsCommandIdChecked(int command_id) const { 67 bool OptionsMenuModel::IsCommandIdChecked(int command_id) const {
72 switch (command_id) { 68 switch (command_id) {
73 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: 69 case NEVER_TRANSLATE_LANGUAGE:
74 return !translate_infobar_delegate_->IsTranslatableLanguageByPrefs(); 70 return !translate_infobar_delegate_->IsTranslatableLanguageByPrefs();
75 71
76 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: 72 case NEVER_TRANSLATE_SITE:
77 return translate_infobar_delegate_->IsSiteBlacklisted(); 73 return translate_infobar_delegate_->IsSiteBlacklisted();
78 74
79 case IDC_TRANSLATE_OPTIONS_ALWAYS: 75 case ALWAYS_TRANSLATE:
80 return translate_infobar_delegate_->ShouldAlwaysTranslate(); 76 return translate_infobar_delegate_->ShouldAlwaysTranslate();
81 77
82 default: 78 default:
83 NOTREACHED() << "Invalid command_id from menu"; 79 NOTREACHED() << "Invalid command_id from menu";
84 break; 80 break;
85 } 81 }
86 return false; 82 return false;
87 } 83 }
88 84
89 bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const { 85 bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const {
90 switch (command_id) { 86 switch (command_id) {
91 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG : 87 case NEVER_TRANSLATE_LANGUAGE:
92 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE : 88 case NEVER_TRANSLATE_SITE:
93 return !translate_infobar_delegate_->ShouldAlwaysTranslate(); 89 return !translate_infobar_delegate_->ShouldAlwaysTranslate();
94 90
95 case IDC_TRANSLATE_OPTIONS_ALWAYS : 91 case ALWAYS_TRANSLATE:
96 return (translate_infobar_delegate_->IsTranslatableLanguageByPrefs() && 92 return (translate_infobar_delegate_->IsTranslatableLanguageByPrefs() &&
97 !translate_infobar_delegate_->IsSiteBlacklisted()); 93 !translate_infobar_delegate_->IsSiteBlacklisted());
98 94
99 default: 95 default:
100 break; 96 break;
101 } 97 }
102 return true; 98 return true;
103 } 99 }
104 100
105 bool OptionsMenuModel::GetAcceleratorForCommandId( 101 bool OptionsMenuModel::GetAcceleratorForCommandId(
106 int command_id, ui::Accelerator* accelerator) { 102 int command_id,
103 ui::Accelerator* accelerator) {
107 return false; 104 return false;
108 } 105 }
109 106
110 void OptionsMenuModel::ExecuteCommand(int command_id, int event_flags) { 107 void OptionsMenuModel::ExecuteCommand(int command_id, int event_flags) {
111 switch (command_id) { 108 switch (command_id) {
112 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: 109 case NEVER_TRANSLATE_LANGUAGE:
113 translate_infobar_delegate_->ToggleTranslatableLanguageByPrefs(); 110 translate_infobar_delegate_->ToggleTranslatableLanguageByPrefs();
114 break; 111 break;
115 112
116 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: 113 case NEVER_TRANSLATE_SITE:
117 translate_infobar_delegate_->ToggleSiteBlacklist(); 114 translate_infobar_delegate_->ToggleSiteBlacklist();
118 break; 115 break;
119 116
120 case IDC_TRANSLATE_OPTIONS_ALWAYS: 117 case ALWAYS_TRANSLATE:
121 translate_infobar_delegate_->ToggleAlwaysTranslate(); 118 translate_infobar_delegate_->ToggleAlwaysTranslate();
122 break; 119 break;
123 120
124 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION: 121 case REPORT_BAD_DETECTION:
125 translate_infobar_delegate_->ReportLanguageDetectionError(); 122 translate_infobar_delegate_->ReportLanguageDetectionError();
126 break; 123 break;
127 124
128 case IDC_TRANSLATE_OPTIONS_ABOUT: { 125 case ABOUT_TRANSLATE: {
129 TranslateDriver* translate_driver = 126 TranslateDriver* translate_driver =
130 translate_infobar_delegate_->GetTranslateDriver(); 127 translate_infobar_delegate_->GetTranslateDriver();
131 if (translate_driver) 128 if (translate_driver)
132 translate_driver->OpenUrlInNewTab(GURL(kAboutGoogleTranslateURL)); 129 translate_driver->OpenUrlInNewTab(GURL(kAboutGoogleTranslateURL));
133 break; 130 break;
134 } 131 }
135 132
136 default: 133 default:
137 NOTREACHED() << "Invalid command id from menu."; 134 NOTREACHED() << "Invalid command id from menu.";
138 break; 135 break;
139 } 136 }
140 } 137 }
OLDNEW
« no previous file with comments | « components/translate/core/browser/options_menu_model.h ('k') | components/translate/core/browser/translate_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698