| 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_pinyin_config_view.h" | 5 #include "chrome/browser/chromeos/options/language_pinyin_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/common/notification_type.h" | 9 #include "chrome/common/notification_type.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 12 #include "chrome/browser/chromeos/cros/input_method_library.h" | 12 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 13 #include "chrome/browser/chromeos/options/language_config_util.h" | 13 #include "chrome/browser/chromeos/options/language_config_util.h" |
| 14 #include "chrome/browser/chromeos/preferences.h" | 14 #include "chrome/browser/chromeos/preferences.h" |
| 15 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.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 LanguagePinyinConfigView::LanguagePinyinConfigView(Profile* profile) | 26 LanguagePinyinConfigView::LanguagePinyinConfigView(Profile* profile) |
| 27 : OptionsPageView(profile), contents_(NULL) { | 27 : OptionsPageView(profile), contents_(NULL) { |
| 28 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | 28 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
| 29 pinyin_boolean_prefs_[i].Init( | 29 pinyin_boolean_prefs_[i].Init( |
| 30 kPinyinBooleanPrefs[i].pref_name, profile->GetPrefs(), this); | 30 language_prefs::kPinyinBooleanPrefs[i].pref_name, profile->GetPrefs(), |
| 31 this); |
| 31 pinyin_boolean_checkboxes_[i] = NULL; | 32 pinyin_boolean_checkboxes_[i] = NULL; |
| 32 } | 33 } |
| 33 | 34 |
| 34 double_pinyin_schema_.multiple_choice_pref.Init( | 35 double_pinyin_schema_.multiple_choice_pref.Init( |
| 35 kPinyinDoublePinyinSchema.pref_name, profile->GetPrefs(), this); | 36 language_prefs::kPinyinDoublePinyinSchema.pref_name, |
| 37 profile->GetPrefs(), this); |
| 36 double_pinyin_schema_.combobox_model = | 38 double_pinyin_schema_.combobox_model = |
| 37 new LanguageComboboxModel<int>(&kPinyinDoublePinyinSchema); | 39 new LanguageComboboxModel<int>( |
| 40 &language_prefs::kPinyinDoublePinyinSchema); |
| 38 double_pinyin_schema_.combobox = NULL; | 41 double_pinyin_schema_.combobox = NULL; |
| 39 } | 42 } |
| 40 | 43 |
| 41 LanguagePinyinConfigView::~LanguagePinyinConfigView() { | 44 LanguagePinyinConfigView::~LanguagePinyinConfigView() { |
| 42 } | 45 } |
| 43 | 46 |
| 44 void LanguagePinyinConfigView::ButtonPressed( | 47 void LanguagePinyinConfigView::ButtonPressed( |
| 45 views::Button* sender, const views::Event& event) { | 48 views::Button* sender, const views::Event& event) { |
| 46 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | 49 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); |
| 47 const int pref_id = checkbox->tag(); | 50 const int pref_id = checkbox->tag(); |
| 48 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumPinyinBooleanPrefs)); | 51 DCHECK(pref_id >= 0 && pref_id < static_cast<int>( |
| 52 language_prefs::kNumPinyinBooleanPrefs)); |
| 49 pinyin_boolean_prefs_[pref_id].SetValue(checkbox->checked()); | 53 pinyin_boolean_prefs_[pref_id].SetValue(checkbox->checked()); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void LanguagePinyinConfigView::ItemChanged( | 56 void LanguagePinyinConfigView::ItemChanged( |
| 53 views::Combobox* sender, int prev_index, int new_index) { | 57 views::Combobox* sender, int prev_index, int new_index) { |
| 54 if (double_pinyin_schema_.combobox == sender) { | 58 if (double_pinyin_schema_.combobox == sender) { |
| 55 const int config_value = | 59 const int config_value = |
| 56 double_pinyin_schema_.combobox_model->GetConfigValueAt(new_index); | 60 double_pinyin_schema_.combobox_model->GetConfigValueAt(new_index); |
| 57 LOG(INFO) << "Changing Pinyin pref to " << config_value; | 61 LOG(INFO) << "Changing Pinyin pref to " << config_value; |
| 58 // Update the Chrome pref. | 62 // Update the Chrome pref. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 contents_->SetLayoutManager(layout); | 106 contents_->SetLayoutManager(layout); |
| 103 | 107 |
| 104 const int kColumnSetId = 0; | 108 const int kColumnSetId = 0; |
| 105 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 109 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
| 106 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 110 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 107 GridLayout::USE_PREF, 0, 0); | 111 GridLayout::USE_PREF, 0, 0); |
| 108 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 112 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 109 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 113 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 110 GridLayout::USE_PREF, 0, 0); | 114 GridLayout::USE_PREF, 0, 0); |
| 111 | 115 |
| 112 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | 116 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
| 113 pinyin_boolean_checkboxes_[i] = new views::Checkbox( | 117 pinyin_boolean_checkboxes_[i] = new views::Checkbox( |
| 114 l10n_util::GetString(kPinyinBooleanPrefs[i].message_id)); | 118 l10n_util::GetString( |
| 119 language_prefs::kPinyinBooleanPrefs[i].message_id)); |
| 115 pinyin_boolean_checkboxes_[i]->set_listener(this); | 120 pinyin_boolean_checkboxes_[i]->set_listener(this); |
| 116 pinyin_boolean_checkboxes_[i]->set_tag(i); | 121 pinyin_boolean_checkboxes_[i]->set_tag(i); |
| 117 } | 122 } |
| 118 double_pinyin_schema_.combobox = | 123 double_pinyin_schema_.combobox = |
| 119 new LanguageCombobox(double_pinyin_schema_.combobox_model); | 124 new LanguageCombobox(double_pinyin_schema_.combobox_model); |
| 120 double_pinyin_schema_.combobox->set_listener(this); | 125 double_pinyin_schema_.combobox->set_listener(this); |
| 121 | 126 |
| 122 NotifyPrefChanged(); | 127 NotifyPrefChanged(); |
| 123 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | 128 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
| 124 layout->StartRow(0, kColumnSetId); | 129 layout->StartRow(0, kColumnSetId); |
| 125 layout->AddView(pinyin_boolean_checkboxes_[i]); | 130 layout->AddView(pinyin_boolean_checkboxes_[i]); |
| 126 } | 131 } |
| 127 layout->StartRow(0, kColumnSetId); | 132 layout->StartRow(0, kColumnSetId); |
| 128 layout->AddView( | 133 layout->AddView( |
| 129 new views::Label(double_pinyin_schema_.combobox_model->GetLabel())); | 134 new views::Label(double_pinyin_schema_.combobox_model->GetLabel())); |
| 130 layout->AddView(double_pinyin_schema_.combobox); | 135 layout->AddView(double_pinyin_schema_.combobox); |
| 131 } | 136 } |
| 132 | 137 |
| 133 void LanguagePinyinConfigView::Observe(NotificationType type, | 138 void LanguagePinyinConfigView::Observe(NotificationType type, |
| 134 const NotificationSource& source, | 139 const NotificationSource& source, |
| 135 const NotificationDetails& details) { | 140 const NotificationDetails& details) { |
| 136 if (type == NotificationType::PREF_CHANGED) { | 141 if (type == NotificationType::PREF_CHANGED) { |
| 137 NotifyPrefChanged(); | 142 NotifyPrefChanged(); |
| 138 } | 143 } |
| 139 } | 144 } |
| 140 | 145 |
| 141 void LanguagePinyinConfigView::NotifyPrefChanged() { | 146 void LanguagePinyinConfigView::NotifyPrefChanged() { |
| 142 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | 147 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
| 143 const bool checked = pinyin_boolean_prefs_[i].GetValue(); | 148 const bool checked = pinyin_boolean_prefs_[i].GetValue(); |
| 144 pinyin_boolean_checkboxes_[i]->SetChecked(checked); | 149 pinyin_boolean_checkboxes_[i]->SetChecked(checked); |
| 145 } | 150 } |
| 146 const int value = double_pinyin_schema_.multiple_choice_pref.GetValue(); | 151 const int value = double_pinyin_schema_.multiple_choice_pref.GetValue(); |
| 147 for (int i = 0; i < double_pinyin_schema_.combobox_model->num_items(); ++i) { | 152 for (int i = 0; i < double_pinyin_schema_.combobox_model->num_items(); ++i) { |
| 148 if (double_pinyin_schema_.combobox_model->GetConfigValueAt(i) == value) { | 153 if (double_pinyin_schema_.combobox_model->GetConfigValueAt(i) == value) { |
| 149 double_pinyin_schema_.combobox->SetSelectedItem(i); | 154 double_pinyin_schema_.combobox->SetSelectedItem(i); |
| 150 break; | 155 break; |
| 151 } | 156 } |
| 152 } | 157 } |
| 153 } | 158 } |
| 154 | 159 |
| 155 } // namespace chromeos | 160 } // namespace chromeos |
| OLD | NEW |