OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/options/language_mozc_config_view.h" | 5 #include "chrome/browser/chromeos/options/language_mozc_config_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
10 #include "chrome/browser/chromeos/options/language_config_util.h" | 10 #include "chrome/browser/chromeos/options/language_config_util.h" |
11 #include "chrome/browser/chromeos/preferences.h" | 11 #include "chrome/browser/chromeos/preferences.h" |
12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
13 #include "chrome/common/notification_type.h" | 13 #include "chrome/common/notification_type.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
17 #include "views/controls/button/checkbox.h" | 17 #include "views/controls/button/checkbox.h" |
18 #include "views/controls/button/native_button.h" | 18 #include "views/controls/button/native_button.h" |
19 #include "views/grid_layout.h" | 19 #include "views/grid_layout.h" |
20 #include "views/standard_layout.h" | 20 #include "views/standard_layout.h" |
21 #include "views/window/window.h" | 21 #include "views/window/window.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 // The tags are used to identify buttons in ButtonPressed(). | 24 // The tags are used to identify buttons in ButtonPressed(). |
25 enum ButtonTag { | 25 enum ButtonTag { |
26 // 0 to kNumMozcBooleanPrefs - 1 are reserved for the checkboxes for integer | 26 // 0 to kNumMozcBooleanPrefs - 1 are reserved for the checkboxes for integer |
27 // preferences. | 27 // preferences. |
28 kResetToDefaultsButton = chromeos::kNumMozcBooleanPrefs, | 28 kResetToDefaultsButton = chromeos::language_prefs::kNumMozcBooleanPrefs, |
29 }; | 29 }; |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 | 33 |
34 LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile) | 34 LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile) |
35 : OptionsPageView(profile), | 35 : OptionsPageView(profile), |
36 contents_(NULL), | 36 contents_(NULL), |
37 reset_to_defaults_button_(NULL) { | 37 reset_to_defaults_button_(NULL) { |
38 for (size_t i = 0; i < kNumMozcBooleanPrefs; ++i) { | 38 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
39 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; | 39 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; |
40 current.boolean_pref.Init( | 40 current.boolean_pref.Init( |
41 kMozcBooleanPrefs[i].pref_name, profile->GetPrefs(), this); | 41 language_prefs::kMozcBooleanPrefs[i].pref_name, profile->GetPrefs(), |
| 42 this); |
42 current.checkbox = NULL; | 43 current.checkbox = NULL; |
43 } | 44 } |
44 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 45 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
45 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 46 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
46 current.multiple_choice_pref.Init( | 47 current.multiple_choice_pref.Init( |
47 kMozcMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); | 48 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, |
| 49 profile->GetPrefs(), this); |
48 current.combobox_model = | 50 current.combobox_model = |
49 new LanguageComboboxModel<const char*>(&kMozcMultipleChoicePrefs[i]); | 51 new LanguageComboboxModel<const char*>( |
| 52 &language_prefs::kMozcMultipleChoicePrefs[i]); |
50 current.combobox = NULL; | 53 current.combobox = NULL; |
51 } | 54 } |
52 for (size_t i = 0; i < kNumMozcIntegerPrefs; ++i) { | 55 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
53 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; | 56 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; |
54 current.integer_pref.Init( | 57 current.integer_pref.Init( |
55 kMozcIntegerPrefs[i].pref_name, profile->GetPrefs(), this); | 58 language_prefs::kMozcIntegerPrefs[i].pref_name, profile->GetPrefs(), |
| 59 this); |
56 current.slider = NULL; | 60 current.slider = NULL; |
57 } | 61 } |
58 } | 62 } |
59 | 63 |
60 LanguageMozcConfigView::~LanguageMozcConfigView() { | 64 LanguageMozcConfigView::~LanguageMozcConfigView() { |
61 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 65 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
62 delete prefs_and_comboboxes_[i].combobox_model; | 66 delete prefs_and_comboboxes_[i].combobox_model; |
63 } | 67 } |
64 } | 68 } |
65 | 69 |
66 void LanguageMozcConfigView::ButtonPressed( | 70 void LanguageMozcConfigView::ButtonPressed( |
67 views::Button* sender, const views::Event& event) { | 71 views::Button* sender, const views::Event& event) { |
68 const int pref_id = sender->tag(); | 72 const int pref_id = sender->tag(); |
69 if (pref_id == kResetToDefaultsButton) { | 73 if (pref_id == kResetToDefaultsButton) { |
70 ResetToDefaults(); | 74 ResetToDefaults(); |
71 return; | 75 return; |
72 } | 76 } |
73 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | 77 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); |
74 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumMozcBooleanPrefs)); | 78 DCHECK(pref_id >= 0 && pref_id < static_cast<int>( |
| 79 language_prefs::kNumMozcBooleanPrefs)); |
75 prefs_and_checkboxes_[pref_id].boolean_pref.SetValue(checkbox->checked()); | 80 prefs_and_checkboxes_[pref_id].boolean_pref.SetValue(checkbox->checked()); |
76 } | 81 } |
77 | 82 |
78 void LanguageMozcConfigView::ItemChanged( | 83 void LanguageMozcConfigView::ItemChanged( |
79 views::Combobox* sender, int prev_index, int new_index) { | 84 views::Combobox* sender, int prev_index, int new_index) { |
80 if (new_index < 0 || sender->model()->GetItemCount() <= new_index) { | 85 if (new_index < 0 || sender->model()->GetItemCount() <= new_index) { |
81 LOG(ERROR) << "Invalid new_index: " << new_index; | 86 LOG(ERROR) << "Invalid new_index: " << new_index; |
82 return; | 87 return; |
83 } | 88 } |
84 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 89 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
85 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 90 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
86 if (current.combobox == sender) { | 91 if (current.combobox == sender) { |
87 const std::string config_value = | 92 const std::string config_value = |
88 current.combobox_model->GetConfigValueAt(new_index); | 93 current.combobox_model->GetConfigValueAt(new_index); |
89 LOG(INFO) << "Changing Mozc pref to " << config_value; | 94 LOG(INFO) << "Changing Mozc pref to " << config_value; |
90 // Update the Chrome pref. | 95 // Update the Chrome pref. |
91 current.multiple_choice_pref.SetValue(config_value); | 96 current.multiple_choice_pref.SetValue(config_value); |
92 break; | 97 break; |
93 } | 98 } |
94 } | 99 } |
95 } | 100 } |
96 | 101 |
97 void LanguageMozcConfigView::SliderValueChanged(views::Slider* sender) { | 102 void LanguageMozcConfigView::SliderValueChanged(views::Slider* sender) { |
98 size_t pref_id; | 103 size_t pref_id; |
99 for (pref_id = 0; pref_id < kNumMozcIntegerPrefs; ++pref_id) { | 104 for (pref_id = 0; pref_id < language_prefs::kNumMozcIntegerPrefs; |
| 105 ++pref_id) { |
100 if (prefs_and_sliders_[pref_id].slider == sender) | 106 if (prefs_and_sliders_[pref_id].slider == sender) |
101 break; | 107 break; |
102 } | 108 } |
103 DCHECK(pref_id < kNumMozcIntegerPrefs); | 109 DCHECK(pref_id < language_prefs::kNumMozcIntegerPrefs); |
104 prefs_and_sliders_[pref_id].integer_pref.SetValue(sender->value()); | 110 prefs_and_sliders_[pref_id].integer_pref.SetValue(sender->value()); |
105 } | 111 } |
106 | 112 |
107 void LanguageMozcConfigView::Layout() { | 113 void LanguageMozcConfigView::Layout() { |
108 // Not sure why but this is needed to show contents in the dialog. | 114 // Not sure why but this is needed to show contents in the dialog. |
109 contents_->SetBounds(0, 0, width(), height()); | 115 contents_->SetBounds(0, 0, width(), height()); |
110 } | 116 } |
111 | 117 |
112 int LanguageMozcConfigView::GetDialogButtons() const { | 118 int LanguageMozcConfigView::GetDialogButtons() const { |
113 return MessageBoxFlags::DIALOGBUTTON_OK; | 119 return MessageBoxFlags::DIALOGBUTTON_OK; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 contents_->SetLayoutManager(layout); | 157 contents_->SetLayoutManager(layout); |
152 | 158 |
153 const int kColumnSetId = 0; | 159 const int kColumnSetId = 0; |
154 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 160 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
155 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 161 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
156 GridLayout::USE_PREF, 0, 0); | 162 GridLayout::USE_PREF, 0, 0); |
157 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 163 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
158 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 164 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
159 GridLayout::USE_PREF, 0, 0); | 165 GridLayout::USE_PREF, 0, 0); |
160 | 166 |
161 for (size_t i = 0; i < kNumMozcBooleanPrefs; ++i) { | 167 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
162 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; | 168 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; |
163 current.checkbox = new views::Checkbox( | 169 current.checkbox = new views::Checkbox( |
164 l10n_util::GetString(kMozcBooleanPrefs[i].message_id)); | 170 l10n_util::GetString(language_prefs::kMozcBooleanPrefs[i].message_id)); |
165 current.checkbox->set_listener(this); | 171 current.checkbox->set_listener(this); |
166 current.checkbox->set_tag(i); | 172 current.checkbox->set_tag(i); |
167 } | 173 } |
168 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 174 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
169 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 175 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
170 current.combobox = new LanguageCombobox(current.combobox_model); | 176 current.combobox = new LanguageCombobox(current.combobox_model); |
171 current.combobox->set_listener(this); | 177 current.combobox->set_listener(this); |
172 } | 178 } |
173 for (size_t i = 0; i < kNumMozcIntegerPrefs; ++i) { | 179 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
174 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; | 180 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; |
175 current.slider = new views::Slider( | 181 current.slider = new views::Slider( |
176 kMozcIntegerPrefs[i].min_pref_value, | 182 language_prefs::kMozcIntegerPrefs[i].min_pref_value, |
177 kMozcIntegerPrefs[i].max_pref_value, | 183 language_prefs::kMozcIntegerPrefs[i].max_pref_value, |
178 1, | 184 1, |
179 static_cast<views::Slider::StyleFlags>( | 185 static_cast<views::Slider::StyleFlags>( |
180 views::Slider::STYLE_DRAW_VALUE | | 186 views::Slider::STYLE_DRAW_VALUE | |
181 views::Slider::STYLE_UPDATE_ON_RELEASE), | 187 views::Slider::STYLE_UPDATE_ON_RELEASE), |
182 this); | 188 this); |
183 } | 189 } |
184 NotifyPrefChanged(); // Sync the comboboxes with current Chrome prefs. | 190 NotifyPrefChanged(); // Sync the comboboxes with current Chrome prefs. |
185 | 191 |
186 reset_to_defaults_button_ = new views::NativeButton( | 192 reset_to_defaults_button_ = new views::NativeButton( |
187 this, l10n_util::GetString( | 193 this, l10n_util::GetString( |
188 IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_RESET_TO_DEFAULTS_BUTTON)); | 194 IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_RESET_TO_DEFAULTS_BUTTON)); |
189 reset_to_defaults_button_->set_tag(kResetToDefaultsButton); | 195 reset_to_defaults_button_->set_tag(kResetToDefaultsButton); |
190 layout->StartRow(0, kColumnSetId); | 196 layout->StartRow(0, kColumnSetId); |
191 layout->AddView(reset_to_defaults_button_); | 197 layout->AddView(reset_to_defaults_button_); |
192 | 198 |
193 // Show the checkboxes. | 199 // Show the checkboxes. |
194 for (size_t i = 0; i < kNumMozcBooleanPrefs; ++i) { | 200 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
195 const MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; | 201 const MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; |
196 layout->StartRow(0, kColumnSetId); | 202 layout->StartRow(0, kColumnSetId); |
197 layout->AddView(current.checkbox, 3, 1); | 203 layout->AddView(current.checkbox, 3, 1); |
198 } | 204 } |
199 // Show the comboboxes. | 205 // Show the comboboxes. |
200 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 206 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
201 const MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 207 const MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
202 layout->StartRow(0, kColumnSetId); | 208 layout->StartRow(0, kColumnSetId); |
203 layout->AddView(new views::Label(current.combobox_model->GetLabel())); | 209 layout->AddView(new views::Label(current.combobox_model->GetLabel())); |
204 layout->AddView(current.combobox); | 210 layout->AddView(current.combobox); |
205 } | 211 } |
206 for (size_t i = 0; i < kNumMozcIntegerPrefs; ++i) { | 212 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
207 const MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; | 213 const MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; |
208 layout->StartRow(0, kColumnSetId); | 214 layout->StartRow(0, kColumnSetId); |
209 layout->AddView(new views::Label( | 215 layout->AddView(new views::Label( |
210 l10n_util::GetString(kMozcIntegerPrefs[i].message_id))); | 216 l10n_util::GetString( |
| 217 language_prefs::kMozcIntegerPrefs[i].message_id))); |
211 layout->AddView(current.slider); | 218 layout->AddView(current.slider); |
212 } | 219 } |
213 NotifyPrefChanged(); // Sync the slider with current Chrome prefs. | 220 NotifyPrefChanged(); // Sync the slider with current Chrome prefs. |
214 } | 221 } |
215 | 222 |
216 void LanguageMozcConfigView::Observe(NotificationType type, | 223 void LanguageMozcConfigView::Observe(NotificationType type, |
217 const NotificationSource& source, | 224 const NotificationSource& source, |
218 const NotificationDetails& details) { | 225 const NotificationDetails& details) { |
219 if (type == NotificationType::PREF_CHANGED) { | 226 if (type == NotificationType::PREF_CHANGED) { |
220 NotifyPrefChanged(); | 227 NotifyPrefChanged(); |
221 } | 228 } |
222 } | 229 } |
223 | 230 |
224 void LanguageMozcConfigView::NotifyPrefChanged() { | 231 void LanguageMozcConfigView::NotifyPrefChanged() { |
225 // Update comboboxes. | 232 // Update comboboxes. |
226 // TODO(yusukes): We don't have to update all UI controls. | 233 // TODO(yusukes): We don't have to update all UI controls. |
227 for (size_t i = 0; i < kNumMozcBooleanPrefs; ++i) { | 234 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
228 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; | 235 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; |
229 const bool checked = current.boolean_pref.GetValue(); | 236 const bool checked = current.boolean_pref.GetValue(); |
230 current.checkbox->SetChecked(checked); | 237 current.checkbox->SetChecked(checked); |
231 } | 238 } |
232 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 239 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
233 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 240 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
234 const std::string value = current.multiple_choice_pref.GetValue(); | 241 const std::string value = current.multiple_choice_pref.GetValue(); |
235 for (int i = 0; i < current.combobox_model->num_items(); ++i) { | 242 for (int i = 0; i < current.combobox_model->num_items(); ++i) { |
236 if (current.combobox_model->GetConfigValueAt(i) == value) { | 243 if (current.combobox_model->GetConfigValueAt(i) == value) { |
237 current.combobox->SetSelectedItem(i); | 244 current.combobox->SetSelectedItem(i); |
238 break; | 245 break; |
239 } | 246 } |
240 } | 247 } |
241 } | 248 } |
242 for (size_t i = 0; i < kNumMozcIntegerPrefs; ++i) { | 249 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
243 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; | 250 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; |
244 const int value = current.integer_pref.GetValue(); | 251 const int value = current.integer_pref.GetValue(); |
245 current.slider->SetValue(value); | 252 current.slider->SetValue(value); |
246 } | 253 } |
247 } | 254 } |
248 | 255 |
249 void LanguageMozcConfigView::ResetToDefaults() { | 256 void LanguageMozcConfigView::ResetToDefaults() { |
250 for (size_t i = 0; i < kNumMozcBooleanPrefs; ++i) { | 257 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
251 prefs_and_checkboxes_[i].boolean_pref.SetValue( | 258 prefs_and_checkboxes_[i].boolean_pref.SetValue( |
252 kMozcBooleanPrefs[i].default_pref_value); | 259 language_prefs::kMozcBooleanPrefs[i].default_pref_value); |
253 } | 260 } |
254 for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { | 261 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
255 prefs_and_comboboxes_[i].multiple_choice_pref.SetValue( | 262 prefs_and_comboboxes_[i].multiple_choice_pref.SetValue( |
256 kMozcMultipleChoicePrefs[i].default_pref_value); | 263 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value); |
257 } | 264 } |
258 for (size_t i = 0; i < kNumMozcIntegerPrefs; ++i) { | 265 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
259 prefs_and_sliders_[i].integer_pref.SetValue( | 266 prefs_and_sliders_[i].integer_pref.SetValue( |
260 kMozcIntegerPrefs[i].default_pref_value); | 267 language_prefs::kMozcIntegerPrefs[i].default_pref_value); |
261 } | 268 } |
262 // Reflect the preference changes to the controls. | 269 // Reflect the preference changes to the controls. |
263 NotifyPrefChanged(); | 270 NotifyPrefChanged(); |
264 } | 271 } |
265 | 272 |
266 } // namespace chromeos | 273 } // namespace chromeos |
OLD | NEW |