From 1919eb8951da6ec151d9d9418f0ae5affcfe8b6e Mon Sep 17 00:00:00 2001 From: "satorux@chromium.org" Date: Mon, 15 Mar 2010 07:55:14 +0000 Subject: Move Hangul IME settings to a separate dialog. We'll have a separate dialog for each input method that has settings. Review URL: http://codereview.chromium.org/889002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41566 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chromeos/options/language_config_view.cc | 186 ++++++--------------- .../chromeos/options/language_config_view.h | 27 +-- .../options/language_hangul_config_view.cc | 171 +++++++++++++++++++ .../chromeos/options/language_hangul_config_view.h | 65 +++++++ 4 files changed, 291 insertions(+), 158 deletions(-) create mode 100644 chrome/browser/chromeos/options/language_hangul_config_view.cc create mode 100644 chrome/browser/chromeos/options/language_hangul_config_view.h (limited to 'chrome/browser/chromeos/options') diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc index a3b0305..e8eb445 100644 --- a/chrome/browser/chromeos/options/language_config_view.cc +++ b/chrome/browser/chromeos/options/language_config_view.cc @@ -7,11 +7,11 @@ #include #include -#include "app/combobox_model.h" #include "app/l10n_util.h" #include "app/table_model.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/language_library.h" +#include "chrome/browser/chromeos/options/language_hangul_config_view.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "views/controls/button/checkbox.h" @@ -22,9 +22,6 @@ namespace chromeos { -const char LanguageConfigView::kHangulSection[] = "engine/Hangul"; -const char LanguageConfigView::kHangulKeyboardConfigName[] = "HangulKeyboard"; - // This is a checkbox associated with input language information. class LanguageCheckbox : public views::Checkbox { public: @@ -42,61 +39,6 @@ class LanguageCheckbox : public views::Checkbox { DISALLOW_COPY_AND_ASSIGN(LanguageCheckbox); }; -// The combobox model for the list of hangul keyboards. -class HangulKeyboardComboboxModel : public ComboboxModel { - public: - HangulKeyboardComboboxModel() { - // We have to sync the IDs ("2", "3f", "39", ...) with those in - // ibus-hangul/setup/main.py. - // TODO(yusukes): Use l10n_util::GetString for these label strings. - layouts_.push_back(std::make_pair(L"Dubeolsik", "2")); - layouts_.push_back(std::make_pair(L"Sebeolsik Final", "3f")); - layouts_.push_back(std::make_pair(L"Sebeolsik 390", "39")); - layouts_.push_back(std::make_pair(L"Sebeolsik No-shift", "3s")); - layouts_.push_back(std::make_pair(L"Sebeolsik 2 set", "32")); - } - - // Implements ComboboxModel interface. - virtual int GetItemCount() { - return static_cast(layouts_.size()); - } - - // Implements ComboboxModel interface. - virtual std::wstring GetItemAt(int index) { - if (index < 0 || index > GetItemCount()) { - LOG(ERROR) << "Index is out of bounds: " << index; - return L""; - } - return 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(i); - } - } - return -1; - } - - private: - std::vector > layouts_; - DISALLOW_COPY_AND_ASSIGN(HangulKeyboardComboboxModel); -}; - // The table model for the list of preferred languages. class PreferredLanguageTableModel : public TableModel { public: @@ -122,12 +64,12 @@ class PreferredLanguageTableModel : public TableModel { DISALLOW_COPY_AND_ASSIGN(PreferredLanguageTableModel); }; -LanguageConfigView::LanguageConfigView() - : contents_(NULL), - hangul_keyboard_combobox_(NULL), - hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel), - preferred_language_table_(NULL), - preferred_language_table_model_(new PreferredLanguageTableModel) { +LanguageConfigView::LanguageConfigView() : + contents_(NULL), + hangul_configure_button_(NULL), + language_checkbox_(NULL), + preferred_language_table_(NULL), + preferred_language_table_model_(new PreferredLanguageTableModel) { } LanguageConfigView::~LanguageConfigView() { @@ -140,46 +82,43 @@ LanguageConfigView::~LanguageConfigView() { void LanguageConfigView::ButtonPressed( views::Button* sender, const views::Event& event) { - LanguageCheckbox* checkbox = static_cast(sender); - const InputLanguage& language = checkbox->language(); - // Check if the checkbox is now being checked. - if (checkbox->checked()) { - // TODO(yusukes): limit the number of active languages so the pop-up menu - // of the language_menu_button does not overflow. - - // Try to activate the language. - if (!LanguageLibrary::Get()->ActivateLanguage(language.category, - language.id)) { - // Activation should never fail (failure means something is broken), - // but if it fails we just revert the checkbox and ignore the error. - // TODO(satorux): Implement a better error handling if it becomes - // necessary. - checkbox->SetChecked(false); - LOG(ERROR) << "Failed to activate language: " << language.display_name; - } - } else { - // Try to deactivate the language. - if (!LanguageLibrary::Get()->DeactivateLanguage(language.category, + if (sender == static_cast(hangul_configure_button_)) { + views::Window* window = views::Window::CreateChromeWindow( + NULL, gfx::Rect(), new LanguageHangulConfigView()); + window->SetIsAlwaysOnTop(true); + window->Show(); + } else if (sender == static_cast(language_checkbox_)) { + LanguageCheckbox* checkbox = static_cast(sender); + const InputLanguage& language = checkbox->language(); + // Check if the checkbox is now being checked. + if (checkbox->checked()) { + // TODO(yusukes): limit the number of active languages so the pop-up menu + // of the language_menu_button does not overflow. + + // Try to activate the language. + if (!LanguageLibrary::Get()->ActivateLanguage(language.category, language.id)) { - // See a comment above about the activation failure. - checkbox->SetChecked(true); - LOG(ERROR) << "Failed to deactivate language: " << language.display_name; + // Activation should never fail (failure means something is broken), + // but if it fails we just revert the checkbox and ignore the error. + // TODO(satorux): Implement a better error handling if it becomes + // necessary. + checkbox->SetChecked(false); + LOG(ERROR) << "Failed to activate language: " + << language.display_name; + } + } else { + // Try to deactivate the language. + if (!LanguageLibrary::Get()->DeactivateLanguage(language.category, + language.id)) { + // See a comment above about the activation failure. + checkbox->SetChecked(true); + LOG(ERROR) << "Failed to deactivate language: " + << language.display_name; + } } } } -void LanguageConfigView::ItemChanged( - views::Combobox* sender, int prev_index, int new_index) { - ImeConfigValue config; - config.type = ImeConfigValue::kValueTypeString; - config.string_value = - hangul_keyboard_combobox_model_->GetItemIDAt(new_index); - LanguageLibrary::Get()->SetImeConfig( - kHangulSection, kHangulKeyboardConfigName, config); - - UpdateHangulKeyboardCombobox(); -} - void LanguageConfigView::Layout() { // Not sure why but this is needed to show contents in the dialog. contents_->SetBounds(0, 0, width(), height()); @@ -273,7 +212,6 @@ void LanguageConfigView::Init() { column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, GridLayout::USE_PREF, 0, 0); - // GetActiveLanguages() and GetSupportedLanguages() never return NULL. scoped_ptr active_language_list( LanguageLibrary::Get()->GetActiveLanguages()); @@ -289,52 +227,26 @@ void LanguageConfigView::Init() { active_language_list->end(), language) != active_language_list->end()); // Create a checkbox. - LanguageCheckbox* checkbox = new LanguageCheckbox(language); - checkbox->SetChecked(language_is_active); - checkbox->set_listener(this); + language_checkbox_ = new LanguageCheckbox(language); + language_checkbox_->SetChecked(language_is_active); + language_checkbox_->set_listener(this); // We use two columns. Start a column if the counter is an even number. if (i % 2 == 0) { layout->StartRow(0, kDoubleColumnSetId); } // Add the checkbox to the layout manager. - layout->AddView(checkbox); + layout->AddView(language_checkbox_); } - // Settings for IME engines. - // TODO(yusukes): This is a temporary location of the settings. Ask UX team - // where is the best place for this and then move the code. - // TODO(yusukes): Use l10n_util::GetString for all views::Labels. - // TODO(satorux): Move this to a separate dialog. - - // Hangul IME - hangul_keyboard_combobox_ - = new views::Combobox(hangul_keyboard_combobox_model_.get()); - hangul_keyboard_combobox_->set_listener(this); - UpdateHangulKeyboardCombobox(); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - layout->StartRow(0, kSingleColumnSetId); - layout->AddView( - new views::Label( - l10n_util::GetString(IDS_OPTIONS_SETTINGS_HANGUL_IME_TEXT)), - 1, 1, GridLayout::LEADING, GridLayout::LEADING); + // Add the configure button for the Hangul IME. + // TODO(satorux): We'll have better UI for this soon. layout->StartRow(0, kDoubleColumnSetId); + hangul_configure_button_ = new views::NativeButton( + this, l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE)); layout->AddView(new views::Label( - l10n_util::GetString(IDS_OPTIONS_SETTINGS_KEYBOARD_LAYOUT_TEXT))); - layout->AddView(hangul_keyboard_combobox_); -} - -void LanguageConfigView::UpdateHangulKeyboardCombobox() { - DCHECK(hangul_keyboard_combobox_); - ImeConfigValue config; - if (LanguageLibrary::Get()->GetImeConfig( - kHangulSection, kHangulKeyboardConfigName, &config)) { - const int index - = hangul_keyboard_combobox_model_->GetIndexFromID(config.string_value); - if (index >= 0) { - hangul_keyboard_combobox_->SetSelectedItem(index); - } - } + l10n_util::GetString(IDS_OPTIONS_SETTINGS_HANGUL_IME_TEXT))); + layout->AddView(hangul_configure_button_); } } // namespace chromeos diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h index 2943517..2da1bd3 100644 --- a/chrome/browser/chromeos/options/language_config_view.h +++ b/chrome/browser/chromeos/options/language_config_view.h @@ -8,19 +8,19 @@ #include #include "chrome/browser/chromeos/cros/language_library.h" -#include "views/controls/combobox/combobox.h" +#include "views/controls/button/native_button.h" #include "views/controls/label.h" -#include "views/controls/table/table_view_observer.h" #include "views/controls/table/table_view2.h" +#include "views/controls/table/table_view_observer.h" #include "views/window/dialog_delegate.h" namespace chromeos { -class HangulKeyboardComboboxModel; +class LanguageCheckbox; +class LanguageHangulConfigView; class PreferredLanguageTableModel; // A dialog box for showing a password textfield. class LanguageConfigView : public views::ButtonListener, - public views::Combobox::Listener, public views::DialogDelegate, public views::TableViewObserver, public views::View { @@ -32,16 +32,9 @@ class LanguageConfigView : public views::ButtonListener, 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; } - - // views::View overrides. virtual std::wstring GetWindowTitle() const; // views::View overrides: @@ -57,22 +50,14 @@ class LanguageConfigView : public views::ButtonListener, private: // Initializes UI. void Init(); - // Updates the hangul keyboard combobox. - void UpdateHangulKeyboardCombobox(); - - // GConf config path names for the Korean IME. - static const char kHangulSection[]; - static const char kHangulKeyboardConfigName[]; views::View* contents_; + views::NativeButton* hangul_configure_button_; + LanguageCheckbox* language_checkbox_; - // A combobox for Hangul keyboard layouts and its model. - views::Combobox* hangul_keyboard_combobox_; - scoped_ptr hangul_keyboard_combobox_model_; // A table for preferred languages and its model. views::TableView2* preferred_language_table_; scoped_ptr preferred_language_table_model_; - DISALLOW_COPY_AND_ASSIGN(LanguageConfigView); }; diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.cc b/chrome/browser/chromeos/options/language_hangul_config_view.cc new file mode 100644 index 0000000..a4167c0 --- /dev/null +++ b/chrome/browser/chromeos/options/language_hangul_config_view.cc @@ -0,0 +1,171 @@ +// 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/combobox_model.h" +#include "app/l10n_util.h" +#include "chrome/browser/chromeos/cros/language_library.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 { + +const char LanguageHangulConfigView::kHangulSection[] = "engine/Hangul"; +const char LanguageHangulConfigView::kHangulKeyboardConfigName[] = + "HangulKeyboard"; + +// The combobox model for the list of hangul keyboards. +class HangulKeyboardComboboxModel : public ComboboxModel { + public: + HangulKeyboardComboboxModel() { + // We have to sync the IDs ("2", "3f", "39", ...) with those in + // ibus-hangul/setup/main.py. + // TODO(yusukes): Use l10n_util::GetString for these label strings. + layouts_.push_back(std::make_pair(L"Dubeolsik", "2")); + layouts_.push_back(std::make_pair(L"Sebeolsik Final", "3f")); + layouts_.push_back(std::make_pair(L"Sebeolsik 390", "39")); + layouts_.push_back(std::make_pair(L"Sebeolsik No-shift", "3s")); + layouts_.push_back(std::make_pair(L"Sebeolsik 2 set", "32")); + } + + // Implements ComboboxModel interface. + virtual int GetItemCount() { + return static_cast(layouts_.size()); + } + + // Implements ComboboxModel interface. + virtual std::wstring GetItemAt(int index) { + if (index < 0 || index > GetItemCount()) { + LOG(ERROR) << "Index is out of bounds: " << index; + return L""; + } + return 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(i); + } + } + return -1; + } + + private: + std::vector > layouts_; + DISALLOW_COPY_AND_ASSIGN(HangulKeyboardComboboxModel); +}; + +LanguageHangulConfigView::LanguageHangulConfigView() : + contents_(NULL), + hangul_keyboard_combobox_(NULL), + hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel) { +} + +LanguageHangulConfigView::~LanguageHangulConfigView() { +} + +void LanguageHangulConfigView::ItemChanged( + views::Combobox* sender, int prev_index, int new_index) { + ImeConfigValue config; + config.type = ImeConfigValue::kValueTypeString; + config.string_value = + hangul_keyboard_combobox_model_->GetItemIDAt(new_index); + LanguageLibrary::Get()->SetImeConfig( + kHangulSection, kHangulKeyboardConfigName, config); + + UpdateHangulKeyboardCombobox(); +} + +void LanguageHangulConfigView::Layout() { + // Not sure why but this is needed to show contents in the dialog. + contents_->SetBounds(0, 0, width(), height()); +} + +std::wstring LanguageHangulConfigView::GetWindowTitle() const { + return l10n_util::GetString( + 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_FONTSLANG_DIALOG_WIDTH_CHARS, + IDS_FONTSLANG_DIALOG_HEIGHT_LINES)); +} + +void LanguageHangulConfigView::ViewHierarchyChanged( + bool is_add, views::View* parent, views::View* child) { + // Can't init before we're inserted into a Container. + if (is_add && child == this) { + Init(); + } +} + +void LanguageHangulConfigView::Init() { + using views::ColumnSet; + using views::GridLayout; + + if (contents_) return; // Already initialized. + 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( + l10n_util::GetString(IDS_OPTIONS_SETTINGS_KEYBOARD_LAYOUT_TEXT))); + + hangul_keyboard_combobox_ + = new views::Combobox(hangul_keyboard_combobox_model_.get()); + hangul_keyboard_combobox_->set_listener(this); + UpdateHangulKeyboardCombobox(); + layout->AddView(hangul_keyboard_combobox_); +} + +void LanguageHangulConfigView::UpdateHangulKeyboardCombobox() { + DCHECK(hangul_keyboard_combobox_); + ImeConfigValue config; + if (LanguageLibrary::Get()->GetImeConfig( + kHangulSection, kHangulKeyboardConfigName, &config)) { + const int index + = hangul_keyboard_combobox_model_->GetIndexFromID(config.string_value); + 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 new file mode 100644 index 0000000..c4798eb --- /dev/null +++ b/chrome/browser/chromeos/options/language_hangul_config_view.h @@ -0,0 +1,65 @@ +// 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_HANGUL_CONFIG_VIEW_H_ +#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_HANGUL_CONFIG_VIEW_H_ + +#include + +#include "base/scoped_ptr.h" +#include "chrome/browser/chromeos/cros/language_library.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 a password textfield. +class LanguageHangulConfigView : public views::Combobox::Listener, + public views::DialogDelegate, + public views::View { + public: + LanguageHangulConfigView(); + 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 std::wstring GetWindowTitle() const; + + // views::View overrides: + virtual void Layout(); + virtual gfx::Size GetPreferredSize(); + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + + private: + // Initializes UI. + void Init(); + // Updates the hangul keyboard combobox. + void UpdateHangulKeyboardCombobox(); + + // GConf config path names for the Korean IME. + static const char kHangulSection[]; + static const char kHangulKeyboardConfigName[]; + + views::View* contents_; + + // A combobox for Hangul keyboard layouts and its model. + views::Combobox* hangul_keyboard_combobox_; + scoped_ptr hangul_keyboard_combobox_model_; + + DISALLOW_COPY_AND_ASSIGN(LanguageHangulConfigView); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_HANGUL_CONFIG_VIEW_H_ -- cgit v1.1