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_chewing_config_view.h" | 5 #include "chrome/browser/chromeos/options/language_chewing_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/cros/input_method_library.h" | 10 #include "chrome/browser/chromeos/cros/input_method_library.h" |
11 #include "chrome/browser/chromeos/options/language_config_util.h" | 11 #include "chrome/browser/chromeos/options/language_config_util.h" |
12 #include "chrome/browser/chromeos/preferences.h" | 12 #include "chrome/browser/chromeos/preferences.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "grit/locale_settings.h" | 17 #include "grit/locale_settings.h" |
18 #include "views/controls/button/checkbox.h" | 18 #include "views/controls/button/checkbox.h" |
19 #include "views/controls/label.h" | 19 #include "views/controls/label.h" |
20 #include "views/grid_layout.h" | 20 #include "views/grid_layout.h" |
21 #include "views/standard_layout.h" | 21 #include "views/standard_layout.h" |
22 #include "views/window/window.h" | 22 #include "views/window/window.h" |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 | 25 |
26 LanguageChewingConfigView::LanguageChewingConfigView(Profile* profile) | 26 LanguageChewingConfigView::LanguageChewingConfigView(Profile* profile) |
27 : OptionsPageView(profile), contents_(NULL) { | 27 : OptionsPageView(profile), contents_(NULL) { |
28 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 28 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
29 chewing_boolean_prefs_[i].Init( | 29 chewing_boolean_prefs_[i].Init( |
30 kChewingBooleanPrefs[i].pref_name, profile->GetPrefs(), this); | 30 language_prefs::kChewingBooleanPrefs[i].pref_name, |
| 31 profile->GetPrefs(), this); |
31 chewing_boolean_checkboxes_[i] = NULL; | 32 chewing_boolean_checkboxes_[i] = NULL; |
32 } | 33 } |
33 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 34 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
34 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 35 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
35 current.multiple_choice_pref.Init( | 36 current.multiple_choice_pref.Init( |
36 kChewingMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); | 37 language_prefs::kChewingMultipleChoicePrefs[i].pref_name, |
| 38 profile->GetPrefs(), this); |
37 current.combobox_model = | 39 current.combobox_model = |
38 new LanguageComboboxModel<const char*>(&kChewingMultipleChoicePrefs[i]); | 40 new LanguageComboboxModel<const char*>( |
| 41 &language_prefs::kChewingMultipleChoicePrefs[i]); |
39 current.combobox = NULL; | 42 current.combobox = NULL; |
40 } | 43 } |
41 | 44 |
42 hsu_sel_key_type_.multiple_choice_pref.Init( | 45 hsu_sel_key_type_.multiple_choice_pref.Init( |
43 kChewingHsuSelKeyType.pref_name, profile->GetPrefs(), this); | 46 language_prefs::kChewingHsuSelKeyType.pref_name, profile->GetPrefs(), |
| 47 this); |
44 hsu_sel_key_type_.combobox_model = | 48 hsu_sel_key_type_.combobox_model = |
45 new LanguageComboboxModel<int>(&kChewingHsuSelKeyType); | 49 new LanguageComboboxModel<int>(&language_prefs::kChewingHsuSelKeyType); |
46 hsu_sel_key_type_.combobox = NULL; | 50 hsu_sel_key_type_.combobox = NULL; |
47 | 51 |
48 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { | 52 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
49 chewing_integer_prefs_[i].Init( | 53 chewing_integer_prefs_[i].Init( |
50 kChewingIntegerPrefs[i].pref_name, profile->GetPrefs(), this); | 54 language_prefs::kChewingIntegerPrefs[i].pref_name, |
| 55 profile->GetPrefs(), this); |
51 chewing_integer_sliders_[i] = NULL; | 56 chewing_integer_sliders_[i] = NULL; |
52 } | 57 } |
53 } | 58 } |
54 | 59 |
55 LanguageChewingConfigView::~LanguageChewingConfigView() { | 60 LanguageChewingConfigView::~LanguageChewingConfigView() { |
56 } | 61 } |
57 | 62 |
58 void LanguageChewingConfigView::ButtonPressed( | 63 void LanguageChewingConfigView::ButtonPressed( |
59 views::Button* sender, const views::Event& event) { | 64 views::Button* sender, const views::Event& event) { |
60 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | 65 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); |
61 const int pref_id = checkbox->tag(); | 66 const int pref_id = checkbox->tag(); |
62 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumChewingBooleanPrefs)); | 67 DCHECK(pref_id >= 0 && pref_id < static_cast<int>( |
| 68 language_prefs::kNumChewingBooleanPrefs)); |
63 chewing_boolean_prefs_[pref_id].SetValue(checkbox->checked()); | 69 chewing_boolean_prefs_[pref_id].SetValue(checkbox->checked()); |
64 } | 70 } |
65 | 71 |
66 void LanguageChewingConfigView::ItemChanged( | 72 void LanguageChewingConfigView::ItemChanged( |
67 views::Combobox* sender, int prev_index, int new_index) { | 73 views::Combobox* sender, int prev_index, int new_index) { |
68 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 74 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
69 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 75 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
70 if (current.combobox == sender) { | 76 if (current.combobox == sender) { |
71 const std::string config_value = | 77 const std::string config_value = |
72 current.combobox_model->GetConfigValueAt(new_index); | 78 current.combobox_model->GetConfigValueAt(new_index); |
73 LOG(INFO) << "Changing Chewing pref to " << config_value; | 79 LOG(INFO) << "Changing Chewing pref to " << config_value; |
74 // Update the Chrome pref. | 80 // Update the Chrome pref. |
75 current.multiple_choice_pref.SetValue(config_value); | 81 current.multiple_choice_pref.SetValue(config_value); |
76 break; | 82 break; |
77 } | 83 } |
78 } | 84 } |
79 if (hsu_sel_key_type_.combobox == sender) { | 85 if (hsu_sel_key_type_.combobox == sender) { |
80 const int config_value = | 86 const int config_value = |
81 hsu_sel_key_type_.combobox_model->GetConfigValueAt(new_index); | 87 hsu_sel_key_type_.combobox_model->GetConfigValueAt(new_index); |
82 LOG(INFO) << "Changing Chewing pref to " << config_value; | 88 LOG(INFO) << "Changing Chewing pref to " << config_value; |
83 // Update the Chrome pref. | 89 // Update the Chrome pref. |
84 hsu_sel_key_type_.multiple_choice_pref.SetValue(config_value); | 90 hsu_sel_key_type_.multiple_choice_pref.SetValue(config_value); |
85 } | 91 } |
86 } | 92 } |
87 | 93 |
88 void LanguageChewingConfigView::SliderValueChanged(views::Slider* sender) { | 94 void LanguageChewingConfigView::SliderValueChanged(views::Slider* sender) { |
89 size_t pref_id; | 95 size_t pref_id; |
90 for (pref_id = 0; pref_id < kNumChewingIntegerPrefs; ++pref_id) { | 96 for (pref_id = 0; pref_id < language_prefs::kNumChewingIntegerPrefs; |
| 97 ++pref_id) { |
91 if (chewing_integer_sliders_[pref_id] == sender) | 98 if (chewing_integer_sliders_[pref_id] == sender) |
92 break; | 99 break; |
93 } | 100 } |
94 DCHECK(pref_id < kNumChewingIntegerPrefs); | 101 DCHECK(pref_id < language_prefs::kNumChewingIntegerPrefs); |
95 chewing_integer_prefs_[pref_id].SetValue(sender->value()); | 102 chewing_integer_prefs_[pref_id].SetValue(sender->value()); |
96 } | 103 } |
97 | 104 |
98 | 105 |
99 void LanguageChewingConfigView::Layout() { | 106 void LanguageChewingConfigView::Layout() { |
100 // Not sure why but this is needed to show contents in the dialog. | 107 // Not sure why but this is needed to show contents in the dialog. |
101 contents_->SetBounds(0, 0, width(), height()); | 108 contents_->SetBounds(0, 0, width(), height()); |
102 } | 109 } |
103 | 110 |
104 int LanguageChewingConfigView::GetDialogButtons() const { | 111 int LanguageChewingConfigView::GetDialogButtons() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 contents_->SetLayoutManager(layout); | 144 contents_->SetLayoutManager(layout); |
138 | 145 |
139 const int kColumnSetId = 0; | 146 const int kColumnSetId = 0; |
140 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 147 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
141 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 148 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
142 GridLayout::USE_PREF, 0, 0); | 149 GridLayout::USE_PREF, 0, 0); |
143 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 150 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
144 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, | 151 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, |
145 GridLayout::USE_PREF, 0, 0); | 152 GridLayout::USE_PREF, 0, 0); |
146 | 153 |
147 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 154 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
148 chewing_boolean_checkboxes_[i] = new views::Checkbox( | 155 chewing_boolean_checkboxes_[i] = new views::Checkbox( |
149 l10n_util::GetString(kChewingBooleanPrefs[i].message_id)); | 156 l10n_util::GetString( |
| 157 language_prefs::kChewingBooleanPrefs[i].message_id)); |
150 chewing_boolean_checkboxes_[i]->set_listener(this); | 158 chewing_boolean_checkboxes_[i]->set_listener(this); |
151 chewing_boolean_checkboxes_[i]->set_tag(i); | 159 chewing_boolean_checkboxes_[i]->set_tag(i); |
152 } | 160 } |
153 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 161 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
154 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 162 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
155 current.combobox = new LanguageCombobox(current.combobox_model); | 163 current.combobox = new LanguageCombobox(current.combobox_model); |
156 current.combobox->set_listener(this); | 164 current.combobox->set_listener(this); |
157 } | 165 } |
158 hsu_sel_key_type_.combobox = | 166 hsu_sel_key_type_.combobox = |
159 new LanguageCombobox(hsu_sel_key_type_.combobox_model); | 167 new LanguageCombobox(hsu_sel_key_type_.combobox_model); |
160 hsu_sel_key_type_.combobox->set_listener(this); | 168 hsu_sel_key_type_.combobox->set_listener(this); |
161 | 169 |
162 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { | 170 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
163 chewing_integer_sliders_[i] = new views::Slider( | 171 chewing_integer_sliders_[i] = new views::Slider( |
164 kChewingIntegerPrefs[i].min_pref_value, | 172 language_prefs::kChewingIntegerPrefs[i].min_pref_value, |
165 kChewingIntegerPrefs[i].max_pref_value, | 173 language_prefs::kChewingIntegerPrefs[i].max_pref_value, |
166 1, | 174 1, |
167 static_cast<views::Slider::StyleFlags>( | 175 static_cast<views::Slider::StyleFlags>( |
168 views::Slider::STYLE_DRAW_VALUE | | 176 views::Slider::STYLE_DRAW_VALUE | |
169 views::Slider::STYLE_UPDATE_ON_RELEASE), | 177 views::Slider::STYLE_UPDATE_ON_RELEASE), |
170 this); | 178 this); |
171 } | 179 } |
172 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 180 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
173 layout->StartRow(0, kColumnSetId); | 181 layout->StartRow(0, kColumnSetId); |
174 layout->AddView(chewing_boolean_checkboxes_[i]); | 182 layout->AddView(chewing_boolean_checkboxes_[i]); |
175 } | 183 } |
176 | 184 |
177 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { | 185 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
178 layout->StartRow(0, kColumnSetId); | 186 layout->StartRow(0, kColumnSetId); |
179 layout->AddView(new views::Label( | 187 layout->AddView(new views::Label( |
180 l10n_util::GetString(kChewingIntegerPrefs[i].message_id))); | 188 l10n_util::GetString( |
| 189 language_prefs::kChewingIntegerPrefs[i].message_id))); |
181 layout->AddView(chewing_integer_sliders_[i]); | 190 layout->AddView(chewing_integer_sliders_[i]); |
182 } | 191 } |
183 NotifyPrefChanged(); | 192 NotifyPrefChanged(); |
184 | 193 |
185 // Show the comboboxes. | 194 // Show the comboboxes. |
186 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 195 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
187 const ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 196 const ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
188 layout->StartRow(0, kColumnSetId); | 197 layout->StartRow(0, kColumnSetId); |
189 layout->AddView(new views::Label(current.combobox_model->GetLabel())); | 198 layout->AddView(new views::Label(current.combobox_model->GetLabel())); |
190 layout->AddView(current.combobox); | 199 layout->AddView(current.combobox); |
191 } | 200 } |
192 layout->StartRow(0, kColumnSetId); | 201 layout->StartRow(0, kColumnSetId); |
193 layout->AddView( | 202 layout->AddView( |
194 new views::Label(hsu_sel_key_type_.combobox_model->GetLabel())); | 203 new views::Label(hsu_sel_key_type_.combobox_model->GetLabel())); |
195 layout->AddView(hsu_sel_key_type_.combobox); | 204 layout->AddView(hsu_sel_key_type_.combobox); |
196 } | 205 } |
197 | 206 |
198 void LanguageChewingConfigView::Observe(NotificationType type, | 207 void LanguageChewingConfigView::Observe(NotificationType type, |
199 const NotificationSource& source, | 208 const NotificationSource& source, |
200 const NotificationDetails& details) { | 209 const NotificationDetails& details) { |
201 if (type == NotificationType::PREF_CHANGED) { | 210 if (type == NotificationType::PREF_CHANGED) { |
202 NotifyPrefChanged(); | 211 NotifyPrefChanged(); |
203 } | 212 } |
204 } | 213 } |
205 | 214 |
206 void LanguageChewingConfigView::NotifyPrefChanged() { | 215 void LanguageChewingConfigView::NotifyPrefChanged() { |
207 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 216 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
208 const bool checked = chewing_boolean_prefs_[i].GetValue(); | 217 const bool checked = chewing_boolean_prefs_[i].GetValue(); |
209 chewing_boolean_checkboxes_[i]->SetChecked(checked); | 218 chewing_boolean_checkboxes_[i]->SetChecked(checked); |
210 } | 219 } |
211 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { | 220 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
212 const int value = chewing_integer_prefs_[i].GetValue(); | 221 const int value = chewing_integer_prefs_[i].GetValue(); |
213 chewing_integer_sliders_[i]->SetValue(value); | 222 chewing_integer_sliders_[i]->SetValue(value); |
214 } | 223 } |
215 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 224 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
216 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 225 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
217 const std::string value = current.multiple_choice_pref.GetValue(); | 226 const std::string value = current.multiple_choice_pref.GetValue(); |
218 for (int i = 0; i < current.combobox_model->num_items(); ++i) { | 227 for (int i = 0; i < current.combobox_model->num_items(); ++i) { |
219 if (current.combobox_model->GetConfigValueAt(i) == value) { | 228 if (current.combobox_model->GetConfigValueAt(i) == value) { |
220 current.combobox->SetSelectedItem(i); | 229 current.combobox->SetSelectedItem(i); |
221 break; | 230 break; |
222 } | 231 } |
223 } | 232 } |
224 } | 233 } |
225 const int value = hsu_sel_key_type_.multiple_choice_pref.GetValue(); | 234 const int value = hsu_sel_key_type_.multiple_choice_pref.GetValue(); |
226 for (int i = 0; i < hsu_sel_key_type_.combobox_model->num_items(); ++i) { | 235 for (int i = 0; i < hsu_sel_key_type_.combobox_model->num_items(); ++i) { |
227 if (hsu_sel_key_type_.combobox_model->GetConfigValueAt(i) == value) { | 236 if (hsu_sel_key_type_.combobox_model->GetConfigValueAt(i) == value) { |
228 hsu_sel_key_type_.combobox->SetSelectedItem(i); | 237 hsu_sel_key_type_.combobox->SetSelectedItem(i); |
229 break; | 238 break; |
230 } | 239 } |
231 } | 240 } |
232 } | 241 } |
233 | 242 |
234 } // namespace chromeos | 243 } // namespace chromeos |
OLD | NEW |