Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_pinyin_config_view.h" | |
| 6 | |
| 7 #include "app/combobox_model.h" | |
| 8 #include "app/l10n_util.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/common/notification_type.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 13 #include "chrome/browser/chromeos/cros/language_library.h" | |
| 14 #include "chrome/browser/chromeos/preferences.h" | |
| 15 #include "chrome/browser/profile.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "grit/locale_settings.h" | |
| 18 #include "views/controls/button/checkbox.h" | |
| 19 #include "views/controls/label.h" | |
| 20 #include "views/grid_layout.h" | |
| 21 #include "views/standard_layout.h" | |
| 22 #include "views/window/window.h" | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 LanguagePinyinConfigView::LanguagePinyinConfigView(Profile* profile) | |
| 27 : OptionsPageView(profile), contents_(NULL) { | |
| 28 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | |
| 29 pinyin_boolean_prefs_[i].Init( | |
| 30 kPinyinBooleanPrefs[i].pref_name, profile->GetPrefs(), this); | |
| 31 pinyin_boolean_checkboxes_[i] = NULL; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 LanguagePinyinConfigView::~LanguagePinyinConfigView() { | |
| 36 } | |
| 37 | |
| 38 void LanguagePinyinConfigView::ButtonPressed( | |
| 39 views::Button* sender, const views::Event& event) { | |
|
tfarina (gmail-do not use)
2010/04/27 18:14:21
this could be better aligned (readable), as:
...(v
| |
| 40 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | |
| 41 const int pref_id = checkbox->tag(); | |
| 42 DCHECK(pref_id >= 0 && pref_id < static_cast<int>(kNumPinyinBooleanPrefs)); | |
| 43 pinyin_boolean_prefs_[pref_id].SetValue(checkbox->checked()); | |
| 44 } | |
| 45 | |
| 46 void LanguagePinyinConfigView::Layout() { | |
| 47 // Not sure why but this is needed to show contents in the dialog. | |
| 48 contents_->SetBounds(0, 0, width(), height()); | |
| 49 } | |
| 50 | |
| 51 std::wstring LanguagePinyinConfigView::GetWindowTitle() const { | |
| 52 return l10n_util::GetString( | |
| 53 IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_SETTINGS_TITLE); | |
| 54 } | |
| 55 | |
| 56 gfx::Size LanguagePinyinConfigView::GetPreferredSize() { | |
| 57 // TODO(satorux): Create our own localized content size once the UI is done. | |
| 58 return gfx::Size(views::Window::GetLocalizedContentsSize( | |
| 59 IDS_FONTSLANG_DIALOG_WIDTH_CHARS, | |
| 60 IDS_FONTSLANG_DIALOG_HEIGHT_LINES)); | |
| 61 } | |
| 62 | |
| 63 void LanguagePinyinConfigView::InitControlLayout() { | |
| 64 using views::ColumnSet; | |
| 65 using views::GridLayout; | |
| 66 | |
| 67 contents_ = new views::View; | |
| 68 AddChildView(contents_); | |
| 69 | |
| 70 GridLayout* layout = new GridLayout(contents_); | |
| 71 layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, | |
| 72 kPanelVertMargin, kPanelHorizMargin); | |
| 73 contents_->SetLayoutManager(layout); | |
| 74 | |
| 75 const int kColumnSetId = 0; | |
| 76 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | |
| 77 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
| 78 GridLayout::USE_PREF, 0, 0); | |
| 79 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | |
| 80 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
| 81 GridLayout::USE_PREF, 0, 0); | |
| 82 | |
| 83 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | |
| 84 pinyin_boolean_checkboxes_[i] = new views::Checkbox( | |
| 85 l10n_util::GetString(kPinyinBooleanPrefs[i].message_id)); | |
| 86 pinyin_boolean_checkboxes_[i]->set_listener(this); | |
| 87 pinyin_boolean_checkboxes_[i]->set_tag(i); | |
| 88 } | |
| 89 NotifyPrefChanged(); | |
| 90 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | |
| 91 layout->StartRow(0, kColumnSetId); | |
| 92 layout->AddView(pinyin_boolean_checkboxes_[i]); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void LanguagePinyinConfigView::Observe(NotificationType type, | |
| 97 const NotificationSource& source, | |
| 98 const NotificationDetails& details) { | |
| 99 if (type == NotificationType::PREF_CHANGED) { | |
|
tfarina (gmail-do not use)
2010/04/27 18:14:21
chromium style is to not add {} in single line sta
satorux1
2010/04/28 05:37:05
Is it? Could you tell us where it is defined?
| |
| 100 NotifyPrefChanged(); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 void LanguagePinyinConfigView::NotifyPrefChanged() { | |
| 105 for (size_t i = 0; i < kNumPinyinBooleanPrefs; ++i) { | |
| 106 const bool checked = pinyin_boolean_prefs_[i].GetValue(); | |
| 107 pinyin_boolean_checkboxes_[i]->SetChecked(checked); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 } // namespace chromeos | |
| OLD | NEW |