From 733436966716d5307a251c2852931531edc9b963 Mon Sep 17 00:00:00 2001 From: "mattm@chromium.org" Date: Tue, 18 Aug 2009 01:04:45 +0000 Subject: Factor out views::Combobox::Model so that it can be used cross-platform. This removes the Combobox* source arg from the Model methods, which wasn't really used by anything. BUG=none TEST=none Review URL: http://codereview.chromium.org/165514 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23603 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/views/bookmark_bubble_view.cc | 9 ++++----- chrome/browser/views/bookmark_bubble_view.h | 7 ++++--- chrome/browser/views/bug_report_view.cc | 9 +++++---- chrome/browser/views/clear_browsing_data.cc | 9 +++------ chrome/browser/views/clear_browsing_data.h | 9 +++++---- chrome/browser/views/first_run_customize_view.cc | 5 ++--- chrome/browser/views/first_run_customize_view.h | 9 +++++---- chrome/browser/views/importer_view.cc | 6 ++---- chrome/browser/views/importer_view.h | 9 +++++---- chrome/browser/views/options/advanced_contents_view.cc | 7 ++++--- chrome/browser/views/options/fonts_page_view.cc | 9 +++++---- chrome/browser/views/options/general_page_view.cc | 16 ++++++++-------- chrome/browser/views/options/language_combobox_model.cc | 7 +++---- chrome/browser/views/options/language_combobox_model.h | 10 +++++----- chrome/browser/views/select_profile_dialog.cc | 6 ++---- chrome/browser/views/select_profile_dialog.h | 9 +++++---- 16 files changed, 67 insertions(+), 69 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index ba101f1a..8a21fe3 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -105,13 +105,12 @@ BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel( find(nodes_.begin(), nodes_.end(), node->GetParent()) - nodes_.begin()); } -int BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemCount( - Combobox* source) { +int BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemCount() { return static_cast(nodes_.size() + 1); } std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( - Combobox* source, int index) { + int index) { if (index == nodes_.size()) return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); return nodes_[index]->GetTitle(); @@ -336,7 +335,7 @@ void BookmarkBubbleView::LinkActivated(Link* source, int event_flags) { void BookmarkBubbleView::ItemChanged(Combobox* combobox, int prev_index, int new_index) { - if (new_index + 1 == parent_model_.GetItemCount(parent_combobox_)) { + if (new_index + 1 == parent_model_.GetItemCount()) { UserMetrics::RecordAction(L"BookmarkBubble_EditFromCombobox", profile_); ShowEditor(); @@ -417,7 +416,7 @@ void BookmarkBubbleView::ApplyEdits() { } // Last index means 'Choose another folder...' if (parent_combobox_->selected_item() < - parent_model_.GetItemCount(parent_combobox_) - 1) { + parent_model_.GetItemCount() - 1) { const BookmarkNode* new_parent = parent_model_.GetNodeAt(parent_combobox_->selected_item()); if (new_parent != node->GetParent()) { diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h index 517aea9..ebcc445 100644 --- a/chrome/browser/views/bookmark_bubble_view.h +++ b/chrome/browser/views/bookmark_bubble_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_BUBBLE_VIEW_H_ #define CHROME_BROWSER_VIEWS_BOOKMARK_BUBBLE_VIEW_H_ +#include "app/combobox_model.h" #include "base/gfx/rect.h" #include "chrome/browser/views/info_bubble.h" #include "googleurl/src/gurl.h" @@ -60,13 +61,13 @@ class BookmarkBubbleView : public views::View, // Model for the combobox showing the list of folders to choose from. The // list always contains the bookmark bar, other node and parent. The list // also contains an extra item that shows the text 'Choose another folder...'. - class RecentlyUsedFoldersModel : public views::Combobox::Model { + class RecentlyUsedFoldersModel : public ComboboxModel { public: RecentlyUsedFoldersModel(BookmarkModel* bb_model, const BookmarkNode* node); // Combobox::Model methods. Call through to nodes_. - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // Returns the node at the specified index. const BookmarkNode* GetNodeAt(int index); diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc index 109ecd5..f48572d 100644 --- a/chrome/browser/views/bug_report_view.cc +++ b/chrome/browser/views/bug_report_view.cc @@ -4,6 +4,7 @@ #include "chrome/browser/views/bug_report_view.h" +#include "app/combobox_model.h" #include "app/l10n_util.h" #include "app/win_util.h" #include "base/file_version_info.h" @@ -42,7 +43,7 @@ static const int kDescriptionLines = 5; static const char kReportPhishingUrl[] = "http://www.google.com/safebrowsing/report_phish/"; -class BugReportComboBoxModel : public views::Combobox::Model { +class BugReportComboBoxModel : public ComboboxModel { public: BugReportComboBoxModel() {} @@ -57,12 +58,12 @@ class BugReportComboBoxModel : public views::Combobox::Model { OTHER_PROBLEM }; - // views::Combobox::Model interface. - virtual int GetItemCount(views::Combobox* source) { + // ComboboxModel interface. + virtual int GetItemCount() { return OTHER_PROBLEM + 1; } - virtual std::wstring GetItemAt(views::Combobox* source, int index) { + virtual std::wstring GetItemAt(int index) { return GetItemAtIndex(index); } diff --git a/chrome/browser/views/clear_browsing_data.cc b/chrome/browser/views/clear_browsing_data.cc index 9b8cf76..ba6417a 100644 --- a/chrome/browser/views/clear_browsing_data.cc +++ b/chrome/browser/views/clear_browsing_data.cc @@ -310,16 +310,13 @@ views::View* ClearBrowsingDataView::GetContentsView() { } //////////////////////////////////////////////////////////////////////////////// -// ClearBrowsingDataView, views::Combobox::Model implementation: +// ClearBrowsingDataView, ComboboxModel implementation: -int ClearBrowsingDataView::GetItemCount(views::Combobox* source) { - DCHECK(source == time_period_combobox_); +int ClearBrowsingDataView::GetItemCount() { return 4; } -std::wstring ClearBrowsingDataView::GetItemAt(views::Combobox* source, - int index) { - DCHECK(source == time_period_combobox_); +std::wstring ClearBrowsingDataView::GetItemAt(int index) { switch (index) { case 0: return l10n_util::GetString(IDS_CLEAR_DATA_DAY); case 1: return l10n_util::GetString(IDS_CLEAR_DATA_WEEK); diff --git a/chrome/browser/views/clear_browsing_data.h b/chrome/browser/views/clear_browsing_data.h index cb84d08..f7b1743 100644 --- a/chrome/browser/views/clear_browsing_data.h +++ b/chrome/browser/views/clear_browsing_data.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_CLEAR_BROWSING_DATA_H_ #define CHROME_BROWSER_VIEWS_CLEAR_BROWSING_DATA_H_ +#include "app/combobox_model.h" #include "chrome/browser/browsing_data_remover.h" #include "views/controls/button/button.h" #include "views/controls/combobox/combobox.h" @@ -32,7 +33,7 @@ class MessageLoop; class ClearBrowsingDataView : public views::View, public views::DialogDelegate, public views::ButtonListener, - public views::Combobox::Model, + public ComboboxModel, public views::Combobox::Listener, public BrowsingDataRemover::Observer { public: @@ -63,9 +64,9 @@ class ClearBrowsingDataView : public views::View, virtual bool Accept(); virtual views::View* GetContentsView(); - // Overridden from views::Combobox::Model: - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + // Overridden from ComboboxModel: + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // Overridden from views::Combobox::Listener: virtual void ItemChanged(views::Combobox* sender, int prev_index, diff --git a/chrome/browser/views/first_run_customize_view.cc b/chrome/browser/views/first_run_customize_view.cc index f93d7a7..5ae339b 100644 --- a/chrome/browser/views/first_run_customize_view.cc +++ b/chrome/browser/views/first_run_customize_view.cc @@ -163,12 +163,11 @@ void FirstRunCustomizeView::ButtonPressed(views::Button* sender) { } } -int FirstRunCustomizeView::GetItemCount(views::Combobox* source) { +int FirstRunCustomizeView::GetItemCount() { return importer_host_->GetAvailableProfileCount(); } -std::wstring FirstRunCustomizeView::GetItemAt(views::Combobox* source, - int index) { +std::wstring FirstRunCustomizeView::GetItemAt(int index) { return importer_host_->GetSourceProfileNameAt(index); } diff --git a/chrome/browser/views/first_run_customize_view.h b/chrome/browser/views/first_run_customize_view.h index 990bf27..1dcf1a0 100644 --- a/chrome/browser/views/first_run_customize_view.h +++ b/chrome/browser/views/first_run_customize_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_FIRST_RUN_CUSTOMIZE_VIEW_H_ #define CHROME_BROWSER_VIEWS_FIRST_RUN_CUSTOMIZE_VIEW_H_ +#include "app/combobox_model.h" #include "chrome/browser/views/first_run_view_base.h" #include "views/controls/button/button.h" #include "views/controls/combobox/combobox.h" @@ -26,7 +27,7 @@ class Profile; // some simple customizations during the first run. class FirstRunCustomizeView : public FirstRunViewBase, public views::ButtonListener, - public views::Combobox::Model { + public ComboboxModel { public: class CustomizeViewObserver { public: @@ -54,9 +55,9 @@ class FirstRunCustomizeView : public FirstRunViewBase, // Overridden form views::ButtonListener. virtual void ButtonPressed(views::Button* sender); - // Overridden form views::Combobox::Model. - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + // Overridden form ComboboxModel. + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // Overridden from views::WindowDelegate. virtual std::wstring GetWindowTitle() const; diff --git a/chrome/browser/views/importer_view.cc b/chrome/browser/views/importer_view.cc index 77d3e67..5df68ef 100644 --- a/chrome/browser/views/importer_view.cc +++ b/chrome/browser/views/importer_view.cc @@ -150,8 +150,7 @@ views::View* ImporterView::GetContentsView() { return this; } -int ImporterView::GetItemCount(views::Combobox* source) { - DCHECK(source == profile_combobox_); +int ImporterView::GetItemCount() { DCHECK(importer_host_.get()); int item_count = importer_host_->GetAvailableProfileCount(); if (checkbox_items_.size() < static_cast(item_count)) @@ -159,8 +158,7 @@ int ImporterView::GetItemCount(views::Combobox* source) { return item_count; } -std::wstring ImporterView::GetItemAt(views::Combobox* source, int index) { - DCHECK(source == profile_combobox_); +std::wstring ImporterView::GetItemAt(int index) { DCHECK(importer_host_.get()); return importer_host_->GetSourceProfileNameAt(index); } diff --git a/chrome/browser/views/importer_view.h b/chrome/browser/views/importer_view.h index 9194e75..88a07cb 100644 --- a/chrome/browser/views/importer_view.h +++ b/chrome/browser/views/importer_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_IMPORTER_VIEW_H__ #define CHROME_BROWSER_VIEWS_IMPORTER_VIEW_H__ +#include "app/combobox_model.h" #include "chrome/browser/importer/importer.h" #include "views/controls/button/native_button.h" #include "views/controls/combobox/combobox.h" @@ -25,7 +26,7 @@ class Profile; // So now use dialog as a placeholder. class ImporterView : public views::View, public views::DialogDelegate, - public views::Combobox::Model, + public ComboboxModel, public views::Combobox::Listener, public ImportObserver { public: @@ -44,9 +45,9 @@ class ImporterView : public views::View, virtual bool Accept(); virtual views::View* GetContentsView(); - // Overridden from views::Combobox::Model. - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + // Overridden from ComboboxModel. + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // Overridden from ChromeViews::Combobox::Listener virtual void ItemChanged(views::Combobox* combobox, diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index c5edfb3..d72ef65 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -12,6 +12,7 @@ #include #include +#include "app/combobox_model.h" #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" @@ -420,16 +421,16 @@ void AdvancedSection::InitControlLayout() { //////////////////////////////////////////////////////////////////////////////// // PrivacySection -class CookieBehaviorComboModel : public views::Combobox::Model { +class CookieBehaviorComboModel : public ComboboxModel { public: CookieBehaviorComboModel() {} // Return the number of items in the combo box. - virtual int GetItemCount(views::Combobox* source) { + virtual int GetItemCount() { return 3; } - virtual std::wstring GetItemAt(views::Combobox* source, int index) { + virtual std::wstring GetItemAt(int index) { const int kStringIDs[] = { IDS_OPTIONS_COOKIES_ACCEPT_ALL_COOKIES, IDS_OPTIONS_COOKIES_RESTRICT_THIRD_PARTY_COOKIES, diff --git a/chrome/browser/views/options/fonts_page_view.cc b/chrome/browser/views/options/fonts_page_view.cc index 7e99e9d..2affdb8 100644 --- a/chrome/browser/views/options/fonts_page_view.cc +++ b/chrome/browser/views/options/fonts_page_view.cc @@ -11,6 +11,7 @@ #include +#include "app/combobox_model.h" #include "app/gfx/canvas.h" #include "app/gfx/font.h" #include "app/l10n_util.h" @@ -38,7 +39,7 @@ static std::vector sorted_encoding_list; } // namespace -class DefaultEncodingComboboxModel : public views::Combobox::Model { +class DefaultEncodingComboboxModel : public ComboboxModel { public: DefaultEncodingComboboxModel() { canonical_encoding_names_length_ = @@ -57,12 +58,12 @@ class DefaultEncodingComboboxModel : public views::Combobox::Model { virtual ~DefaultEncodingComboboxModel() {} - // Overridden from views::Combobox::Model. - virtual int GetItemCount(views::Combobox* source) { + // Overridden from ComboboxModel. + virtual int GetItemCount() { return canonical_encoding_names_length_; } - virtual std::wstring GetItemAt(views::Combobox* source, int index) { + virtual std::wstring GetItemAt(int index) { DCHECK(index >= 0 && canonical_encoding_names_length_ > index); return sorted_encoding_list[index].encoding_display_name; } diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index f639efe..a1d9034 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -4,6 +4,7 @@ #include "chrome/browser/views/options/general_page_view.h" +#include "app/combobox_model.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/gfx/png_decoder.h" @@ -266,7 +267,7 @@ CustomHomePagesTableModel::Entry* /////////////////////////////////////////////////////////////////////////////// // SearchEngineListModel -class SearchEngineListModel : public views::Combobox::Model, +class SearchEngineListModel : public ComboboxModel, public TemplateURLModelObserver { public: explicit SearchEngineListModel(Profile* profile); @@ -276,9 +277,9 @@ class SearchEngineListModel : public views::Combobox::Model, // so that when the TemplateURLModel changes the combobox can be updated. void SetCombobox(views::Combobox* combobox); - // views::Combobox::Model overrides: - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + // ComboboxModel overrides: + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // Returns the TemplateURL at the specified index. const TemplateURL* GetTemplateURLAt(int index); @@ -331,13 +332,12 @@ void SearchEngineListModel::SetCombobox(views::Combobox* combobox) { combobox_->SetEnabled(false); } -int SearchEngineListModel::GetItemCount(views::Combobox* source) { +int SearchEngineListModel::GetItemCount() { return static_cast(template_urls_.size()); } -std::wstring SearchEngineListModel::GetItemAt(views::Combobox* source, - int index) { - DCHECK(index < GetItemCount(combobox_)); +std::wstring SearchEngineListModel::GetItemAt(int index) { + DCHECK(index < GetItemCount()); return template_urls_[index]->short_name(); } diff --git a/chrome/browser/views/options/language_combobox_model.cc b/chrome/browser/views/options/language_combobox_model.cc index 5e960e1..a026ab6 100644 --- a/chrome/browser/views/options/language_combobox_model.cc +++ b/chrome/browser/views/options/language_combobox_model.cc @@ -71,13 +71,12 @@ void LanguageComboboxModel::InitNativeNames( &locale_names_); } -// Overridden from views::Combobox::Model: -int LanguageComboboxModel::GetItemCount(views::Combobox* source) { +// Overridden from ComboboxModel: +int LanguageComboboxModel::GetItemCount() { return static_cast(locale_names_.size()); } -std::wstring LanguageComboboxModel::GetItemAt(views::Combobox* source, - int index) { +std::wstring LanguageComboboxModel::GetItemAt(int index) { DCHECK(static_cast(locale_names_.size()) > index); LocaleDataMap::const_iterator it = native_names_.find(locale_names_[index]); diff --git a/chrome/browser/views/options/language_combobox_model.h b/chrome/browser/views/options/language_combobox_model.h index 9109151..6298925 100644 --- a/chrome/browser/views/options/language_combobox_model.h +++ b/chrome/browser/views/options/language_combobox_model.h @@ -5,13 +5,13 @@ #ifndef CHROME_BROWSER_VIEWS_OPTIONS_LANGUAGE_COMBOBOX_MODEL_H_ #define CHROME_BROWSER_VIEWS_OPTIONS_LANGUAGE_COMBOBOX_MODEL_H_ +#include "app/combobox_model.h" #include "chrome/browser/profile.h" -#include "views/controls/combobox/combobox.h" /////////////////////////////////////////////////////////////////////////////// // LanguageComboboxModel // The model that fills the dropdown of valid UI languages. -class LanguageComboboxModel : public views::Combobox::Model { +class LanguageComboboxModel : public ComboboxModel { public: struct LocaleData { LocaleData() { } @@ -33,10 +33,10 @@ class LanguageComboboxModel : public views::Combobox::Model { void InitNativeNames(const std::vector& locale_codes); - // Overridden from views::Combobox::Model: - virtual int GetItemCount(views::Combobox* source); + // Overridden from ComboboxModel: + virtual int GetItemCount(); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + virtual std::wstring GetItemAt(int index); // Return the locale for the given index. E.g., may return pt-BR. std::string GetLocaleFromIndex(int index); diff --git a/chrome/browser/views/select_profile_dialog.cc b/chrome/browser/views/select_profile_dialog.cc index 6c4dead..d4af82e 100644 --- a/chrome/browser/views/select_profile_dialog.cc +++ b/chrome/browser/views/select_profile_dialog.cc @@ -109,15 +109,13 @@ views::View* SelectProfileDialog::GetContentsView() { return this; } -int SelectProfileDialog::GetItemCount(views::Combobox* source) { +int SelectProfileDialog::GetItemCount() { // Always show one more item in the combo box that allows the user to select // . return profiles_.size() + 1; } -std::wstring SelectProfileDialog::GetItemAt(views::Combobox* source, - int index) { - DCHECK(source == profile_combobox_); +std::wstring SelectProfileDialog::GetItemAt(int index) { DCHECK(index >= 0 && index <= static_cast(profiles_.size())); // For the last item in the drop down, return the text, // otherwise return the corresponding profile name from the vector. diff --git a/chrome/browser/views/select_profile_dialog.h b/chrome/browser/views/select_profile_dialog.h index 22750b5..9c309de 100644 --- a/chrome/browser/views/select_profile_dialog.h +++ b/chrome/browser/views/select_profile_dialog.h @@ -10,6 +10,7 @@ #include +#include "app/combobox_model.h" #include "base/basictypes.h" #include "base/message_loop.h" #include "base/ref_counted.h" @@ -28,7 +29,7 @@ class Window; class SelectProfileDialog : public views::DialogDelegate, public views::View, - public views::Combobox::Model, + public ComboboxModel, public GetProfilesHelper::Delegate { public: // Creates and runs the dialog. @@ -54,9 +55,9 @@ class SelectProfileDialog virtual std::wstring GetWindowTitle() const; virtual bool IsModal() const { return false; } - // views::Combobox::Model methods. - virtual int GetItemCount(views::Combobox* source); - virtual std::wstring GetItemAt(views::Combobox* source, int index); + // ComboboxModel methods. + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); // GetProfilesHelper::Delegate method. virtual void OnGetProfilesDone(const std::vector& profiles); -- cgit v1.1