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

Side by Side Diff: chrome/browser/chromeos/options/language_mozc_config_view.cc

Issue 6336005: Remove unused language options code, which has been superseded by DOMUI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/options/language_mozc_config_view.h"
6
7 #include "app/l10n_util.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/options/language_config_util.h"
11 #include "chrome/browser/chromeos/preferences.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/notification_type.h"
14 #include "grit/generated_resources.h"
15 #include "grit/locale_settings.h"
16 #include "views/controls/button/checkbox.h"
17 #include "views/controls/button/native_button.h"
18 #include "views/grid_layout.h"
19 #include "views/standard_layout.h"
20 #include "views/window/window.h"
21
22 namespace {
23 // The tags are used to identify buttons in ButtonPressed().
24 enum ButtonTag {
25 // 0 to kNumMozcBooleanPrefs - 1 are reserved for the checkboxes for integer
26 // preferences.
27 kResetToDefaultsButton = chromeos::language_prefs::kNumMozcBooleanPrefs,
28 };
29 } // namespace
30
31 namespace chromeos {
32
33 LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile)
34 : OptionsPageView(profile),
35 contents_(NULL),
36 reset_to_defaults_button_(NULL) {
37 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
38 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i];
39 current.boolean_pref.Init(
40 language_prefs::kMozcBooleanPrefs[i].pref_name, profile->GetPrefs(),
41 this);
42 current.checkbox = NULL;
43 }
44 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
45 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i];
46 current.multiple_choice_pref.Init(
47 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
48 profile->GetPrefs(), this);
49 current.combobox_model =
50 new LanguageComboboxModel<const char*>(
51 &language_prefs::kMozcMultipleChoicePrefs[i]);
52 current.combobox = NULL;
53 }
54 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
55 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i];
56 current.integer_pref.Init(
57 language_prefs::kMozcIntegerPrefs[i].pref_name, profile->GetPrefs(),
58 this);
59 current.slider = NULL;
60 }
61 }
62
63 LanguageMozcConfigView::~LanguageMozcConfigView() {
64 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
65 delete prefs_and_comboboxes_[i].combobox_model;
66 }
67 }
68
69 void LanguageMozcConfigView::ButtonPressed(
70 views::Button* sender, const views::Event& event) {
71 const int pref_id = sender->tag();
72 if (pref_id == kResetToDefaultsButton) {
73 ResetToDefaults();
74 return;
75 }
76 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender);
77 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(
78 language_prefs::kNumMozcBooleanPrefs));
79 prefs_and_checkboxes_[pref_id].boolean_pref.SetValue(checkbox->checked());
80 }
81
82 void LanguageMozcConfigView::ItemChanged(
83 views::Combobox* sender, int prev_index, int new_index) {
84 if (new_index < 0 || sender->model()->GetItemCount() <= new_index) {
85 LOG(ERROR) << "Invalid new_index: " << new_index;
86 return;
87 }
88 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
89 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i];
90 if (current.combobox == sender) {
91 const std::string config_value =
92 current.combobox_model->GetConfigValueAt(new_index);
93 VLOG(1) << "Changing Mozc pref to " << config_value;
94 // Update the Chrome pref.
95 current.multiple_choice_pref.SetValue(config_value);
96 break;
97 }
98 }
99 }
100
101 void LanguageMozcConfigView::SliderValueChanged(views::Slider* sender) {
102 size_t pref_id;
103 for (pref_id = 0; pref_id < language_prefs::kNumMozcIntegerPrefs;
104 ++pref_id) {
105 if (prefs_and_sliders_[pref_id].slider == sender)
106 break;
107 }
108 DCHECK(pref_id < language_prefs::kNumMozcIntegerPrefs);
109 prefs_and_sliders_[pref_id].integer_pref.SetValue(sender->value());
110 }
111
112 void LanguageMozcConfigView::Layout() {
113 // Not sure why but this is needed to show contents in the dialog.
114 contents_->SetBounds(0, 0, width(), height());
115 }
116
117 int LanguageMozcConfigView::GetDialogButtons() const {
118 return MessageBoxFlags::DIALOGBUTTON_OK;
119 }
120
121 std::wstring LanguageMozcConfigView::GetDialogButtonLabel(
122 MessageBoxFlags::DialogButton button) const {
123 if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
124 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK));
125 }
126 return L"";
127 }
128
129 std::wstring LanguageMozcConfigView::GetWindowTitle() const {
130 return UTF16ToWide(l10n_util::GetStringUTF16(
131 IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_SETTINGS_TITLE));
132 }
133
134 gfx::Size LanguageMozcConfigView::GetPreferredSize() {
135 // TODO(satorux): Create our own localized content size once the UI is done.
136 gfx::Size preferred_size = views::Window::GetLocalizedContentsSize(
137 IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS,
138 IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES);
139 // TODO(mazda): Remove the manual adjustment.
140 // The padding is needed for accommodating all the controls in the dialog.
141 const int kHeightPadding = 80;
142 preferred_size.Enlarge(0, kHeightPadding);
143 return preferred_size;
144 }
145
146 void LanguageMozcConfigView::InitControlLayout() {
147 using views::ColumnSet;
148 using views::GridLayout;
149
150 contents_ = new views::View;
151 AddChildView(contents_);
152
153 GridLayout* layout = new GridLayout(contents_);
154 layout->SetInsets(kPanelVertMargin, kPanelHorizMargin,
155 kPanelVertMargin, kPanelHorizMargin);
156 contents_->SetLayoutManager(layout);
157
158 const int kColumnSetId = 0;
159 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId);
160 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
161 GridLayout::USE_PREF, 0, 0);
162 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
163 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
164 GridLayout::USE_PREF, 0, 0);
165
166 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
167 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i];
168 current.checkbox = new views::Checkbox(UTF16ToWide(
169 l10n_util::GetStringUTF16(
170 language_prefs::kMozcBooleanPrefs[i].message_id)));
171 current.checkbox->set_listener(this);
172 current.checkbox->set_tag(i);
173 }
174 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
175 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i];
176 current.combobox = new LanguageCombobox(current.combobox_model);
177 current.combobox->set_listener(this);
178 }
179 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
180 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i];
181 current.slider = new views::Slider(
182 language_prefs::kMozcIntegerPrefs[i].min_pref_value,
183 language_prefs::kMozcIntegerPrefs[i].max_pref_value,
184 1,
185 static_cast<views::Slider::StyleFlags>(
186 views::Slider::STYLE_DRAW_VALUE |
187 views::Slider::STYLE_UPDATE_ON_RELEASE),
188 this);
189 }
190 NotifyPrefChanged(); // Sync the comboboxes with current Chrome prefs.
191
192 reset_to_defaults_button_ = new views::NativeButton(
193 this, UTF16ToWide(l10n_util::GetStringUTF16(
194 IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_RESET_TO_DEFAULTS_BUTTON)));
195 reset_to_defaults_button_->set_tag(kResetToDefaultsButton);
196 layout->StartRow(0, kColumnSetId);
197 layout->AddView(reset_to_defaults_button_);
198
199 // Show the checkboxes.
200 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
201 const MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i];
202 layout->StartRow(0, kColumnSetId);
203 layout->AddView(current.checkbox, 3, 1);
204 }
205 // Show the comboboxes.
206 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
207 const MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i];
208 layout->StartRow(0, kColumnSetId);
209 layout->AddView(new views::Label(current.combobox_model->GetLabel()));
210 layout->AddView(current.combobox);
211 }
212 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
213 const MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i];
214 layout->StartRow(0, kColumnSetId);
215 layout->AddView(new views::Label(
216 UTF16ToWide(l10n_util::GetStringUTF16(
217 language_prefs::kMozcIntegerPrefs[i].message_id))));
218 layout->AddView(current.slider);
219 }
220 NotifyPrefChanged(); // Sync the slider with current Chrome prefs.
221 }
222
223 void LanguageMozcConfigView::Observe(NotificationType type,
224 const NotificationSource& source,
225 const NotificationDetails& details) {
226 if (type == NotificationType::PREF_CHANGED) {
227 NotifyPrefChanged();
228 }
229 }
230
231 void LanguageMozcConfigView::NotifyPrefChanged() {
232 // Update comboboxes.
233 // TODO(yusukes): We don't have to update all UI controls.
234 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
235 MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i];
236 const bool checked = current.boolean_pref.GetValue();
237 current.checkbox->SetChecked(checked);
238 }
239 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
240 MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i];
241 const std::string value = current.multiple_choice_pref.GetValue();
242 for (int i = 0; i < current.combobox_model->num_items(); ++i) {
243 if (current.combobox_model->GetConfigValueAt(i) == value) {
244 current.combobox->SetSelectedItem(i);
245 break;
246 }
247 }
248 }
249 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
250 MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i];
251 const int value = current.integer_pref.GetValue();
252 current.slider->SetValue(value);
253 }
254 }
255
256 void LanguageMozcConfigView::ResetToDefaults() {
257 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
258 prefs_and_checkboxes_[i].boolean_pref.SetValue(
259 language_prefs::kMozcBooleanPrefs[i].default_pref_value);
260 }
261 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
262 prefs_and_comboboxes_[i].multiple_choice_pref.SetValue(
263 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value);
264 }
265 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
266 prefs_and_sliders_[i].integer_pref.SetValue(
267 language_prefs::kMozcIntegerPrefs[i].default_pref_value);
268 }
269 // Reflect the preference changes to the controls.
270 NotifyPrefChanged();
271 }
272
273 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698