diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-19 05:34:08 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-19 05:34:08 +0000 |
commit | 695e65dc775445c0bd2226a49a91431a55c13b8d (patch) | |
tree | e3912ea4046b2b836bad15c0095d9368a87e868c | |
parent | aecc4d17d1e92344ab607b2baaad1b7057b100b4 (diff) | |
download | chromium_src-695e65dc775445c0bd2226a49a91431a55c13b8d.zip chromium_src-695e65dc775445c0bd2226a49a91431a55c13b8d.tar.gz chromium_src-695e65dc775445c0bd2226a49a91431a55c13b8d.tar.bz2 |
Remove unused language options code, which has been superseded by DOMUI.
BUG=chromium-os:8307
TEST=Compiled and saw it runs on netbook.
Review URL: http://codereview.chromium.org/6336005
Patch from Matt Falken <falken@chromium.org>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71766 0039d316-1c4b-4281-b951-d872f2087c98
18 files changed, 1 insertions, 2785 deletions
diff --git a/chrome/browser/chromeos/options/language_chewing_config_view.cc b/chrome/browser/chromeos/options/language_chewing_config_view.cc deleted file mode 100644 index a4c03cb..0000000 --- a/chrome/browser/chromeos/options/language_chewing_config_view.cc +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_chewing_config_view.h" - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/options/language_config_util.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/notification_type.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/label.h" -#include "views/grid_layout.h" -#include "views/standard_layout.h" -#include "views/window/window.h" - -namespace chromeos { - -LanguageChewingConfigView::LanguageChewingConfigView(Profile* profile) - : OptionsPageView(profile), contents_(NULL) { - for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { - chewing_boolean_prefs_[i].Init( - language_prefs::kChewingBooleanPrefs[i].pref_name, - profile->GetPrefs(), this); - chewing_boolean_checkboxes_[i] = NULL; - } - for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { - ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.multiple_choice_pref.Init( - language_prefs::kChewingMultipleChoicePrefs[i].pref_name, - profile->GetPrefs(), this); - current.combobox_model = - new LanguageComboboxModel<const char*>( - &language_prefs::kChewingMultipleChoicePrefs[i]); - current.combobox = NULL; - } - - hsu_sel_key_type_.multiple_choice_pref.Init( - language_prefs::kChewingHsuSelKeyType.pref_name, profile->GetPrefs(), - this); - hsu_sel_key_type_.combobox_model = - new LanguageComboboxModel<int>(&language_prefs::kChewingHsuSelKeyType); - hsu_sel_key_type_.combobox = NULL; - - for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { - chewing_integer_prefs_[i].Init( - language_prefs::kChewingIntegerPrefs[i].pref_name, - profile->GetPrefs(), this); - chewing_integer_sliders_[i] = NULL; - } -} - -LanguageChewingConfigView::~LanguageChewingConfigView() { -} - -void LanguageChewingConfigView::ButtonPressed( - views::Button* sender, const views::Event& event) { - views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); - const int pref_id = checkbox->tag(); - DCHECK(pref_id >= 0 && pref_id < static_cast<int>( - language_prefs::kNumChewingBooleanPrefs)); - chewing_boolean_prefs_[pref_id].SetValue(checkbox->checked()); -} - -void LanguageChewingConfigView::ItemChanged( - views::Combobox* sender, int prev_index, int new_index) { - for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { - ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - if (current.combobox == sender) { - const std::string config_value = - current.combobox_model->GetConfigValueAt(new_index); - VLOG(1) << "Changing Chewing pref to " << config_value; - // Update the Chrome pref. - current.multiple_choice_pref.SetValue(config_value); - break; - } - } - if (hsu_sel_key_type_.combobox == sender) { - const int config_value = - hsu_sel_key_type_.combobox_model->GetConfigValueAt(new_index); - VLOG(1) << "Changing Chewing pref to " << config_value; - // Update the Chrome pref. - hsu_sel_key_type_.multiple_choice_pref.SetValue(config_value); - } -} - -void LanguageChewingConfigView::SliderValueChanged(views::Slider* sender) { - size_t pref_id; - for (pref_id = 0; pref_id < language_prefs::kNumChewingIntegerPrefs; - ++pref_id) { - if (chewing_integer_sliders_[pref_id] == sender) - break; - } - DCHECK(pref_id < language_prefs::kNumChewingIntegerPrefs); - chewing_integer_prefs_[pref_id].SetValue(sender->value()); -} - - -void LanguageChewingConfigView::Layout() { - // Not sure why but this is needed to show contents in the dialog. - contents_->SetBounds(0, 0, width(), height()); -} - -int LanguageChewingConfigView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_OK; -} - -std::wstring LanguageChewingConfigView::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK)); - } - return L""; -} - -std::wstring LanguageChewingConfigView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_SETTINGS_TITLE)); -} - -gfx::Size LanguageChewingConfigView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, - IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES)); -} - -void LanguageChewingConfigView::InitControlLayout() { - using views::ColumnSet; - using views::GridLayout; - - contents_ = new views::View; - AddChildView(contents_); - - GridLayout* layout = new GridLayout(contents_); - layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, - kPanelVertMargin, kPanelHorizMargin); - contents_->SetLayoutManager(layout); - - const int kColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, - GridLayout::USE_PREF, 0, 0); - - for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { - chewing_boolean_checkboxes_[i] = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16( - language_prefs::kChewingBooleanPrefs[i].message_id))); - chewing_boolean_checkboxes_[i]->set_listener(this); - chewing_boolean_checkboxes_[i]->set_tag(i); - } - for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { - ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.combobox = new LanguageCombobox(current.combobox_model); - current.combobox->set_listener(this); - } - hsu_sel_key_type_.combobox = - new LanguageCombobox(hsu_sel_key_type_.combobox_model); - hsu_sel_key_type_.combobox->set_listener(this); - - for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { - chewing_integer_sliders_[i] = new views::Slider( - language_prefs::kChewingIntegerPrefs[i].min_pref_value, - language_prefs::kChewingIntegerPrefs[i].max_pref_value, - 1, - static_cast<views::Slider::StyleFlags>( - views::Slider::STYLE_DRAW_VALUE | - views::Slider::STYLE_UPDATE_ON_RELEASE), - this); - } - for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { - layout->StartRow(0, kColumnSetId); - layout->AddView(chewing_boolean_checkboxes_[i]); - } - - for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { - layout->StartRow(0, kColumnSetId); - layout->AddView(new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - language_prefs::kChewingIntegerPrefs[i].message_id)))); - layout->AddView(chewing_integer_sliders_[i]); - } - NotifyPrefChanged(); - - // Show the comboboxes. - for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { - const ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - layout->StartRow(0, kColumnSetId); - layout->AddView(new views::Label(current.combobox_model->GetLabel())); - layout->AddView(current.combobox); - } - layout->StartRow(0, kColumnSetId); - layout->AddView( - new views::Label(hsu_sel_key_type_.combobox_model->GetLabel())); - layout->AddView(hsu_sel_key_type_.combobox); -} - -void LanguageChewingConfigView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - NotifyPrefChanged(); - } -} - -void LanguageChewingConfigView::NotifyPrefChanged() { - for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { - const bool checked = chewing_boolean_prefs_[i].GetValue(); - chewing_boolean_checkboxes_[i]->SetChecked(checked); - } - for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { - const int value = chewing_integer_prefs_[i].GetValue(); - chewing_integer_sliders_[i]->SetValue(value); - } - for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { - ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - const std::string value = current.multiple_choice_pref.GetValue(); - for (int i = 0; i < current.combobox_model->num_items(); ++i) { - if (current.combobox_model->GetConfigValueAt(i) == value) { - current.combobox->SetSelectedItem(i); - break; - } - } - } - const int value = hsu_sel_key_type_.multiple_choice_pref.GetValue(); - for (int i = 0; i < hsu_sel_key_type_.combobox_model->num_items(); ++i) { - if (hsu_sel_key_type_.combobox_model->GetConfigValueAt(i) == value) { - hsu_sel_key_type_.combobox->SetSelectedItem(i); - break; - } - } -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_chewing_config_view.h b/chrome/browser/chromeos/options/language_chewing_config_view.h deleted file mode 100644 index c277d04..0000000 --- a/chrome/browser/chromeos/options/language_chewing_config_view.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CHEWING_CONFIG_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CHEWING_CONFIG_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/language_preferences.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/label.h" -#include "views/controls/slider/slider.h" -#include "views/window/dialog_delegate.h" - -namespace chromeos { - -class LanguageCombobox; -template <typename DataType> -class LanguageComboboxModel; - -// A dialog box for showing Traditional Chinese (Chewing) input method -// preferences. -class LanguageChewingConfigView : public views::ButtonListener, - public views::Combobox::Listener, - public views::DialogDelegate, - public views::SliderListener, - public OptionsPageView { - public: - explicit LanguageChewingConfigView(Profile* profile); - virtual ~LanguageChewingConfigView(); - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::Combobox::Listener overrides. - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - // views::SliderListener overrides. - virtual void SliderValueChanged(views::Slider* sender); - - // views::DialogDelegate overrides. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual std::wstring GetWindowTitle() const; - - // views::View overrides. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // OptionsPageView overrides. - virtual void InitControlLayout(); - - // NotificationObserver overrides. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Updates the chewing checkboxes. - void NotifyPrefChanged(); - - BooleanPrefMember chewing_boolean_prefs_[ - language_prefs::kNumChewingBooleanPrefs]; - IntegerPrefMember chewing_integer_prefs_[ - language_prefs::kNumChewingIntegerPrefs]; - views::View* contents_; - - // Checkboxes for Chewing. - views::Checkbox* chewing_boolean_checkboxes_[ - language_prefs::kNumChewingBooleanPrefs]; - - views::Slider* chewing_integer_sliders_[ - language_prefs::kNumChewingIntegerPrefs]; - - struct ChewingPrefAndAssociatedCombobox { - StringPrefMember multiple_choice_pref; - LanguageComboboxModel<const char*>* combobox_model; - LanguageCombobox* combobox; - } prefs_and_comboboxes_[language_prefs::kNumChewingMultipleChoicePrefs]; - - struct HsuSelKeyTypePrefAndAssociatedCombobox { - IntegerPrefMember multiple_choice_pref; - LanguageComboboxModel<int>* combobox_model; - LanguageCombobox* combobox; - } hsu_sel_key_type_; - - DISALLOW_COPY_AND_ASSIGN(LanguageChewingConfigView); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CHEWING_CONFIG_VIEW_H_ diff --git a/chrome/browser/chromeos/options/language_config_model.cc b/chrome/browser/chromeos/options/language_config_model.cc deleted file mode 100644 index cd400e5..0000000 --- a/chrome/browser/chromeos/options/language_config_model.cc +++ /dev/null @@ -1,277 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_config_model.h" - -#include <algorithm> -#include <functional> -#include <utility> - -#include "app/l10n_util.h" -#include "base/string_split.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/input_method/input_method_util.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" - -namespace chromeos { - -AddLanguageComboboxModel::AddLanguageComboboxModel( - Profile* profile, - const std::vector<std::string>& locale_codes) - : LanguageComboboxModel(profile, locale_codes) { -} - -int AddLanguageComboboxModel::GetItemCount() { - // +1 for "Add language". - return get_languages_count() + 1 - ignore_set_.size(); -} - -string16 AddLanguageComboboxModel::GetItemAt(int index) { - // Show "Add language" as the first item. - if (index == 0) { - return l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_COMBOBOX); - } - return GetLanguageNameAt(GetLanguageIndex(index)); -} - -int AddLanguageComboboxModel::GetLanguageIndex(int index) const { - // The adjusted_index is counted while ignoring languages in ignore_set_. - int adjusted_index = 0; - for (int i = 0; i < get_languages_count(); ++i) { - if (ignore_set_.count(GetLocaleFromIndex(i)) > 0) { - continue; - } - // -1 for "Add language". - if (adjusted_index == index - 1) { - return i; - } - ++adjusted_index; - } - return 0; -} - -void AddLanguageComboboxModel::SetIgnored( - const std::string& language_code, bool ignored) { - if (ignored) { - // Add to the ignore_set_ if the language code is known (i.e. reject - // unknown language codes just in case). - if (GetIndexFromLocale(language_code) != -1) { - ignore_set_.insert(language_code); - } else { - LOG(ERROR) << "Unknown language code: " << language_code; - } - } else { - ignore_set_.erase(language_code); - } -} - -LanguageConfigModel::LanguageConfigModel(PrefService* pref_service) - : pref_service_(pref_service) { - // Initialize the maps and vectors. - InitInputMethodIdVectors(); - - preferred_languages_pref_.Init( - prefs::kLanguagePreferredLanguages, pref_service_, this); - preload_engines_pref_.Init( - prefs::kLanguagePreloadEngines, pref_service_, this); - // TODO(yusukes): It might be safer to call GetActiveLanguages() cros API - // here and compare the result and preload_engines_pref_.GetValue(). - // If there's a discrepancy between IBus setting and Chrome prefs, we - // can resolve it by calling preload_engines_pref_SetValue() here. - - // Initialize the language codes currently activated. - NotifyPrefChanged(); -} - -size_t LanguageConfigModel::CountNumActiveInputMethods( - const std::string& language_code) { - int num_selected_active_input_methods = 0; - std::vector<std::string> input_method_ids; - input_method::GetInputMethodIdsFromLanguageCode( - language_code, input_method::kAllInputMethods, &input_method_ids); - for (size_t i = 0; i < input_method_ids.size(); ++i) { - if (InputMethodIsActivated(input_method_ids[i])) { - ++num_selected_active_input_methods; - } - } - return num_selected_active_input_methods; -} - -bool LanguageConfigModel::HasLanguageCode( - const std::string& language_code) const { - return std::find(preferred_language_codes_.begin(), - preferred_language_codes_.end(), - language_code) != preferred_language_codes_.end(); -} - -size_t LanguageConfigModel::AddLanguageCode( - const std::string& language_code) { - preferred_language_codes_.push_back(language_code); - // Sort the language codes by names. This is not efficient, but - // acceptable as the language list is about 40 item long at most. In - // theory, we could find the position to insert rather than sorting, but - // it would be complex as we need to use unicode string comparator. - input_method::SortLanguageCodesByNames(&preferred_language_codes_); - // Find the language code just added in the sorted language codes. - const int added_at = - std::distance(preferred_language_codes_.begin(), - std::find(preferred_language_codes_.begin(), - preferred_language_codes_.end(), - language_code)); - preferred_languages_pref_.SetValue( - JoinString(preferred_language_codes_, ',')); - return added_at; -} - -void LanguageConfigModel::RemoveLanguageAt(size_t row) { - preferred_language_codes_.erase(preferred_language_codes_.begin() + row); - preferred_languages_pref_.SetValue( - JoinString(preferred_language_codes_, ',')); -} - -void LanguageConfigModel::UpdateInputMethodPreferences( - const std::vector<std::string>& in_new_input_method_ids) { - std::vector<std::string> new_input_method_ids = in_new_input_method_ids; - // Note: Since |new_input_method_ids| is alphabetically sorted and the sort - // function below uses stable sort, the relateve order of input methods that - // belong to the same language (e.g. "mozc" and "xkb:jp::jpn") is maintained. - input_method::SortInputMethodIdsByNames(&new_input_method_ids); - preload_engines_pref_.SetValue(JoinString(new_input_method_ids, ',')); -} - -void LanguageConfigModel::DeactivateInputMethodsFor( - const std::string& language_code) { - for (size_t i = 0; i < num_supported_input_method_ids(); ++i) { - if (input_method::GetLanguageCodeFromInputMethodId( - supported_input_method_id_at(i)) == - language_code) { - // What happens if we disable the input method currently active? - // IBus should take care of it, so we don't do anything special - // here. See crosbug.com/2443. - SetInputMethodActivated(supported_input_method_id_at(i), false); - // Do not break; here in order to disable all engines that belong to - // |language_code|. - } - } -} - -void LanguageConfigModel::SetInputMethodActivated( - const std::string& input_method_id, bool activated) { - DCHECK(!input_method_id.empty()); - std::vector<std::string> input_method_ids; - GetActiveInputMethodIds(&input_method_ids); - - std::set<std::string> input_method_id_set(input_method_ids.begin(), - input_method_ids.end()); - if (activated) { - // Add |id| if it's not already added. - input_method_id_set.insert(input_method_id); - } else { - input_method_id_set.erase(input_method_id); - } - - // Update Chrome's preference. - std::vector<std::string> new_input_method_ids(input_method_id_set.begin(), - input_method_id_set.end()); - UpdateInputMethodPreferences(new_input_method_ids); -} - -bool LanguageConfigModel::InputMethodIsActivated( - const std::string& input_method_id) { - std::vector<std::string> input_method_ids; - GetActiveInputMethodIds(&input_method_ids); - return (std::find(input_method_ids.begin(), input_method_ids.end(), - input_method_id) != input_method_ids.end()); -} - -void LanguageConfigModel::GetActiveInputMethodIds( - std::vector<std::string>* out_input_method_ids) { - const std::string value = preload_engines_pref_.GetValue(); - out_input_method_ids->clear(); - if (!value.empty()) - base::SplitString(value, ',', out_input_method_ids); -} - -void LanguageConfigModel::GetPreferredLanguageCodes( - std::vector<std::string>* out_language_codes) { - const std::string value = preferred_languages_pref_.GetValue(); - out_language_codes->clear(); - if (!value.empty()) - base::SplitString(value, ',', out_language_codes); -} - -void LanguageConfigModel::GetInputMethodIdsFromLanguageCode( - const std::string& language_code, - std::vector<std::string>* input_method_ids) const { - DCHECK(input_method_ids); - input_method_ids->clear(); - input_method::GetInputMethodIdsFromLanguageCode( - language_code, input_method::kAllInputMethods, input_method_ids); -} - -void LanguageConfigModel::NotifyPrefChanged() { - GetPreferredLanguageCodes(&preferred_language_codes_); -} - -void LanguageConfigModel::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - NotifyPrefChanged(); - } -} - -void LanguageConfigModel::InitInputMethodIdVectors() { - // The two sets are used to build lists without duplication. - std::set<std::string> supported_language_code_set; - std::set<std::string> supported_input_method_id_set; - // Build the id to descriptor map for handling kExtraLanguages later. - std::map<std::string, const InputMethodDescriptor*> id_to_descriptor_map; - - // GetSupportedLanguages() never return NULL. - scoped_ptr<InputMethodDescriptors> supported_input_methods( - CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); - for (size_t i = 0; i < supported_input_methods->size(); ++i) { - const InputMethodDescriptor& input_method = supported_input_methods->at(i); - const std::string language_code = - input_method::GetLanguageCodeFromDescriptor(input_method); - // Add the language code and the input method id to the sets. - supported_language_code_set.insert(language_code); - supported_input_method_id_set.insert(input_method.id); - // Remember the pair. - id_to_descriptor_map.insert( - std::make_pair(input_method.id, &input_method)); - } - - // Go through the languages listed in kExtraLanguages. - for (size_t i = 0; i < arraysize(input_method::kExtraLanguages); ++i) { - const char* language_code = input_method::kExtraLanguages[i].language_code; - const char* input_method_id = - input_method::kExtraLanguages[i].input_method_id; - std::map<std::string, const InputMethodDescriptor*>::const_iterator iter = - id_to_descriptor_map.find(input_method_id); - // If the associated input method descriptor is found, add the - // language code and the input method. - if (iter != id_to_descriptor_map.end()) { - const InputMethodDescriptor& input_method = *(iter->second); - // Add the language code and the input method id to the sets. - supported_language_code_set.insert(language_code); - supported_input_method_id_set.insert(input_method.id); - } - } - - // Build the vectors from the sets. - supported_language_codes_.assign(supported_language_code_set.begin(), - supported_language_code_set.end()); - supported_input_method_ids_.assign(supported_input_method_id_set.begin(), - supported_input_method_id_set.end()); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_config_model.h b/chrome/browser/chromeos/options/language_config_model.h deleted file mode 100644 index c401c6f3..0000000 --- a/chrome/browser/chromeos/options/language_config_model.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ -#pragma once - -#include <set> -#include <string> -#include <vector> - -#include "base/string16.h" -#include "chrome/browser/language_combobox_model.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/prefs/pref_service.h" -#include "third_party/cros/chromeos_input_method.h" - -class Profile; - -namespace chromeos { - -// The combobox model is used for adding languages in the language config -// view. -class AddLanguageComboboxModel : public ::LanguageComboboxModel { - public: - AddLanguageComboboxModel(Profile* profile, - const std::vector<std::string>& locale_codes); - // LanguageComboboxModel overrides. - virtual int GetItemCount(); - virtual string16 GetItemAt(int index); - - // Converts the given index (index of the items in the combobox) to the - // index of the internal language list. The returned index can be used - // for GetLocaleFromIndex() and GetLanguageNameAt(). - int GetLanguageIndex(int index) const; - - // Marks the given language code to be ignored. Ignored languages won't - // be shown in the combobox. It would be simpler if we could remove and - // add language codes from the model, but ComboboxModel does not allow - // items to be added/removed. Thus we use |ignore_set_| instead. - void SetIgnored(const std::string& language_code, bool ignored); - - private: - std::set<std::string> ignore_set_; - DISALLOW_COPY_AND_ASSIGN(AddLanguageComboboxModel); -}; - -// The model of LanguageConfigView. -class LanguageConfigModel : public NotificationObserver { - public: - explicit LanguageConfigModel(PrefService* pref_service); - - // Counts the number of active input methods for the given language code. - size_t CountNumActiveInputMethods(const std::string& language_code); - - // Returns true if the language code is in the preferred language list. - bool HasLanguageCode(const std::string& language_code) const; - - // Adds the given language to the preferred language list, and returns - // the index of the row where the language is added. - size_t AddLanguageCode(const std::string& language_code); - - // Removes the language at the given row. - void RemoveLanguageAt(size_t row); - - // Updates Chrome's input method preferences. - void UpdateInputMethodPreferences( - const std::vector<std::string>& new_input_method_ids); - - // Deactivates the input methods for the given language code. - void DeactivateInputMethodsFor(const std::string& language_code); - - // Activates or deactivates an IME whose ID is |input_method_id|. - void SetInputMethodActivated(const std::string& input_method_id, - bool activated); - - // Returns true if an IME of |input_method_id| is activated. - bool InputMethodIsActivated(const std::string& input_method_id); - - // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd" from - // the underlying preference object. The original contents of - // |out_input_method_ids| are lost. - void GetActiveInputMethodIds( - std::vector<std::string>* out_input_method_ids); - - // Gets the list of preferred language codes like "en-US" and "fr" from - // the underlying preference object. The original contents of - // |out_language_codes| are lost. - void GetPreferredLanguageCodes( - std::vector<std::string>* out_language_codes); - - // Gets the list of input method ids associated with the given language - // code. The original contents of |input_method_ids| will be lost. - void GetInputMethodIdsFromLanguageCode( - const std::string& language_code, - std::vector<std::string>* input_method_ids) const; - - // Callback for |preferred_language_codes_| pref updates. Initializes - // the preferred language codes based on the updated pref value. - void NotifyPrefChanged(); - - // NotificationObserver overrides. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - const std::string& preferred_language_code_at(size_t at) const { - return preferred_language_codes_[at]; - } - - size_t num_preferred_language_codes() const { - return preferred_language_codes_.size(); - } - - const std::string& supported_input_method_id_at(size_t at) const { - return supported_input_method_ids_[at]; - } - - size_t num_supported_input_method_ids() const { - return supported_input_method_ids_.size(); - } - - const std::vector<std::string>& supported_language_codes() const { - return supported_language_codes_; - } - - private: - // Initializes id_to_{code,display_name}_map_ maps, - // as well as supported_{language_codes,input_method_ids}_ vectors. - void InitInputMethodIdVectors(); - - PrefService* pref_service_; - // The codes of the preferred languages. - std::vector<std::string> preferred_language_codes_; - StringPrefMember preferred_languages_pref_; - StringPrefMember preload_engines_pref_; - // List of supported language codes like "en" and "ja". - std::vector<std::string> supported_language_codes_; - // List of supported IME IDs like "pinyin" and "m17n:ar:kbd". - std::vector<std::string> supported_input_method_ids_; - - DISALLOW_COPY_AND_ASSIGN(LanguageConfigModel); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ diff --git a/chrome/browser/chromeos/options/language_config_model_unittest.cc b/chrome/browser/chromeos/options/language_config_model_unittest.cc deleted file mode 100644 index 0d7e12f..0000000 --- a/chrome/browser/chromeos/options/language_config_model_unittest.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <map> -#include <string> -#include <utility> -#include <vector> - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/options/language_config_model.h" -#include "grit/generated_resources.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chromeos { - -TEST(AddLanguageComboboxModelTest, AddLanguageComboboxModel) { - std::vector<std::string> language_codes; - language_codes.push_back("de"); - language_codes.push_back("fr"); - language_codes.push_back("ko"); - AddLanguageComboboxModel model(NULL, language_codes); - - // GetItemCount() should return 4 ("Add language" + 3 language codes). - ASSERT_EQ(4, model.GetItemCount()); - - // The first item should be "Add language" labe. - EXPECT_EQ(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_COMBOBOX), - model.GetItemAt(0)); - // Other items should be sorted language display names for UI (hence - // French comes before German). Note that the returned display names - // are followed by their native representations. To simplify matching, - // use StartsWith() here. - EXPECT_TRUE(StartsWith(model.GetItemAt(1), ASCIIToUTF16("French"), true)) - << model.GetItemAt(1); - EXPECT_TRUE(StartsWith(model.GetItemAt(2), ASCIIToUTF16("German"), true)) - << model.GetItemAt(2); - EXPECT_TRUE(StartsWith(model.GetItemAt(3), ASCIIToUTF16("Korean"), true)) - << model.GetItemAt(3); - - // GetLanguageIndex() returns the given index -1 to offset "Add language". - EXPECT_EQ(0, model.GetLanguageIndex(1)); - EXPECT_EQ(1, model.GetLanguageIndex(2)); - EXPECT_EQ(2, model.GetLanguageIndex(3)); - - // The returned index can be used for GetLocaleFromIndex(). - EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2))); - EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3))); - - // GetIndexFromLocale() returns the language index. - EXPECT_EQ(0, model.GetIndexFromLocale("fr")); - EXPECT_EQ(1, model.GetIndexFromLocale("de")); - EXPECT_EQ(2, model.GetIndexFromLocale("ko")); - EXPECT_EQ(-1, model.GetIndexFromLocale("ja")); // Not in the model. - - // Mark "de" to be ignored, and check if it's gone. - model.SetIgnored("de", true); - ASSERT_EQ(3, model.GetItemCount()); - EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(2))); - - // Mark "ko" to be ignored, and check if it's gone. - model.SetIgnored("ko", true); - ASSERT_EQ(2, model.GetItemCount()); - EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - - // Mark "fr" to be ignored, and check if it's gone. - model.SetIgnored("fr", true); - ASSERT_EQ(1, model.GetItemCount()); - - // Mark "de" not to be ignored, and see if it's back. - model.SetIgnored("de", false); - ASSERT_EQ(2, model.GetItemCount()); - EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - - // Mark "fr" not to be ignored, and see if it's back. - model.SetIgnored("fr", false); - ASSERT_EQ(3, model.GetItemCount()); - EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2))); - - // Mark "ko" not to be ignored, and see if it's back. - model.SetIgnored("ko", false); - ASSERT_EQ(4, model.GetItemCount()); - EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1))); - EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2))); - EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3))); - - // Mark "ja" (not in the model) to be ignored. - model.SetIgnored("ja", true); - // The GetItemCount() should not be changed. - ASSERT_EQ(4, model.GetItemCount()); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_config_util.h b/chrome/browser/chromeos/options/language_config_util.h deleted file mode 100644 index dcd248c..0000000 --- a/chrome/browser/chromeos/options/language_config_util.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ -#pragma once - -#include "base/string16.h" -#include "chrome/browser/chromeos/language_preferences.h" -#include "ui/base/models/combobox_model.h" -#include "views/controls/combobox/combobox.h" - -namespace chromeos { - -// The combobox model for Language input method prefs. -template <typename DataType> -class LanguageComboboxModel : public ui::ComboboxModel { - public: - explicit LanguageComboboxModel( - const language_prefs::LanguageMultipleChoicePreference<DataType>* - pref_data) - : pref_data_(pref_data), num_items_(0) { - // Check how many items are defined in the |pref_data->values_and_ids| - // array. - for (size_t i = 0; - i < language_prefs::LanguageMultipleChoicePreference<DataType>:: - kMaxItems; ++i) { - if ((pref_data_->values_and_ids)[i].item_message_id == 0) { - break; - } - ++num_items_; - } - } - - // Implements ui::ComboboxModel interface. - virtual int GetItemCount() { - return num_items_; - } - - // Implements ui::ComboboxModel interface. - virtual string16 GetItemAt(int index) { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return string16(); - } - const int message_id = (pref_data_->values_and_ids)[index].item_message_id; - return l10n_util::GetStringUTF16(message_id); - } - - // Gets a label for the combobox like "Input mode". This function is NOT part - // of the ComboboxModel interface. - std::wstring GetLabel() const { - return UTF16ToWide(l10n_util::GetStringUTF16(pref_data_->label_message_id)); - } - - // Gets a config value for the ibus configuration daemon (e.g. "KUTEN_TOUTEN", - // "KUTEN_PERIOD", ..) for an item at zero-origin |index|. This function is - // NOT part of the ComboboxModel interface. - DataType GetConfigValueAt(int index) const { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return (pref_data_->values_and_ids)[0].ibus_config_value; - } - return (pref_data_->values_and_ids)[index].ibus_config_value; - } - - int num_items() { - return num_items_; - } - - private: - const language_prefs::LanguageMultipleChoicePreference<DataType>* pref_data_; - int num_items_; - - DISALLOW_COPY_AND_ASSIGN(LanguageComboboxModel); -}; - -// The combobox for the dialog which has minimum width. -class LanguageCombobox : public views::Combobox { - public: - explicit LanguageCombobox(ui::ComboboxModel* model) : Combobox(model) { - } - - virtual gfx::Size GetPreferredSize() { - gfx::Size size = Combobox::GetPreferredSize(); - if (size.width() < kMinComboboxWidth) { - size.set_width(kMinComboboxWidth); - } - return size; - } - - private: - static const int kMinComboboxWidth = 250; - - DISALLOW_COPY_AND_ASSIGN(LanguageCombobox); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc deleted file mode 100644 index 5198ef9..0000000 --- a/chrome/browser/chromeos/options/language_config_view.cc +++ /dev/null @@ -1,631 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_config_view.h" - -#include <algorithm> - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/input_method/input_method_util.h" -#include "chrome/browser/chromeos/options/language_chewing_config_view.h" -#include "chrome/browser/chromeos/options/language_hangul_config_view.h" -#include "chrome/browser/chromeos/options/language_mozc_config_view.h" -#include "chrome/browser/chromeos/options/language_pinyin_config_view.h" -#include "chrome/browser/chromeos/options/options_window_view.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/browser/metrics/user_metrics.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/views/restart_message_box.h" -#include "chrome/browser/ui/views/window.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/pref_names.h" -#include "gfx/font.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/label.h" -#include "views/fill_layout.h" -#include "views/standard_layout.h" -#include "views/window/window.h" - -namespace chromeos { -using views::ColumnSet; -using views::GridLayout; - -namespace { - -// The width of the preferred language table shown on the left side. -const int kPreferredLanguageTableWidth = 300; - -// Creates the LanguageHangulConfigView. The function is used to create -// the object via a function pointer. See also InitInputMethodConfigViewMap(). -views::DialogDelegate* CreateLanguageChewingConfigView(Profile* profile) { - return new LanguageChewingConfigView(profile); -} -views::DialogDelegate* CreateLanguageHangulConfigView(Profile* profile) { - return new LanguageHangulConfigView(profile); -} -views::DialogDelegate* CreateLanguagePinyinConfigView(Profile* profile) { - return new LanguagePinyinConfigView(profile); -} -views::DialogDelegate* CreateLanguageMozcConfigView(Profile* profile) { - return new LanguageMozcConfigView(profile); -} - -// The tags are used to identify buttons in ButtonPressed(). -enum ButtonTag { - kChangeUiLanguageButton, - kConfigureInputMethodButton, - kRemoveLanguageButton, - kSelectInputMethodButton, -}; - -// The column set IDs are used for creating the per-language config view. -const int kPerLanguageTitleColumnSetId = 1; -const int kPerLanguageDoubleColumnSetId = 2; -const int kPerLanguageSingleColumnSetId = 3; - -} // namespace - -// This is a native button associated with input method information. -class InputMethodButton : public views::NativeButton { - public: - InputMethodButton(views::ButtonListener* listener, - const std::wstring& label, - const std::string& input_method_id) - : views::NativeButton(listener, label), - input_method_id_(input_method_id) { - } - - const std::string& input_method_id() const { - return input_method_id_; - } - - private: - std::string input_method_id_; - DISALLOW_COPY_AND_ASSIGN(InputMethodButton); -}; - -// This is a native button associated with UI language information. -class UiLanguageButton : public views::NativeButton { - public: - UiLanguageButton(views::ButtonListener* listener, - const std::wstring& label, - const std::string& language_code) - : views::NativeButton(listener, label), - language_code_(language_code) { - } - - const std::string& language_code() const { - return language_code_; - } - - private: - std::string language_code_; - DISALLOW_COPY_AND_ASSIGN(UiLanguageButton); -}; - -// This is a checkbox button associated with input method information. -class InputMethodCheckbox : public views::Checkbox { - public: - InputMethodCheckbox(const std::wstring& display_name, - const std::string& input_method_id) - : views::Checkbox(display_name), - input_method_id_(input_method_id) { - } - - const std::string& input_method_id() const { - return input_method_id_; - } - - private: - std::string input_method_id_; - DISALLOW_COPY_AND_ASSIGN(InputMethodCheckbox); -}; - -LanguageConfigView::LanguageConfigView(Profile* profile) - : OptionsPageView(profile), - model_(profile->GetPrefs()), - root_container_(NULL), - right_container_(NULL), - remove_language_button_(NULL), - preferred_language_table_(NULL) { -} - -LanguageConfigView::~LanguageConfigView() { -} - -void LanguageConfigView::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender->tag() == kRemoveLanguageButton) { - OnRemoveLanguage(); - } else if (sender->tag() == kSelectInputMethodButton) { - InputMethodCheckbox* checkbox = - static_cast<InputMethodCheckbox*>(sender); - const std::string& input_method_id = checkbox->input_method_id(); - model_.SetInputMethodActivated(input_method_id, checkbox->checked()); - if (checkbox->checked()) { - EnableAllCheckboxes(); - } else { - MaybeDisableLastCheckbox(); - } - } else if (sender->tag() == kConfigureInputMethodButton) { - InputMethodButton* button = static_cast<InputMethodButton*>(sender); - views::DialogDelegate* config_view = - CreateInputMethodConfigureView(button->input_method_id()); - if (!config_view) { - DLOG(FATAL) << "Config view not found: " << button->input_method_id(); - return; - } - views::Window* window = browser::CreateViewsWindow( - GetOptionsViewParent(), gfx::Rect(), config_view); - window->SetIsAlwaysOnTop(true); - window->Show(); - } else if (sender->tag() == kChangeUiLanguageButton) { - UiLanguageButton* button = static_cast<UiLanguageButton*>(sender); - PrefService* prefs = g_browser_process->local_state(); - if (prefs) { - prefs->SetString(prefs::kApplicationLocale, button->language_code()); - prefs->SavePersistentPrefs(); - RestartMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow()); - } - } -} - -std::wstring LanguageConfigView::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_DONE)); - } - return L""; -} - -std::wstring LanguageConfigView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_DIALOG_TITLE)); -} - -void LanguageConfigView::Layout() { - // Not sure why but this is needed to show contents in the dialog. - root_container_->SetBounds(0, 0, width(), height()); -} - -gfx::Size LanguageConfigView::GetPreferredSize() { - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, - IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES)); -} - -void LanguageConfigView::OnSelectionChanged() { - right_container_->RemoveAllChildViews(true); // Delete the child views. - - const int row = preferred_language_table_->GetFirstSelectedRow(); - const std::string& language_code = model_.preferred_language_code_at(row); - - // Count the number of all active input methods. - std::vector<std::string> active_input_method_ids; - model_.GetActiveInputMethodIds(&active_input_method_ids); - const int num_all_active_input_methods = active_input_method_ids.size(); - - // Count the number of active input methods for the selected language. - int num_selected_active_input_methods = - model_.CountNumActiveInputMethods(language_code); - - bool remove_button_enabled = false; - // Allow removing the language only if the following conditions are met: - // 1. There are more than one language. - // 2. The languge in the current row is not set to the display language. - // 3. Removing the selected language does not result in "zero input method". - if (preferred_language_table_->GetRowCount() > 1 && - language_code != g_browser_process->GetApplicationLocale() && - num_all_active_input_methods > num_selected_active_input_methods) { - remove_button_enabled = true; - } - remove_language_button_->SetEnabled(remove_button_enabled); - - // Add the per language config view to the right area. - right_container_->AddChildView(CreatePerLanguageConfigView(language_code)); - MaybeDisableLastCheckbox(); - // Layout the right container. This is needed for the contents on the - // right to be displayed properly. - right_container_->Layout(); -} - -string16 LanguageConfigView::GetText(int row, int column_id) { - if (row >= 0 && row < static_cast<int>( - model_.num_preferred_language_codes())) { - return input_method::GetLanguageDisplayNameFromCode( - model_.preferred_language_code_at(row)); - } - NOTREACHED(); - return string16(); -} - -void LanguageConfigView::SetObserver(ui::TableModelObserver* observer) { - // We don't need the observer for the table mode, since we implement the - // table model as part of the LanguageConfigView class. - // http://crbug.com/38266 -} - -int LanguageConfigView::RowCount() { - // Returns the number of rows of the language table. - return model_.num_preferred_language_codes(); -} - -void LanguageConfigView::ItemChanged(views::Combobox* combobox, - int prev_index, - int new_index) { - // Ignore the first item used for showing "Add language". - if (new_index <= 0) { - return; - } - // Get the language selected. - std::string language_selected = add_language_combobox_model_-> - GetLocaleFromIndex( - add_language_combobox_model_->GetLanguageIndex(new_index)); - OnAddLanguage(language_selected); -} - -void LanguageConfigView::InitControlLayout() { - // Initialize the map. - InitInputMethodConfigViewMap(); - - root_container_ = new views::View; - AddChildView(root_container_); - - // Set up the layout manager for the root container. We'll place the - // language table on the left, and the per language config on the right. - GridLayout* root_layout = new GridLayout(root_container_); - root_container_->SetLayoutManager(root_layout); - root_layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, - kPanelVertMargin, kPanelHorizMargin); - - // Set up column sets for the grid layout. - const int kMainColumnSetId = 0; - ColumnSet* column_set = root_layout->AddColumnSet(kMainColumnSetId); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, - GridLayout::FIXED, kPreferredLanguageTableWidth, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0, - GridLayout::USE_PREF, 0, 0); - const int kBottomColumnSetId = 1; - column_set = root_layout->AddColumnSet(kBottomColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // Set up the container for the contents on the right. Just adds a - // place holder here. This will get replaced in OnSelectionChanged(). - right_container_ = new views::View; - right_container_->SetLayoutManager(new views::FillLayout); - right_container_->AddChildView(new views::View); - - // Add the contents on the left and the right. - root_layout->StartRow(1 /* expand */, kMainColumnSetId); - root_layout->AddView(CreateContentsOnLeft()); - root_layout->AddView(right_container_); - - // Add the contents on the bottom. - root_layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - root_layout->StartRow(0, kBottomColumnSetId); - root_layout->AddView(CreateContentsOnBottom()); - - // Select the first row in the language table. - // There should be at least one language in the table, but we check it - // here so this won't result in crash in case there is no row in the table. - if (model_.num_preferred_language_codes() > 0) { - preferred_language_table_->SelectRow(0); - } -} - -void LanguageConfigView::Show(Profile* profile, gfx::NativeWindow parent) { - UserMetrics::RecordAction(UserMetricsAction("LanguageConfigView_Open")); - views::Window* window = browser::CreateViewsWindow( - parent, gfx::Rect(), new LanguageConfigView(profile)); - window->SetIsAlwaysOnTop(true); - window->Show(); -} - -void LanguageConfigView::InitInputMethodConfigViewMap() { - input_method_config_view_map_["chewing"] = CreateLanguageChewingConfigView; - input_method_config_view_map_["hangul"] = CreateLanguageHangulConfigView; - input_method_config_view_map_["mozc"] = CreateLanguageMozcConfigView; - input_method_config_view_map_["mozc-dv"] = CreateLanguageMozcConfigView; - input_method_config_view_map_["mozc-jp"] = CreateLanguageMozcConfigView; - input_method_config_view_map_["pinyin"] = CreateLanguagePinyinConfigView; -} - -void LanguageConfigView::OnAddLanguage(const std::string& language_code) { - // Skip if the language is already in the preferred_language_codes_. - if (model_.HasLanguageCode(language_code)) { - return; - } - // Activate the first input language associated with the language. We have - // to call this before the OnItemsAdded() call below so the checkbox - // for the first input language gets checked. - std::vector<std::string> input_method_ids; - model_.GetInputMethodIdsFromLanguageCode(language_code, &input_method_ids); - if (!input_method_ids.empty()) { - model_.SetInputMethodActivated(input_method_ids[0], true); - } - - // Append the language to the list of language codes. - const int added_at = model_.AddLanguageCode(language_code); - // Notify the table that the new row added at |added_at|. - preferred_language_table_->OnItemsAdded(added_at, 1); - // For some reason, OnItemsAdded() alone does not redraw the table. Need - // to tell the table that items are changed. TODO(satorux): Investigate - // if it's a bug in TableView2. - preferred_language_table_->OnItemsChanged( - 0, model_.num_preferred_language_codes()); - // Switch to the row added. - preferred_language_table_->SelectRow(added_at); - - // Mark the language to be ignored. - add_language_combobox_model_->SetIgnored(language_code, true); - ResetAddLanguageCombobox(); -} - -void LanguageConfigView::OnRemoveLanguage() { - const int row = preferred_language_table_->GetFirstSelectedRow(); - const std::string& language_code = model_.preferred_language_code_at(row); - // Mark the language not to be ignored. - add_language_combobox_model_->SetIgnored(language_code, false); - ResetAddLanguageCombobox(); - // Deactivate the associated input methods. - model_.DeactivateInputMethodsFor(language_code); - // Remove the language code and the row from the table. - model_.RemoveLanguageAt(row); - preferred_language_table_->OnItemsRemoved(row, 1); - // Switch to the previous row, or the first row. - // There should be at least one row in the table. - preferred_language_table_->SelectRow(std::max(row - 1, 0)); -} - -void LanguageConfigView::ResetAddLanguageCombobox() { - // -1 to ignore "Add language". If there are more than one language, - // enable the combobox. Otherwise, disable it. - if (add_language_combobox_model_->GetItemCount() - 1 > 0) { - add_language_combobox_->SetEnabled(true); - } else { - add_language_combobox_->SetEnabled(false); - } - // Go back to the initial "Add language" state. - add_language_combobox_->ModelChanged(); - add_language_combobox_->SetSelectedItem(0); -} - -views::View* LanguageConfigView::CreateContentsOnLeft() { - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - // Set up column sets for the grid layout. - const int kTableColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kTableColumnSetId); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - // Create the language table. - std::vector<TableColumn> columns; - TableColumn column(0, - l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_LANGUAGES), - TableColumn::LEFT, -1, 0); - columns.push_back(column); - // We don't show horizontal and vertical lines. - const int options = (views::TableView2::SINGLE_SELECTION | - views::TableView2::RESIZABLE_COLUMNS | - views::TableView2::AUTOSIZE_COLUMNS); - preferred_language_table_ = - new views::TableView2(this, columns, views::TEXT_ONLY, options); - // Set the observer so OnSelectionChanged() will be invoked when a - // selection is changed in the table. - preferred_language_table_->SetObserver(this); - - // Add the language table. - layout->StartRow(1 /* expand vertically */, kTableColumnSetId); - layout->AddView(preferred_language_table_); - - return contents; -} - -views::View* LanguageConfigView::CreateContentsOnBottom() { - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - // Set up column sets for the grid layout. - const int kButtonsColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kButtonsColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, - GridLayout::USE_PREF, 0, 0); - - // Create the add language combobox model_. - // LanguageComboboxModel sorts languages by their display names. - add_language_combobox_model_.reset( - new AddLanguageComboboxModel(NULL, model_.supported_language_codes())); - // Mark the existing preferred languages to be ignored. - for (size_t i = 0; i < model_.num_preferred_language_codes(); ++i) { - add_language_combobox_model_->SetIgnored( - model_.preferred_language_code_at(i), - true); - } - // Create the add language combobox. - add_language_combobox_ - = new views::Combobox(add_language_combobox_model_.get()); - add_language_combobox_->set_listener(this); - ResetAddLanguageCombobox(); - - // Create the remove button. - remove_language_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON))); - remove_language_button_->set_tag(kRemoveLanguageButton); - - // Add the add and remove buttons. - layout->StartRow(0, kButtonsColumnSetId); - layout->AddView(add_language_combobox_); - layout->AddView(remove_language_button_); - - return contents; -} - -views::View* LanguageConfigView::CreatePerLanguageConfigView( - const std::string& target_language_code) { - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - // Set up column sets for the grid layout. - ColumnSet* column_set = layout->AddColumnSet(kPerLanguageTitleColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - column_set = layout->AddColumnSet(kPerLanguageDoubleColumnSetId); - column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - column_set = layout->AddColumnSet(kPerLanguageSingleColumnSetId); - column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - AddUiLanguageSection(target_language_code, layout); - layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); - AddInputMethodSection(target_language_code, layout); - - return contents; -} - -void LanguageConfigView::AddUiLanguageSection(const std::string& language_code, - views::GridLayout* layout) { - // Create the language name label. - const std::string application_locale = - g_browser_process->GetApplicationLocale(); - const string16 language_name16 = l10n_util::GetDisplayNameForLocale( - language_code, application_locale, true); - const std::wstring language_name = UTF16ToWide(language_name16); - views::Label* language_name_label = new views::Label(language_name); - language_name_label->SetFont( - language_name_label->font().DeriveFont(0, gfx::Font::BOLD)); - - // Add the language name label. - layout->StartRow(0, kPerLanguageTitleColumnSetId); - layout->AddView(language_name_label); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - - layout->StartRow(0, kPerLanguageSingleColumnSetId); - if (application_locale == language_code) { - layout->AddView( - new views::Label( - UTF16ToWide(l10n_util::GetStringFUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, - l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))))); - } else { - UiLanguageButton* button = new UiLanguageButton( - this, UTF16ToWide(l10n_util::GetStringFUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, - l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))), - language_code); - button->set_tag(kChangeUiLanguageButton); - layout->AddView(button); - } -} - -void LanguageConfigView::AddInputMethodSection( - const std::string& language_code, - views::GridLayout* layout) { - // Create the input method title label. - views::Label* input_method_title_label = new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD))); - input_method_title_label->SetFont( - input_method_title_label->font().DeriveFont(0, gfx::Font::BOLD)); - - // Add the input method title label. - layout->StartRow(0, kPerLanguageTitleColumnSetId); - layout->AddView(input_method_title_label); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - - // Add input method names and configuration buttons. - input_method_checkboxes_.clear(); - - // Get the list of input method ids associated with the language code. - std::vector<std::string> input_method_ids; - model_.GetInputMethodIdsFromLanguageCode(language_code, &input_method_ids); - - for (size_t i = 0; i < input_method_ids.size(); ++i) { - const std::string& input_method_id = input_method_ids[i]; - const std::string display_name = - input_method::GetInputMethodDisplayNameFromId(input_method_id); - layout->StartRow(0, kPerLanguageDoubleColumnSetId); - InputMethodCheckbox* checkbox - = new InputMethodCheckbox(UTF8ToWide(display_name), - input_method_id); - checkbox->set_listener(this); - checkbox->set_tag(kSelectInputMethodButton); - if (model_.InputMethodIsActivated(input_method_id)) { - checkbox->SetChecked(true); - } - - layout->AddView(checkbox); - input_method_checkboxes_.insert(checkbox); - // Add "configure" button for the input method if we have a - // configuration dialog for it. - if (input_method_config_view_map_.count(input_method_id) > 0) { - InputMethodButton* button = new InputMethodButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE)), - input_method_id); - button->set_tag(kConfigureInputMethodButton); - layout->AddView(button); - } - } -} - -views::DialogDelegate* LanguageConfigView::CreateInputMethodConfigureView( - const std::string& input_method_id) { - InputMethodConfigViewMap::const_iterator iter = - input_method_config_view_map_.find(input_method_id); - if (iter != input_method_config_view_map_.end()) { - CreateDialogDelegateFunction function = iter->second; - return function(profile()); - } - return NULL; -} - -void LanguageConfigView::MaybeDisableLastCheckbox() { - std::vector<std::string> input_method_ids; - model_.GetActiveInputMethodIds(&input_method_ids); - if (input_method_ids.size() <= 1) { - for (std::set<InputMethodCheckbox*>::iterator checkbox = - input_method_checkboxes_.begin(); - checkbox != input_method_checkboxes_.end(); ++checkbox) { - if ((*checkbox)->checked()) - (*checkbox)->SetEnabled(false); - } - } -} - -void LanguageConfigView::EnableAllCheckboxes() { - for (std::set<InputMethodCheckbox*>::iterator checkbox = - input_method_checkboxes_.begin(); - checkbox != input_method_checkboxes_.end(); ++checkbox) { - (*checkbox)->SetEnabled(true); - } -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h deleted file mode 100644 index 08a8083..0000000 --- a/chrome/browser/chromeos/options/language_config_view.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_VIEW_H_ -#pragma once - -#include <map> -#include <set> -#include <string> - -#include "base/compiler_specific.h" -#include "chrome/browser/chromeos/options/language_config_model.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "ui/base/models/table_model.h" -#include "views/controls/button/native_button.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/label.h" -#include "views/controls/table/table_view2.h" -#include "views/controls/table/table_view_observer.h" -#include "views/grid_layout.h" -#include "views/window/dialog_delegate.h" - -namespace chromeos { - -class InputMethodButton; -class InputMethodCheckbox; -class PreferredLanguageTableModel; - -// A dialog box for configuring the languages. -class LanguageConfigView : public ui::TableModel, - public views::ButtonListener, - public views::Combobox::Listener, - public views::DialogDelegate, - public views::TableViewObserver, - public OptionsPageView { - public: - explicit LanguageConfigView(Profile* profile); - virtual ~LanguageConfigView(); - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, - const views::Event& event); - - // views::DialogDelegate overrides. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual int GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_OK; - } - virtual std::wstring GetWindowTitle() const; - - // views::View overrides: - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // views::TableViewObserver overrides: - virtual void OnSelectionChanged(); - - // TableModel overrides: - // To workaround crbug.com/38266, implement TreeModel as part of - // LanguageConfigView class, rather than a separate class. - // TODO(satorux): Implement TableModel as a separate class once the bug - // is fixed. - virtual string16 GetText(int row, int column_id) OVERRIDE; - virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; - virtual int RowCount() OVERRIDE; - - // views::Combobox::Listener overrides: - virtual void ItemChanged(views::Combobox* combobox, - int prev_index, - int new_index); - - // OptionsPageView overrides. - virtual void InitControlLayout(); - - // Shows the language config dialog in a new window. - static void Show(Profile* profile, gfx::NativeWindow parent); - - private: - // Initializes the input method config view. - void InitInputMethodConfigViewMap(); - - // Invoked when a language is added by the add combobox. - void OnAddLanguage(const std::string& language_code); - - // Invoked when a language is removed by the remove button. - void OnRemoveLanguage(); - - // Resets the add language combobox to the initial "Add language" state. - void ResetAddLanguageCombobox(); - - // Creates the contents on the left, including the language table. - views::View* CreateContentsOnLeft(); - - // Creates the contents on the bottom, including the add language button. - views::View* CreateContentsOnBottom(); - - // Creates the per-language config view. - views::View* CreatePerLanguageConfigView(const std::string& language_code); - - // Adds the UI language section in the per-language config view. - void AddUiLanguageSection(const std::string& language_code, - views::GridLayout* layout); - - // Adds the input method section in the per-language config view. - void AddInputMethodSection(const std::string& language_code, - views::GridLayout* layout); - - // Creates the input method config view based on the given |input_method_id|. - // Returns NULL if the config view is not found. - views::DialogDelegate* CreateInputMethodConfigureView( - const std::string& input_method_id); - - // If there is only one input method left, disable the selected method. - // This is done to prevent the user from disabling all input methods. - void MaybeDisableLastCheckbox(); - - // Enable all input method checkboxes. - void EnableAllCheckboxes(); - - // The model of the view. - LanguageConfigModel model_; - - // The map of the input method id to a pointer to the function for - // creating the input method configuration dialog. - typedef views::DialogDelegate* (*CreateDialogDelegateFunction)(Profile*); - typedef std::map<std::string, - CreateDialogDelegateFunction> InputMethodConfigViewMap; - InputMethodConfigViewMap input_method_config_view_map_; - - // The checkboxes for activating input methods for a language. - std::set<InputMethodCheckbox*> input_method_checkboxes_; - - views::View* root_container_; - views::View* right_container_; - views::NativeButton* remove_language_button_; - views::TableView2* preferred_language_table_; - scoped_ptr<AddLanguageComboboxModel> add_language_combobox_model_; - views::Combobox* add_language_combobox_; - - DISALLOW_COPY_AND_ASSIGN(LanguageConfigView); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_VIEW_H_ diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.cc b/chrome/browser/chromeos/options/language_hangul_config_view.cc deleted file mode 100644 index 3a190aa..0000000 --- a/chrome/browser/chromeos/options/language_hangul_config_view.cc +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_hangul_config_view.h" - -#include "app/l10n_util.h" -#include "base/string16.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/language_preferences.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/pref_names.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "ui/base/models/combobox_model.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/label.h" -#include "views/grid_layout.h" -#include "views/standard_layout.h" -#include "views/window/window.h" - -namespace chromeos { - -// The combobox model for the list of hangul keyboards. -class HangulKeyboardComboboxModel : public ui::ComboboxModel { - public: - HangulKeyboardComboboxModel() { - for (size_t i = 0; i < language_prefs::kNumHangulKeyboardNameIDPairs; - ++i) { - layouts_.push_back(std::make_pair( - l10n_util::GetStringUTF8( - language_prefs::kHangulKeyboardNameIDPairs[i].message_id), - language_prefs::kHangulKeyboardNameIDPairs[i].keyboard_id)); - } - } - - // Implements ui::ComboboxModel interface. - virtual int GetItemCount() { - return static_cast<int>(layouts_.size()); - } - - // Implements ui::ComboboxModel interface. - virtual string16 GetItemAt(int index) { - if (index < 0 || index > GetItemCount()) { - LOG(ERROR) << "Index is out of bounds: " << index; - return string16(); - } - return UTF8ToUTF16(layouts_.at(index).first); - } - - // Gets a keyboard layout ID (e.g. "2", "3f", ..) for an item at zero-origin - // |index|. This function is NOT part of the ComboboxModel interface. - std::string GetItemIDAt(int index) { - if (index < 0 || index > GetItemCount()) { - LOG(ERROR) << "Index is out of bounds: " << index; - return ""; - } - return layouts_.at(index).second; - } - - // Gets an index (>= 0) of an item whose keyboard layout ID is |layout_ld|. - // Returns -1 if such item is not found. This function is NOT part of the - // ComboboxModel interface. - int GetIndexFromID(const std::string& layout_id) { - for (size_t i = 0; i < layouts_.size(); ++i) { - if (GetItemIDAt(i) == layout_id) { - return static_cast<int>(i); - } - } - return -1; - } - - private: - std::vector<std::pair<std::string, std::string> > layouts_; - DISALLOW_COPY_AND_ASSIGN(HangulKeyboardComboboxModel); -}; - -LanguageHangulConfigView::LanguageHangulConfigView(Profile* profile) - : OptionsPageView(profile), - contents_(NULL), - hangul_keyboard_combobox_(NULL), - hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel) { - keyboard_pref_.Init( - prefs::kLanguageHangulKeyboard, profile->GetPrefs(), this); -} - -LanguageHangulConfigView::~LanguageHangulConfigView() { -} - -void LanguageHangulConfigView::ItemChanged( - views::Combobox* sender, int prev_index, int new_index) { - const std::string id = - hangul_keyboard_combobox_model_->GetItemIDAt(new_index); - VLOG(1) << "Changing Hangul keyboard pref to " << id; - keyboard_pref_.SetValue(id); -} - -void LanguageHangulConfigView::Layout() { - // Not sure why but this is needed to show contents in the dialog. - contents_->SetBounds(0, 0, width(), height()); -} - -int LanguageHangulConfigView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_OK; -} - -std::wstring LanguageHangulConfigView::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK)); - } - return L""; -} - -std::wstring LanguageHangulConfigView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_HANGUL_SETTINGS_TITLE)); -} - -gfx::Size LanguageHangulConfigView::GetPreferredSize() { - // TODO(satorux): Create our own localized content size once the UI is done. - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, - IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES)); -} - -void LanguageHangulConfigView::InitControlLayout() { - using views::ColumnSet; - using views::GridLayout; - - contents_ = new views::View; - AddChildView(contents_); - - GridLayout* layout = new GridLayout(contents_); - layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, - kPanelVertMargin, kPanelHorizMargin); - contents_->SetLayoutManager(layout); - - const int kColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, kColumnSetId); - - // Settings for the Hangul IME. - layout->AddView(new views::Label(UTF16ToWide( - l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_KEYBOARD_LAYOUT_TEXT)))); - - hangul_keyboard_combobox_ - = new views::Combobox(hangul_keyboard_combobox_model_.get()); - hangul_keyboard_combobox_->set_listener(this); - - // Initialize the combobox to what's saved in user preferences. Otherwise, - // ItemChanged() will be called with |new_index| == 0. - NotifyPrefChanged(); - layout->AddView(hangul_keyboard_combobox_); -} - -void LanguageHangulConfigView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - // Observe(PREF_CHANGED) is called when the chromeos::Preferences object - // changed the prefs::kLanguageHangulKeyboard preference. Note that this - // function is NOT called when this dialog calls keyboard_pref_.SetValue(). - NotifyPrefChanged(); - } -} - -void LanguageHangulConfigView::NotifyPrefChanged() { - const std::string id = keyboard_pref_.GetValue(); - const int index = - hangul_keyboard_combobox_model_->GetIndexFromID(id); - if (index >= 0) - hangul_keyboard_combobox_->SetSelectedItem(index); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.h b/chrome/browser/chromeos/options/language_hangul_config_view.h deleted file mode 100644 index 55bcef9..0000000 --- a/chrome/browser/chromeos/options/language_hangul_config_view.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_HANGUL_CONFIG_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_HANGUL_CONFIG_VIEW_H_ -#pragma once - -#include <string> - -#include "base/scoped_ptr.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/label.h" -#include "views/window/dialog_delegate.h" - -namespace chromeos { - -class HangulKeyboardComboboxModel; - -// A dialog box for showing Korean input method preferences. -class LanguageHangulConfigView : public views::Combobox::Listener, - public views::DialogDelegate, - public OptionsPageView { - public: - explicit LanguageHangulConfigView(Profile* profile); - virtual ~LanguageHangulConfigView(); - - // views::Combobox::Listener overrides. - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - // views::DialogDelegate overrides. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual std::wstring GetWindowTitle() const; - - // views::View overrides. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // OptionsPageView overrides. - virtual void InitControlLayout(); - - // NotificationObserver overrides. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Updates the hangul keyboard combobox. - void NotifyPrefChanged(); - - StringPrefMember keyboard_pref_; - views::View* contents_; - - // A combobox for Hangul keyboard layouts and its model. - views::Combobox* hangul_keyboard_combobox_; - scoped_ptr<HangulKeyboardComboboxModel> hangul_keyboard_combobox_model_; - - DISALLOW_COPY_AND_ASSIGN(LanguageHangulConfigView); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_HANGUL_CONFIG_VIEW_H_ diff --git a/chrome/browser/chromeos/options/language_mozc_config_view.cc b/chrome/browser/chromeos/options/language_mozc_config_view.cc deleted file mode 100644 index d86a62e..0000000 --- a/chrome/browser/chromeos/options/language_mozc_config_view.cc +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_mozc_config_view.h" - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/options/language_config_util.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/notification_type.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/button/native_button.h" -#include "views/grid_layout.h" -#include "views/standard_layout.h" -#include "views/window/window.h" - -namespace { -// The tags are used to identify buttons in ButtonPressed(). -enum ButtonTag { - // 0 to kNumMozcBooleanPrefs - 1 are reserved for the checkboxes for integer - // preferences. - kResetToDefaultsButton = chromeos::language_prefs::kNumMozcBooleanPrefs, -}; -} // namespace - -namespace chromeos { - -LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile) - : OptionsPageView(profile), - contents_(NULL), - reset_to_defaults_button_(NULL) { - for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { - MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; - current.boolean_pref.Init( - language_prefs::kMozcBooleanPrefs[i].pref_name, profile->GetPrefs(), - this); - current.checkbox = NULL; - } - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.multiple_choice_pref.Init( - language_prefs::kMozcMultipleChoicePrefs[i].pref_name, - profile->GetPrefs(), this); - current.combobox_model = - new LanguageComboboxModel<const char*>( - &language_prefs::kMozcMultipleChoicePrefs[i]); - current.combobox = NULL; - } - for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { - MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; - current.integer_pref.Init( - language_prefs::kMozcIntegerPrefs[i].pref_name, profile->GetPrefs(), - this); - current.slider = NULL; - } -} - -LanguageMozcConfigView::~LanguageMozcConfigView() { - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - delete prefs_and_comboboxes_[i].combobox_model; - } -} - -void LanguageMozcConfigView::ButtonPressed( - views::Button* sender, const views::Event& event) { - const int pref_id = sender->tag(); - if (pref_id == kResetToDefaultsButton) { - ResetToDefaults(); - return; - } - views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); - DCHECK(pref_id >= 0 && pref_id < static_cast<int>( - language_prefs::kNumMozcBooleanPrefs)); - prefs_and_checkboxes_[pref_id].boolean_pref.SetValue(checkbox->checked()); -} - -void LanguageMozcConfigView::ItemChanged( - views::Combobox* sender, int prev_index, int new_index) { - if (new_index < 0 || sender->model()->GetItemCount() <= new_index) { - LOG(ERROR) << "Invalid new_index: " << new_index; - return; - } - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - if (current.combobox == sender) { - const std::string config_value = - current.combobox_model->GetConfigValueAt(new_index); - VLOG(1) << "Changing Mozc pref to " << config_value; - // Update the Chrome pref. - current.multiple_choice_pref.SetValue(config_value); - break; - } - } -} - -void LanguageMozcConfigView::SliderValueChanged(views::Slider* sender) { - size_t pref_id; - for (pref_id = 0; pref_id < language_prefs::kNumMozcIntegerPrefs; - ++pref_id) { - if (prefs_and_sliders_[pref_id].slider == sender) - break; - } - DCHECK(pref_id < language_prefs::kNumMozcIntegerPrefs); - prefs_and_sliders_[pref_id].integer_pref.SetValue(sender->value()); -} - -void LanguageMozcConfigView::Layout() { - // Not sure why but this is needed to show contents in the dialog. - contents_->SetBounds(0, 0, width(), height()); -} - -int LanguageMozcConfigView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_OK; -} - -std::wstring LanguageMozcConfigView::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK)); - } - return L""; -} - -std::wstring LanguageMozcConfigView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_SETTINGS_TITLE)); -} - -gfx::Size LanguageMozcConfigView::GetPreferredSize() { - // TODO(satorux): Create our own localized content size once the UI is done. - gfx::Size preferred_size = views::Window::GetLocalizedContentsSize( - IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, - IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES); - // TODO(mazda): Remove the manual adjustment. - // The padding is needed for accommodating all the controls in the dialog. - const int kHeightPadding = 80; - preferred_size.Enlarge(0, kHeightPadding); - return preferred_size; -} - -void LanguageMozcConfigView::InitControlLayout() { - using views::ColumnSet; - using views::GridLayout; - - contents_ = new views::View; - AddChildView(contents_); - - GridLayout* layout = new GridLayout(contents_); - layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, - kPanelVertMargin, kPanelHorizMargin); - contents_->SetLayoutManager(layout); - - const int kColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { - MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; - current.checkbox = new views::Checkbox(UTF16ToWide( - l10n_util::GetStringUTF16( - language_prefs::kMozcBooleanPrefs[i].message_id))); - current.checkbox->set_listener(this); - current.checkbox->set_tag(i); - } - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.combobox = new LanguageCombobox(current.combobox_model); - current.combobox->set_listener(this); - } - for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { - MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; - current.slider = new views::Slider( - language_prefs::kMozcIntegerPrefs[i].min_pref_value, - language_prefs::kMozcIntegerPrefs[i].max_pref_value, - 1, - static_cast<views::Slider::StyleFlags>( - views::Slider::STYLE_DRAW_VALUE | - views::Slider::STYLE_UPDATE_ON_RELEASE), - this); - } - NotifyPrefChanged(); // Sync the comboboxes with current Chrome prefs. - - reset_to_defaults_button_ = new views::NativeButton( - this, UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_MOZC_RESET_TO_DEFAULTS_BUTTON))); - reset_to_defaults_button_->set_tag(kResetToDefaultsButton); - layout->StartRow(0, kColumnSetId); - layout->AddView(reset_to_defaults_button_); - - // Show the checkboxes. - for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { - const MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; - layout->StartRow(0, kColumnSetId); - layout->AddView(current.checkbox, 3, 1); - } - // Show the comboboxes. - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - const MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - layout->StartRow(0, kColumnSetId); - layout->AddView(new views::Label(current.combobox_model->GetLabel())); - layout->AddView(current.combobox); - } - for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { - const MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; - layout->StartRow(0, kColumnSetId); - layout->AddView(new views::Label( - UTF16ToWide(l10n_util::GetStringUTF16( - language_prefs::kMozcIntegerPrefs[i].message_id)))); - layout->AddView(current.slider); - } - NotifyPrefChanged(); // Sync the slider with current Chrome prefs. -} - -void LanguageMozcConfigView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - NotifyPrefChanged(); - } -} - -void LanguageMozcConfigView::NotifyPrefChanged() { - // Update comboboxes. - // TODO(yusukes): We don't have to update all UI controls. - for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { - MozcPrefAndAssociatedCheckbox& current = prefs_and_checkboxes_[i]; - const bool checked = current.boolean_pref.GetValue(); - current.checkbox->SetChecked(checked); - } - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - const std::string value = current.multiple_choice_pref.GetValue(); - for (int i = 0; i < current.combobox_model->num_items(); ++i) { - if (current.combobox_model->GetConfigValueAt(i) == value) { - current.combobox->SetSelectedItem(i); - break; - } - } - } - for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { - MozcPrefAndAssociatedSlider& current = prefs_and_sliders_[i]; - const int value = current.integer_pref.GetValue(); - current.slider->SetValue(value); - } -} - -void LanguageMozcConfigView::ResetToDefaults() { - for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { - prefs_and_checkboxes_[i].boolean_pref.SetValue( - language_prefs::kMozcBooleanPrefs[i].default_pref_value); - } - for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { - prefs_and_comboboxes_[i].multiple_choice_pref.SetValue( - language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value); - } - for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { - prefs_and_sliders_[i].integer_pref.SetValue( - language_prefs::kMozcIntegerPrefs[i].default_pref_value); - } - // Reflect the preference changes to the controls. - NotifyPrefChanged(); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_mozc_config_view.h b/chrome/browser/chromeos/options/language_mozc_config_view.h deleted file mode 100644 index 6afd504..0000000 --- a/chrome/browser/chromeos/options/language_mozc_config_view.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_MOZC_CONFIG_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_MOZC_CONFIG_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/language_preferences.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/label.h" -#include "views/controls/slider/slider.h" -#include "views/window/dialog_delegate.h" - -namespace views { -class Button; -class Checkbox; -} - -namespace chromeos { - -class LanguageCombobox; -template <typename DataType> -class LanguageComboboxModel; - -// A dialog box for showing Mozc (Japanese input method) preferences. -class LanguageMozcConfigView : public views::ButtonListener, - public views::Combobox::Listener, - public views::DialogDelegate, - public views::SliderListener, - public OptionsPageView { - public: - explicit LanguageMozcConfigView(Profile* profile); - virtual ~LanguageMozcConfigView(); - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::Combobox::Listener overrides. - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - // views::SliderListener overrides. - virtual void SliderValueChanged(views::Slider* sender); - - // views::DialogDelegate overrides. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual std::wstring GetWindowTitle() const; - - // views::View overrides. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // OptionsPageView overrides. - virtual void InitControlLayout(); - - // NotificationObserver overrides. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Updates the mozc keyboard combobox. - void NotifyPrefChanged(); - - // Resets all the preferences to the default values. - void ResetToDefaults(); - - views::View* contents_; - - views::Button* reset_to_defaults_button_; - - struct MozcPrefAndAssociatedCheckbox { - BooleanPrefMember boolean_pref; - views::Checkbox* checkbox; - } prefs_and_checkboxes_[language_prefs::kNumMozcBooleanPrefs]; - - struct MozcPrefAndAssociatedCombobox { - StringPrefMember multiple_choice_pref; - LanguageComboboxModel<const char*>* combobox_model; - LanguageCombobox* combobox; - } prefs_and_comboboxes_[language_prefs::kNumMozcMultipleChoicePrefs]; - - struct MozcPrefAndAssociatedSlider { - IntegerPrefMember integer_pref; - views::Slider* slider; - } prefs_and_sliders_[language_prefs::kNumMozcIntegerPrefs]; - - DISALLOW_COPY_AND_ASSIGN(LanguageMozcConfigView); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_MOZC_CONFIG_VIEW_H_ diff --git a/chrome/browser/chromeos/options/language_pinyin_config_view.cc b/chrome/browser/chromeos/options/language_pinyin_config_view.cc deleted file mode 100644 index 9f506f4..0000000 --- a/chrome/browser/chromeos/options/language_pinyin_config_view.cc +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/options/language_pinyin_config_view.h" - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/options/language_config_util.h" -#include "chrome/browser/chromeos/preferences.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/notification_type.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/label.h" -#include "views/grid_layout.h" -#include "views/standard_layout.h" -#include "views/window/window.h" - -namespace chromeos { - -LanguagePinyinConfigView::LanguagePinyinConfigView(Profile* profile) - : OptionsPageView(profile), contents_(NULL) { - for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { - pinyin_boolean_prefs_[i].Init( - language_prefs::kPinyinBooleanPrefs[i].pref_name, profile->GetPrefs(), - this); - pinyin_boolean_checkboxes_[i] = NULL; - } - - double_pinyin_schema_.multiple_choice_pref.Init( - language_prefs::kPinyinDoublePinyinSchema.pref_name, - profile->GetPrefs(), this); - double_pinyin_schema_.combobox_model = - new LanguageComboboxModel<int>( - &language_prefs::kPinyinDoublePinyinSchema); - double_pinyin_schema_.combobox = NULL; -} - -LanguagePinyinConfigView::~LanguagePinyinConfigView() { -} - -void LanguagePinyinConfigView::ButtonPressed( - views::Button* sender, const views::Event& event) { - views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); - const int pref_id = checkbox->tag(); - DCHECK(pref_id >= 0 && pref_id < static_cast<int>( - language_prefs::kNumPinyinBooleanPrefs)); - pinyin_boolean_prefs_[pref_id].SetValue(checkbox->checked()); -} - -void LanguagePinyinConfigView::ItemChanged( - views::Combobox* sender, int prev_index, int new_index) { - if (double_pinyin_schema_.combobox == sender) { - const int config_value = - double_pinyin_schema_.combobox_model->GetConfigValueAt(new_index); - VLOG(1) << "Changing Pinyin pref to " << config_value; - // Update the Chrome pref. - double_pinyin_schema_.multiple_choice_pref.SetValue(config_value); - } -} - -void LanguagePinyinConfigView::Layout() { - // Not sure why but this is needed to show contents in the dialog. - contents_->SetBounds(0, 0, width(), height()); -} - -int LanguagePinyinConfigView::GetDialogButtons() const { - return MessageBoxFlags::DIALOGBUTTON_OK; -} - -std::wstring LanguagePinyinConfigView::GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK)); - } - return L""; -} - -std::wstring LanguagePinyinConfigView::GetWindowTitle() const { - return UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_SETTINGS_TITLE)); -} - -gfx::Size LanguagePinyinConfigView::GetPreferredSize() { - // TODO(satorux): Create our own localized content size once the UI is done. - return gfx::Size(views::Window::GetLocalizedContentsSize( - IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, - IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES)); -} - -void LanguagePinyinConfigView::InitControlLayout() { - using views::ColumnSet; - using views::GridLayout; - - contents_ = new views::View; - AddChildView(contents_); - - GridLayout* layout = new GridLayout(contents_); - layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, - kPanelVertMargin, kPanelHorizMargin); - contents_->SetLayoutManager(layout); - - const int kColumnSetId = 0; - ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { - pinyin_boolean_checkboxes_[i] = new views::Checkbox( - UTF16ToWide(l10n_util::GetStringUTF16( - language_prefs::kPinyinBooleanPrefs[i].message_id))); - pinyin_boolean_checkboxes_[i]->set_listener(this); - pinyin_boolean_checkboxes_[i]->set_tag(i); - } - double_pinyin_schema_.combobox = - new LanguageCombobox(double_pinyin_schema_.combobox_model); - double_pinyin_schema_.combobox->set_listener(this); - - NotifyPrefChanged(); - for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { - layout->StartRow(0, kColumnSetId); - layout->AddView(pinyin_boolean_checkboxes_[i]); - } - layout->StartRow(0, kColumnSetId); - layout->AddView( - new views::Label(double_pinyin_schema_.combobox_model->GetLabel())); - layout->AddView(double_pinyin_schema_.combobox); -} - -void LanguagePinyinConfigView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - NotifyPrefChanged(); - } -} - -void LanguagePinyinConfigView::NotifyPrefChanged() { - for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { - const bool checked = pinyin_boolean_prefs_[i].GetValue(); - pinyin_boolean_checkboxes_[i]->SetChecked(checked); - } - const int value = double_pinyin_schema_.multiple_choice_pref.GetValue(); - for (int i = 0; i < double_pinyin_schema_.combobox_model->num_items(); ++i) { - if (double_pinyin_schema_.combobox_model->GetConfigValueAt(i) == value) { - double_pinyin_schema_.combobox->SetSelectedItem(i); - break; - } - } -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_pinyin_config_view.h b/chrome/browser/chromeos/options/language_pinyin_config_view.h deleted file mode 100644 index 4bbd1cc2..0000000 --- a/chrome/browser/chromeos/options/language_pinyin_config_view.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_PINYIN_CONFIG_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_PINYIN_CONFIG_VIEW_H_ -#pragma once - -#include <string> - -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "chrome/browser/chromeos/language_preferences.h" -#include "chrome/browser/prefs/pref_member.h" -#include "chrome/browser/ui/views/options/options_page_view.h" -#include "views/controls/button/checkbox.h" -#include "views/controls/combobox/combobox.h" -#include "views/controls/label.h" -#include "views/window/dialog_delegate.h" - -namespace chromeos { - -class LanguageCombobox; -template <typename DataType> -class LanguageComboboxModel; - -// A dialog box for showing Traditional Chinese (Pinyin) input method -// preferences. -class LanguagePinyinConfigView : public views::ButtonListener, - public views::Combobox::Listener, - public views::DialogDelegate, - public OptionsPageView { - public: - explicit LanguagePinyinConfigView(Profile* profile); - virtual ~LanguagePinyinConfigView(); - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // views::Combobox::Listener overrides. - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - // views::DialogDelegate overrides. - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const; - virtual std::wstring GetWindowTitle() const; - - // views::View overrides. - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - // OptionsPageView overrides. - virtual void InitControlLayout(); - - // NotificationObserver overrides. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Updates the pinyin checkboxes. - void NotifyPrefChanged(); - - BooleanPrefMember pinyin_boolean_prefs_[ - language_prefs::kNumPinyinBooleanPrefs]; - // TODO(yusukes): Support integer prefs if needed. - views::View* contents_; - - // A checkboxes for Pinyin. - views::Checkbox* pinyin_boolean_checkboxes_[ - language_prefs::kNumPinyinBooleanPrefs]; - - struct DoublePinyinSchemaPrefAndAssociatedCombobox { - IntegerPrefMember multiple_choice_pref; - LanguageComboboxModel<int>* combobox_model; - LanguageCombobox* combobox; - } double_pinyin_schema_; - - DISALLOW_COPY_AND_ASSIGN(LanguagePinyinConfigView); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_PINYIN_CONFIG_VIEW_H_ diff --git a/chrome/browser/chromeos/options/system_page_view.cc b/chrome/browser/chromeos/options/system_page_view.cc index 500a1f6..e251f50 100644 --- a/chrome/browser/chromeos/options/system_page_view.cc +++ b/chrome/browser/chromeos/options/system_page_view.cc @@ -17,8 +17,6 @@ #include "chrome/browser/chromeos/cros/keyboard_library.h" #include "chrome/browser/chromeos/cros/system_library.h" #include "chrome/browser/chromeos/language_preferences.h" -#include "chrome/browser/chromeos/options/language_config_util.h" -#include "chrome/browser/chromeos/options/language_config_view.h" #include "chrome/browser/chromeos/options/options_window_view.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/profiles/profile.h" @@ -304,139 +302,6 @@ void TouchpadSection::NotifyPrefChanged(const std::string* pref_name) { } } -//////////////////////////////////////////////////////////////////////////////// -// LanguageSection - -// TextInput section for text input settings. -class LanguageSection : public SettingsPageSection, - public views::ButtonListener, - public views::Combobox::Listener { - public: - explicit LanguageSection(Profile* profile); - virtual ~LanguageSection() {} - - private: - enum ButtonTag { - kCustomizeLanguagesButton, - }; - // Overridden from SettingsPageSection: - virtual void InitContents(GridLayout* layout); - void NotifyPrefChanged(const std::string* pref_name); - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, - const views::Event& event); - - // Overridden from views::Combobox::Listener: - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - - IntegerPrefMember xkb_remap_search_key_pref_; - IntegerPrefMember xkb_remap_control_key_pref_; - IntegerPrefMember xkb_remap_alt_key_pref_; - views::Combobox* xkb_modifier_combobox_; - chromeos::LanguageComboboxModel<int> xkb_modifier_combobox_model_; - - DISALLOW_COPY_AND_ASSIGN(LanguageSection); -}; - -LanguageSection::LanguageSection(Profile* profile) - : SettingsPageSection(profile, - IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE), - xkb_modifier_combobox_(NULL), - xkb_modifier_combobox_model_( - &language_prefs::kXkbModifierMultipleChoicePrefs) { - xkb_remap_search_key_pref_.Init( - prefs::kLanguageXkbRemapSearchKeyTo, profile->GetPrefs(), this); - xkb_remap_control_key_pref_.Init( - prefs::kLanguageXkbRemapControlKeyTo, profile->GetPrefs(), this); - xkb_remap_alt_key_pref_.Init( - prefs::kLanguageXkbRemapAltKeyTo, profile->GetPrefs(), this); -} - -void LanguageSection::InitContents(GridLayout* layout) { - // Add the customize button and XKB combobox. - layout->StartRow(0, double_column_view_set_id()); - views::NativeButton* customize_languages_button = new views::NativeButton( - this, - UTF16ToWide(l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE))); - customize_languages_button->set_tag(kCustomizeLanguagesButton); - - xkb_modifier_combobox_ = new views::Combobox(&xkb_modifier_combobox_model_); - xkb_modifier_combobox_->set_listener(this); - - // Initialize the combobox to what's saved in user preferences. Otherwise, - // ItemChanged() will be called with |new_index| == 0. - NotifyPrefChanged(NULL); - - layout->AddView(customize_languages_button, 1, 1, - GridLayout::LEADING, GridLayout::CENTER); - layout->AddView(xkb_modifier_combobox_); - layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); -} - -void LanguageSection::ButtonPressed( - views::Button* sender, const views::Event& event) { - if (sender->tag() == kCustomizeLanguagesButton) { - LanguageConfigView::Show(profile(), GetOptionsViewParent()); - } -} - -void LanguageSection::ItemChanged(views::Combobox* sender, - int prev_index, - int new_index) { - VLOG(1) << "Changing XKB modofier pref to " << new_index; - switch (new_index) { - default: - LOG(ERROR) << "Unexpected mapping: " << new_index; - /* fall through */ - case language_prefs::kNoRemap: - xkb_remap_search_key_pref_.SetValue(kSearchKey); - xkb_remap_control_key_pref_.SetValue(kLeftControlKey); - xkb_remap_alt_key_pref_.SetValue(kLeftAltKey); - break; - case language_prefs::kSwapCtrlAndAlt: - xkb_remap_search_key_pref_.SetValue(kSearchKey); - xkb_remap_control_key_pref_.SetValue(kLeftAltKey); - xkb_remap_alt_key_pref_.SetValue(kLeftControlKey); - break; - case language_prefs::kSwapSearchAndCtrl: - xkb_remap_search_key_pref_.SetValue(kLeftControlKey); - xkb_remap_control_key_pref_.SetValue(kSearchKey); - xkb_remap_alt_key_pref_.SetValue(kLeftAltKey); - break; - } -} - -void LanguageSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo || - *pref_name == prefs::kLanguageXkbRemapControlKeyTo || - *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) { - const int search_remap = xkb_remap_search_key_pref_.GetValue(); - const int control_remap = xkb_remap_control_key_pref_.GetValue(); - const int alt_remap = xkb_remap_alt_key_pref_.GetValue(); - if ((search_remap == kSearchKey) && - (control_remap == kLeftControlKey) && - (alt_remap == kLeftAltKey)) { - xkb_modifier_combobox_->SetSelectedItem(language_prefs::kNoRemap); - } else if ((search_remap == kLeftControlKey) && - (control_remap == kSearchKey) && - (alt_remap == kLeftAltKey)) { - xkb_modifier_combobox_->SetSelectedItem( - language_prefs::kSwapSearchAndCtrl); - } else if ((search_remap == kSearchKey) && - (control_remap == kLeftAltKey) && - (alt_remap == kLeftControlKey)) { - xkb_modifier_combobox_->SetSelectedItem(language_prefs::kSwapCtrlAndAlt); - } else { - LOG(ERROR) << "Unexpected mapping. The prefs are updated by DOMUI?"; - xkb_modifier_combobox_->SetSelectedItem(language_prefs::kNoRemap); - } - } -} - /////////////////////////////////////////////////////////////////////////////// // AccessibilitySection @@ -529,9 +394,6 @@ void SystemPageView::InitControlLayout() { layout->AddView(new TouchpadSection(profile())); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, single_column_view_set_id); - layout->AddView(new LanguageSection(profile())); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); layout->AddView(new AccessibilitySection(profile())); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); } diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 3478b87..c733bf1 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -130,7 +130,6 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/boot_times_loader.h" -#include "chrome/browser/chromeos/options/language_config_view.h" #endif using base::TimeDelta; @@ -1930,7 +1929,7 @@ void Browser::OpenLanguageOptionsDialog() { switches::kDisableTabbedOptions)) { ShowOptionsTab(chrome::kLanguageOptionsSubPage); } else { - chromeos::LanguageConfigView::Show(profile_, NULL); + // Language options dialog has been replaced by DOMUI. } } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1c6e037..6c20c76 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -710,19 +710,6 @@ 'browser/chromeos/offline/offline_load_service.h', 'browser/chromeos/options/internet_page_view.cc', 'browser/chromeos/options/internet_page_view.h', - 'browser/chromeos/options/language_config_model.cc', - 'browser/chromeos/options/language_config_model.h', - 'browser/chromeos/options/language_config_util.h', - 'browser/chromeos/options/language_config_view.cc', - 'browser/chromeos/options/language_config_view.h', - 'browser/chromeos/options/language_chewing_config_view.cc', - 'browser/chromeos/options/language_chewing_config_view.h', - 'browser/chromeos/options/language_hangul_config_view.cc', - 'browser/chromeos/options/language_hangul_config_view.h', - 'browser/chromeos/options/language_pinyin_config_view.cc', - 'browser/chromeos/options/language_pinyin_config_view.h', - 'browser/chromeos/options/language_mozc_config_view.cc', - 'browser/chromeos/options/language_mozc_config_view.h', 'browser/chromeos/options/network_config_view.cc', 'browser/chromeos/options/network_config_view.h', 'browser/chromeos/options/options_window_view.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 9588963..9b9a2e6 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1124,7 +1124,6 @@ 'browser/chromeos/login/wizard_accessibility_handler_unittest.cc', 'browser/chromeos/notifications/desktop_notifications_unittest.cc', 'browser/chromeos/offline/offline_load_page_unittest.cc', - 'browser/chromeos/options/language_config_model_unittest.cc', 'browser/chromeos/plugin_selection_policy_unittest.cc', 'browser/chromeos/proxy_config_service_impl_unittest.cc', 'browser/chromeos/status/input_method_menu_unittest.cc', |