From 627edeba9f3069b36309c30fa526459a191c9731 Mon Sep 17 00:00:00 2001 From: "glotov@google.com" Date: Fri, 5 Mar 2010 18:18:59 +0000 Subject: Separated basic language-list code from the combobox model implementation. This is because we needed a menu (not combobox) with languages in another part of Chromium (CL 661475). BUG=none TEST=none Review URL: http://codereview.chromium.org/668068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40751 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/language_combobox_model.h | 61 +++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'chrome/browser/language_combobox_model.h') diff --git a/chrome/browser/language_combobox_model.h b/chrome/browser/language_combobox_model.h index 98f74a0..8a58d0e 100644 --- a/chrome/browser/language_combobox_model.h +++ b/chrome/browser/language_combobox_model.h @@ -13,9 +13,10 @@ #include "chrome/browser/profile.h" /////////////////////////////////////////////////////////////////////////////// -// LanguageComboboxModel -// The model that fills the dropdown of valid UI languages. -class LanguageComboboxModel : public ComboboxModel { +// LanguageList +// Provides code to enumerate locale names for language selection lists. +// To be used by combobox, menu or other models. +class LanguageList { public: struct LocaleData { LocaleData() { } @@ -27,27 +28,51 @@ class LanguageComboboxModel : public ComboboxModel { }; typedef std::map LocaleDataMap; - LanguageComboboxModel(); - - // Temporary compatibility constructor. - LanguageComboboxModel(Profile* profile, - const std::vector& locale_codes); + LanguageList(); - virtual ~LanguageComboboxModel() {} + explicit LanguageList(const std::vector& locale_codes); - void InitNativeNames(const std::vector& locale_codes); + virtual ~LanguageList() {} - // Overridden from ComboboxModel: - virtual int GetItemCount(); + virtual int get_languages_count() const; - virtual std::wstring GetItemAt(int index); + virtual std::wstring GetLanguageNameAt(int index) const; // Return the locale for the given index. E.g., may return pt-BR. - std::string GetLocaleFromIndex(int index); + std::string GetLocaleFromIndex(int index) const; // Returns the index for the given locale. Returns -1 if the locale is not // in the combobox model. - int GetIndexFromLocale(const std::string& locale); + int GetIndexFromLocale(const std::string& locale) const; + + private: + // The names of all the locales in the current application locale. + std::vector locale_names_; + + // A map of some extra data (LocaleData) keyed off the name of the locale. + LocaleDataMap native_names_; + + void InitNativeNames(const std::vector& locale_codes); + + DISALLOW_COPY_AND_ASSIGN(LanguageList); +}; + +/////////////////////////////////////////////////////////////////////////////// +// LanguageComboboxModel +// The combobox model implementation. +class LanguageComboboxModel : public LanguageList, public ComboboxModel { + public: + LanguageComboboxModel(); + + // Temporary compatibility constructor. + LanguageComboboxModel(Profile* profile, + const std::vector& locale_codes); + + virtual ~LanguageComboboxModel() {} + + virtual int GetItemCount() { return get_languages_count(); } + + virtual std::wstring GetItemAt(int index) { return GetLanguageNameAt(index); } // Returns the index of the language currently specified in the user's // preference file. Note that it's possible for language A to be picked @@ -59,12 +84,6 @@ class LanguageComboboxModel : public ComboboxModel { int GetSelectedLanguageIndex(const std::wstring& prefs); private: - // The names of all the locales in the current application locale. - std::vector locale_names_; - - // A map of some extra data (LocaleData) keyed off the name of the locale. - LocaleDataMap native_names_; - // Profile. Profile* profile_; -- cgit v1.1