diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 09:03:18 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 09:03:18 +0000 |
commit | 2a5cd8d6366d06553f025f4d49e8d22015821d77 (patch) | |
tree | 4250adb8e1797ec4759238288376d300c0f41bcc /chrome | |
parent | 817fc50713c37fb0cb41fbc455d83fb40b40da7e (diff) | |
download | chromium_src-2a5cd8d6366d06553f025f4d49e8d22015821d77.zip chromium_src-2a5cd8d6366d06553f025f4d49e8d22015821d77.tar.gz chromium_src-2a5cd8d6366d06553f025f4d49e8d22015821d77.tar.bz2 |
Combine the combo box class used by mozc and chewing
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2558001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48817 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
7 files changed, 136 insertions, 220 deletions
diff --git a/chrome/browser/chromeos/language_preferences.h b/chrome/browser/chromeos/language_preferences.h index 6674a7b..b4b567d 100644 --- a/chrome/browser/chromeos/language_preferences.h +++ b/chrome/browser/chromeos/language_preferences.h @@ -12,6 +12,19 @@ // Section and config names for the IBus configuration daemon. namespace chromeos { +struct LanguageMultipleChoicePreference { + const wchar_t* pref_name; // Chrome preference name. + const wchar_t* default_pref_value; + const char* ibus_config_name; + // Currently we have 10 combobox items at most. + static const size_t kMaxItems = 10; + struct { + const char* ibus_config_value; + int item_message_id; // Resource grd ID for the combobox item. + } values_and_ids[kMaxItems]; + int label_message_id; // Resource grd ID for the label. +}; + // For ibus-daemon const char kGeneralSectionName[] = "general"; const char kHotKeySectionName[] = "general/hotkey"; @@ -80,19 +93,7 @@ const struct { }; const size_t kNumChewingIntegerPrefs = ARRAYSIZE_UNSAFE(kChewingIntegerPrefs); -const struct ChewingMultipleChoicePreference { - const wchar_t* pref_name; // Chrome preference name. - const wchar_t* default_pref_value; - const char* ibus_config_name; - // Currently we have 10 combobox items at most. - static const size_t kMaxItems = 10; - struct { - const char* ibus_config_value; - int item_message_id; // Resource grd ID for the combobox item. - } values_and_ids[kMaxItems]; - int label_message_id; // Resource grd ID for the label. - -} kChewingMultipleChoicePrefs[] = { +const LanguageMultipleChoicePreference kChewingMultipleChoicePrefs[] = { { prefs::kLanguageChewingKeyboardType, L"default", "KBType", @@ -213,23 +214,7 @@ const size_t kNumPinyinIntegerPrefs = ARRAYSIZE_UNSAFE(kPinyinIntegerPrefs); // For Japanese input method (ibus-mozc) const char kMozcSectionName[] = "engine/Mozc"; -const struct MozcMultipleChoicePreference { - const wchar_t* pref_name; // Chrome preference name. - const wchar_t* default_pref_value; - // The config names and values have to be matched with protobuf member names - // in chromiumos/src/third_party/ibus-mozc/files/src/session/config.proto - // since ibus-mozc uses protobuf reflection APIs to pass prefs to the Mozc - // Japanese converter. - const char* ibus_config_name; - // Currently we have 4 combobox items at most. - static const size_t kMaxItems = 4; - struct { - const char* ibus_config_value; - int item_message_id; // Resource grd ID for the combobox item. - } values_and_ids[kMaxItems]; - int label_message_id; // Resource grd ID for the label. - -} kMozcMultipleChoicePrefs[] = { +const LanguageMultipleChoicePreference kMozcMultipleChoicePrefs[] = { { prefs::kLanguageMozcPreeditMethod, L"ROMAN", "preedit_method", diff --git a/chrome/browser/chromeos/options/language_chewing_config_view.cc b/chrome/browser/chromeos/options/language_chewing_config_view.cc index 0941a62..7dc3afc 100644 --- a/chrome/browser/chromeos/options/language_chewing_config_view.cc +++ b/chrome/browser/chromeos/options/language_chewing_config_view.cc @@ -7,12 +7,13 @@ #include "app/combobox_model.h" #include "app/l10n_util.h" #include "base/utf_string_conversions.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/pref_names.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/language_library.h" +#include "chrome/browser/chromeos/options/language_config_util.h" #include "chrome/browser/chromeos/preferences.h" #include "chrome/browser/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 "views/controls/button/checkbox.h" @@ -23,94 +24,6 @@ namespace chromeos { -// The combobox model for Chewing Chinese input method prefs. -// TODO(zork): Share this with MozcComboboxModel -class ChewingComboboxModel : public ComboboxModel { - public: - explicit ChewingComboboxModel( - const ChewingMultipleChoicePreference* 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 < ChewingMultipleChoicePreference::kMaxItems; ++i) { - if ((pref_data_->values_and_ids)[i].ibus_config_value == NULL) { - break; - } - ++num_items_; - } - } - - // Implements ComboboxModel interface. - virtual int GetItemCount() { - return num_items_; - } - - // Implements ComboboxModel interface. - virtual std::wstring GetItemAt(int index) { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return L""; - } - const int message_id = (pref_data_->values_and_ids)[index].item_message_id; - return l10n_util::GetString(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 l10n_util::GetString(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. - std::wstring GetConfigValueAt(int index) const { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return L""; - } - return UTF8ToWide((pref_data_->values_and_ids)[index].ibus_config_value); - } - - // Gets an index (>= 0) of an item such that GetConfigValueAt(index) is equal - // to the |config_value|. Returns -1 if such item is not found. This function - // is NOT part of the ComboboxModel interface. - int GetIndexFromConfigValue(const std::wstring& config_value) const { - for (int i = 0; i < num_items_; ++i) { - if (GetConfigValueAt(i) == config_value) { - return i; - } - } - return -1; - } - - private: - const ChewingMultipleChoicePreference* pref_data_; - int num_items_; - - DISALLOW_COPY_AND_ASSIGN(ChewingComboboxModel); -}; - -// The combobox for the dialog which has minimum width. -class ChewingCombobox : public views::Combobox { - public: - explicit ChewingCombobox(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 = 100; - - DISALLOW_COPY_AND_ASSIGN(ChewingCombobox); -}; - LanguageChewingConfigView::LanguageChewingConfigView(Profile* profile) : OptionsPageView(profile), contents_(NULL) { for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { @@ -123,7 +36,7 @@ LanguageChewingConfigView::LanguageChewingConfigView(Profile* profile) current.multiple_choice_pref.Init( kChewingMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); current.combobox_model = - new ChewingComboboxModel(&kChewingMultipleChoicePrefs[i]); + new LanguageComboboxModel(&kChewingMultipleChoicePrefs[i]); current.combobox = NULL; } for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { @@ -214,7 +127,7 @@ void LanguageChewingConfigView::InitControlLayout() { } for (size_t i = 0; i < kNumChewingMultipleChoicePrefs; ++i) { ChewingPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.combobox = new ChewingCombobox(current.combobox_model); + current.combobox = new LanguageCombobox(current.combobox_model); current.combobox->set_listener(this); } for (size_t i = 0; i < kNumChewingIntegerPrefs; ++i) { diff --git a/chrome/browser/chromeos/options/language_chewing_config_view.h b/chrome/browser/chromeos/options/language_chewing_config_view.h index 99daa46..82700db 100644 --- a/chrome/browser/chromeos/options/language_chewing_config_view.h +++ b/chrome/browser/chromeos/options/language_chewing_config_view.h @@ -19,8 +19,8 @@ namespace chromeos { -class ChewingCombobox; -class ChewingComboboxModel; +class LanguageCombobox; +class LanguageComboboxModel; // A dialog box for showing Traditional Chinese (Chewing) input method // preferences. @@ -76,8 +76,8 @@ class LanguageChewingConfigView : public views::ButtonListener, struct ChewingPrefAndAssociatedCombobox { StringPrefMember multiple_choice_pref; - ChewingComboboxModel* combobox_model; - ChewingCombobox* combobox; + LanguageComboboxModel* combobox_model; + LanguageCombobox* combobox; } prefs_and_comboboxes_[kNumChewingMultipleChoicePrefs]; DISALLOW_COPY_AND_ASSIGN(LanguageChewingConfigView); diff --git a/chrome/browser/chromeos/options/language_config_util.h b/chrome/browser/chromeos/options/language_config_util.h new file mode 100644 index 0000000..38092a7 --- /dev/null +++ b/chrome/browser/chromeos/options/language_config_util.h @@ -0,0 +1,102 @@ +// 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_ + +#include "chrome/browser/chromeos/language_preferences.h" +#include "views/controls/combobox/combobox.h" + +namespace chromeos { + +// The combobox model for Language input method prefs. +class LanguageComboboxModel : public ComboboxModel { + public: + explicit LanguageComboboxModel( + const LanguageMultipleChoicePreference* 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 < LanguageMultipleChoicePreference::kMaxItems; ++i) { + if ((pref_data_->values_and_ids)[i].ibus_config_value == NULL) { + break; + } + ++num_items_; + } + } + + // Implements ComboboxModel interface. + virtual int GetItemCount() { + return num_items_; + } + + // Implements ComboboxModel interface. + virtual std::wstring GetItemAt(int index) { + if (index < 0 || index >= num_items_) { + LOG(ERROR) << "Index is out of bounds: " << index; + return L""; + } + const int message_id = (pref_data_->values_and_ids)[index].item_message_id; + return l10n_util::GetString(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 l10n_util::GetString(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. + std::wstring GetConfigValueAt(int index) const { + if (index < 0 || index >= num_items_) { + LOG(ERROR) << "Index is out of bounds: " << index; + return L""; + } + return UTF8ToWide((pref_data_->values_and_ids)[index].ibus_config_value); + } + + // Gets an index (>= 0) of an item such that GetConfigValueAt(index) is equal + // to the |config_value|. Returns -1 if such item is not found. This function + // is NOT part of the ComboboxModel interface. + int GetIndexFromConfigValue(const std::wstring& config_value) const { + for (int i = 0; i < num_items_; ++i) { + if (GetConfigValueAt(i) == config_value) { + return i; + } + } + return -1; + } + + private: + const LanguageMultipleChoicePreference* 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(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 = 100; + + DISALLOW_COPY_AND_ASSIGN(LanguageCombobox); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ diff --git a/chrome/browser/chromeos/options/language_mozc_config_view.cc b/chrome/browser/chromeos/options/language_mozc_config_view.cc index 0d83aba..64c7510 100644 --- a/chrome/browser/chromeos/options/language_mozc_config_view.cc +++ b/chrome/browser/chromeos/options/language_mozc_config_view.cc @@ -7,11 +7,12 @@ #include "app/combobox_model.h" #include "app/l10n_util.h" #include "base/utf_string_conversions.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/pref_names.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/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 "views/grid_layout.h" @@ -20,92 +21,6 @@ namespace chromeos { -// The combobox model for Mozc Japanese input method prefs. -class MozcComboboxModel : public ComboboxModel { - public: - explicit MozcComboboxModel(const MozcMultipleChoicePreference* 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 < MozcMultipleChoicePreference::kMaxItems; ++i) { - if ((pref_data_->values_and_ids)[i].ibus_config_value == NULL) { - break; - } - ++num_items_; - } - } - - // Implements ComboboxModel interface. - virtual int GetItemCount() { - return num_items_; - } - - // Implements ComboboxModel interface. - virtual std::wstring GetItemAt(int index) { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return L""; - } - const int message_id = (pref_data_->values_and_ids)[index].item_message_id; - return l10n_util::GetString(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 l10n_util::GetString(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. - std::wstring GetConfigValueAt(int index) const { - if (index < 0 || index >= num_items_) { - LOG(ERROR) << "Index is out of bounds: " << index; - return L""; - } - return UTF8ToWide((pref_data_->values_and_ids)[index].ibus_config_value); - } - - // Gets an index (>= 0) of an item such that GetConfigValueAt(index) is equal - // to the |config_value|. Returns -1 if such item is not found. This function - // is NOT part of the ComboboxModel interface. - int GetIndexFromConfigValue(const std::wstring& config_value) const { - for (int i = 0; i < num_items_; ++i) { - if (GetConfigValueAt(i) == config_value) { - return i; - } - } - return -1; - } - - private: - const MozcMultipleChoicePreference* pref_data_; - int num_items_; - - DISALLOW_COPY_AND_ASSIGN(MozcComboboxModel); -}; - -// The combobox for the dialog which has minimum width. -class MozcCombobox : public views::Combobox { - public: - explicit MozcCombobox(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 = 100; - - DISALLOW_COPY_AND_ASSIGN(MozcCombobox); -}; - LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile) : OptionsPageView(profile), contents_(NULL) { for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { @@ -113,7 +28,7 @@ LanguageMozcConfigView::LanguageMozcConfigView(Profile* profile) current.multiple_choice_pref.Init( kMozcMultipleChoicePrefs[i].pref_name, profile->GetPrefs(), this); current.combobox_model = - new MozcComboboxModel(&kMozcMultipleChoicePrefs[i]); + new LanguageComboboxModel(&kMozcMultipleChoicePrefs[i]); current.combobox = NULL; } } @@ -178,7 +93,7 @@ void LanguageMozcConfigView::InitControlLayout() { for (size_t i = 0; i < kNumMozcMultipleChoicePrefs; ++i) { MozcPrefAndAssociatedCombobox& current = prefs_and_comboboxes_[i]; - current.combobox = new MozcCombobox(current.combobox_model); + current.combobox = new LanguageCombobox(current.combobox_model); current.combobox->set_listener(this); } NotifyPrefChanged(); // Sync the comboboxes with current Chrome prefs. diff --git a/chrome/browser/chromeos/options/language_mozc_config_view.h b/chrome/browser/chromeos/options/language_mozc_config_view.h index a89ea7b..6bf89fd 100644 --- a/chrome/browser/chromeos/options/language_mozc_config_view.h +++ b/chrome/browser/chromeos/options/language_mozc_config_view.h @@ -18,8 +18,8 @@ namespace chromeos { -class MozcCombobox; -class MozcComboboxModel; +class LanguageCombobox; +class LanguageComboboxModel; // A dialog box for showing Mozc (Japanese input method) preferences. class LanguageMozcConfigView : public views::Combobox::Listener, @@ -59,8 +59,8 @@ class LanguageMozcConfigView : public views::Combobox::Listener, struct MozcPrefAndAssociatedCombobox { StringPrefMember multiple_choice_pref; - MozcComboboxModel* combobox_model; - MozcCombobox* combobox; + LanguageComboboxModel* combobox_model; + LanguageCombobox* combobox; } prefs_and_comboboxes_[kNumMozcMultipleChoicePrefs]; DISALLOW_COPY_AND_ASSIGN(LanguageMozcConfigView); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d5dc4d6..dfa497d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -467,6 +467,7 @@ 'browser/chromeos/options/internet_page_view.h', 'browser/chromeos/options/ip_config_view.cc', 'browser/chromeos/options/ip_config_view.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', |