diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-18 01:04:45 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-18 01:04:45 +0000 |
commit | 733436966716d5307a251c2852931531edc9b963 (patch) | |
tree | 14f7a5d2538bb4a70852f5a3e0a6a8e0e94c1b43 /views | |
parent | 489d946c2d39713777826de69d02546c8307e54e (diff) | |
download | chromium_src-733436966716d5307a251c2852931531edc9b963.zip chromium_src-733436966716d5307a251c2852931531edc9b963.tar.gz chromium_src-733436966716d5307a251c2852931531edc9b963.tar.bz2 |
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
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/combobox/combobox.cc | 5 | ||||
-rw-r--r-- | views/controls/combobox/combobox.h | 17 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_win.cc | 5 | ||||
-rw-r--r-- | views/focus/focus_manager_unittest.cc | 13 |
4 files changed, 18 insertions, 22 deletions
diff --git a/views/controls/combobox/combobox.cc b/views/controls/combobox/combobox.cc index 43165a2..5c5596f 100644 --- a/views/controls/combobox/combobox.cc +++ b/views/controls/combobox/combobox.cc @@ -4,6 +4,7 @@ #include "views/controls/combobox/combobox.h" +#include "app/combobox_model.h" #include "base/keyboard_codes.h" #include "base/logging.h" #include "views/controls/combobox/native_combobox_wrapper.h" @@ -16,7 +17,7 @@ const char Combobox::kViewClassName[] = "views/Combobox"; //////////////////////////////////////////////////////////////////////////////// // Combobox, public: -Combobox::Combobox(Model* model) +Combobox::Combobox(ComboboxModel* model) : native_wrapper_(NULL), model_(model), listener_(NULL), @@ -28,7 +29,7 @@ Combobox::~Combobox() { } void Combobox::ModelChanged() { - selected_item_ = std::min(0, model_->GetItemCount(this)); + selected_item_ = std::min(0, model_->GetItemCount()); if (native_wrapper_) native_wrapper_->UpdateFromModel(); } diff --git a/views/controls/combobox/combobox.h b/views/controls/combobox/combobox.h index a66e379..105aa54 100644 --- a/views/controls/combobox/combobox.h +++ b/views/controls/combobox/combobox.h @@ -7,6 +7,8 @@ #include "views/view.h" +class ComboboxModel; + namespace views { class NativeComboboxWrapper; @@ -17,15 +19,6 @@ class Combobox : public View { // The combobox's class name. static const char kViewClassName[]; - class Model { - public: - // Return the number of items in the combo box. - virtual int GetItemCount(Combobox* source) = 0; - - // Return the string that should be used to represent a given item. - virtual std::wstring GetItemAt(Combobox* source, int index) = 0; - }; - class Listener { public: // This is invoked once the selected item changed. @@ -35,7 +28,7 @@ class Combobox : public View { }; // |model| is not owned by the combo box. - explicit Combobox(Model* model); + explicit Combobox(ComboboxModel* model); virtual ~Combobox(); // Register |listener| for item change events. @@ -54,7 +47,7 @@ class Combobox : public View { void SelectionChanged(); // Accessor for |model_|. - Model* model() const { return model_; } + ComboboxModel* model() const { return model_; } // Overridden from View: virtual gfx::Size GetPreferredSize(); @@ -73,7 +66,7 @@ class Combobox : public View { private: // Our model. - Model* model_; + ComboboxModel* model_; // Item change listener. Listener* listener_; diff --git a/views/controls/combobox/native_combobox_win.cc b/views/controls/combobox/native_combobox_win.cc index dee1108..bc6102b 100644 --- a/views/controls/combobox/native_combobox_win.cc +++ b/views/controls/combobox/native_combobox_win.cc @@ -4,6 +4,7 @@ #include "views/controls/combobox/native_combobox_win.h" +#include "app/combobox_model.h" #include "app/gfx/font.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" @@ -43,9 +44,9 @@ void NativeComboboxWin::UpdateFromModel() { gfx::Font font = ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont); int max_width = 0; - int num_items = combobox_->model()->GetItemCount(combobox_); + int num_items = combobox_->model()->GetItemCount(); for (int i = 0; i < num_items; ++i) { - const std::wstring& text = combobox_->model()->GetItemAt(combobox_, i); + const std::wstring& text = combobox_->model()->GetItemAt(i); // Inserting the Unicode formatting characters if necessary so that the // text is displayed correctly in right-to-left UIs. diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 4df7f37..c72a394 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -8,6 +8,7 @@ // the events don't go to the Chrome window. #include "testing/gtest/include/gtest/gtest.h" +#include "app/combobox_model.h" #include "app/resource_bundle.h" #include "base/gfx/rect.h" #include "base/keyboard_codes.h" @@ -255,11 +256,11 @@ class BorderView : public NativeViewHost { DISALLOW_COPY_AND_ASSIGN(BorderView); }; -class DummyComboboxModel : public Combobox::Model { +class DummyComboboxModel : public ComboboxModel { public: - virtual int GetItemCount(Combobox* source) { return 10; } + virtual int GetItemCount() { return 10; } - virtual std::wstring GetItemAt(Combobox* source, int index) { + virtual std::wstring GetItemAt(int index) { return L"Item " + IntToWString(index); } }; @@ -735,16 +736,16 @@ class TestTextfield : public Textfield { } }; -class TestCombobox : public Combobox, public Combobox::Model { +class TestCombobox : public Combobox, public ComboboxModel { public: TestCombobox() : Combobox(this) { } virtual gfx::NativeView TestGetNativeControlView() { return native_wrapper_->GetTestingHandle(); } - virtual int GetItemCount(Combobox* source) { + virtual int GetItemCount() { return 10; } - virtual std::wstring GetItemAt(Combobox* source, int index) { + virtual std::wstring GetItemAt(int index) { return L"Hello combo"; } }; |