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

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

Powered by Google App Engine
This is Rietveld 408576698