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/combobox_model.h" | 7 #include "app/combobox_model.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/common/notification_type.h" | 10 #include "chrome/common/notification_type.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 chewing_boolean_checkboxes_[i] = NULL; | 119 chewing_boolean_checkboxes_[i] = NULL; |
120 } | 120 } |
121 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 121 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { |
122 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 122 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
123 current.multiple_choice_pref.Init( | 123 current.multiple_choice_pref.Init( |
124 kChewingMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); | 124 kChewingMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); |
125 current.combobox_model = | 125 current.combobox_model = |
126 new ChewingComboboxModel(&kChewingMultipleChoicePrefs[i]); | 126 new ChewingComboboxModel(&kChewingMultipleChoicePrefs[i]); |
127 current.combobox = NULL; | 127 current.combobox = NULL; |
128 } | 128 } |
| 129 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { |
| 130 chewing_integer_prefs_[i].Init( |
| 131 kChewingIntegerPrefs[i].pref_name, profile->GetPrefs(), this); |
| 132 chewing_integer_sliders_[i] = NULL; |
| 133 } |
129 } | 134 } |
130 | 135 |
131 LanguageChewingConfigView::~LanguageChewingConfigView() { | 136 LanguageChewingConfigView::~LanguageChewingConfigView() { |
132 } | 137 } |
133 | 138 |
134 void LanguageChewingConfigView::ButtonPressed( | 139 void LanguageChewingConfigView::ButtonPressed( |
135 views::Button* sender, const views::Event& event) { | 140 views::Button* sender, const views::Event& event) { |
136 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | 141 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); |
137 const int pref_id = checkbox->tag(); | 142 const int pref_id = checkbox->tag(); |
138 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumChewingBooleanPrefs)); | 143 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumChewingBooleanPrefs)); |
139 chewing_boolean_prefs_[pref_id].SetValue(checkbox->checked()); | 144 chewing_boolean_prefs_[pref_id].SetValue(checkbox->checked()); |
140 } | 145 } |
141 | 146 |
142 void LanguageChewingConfigView::ItemChanged( | 147 void LanguageChewingConfigView::ItemChanged( |
143 views::Combobox* sender, int prev_index, int new_index) { | 148 views::Combobox* sender, int prev_index, int new_index) { |
144 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 149 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { |
145 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 150 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
146 if (current.combobox == sender) { | 151 if (current.combobox == sender) { |
147 const std::wstring config_value = | 152 const std::wstring config_value = |
148 current.combobox_model->GetConfigValueAt(new_index); | 153 current.combobox_model->GetConfigValueAt(new_index); |
149 LOG(INFO) << "Changing Chewing pref to " << config_value; | 154 LOG(INFO) << "Changing Chewing pref to " << config_value; |
150 // Update the Chrome pref. | 155 // Update the Chrome pref. |
151 current.multiple_choice_pref.SetValue(config_value); | 156 current.multiple_choice_pref.SetValue(config_value); |
152 break; | 157 break; |
153 } | 158 } |
154 } | 159 } |
155 } | 160 } |
156 | 161 |
| 162 void LanguageChewingConfigView::SliderValueChanged(views::Slider* sender) { |
| 163 size_t pref_id; |
| 164 for (pref_id = 0; pref_id < kNumChewingIntegerPrefs; ++pref_id) { |
| 165 if (chewing_integer_sliders_[pref_id] == sender) |
| 166 break; |
| 167 } |
| 168 DCHECK(pref_id < kNumChewingIntegerPrefs); |
| 169 chewing_integer_prefs_[pref_id].SetValue(sender->value()); |
| 170 } |
| 171 |
| 172 |
157 void LanguageChewingConfigView::Layout() { | 173 void LanguageChewingConfigView::Layout() { |
158 // Not sure why but this is needed to show contents in the dialog. | 174 // Not sure why but this is needed to show contents in the dialog. |
159 contents_->SetBounds(0, 0, width(), height()); | 175 contents_->SetBounds(0, 0, width(), height()); |
160 } | 176 } |
161 | 177 |
162 std::wstring LanguageChewingConfigView::GetWindowTitle() const { | 178 std::wstring LanguageChewingConfigView::GetWindowTitle() const { |
163 return l10n_util::GetString( | 179 return l10n_util::GetString( |
164 IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_SETTINGS_TITLE); | 180 IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_SETTINGS_TITLE); |
165 } | 181 } |
166 | 182 |
(...skipping 13 matching lines...) Expand all Loading... |
180 GridLayout* layout = new GridLayout(contents_); | 196 GridLayout* layout = new GridLayout(contents_); |
181 layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, | 197 layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, |
182 kPanelVertMargin, kPanelHorizMargin); | 198 kPanelVertMargin, kPanelHorizMargin); |
183 contents_->SetLayoutManager(layout); | 199 contents_->SetLayoutManager(layout); |
184 | 200 |
185 const int kColumnSetId = 0; | 201 const int kColumnSetId = 0; |
186 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 202 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
187 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 203 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
188 GridLayout::USE_PREF, 0, 0); | 204 GridLayout::USE_PREF, 0, 0); |
189 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 205 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
190 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 206 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
191 GridLayout::USE_PREF, 0, 0); | 207 GridLayout::USE_PREF, 0, 0); |
192 | 208 |
193 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 209 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { |
194 chewing_boolean_checkboxes_[i] = new views::Checkbox( | 210 chewing_boolean_checkboxes_[i] = new views::Checkbox( |
195 l10n_util::GetString(kChewingBooleanPrefs[i].message_id)); | 211 l10n_util::GetString(kChewingBooleanPrefs[i].message_id)); |
196 chewing_boolean_checkboxes_[i]->set_listener(this); | 212 chewing_boolean_checkboxes_[i]->set_listener(this); |
197 chewing_boolean_checkboxes_[i]->set_tag(i); | 213 chewing_boolean_checkboxes_[i]->set_tag(i); |
198 } | 214 } |
199 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 215 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { |
200 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 216 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
201 current.combobox = new ChewingCombobox(current.combobox_model); | 217 current.combobox = new ChewingCombobox(current.combobox_model); |
202 current.combobox->set_listener(this); | 218 current.combobox->set_listener(this); |
203 } | 219 } |
204 NotifyPrefChanged(); | 220 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { |
| 221 chewing_integer_sliders_[i] = new views::Slider( |
| 222 kChewingIntegerPrefs[i].min_pref_value, |
| 223 kChewingIntegerPrefs[i].max_pref_value, |
| 224 1, |
| 225 static_cast<views::Slider::StyleFlags>( |
| 226 views::Slider::STYLE_DRAW_VALUE | |
| 227 views::Slider::STYLE_UPDATE_ON_RELEASE), |
| 228 this); |
| 229 } |
205 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 230 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { |
206 layout->StartRow(0, kColumnSetId); | 231 layout->StartRow(0, kColumnSetId); |
207 layout->AddView(chewing_boolean_checkboxes_[i]); | 232 layout->AddView(chewing_boolean_checkboxes_[i]); |
208 } | 233 } |
209 | 234 |
| 235 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { |
| 236 layout->StartRow(0, kColumnSetId); |
| 237 layout->AddView(new views::Label( |
| 238 l10n_util::GetString(kChewingIntegerPrefs[i].message_id))); |
| 239 layout->AddView(chewing_integer_sliders_[i]); |
| 240 } |
| 241 NotifyPrefChanged(); |
| 242 |
210 // Show the comboboxes. | 243 // Show the comboboxes. |
211 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 244 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { |
212 const ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 245 const ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
213 layout->StartRow(0, kColumnSetId); | 246 layout->StartRow(0, kColumnSetId); |
214 layout->AddView(new views::Label(current.combobox_model->GetLabel())); | 247 layout->AddView(new views::Label(current.combobox_model->GetLabel())); |
215 layout->AddView(current.combobox); | 248 layout->AddView(current.combobox); |
216 } | 249 } |
217 } | 250 } |
218 | 251 |
219 void LanguageChewingConfigView::Observe(NotificationType type, | 252 void LanguageChewingConfigView::Observe(NotificationType type, |
220 const NotificationSource& source, | 253 const NotificationSource& source, |
221 const NotificationDetails& details) { | 254 const NotificationDetails& details) { |
222 if (type == NotificationType::PREF_CHANGED) { | 255 if (type == NotificationType::PREF_CHANGED) { |
223 NotifyPrefChanged(); | 256 NotifyPrefChanged(); |
224 } | 257 } |
225 } | 258 } |
226 | 259 |
227 void LanguageChewingConfigView::NotifyPrefChanged() { | 260 void LanguageChewingConfigView::NotifyPrefChanged() { |
228 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { | 261 for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { |
229 const bool checked = chewing_boolean_prefs_[i].GetValue(); | 262 const bool checked = chewing_boolean_prefs_[i].GetValue(); |
230 chewing_boolean_checkboxes_[i]->SetChecked(checked); | 263 chewing_boolean_checkboxes_[i]->SetChecked(checked); |
231 } | 264 } |
| 265 for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { |
| 266 const int value = chewing_integer_prefs_[i].GetValue(); |
| 267 chewing_integer_sliders_[i]->SetValue(value); |
| 268 } |
232 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { | 269 for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { |
233 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; | 270 ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; |
234 const std::wstring value = current.multiple_choice_pref.GetValue(); | 271 const std::wstring value = current.multiple_choice_pref.GetValue(); |
235 const int combo_index = | 272 const int combo_index = |
236 current.combobox_model->GetIndexFromConfigValue(value); | 273 current.combobox_model->GetIndexFromConfigValue(value); |
237 if (combo_index >= 0) { | 274 if (combo_index >= 0) { |
238 current.combobox->SetSelectedItem(combo_index); | 275 current.combobox->SetSelectedItem(combo_index); |
239 } | 276 } |
240 } | 277 } |
241 } | 278 } |
242 | 279 |
243 } // namespace chromeos | 280 } // namespace chromeos |
OLD | NEW |