diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 19:57:31 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 19:57:31 +0000 |
commit | 67c565eee0066426a716b2c5085a7af04f52e73a (patch) | |
tree | 9919e990c47bed244400e4d7c651d9f099726d83 | |
parent | 09c6dec4e18784861660f716d038035be9540601 (diff) | |
download | chromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.zip chromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.tar.gz chromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.tar.bz2 |
Move TableModel out of views/ and into app/.
Remove stub implementation in temp_scaffolding_stubs.h
Use l10n_util collator helper function in TableModel::Compare
Review URL: http://codereview.chromium.org/126184
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18518 0039d316-1c4b-4281-b951-d872f2087c98
29 files changed, 179 insertions, 222 deletions
diff --git a/app/app.gyp b/app/app.gyp index 3d1d0a5..e316d41d 100644 --- a/app/app.gyp +++ b/app/app.gyp @@ -104,6 +104,9 @@ 'theme_provider.h', 'throb_animation.cc', 'throb_animation.h', + 'table_model.cc', + 'table_model.h', + 'table_model_observer.h', ], 'direct_dependent_settings': { 'include_dirs': [ diff --git a/views/controls/table/table_model.cc b/app/table_model.cc index 7e1dd0e..0f35905 100644 --- a/views/controls/table/table_model.cc +++ b/app/table_model.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "views/controls/table/table_model.h" +#include "app/table_model.h" #include "app/l10n_util.h" +#include "third_party/skia/include/core/SkBitmap.h" -namespace views { +// TableColumn ----------------------------------------------------------------- TableColumn::TableColumn() : id(0), @@ -64,5 +65,42 @@ TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) title = l10n_util::GetString(id); } -} // namespace views +// TableModel ----------------------------------------------------------------- +// Used for sorting. +static Collator* collator = NULL; + +SkBitmap TableModel::GetIcon(int row) { + return SkBitmap(); +} + +int TableModel::CompareValues(int row1, int row2, int column_id) { + DCHECK(row1 >= 0 && row1 < RowCount() && + row2 >= 0 && row2 < RowCount()); + std::wstring value1 = GetText(row1, column_id); + std::wstring value2 = GetText(row2, column_id); + Collator* collator = GetCollator(); + + if (collator) + return l10n_util::CompareStringWithCollator(collator, value1, value2); + + NOTREACHED(); + return 0; +} + +Collator* TableModel::GetCollator() { + if (!collator) { + UErrorCode create_status = U_ZERO_ERROR; + collator = Collator::createInstance(create_status); + if (!U_SUCCESS(create_status)) { + collator = NULL; + NOTREACHED(); + } + } + return collator; +} + +void TableModel::ClearCollator() { + delete collator; + collator = NULL; +} diff --git a/views/controls/table/table_model.h b/app/table_model.h index 5c377c7..ba7043e 100644 --- a/views/controls/table/table_model.h +++ b/app/table_model.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ -#define VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ +#ifndef APP_TABLE_MODEL_H_ +#define APP_TABLE_MODEL_H_ #include <string> #include <vector> @@ -13,8 +13,6 @@ class SkBitmap; -namespace views { - class TableModelObserver; // The model driving the TableView. @@ -92,6 +90,9 @@ class TableModel { // comparison. virtual int CompareValues(int row1, int row2, int column_id); + // Reset the collator. + void ClearCollator(); + protected: // Returns the collator used by CompareValues. Collator* GetCollator(); @@ -149,6 +150,4 @@ struct TableColumn { bool sortable; }; -} // namespace views - -#endif // VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ +#endif // APP_TABLE_MODEL_H_ diff --git a/views/controls/table/table_model_observer.h b/app/table_model_observer.h index b968a9f..fcd50f4 100644 --- a/views/controls/table/table_model_observer.h +++ b/app/table_model_observer.h @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ -#define VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ - -namespace views { +#ifndef APP_TABLE_MODEL_OBSERVER_H_ +#define APP_TABLE_MODEL_OBSERVER_H_ // Observer for a TableModel. Anytime the model changes, it must notify its // observer. @@ -24,6 +22,4 @@ class TableModelObserver { virtual void OnItemsRemoved(int start, int length) = 0; }; -} // namespace views - -#endif // VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ +#endif // APP_TABLE_MODEL_OBSERVER_H_ diff --git a/chrome/browser/bookmarks/bookmark_table_model.cc b/chrome/browser/bookmarks/bookmark_table_model.cc index 4ff6a57..733c99e 100644 --- a/chrome/browser/bookmarks/bookmark_table_model.cc +++ b/chrome/browser/bookmarks/bookmark_table_model.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/table_model_observer.h" #include "base/string_util.h" #include "base/time_format.h" #include "chrome/browser/bookmarks/bookmark_utils.h" @@ -21,10 +22,6 @@ #include "net/base/escape.h" #include "net/base/net_util.h" -#if defined(TOOLKIT_VIEWS) -#include "views/controls/table/table_model_observer.h" -#endif - namespace { // Number of bookmarks shown in recently bookmarked. diff --git a/chrome/browser/bookmarks/bookmark_table_model.h b/chrome/browser/bookmarks/bookmark_table_model.h index db7051f..7dd7f9e 100644 --- a/chrome/browser/bookmarks/bookmark_table_model.h +++ b/chrome/browser/bookmarks/bookmark_table_model.h @@ -5,21 +5,16 @@ #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_TABLE_MODEL_H_ #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_TABLE_MODEL_H_ +#include "app/table_model.h" #include "build/build_config.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#if defined(TOOLKIT_VIEWS) -#include "views/controls/table/table_model.h" -#else -#include "chrome/common/temp_scaffolding_stubs.h" -#endif - // BookmarkTableModel provides a view of the BookmarkModel as a TableModel. // Three variations are provided: // . Recently created bookmarks. // . The children of a particular folder. // . All bookmarks matching the specified text. -class BookmarkTableModel : public views::TableModel, +class BookmarkTableModel : public TableModel, public BookmarkModelObserver { public: // Methods for creating the various BookmarkTableModels. Ownership passes @@ -41,7 +36,7 @@ class BookmarkTableModel : public views::TableModel, // TableModel methods. virtual std::wstring GetText(int row, int column_id); virtual SkBitmap GetIcon(int row); - virtual void SetObserver(views::TableModelObserver* observer) { + virtual void SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -63,14 +58,14 @@ class BookmarkTableModel : public views::TableModel, BookmarkModel* model() const { return model_; } protected: - views::TableModelObserver* observer() const { return observer_; } + TableModelObserver* observer() const { return observer_; } private: // Builds the path shown in the path column for the specified node. void BuildPath(BookmarkNode* node, std::wstring* path); BookmarkModel* model_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; DISALLOW_COPY_AND_ASSIGN(BookmarkTableModel); }; diff --git a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc index 7add6a9..9003256 100644 --- a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/table_model_observer.h" #include "base/string_util.h" #include "base/time.h" #include "chrome/browser/bookmarks/bookmark_table_model.h" #include "chrome/test/testing_profile.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" -#include "views/controls/table/table_model_observer.h" using base::Time; using base::TimeDelta; @@ -23,7 +23,7 @@ using base::TimeDelta; // f2 // url3 (t0 + 1) class BookmarkTableModelTest : public testing::Test, - public views::TableModelObserver { + public TableModelObserver { public: BookmarkTableModelTest() : url1_("http://1"), diff --git a/chrome/browser/task_manager_win.cc b/chrome/browser/task_manager_win.cc index 671c2ea..42b835a 100644 --- a/chrome/browser/task_manager_win.cc +++ b/chrome/browser/task_manager_win.cc @@ -5,6 +5,7 @@ #include "chrome/browser/task_manager.h" #include "app/l10n_util.h" +#include "app/table_model_observer.h" #include "base/stats_table.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser_list.h" @@ -59,7 +60,7 @@ class TaskManagerTableModel : public views::GroupTableModel, std::wstring GetText(int row, int column); SkBitmap GetIcon(int row); void GetGroupRangeForItem(int item, views::GroupRange* range); - void SetObserver(views::TableModelObserver* observer); + void SetObserver(TableModelObserver* observer); virtual int CompareValues(int row1, int row2, int column_id); // TaskManagerModelObserver. @@ -70,7 +71,7 @@ class TaskManagerTableModel : public views::GroupTableModel, private: const TaskManagerModel* model_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; }; int TaskManagerTableModel::RowCount() { @@ -129,7 +130,7 @@ void TaskManagerTableModel::GetGroupRangeForItem(int item, range->length = range_pair.second; } -void TaskManagerTableModel::SetObserver(views::TableModelObserver* observer) { +void TaskManagerTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -243,7 +244,7 @@ class TaskManagerViewImpl : public TaskManagerView, TaskManagerModel* model_; // all possible columns, not necessarily visible - std::vector<views::TableColumn> columns_; + std::vector<TableColumn> columns_; scoped_ptr<TaskManagerTableModel> table_model_; @@ -276,26 +277,26 @@ TaskManagerViewImpl::~TaskManagerViewImpl() { void TaskManagerViewImpl::Init() { table_model_.reset(new TaskManagerTableModel(model_)); - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, - views::TableColumn::LEFT, -1, 1)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, + TableColumn::LEFT, -1, 1)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_CPU_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_NET_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_NET_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; - columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, - views::TableColumn::RIGHT, -1, 0)); + columns_.push_back(TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, + TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; tab_table_ = new views::GroupTableView(table_model_.get(), columns_, @@ -309,8 +310,8 @@ void TaskManagerViewImpl::Init() { tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); UpdateStatsCounters(); - views::TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported", - views::TableColumn::RIGHT, -1, 0); + TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported", + TableColumn::RIGHT, -1, 0); col.sortable = true; columns_.push_back(col); tab_table_->AddColumn(col); @@ -341,8 +342,7 @@ void TaskManagerViewImpl::UpdateStatsCounters() { // stat names not in the string table would be filtered out. // TODO(erikkay): Width is hard-coded right now, so many column // names are clipped. - views::TableColumn col(i, ASCIIToWide(row), views::TableColumn::RIGHT, - 90, 0); + TableColumn col(i, ASCIIToWide(row), TableColumn::RIGHT, 90, 0); col.sortable = true; columns_.push_back(col); tab_table_->AddColumn(col); @@ -562,7 +562,7 @@ void TaskManagerViewImpl::ShowContextMenu(views::View* source, UpdateStatsCounters(); scoped_ptr<views::Menu> menu(views::Menu::Create( this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView())); - for (std::vector<views::TableColumn>::iterator i = + for (std::vector<TableColumn>::iterator i = columns_.begin(); i != columns_.end(); ++i) { menu->AppendMenuItem(i->id, i->title, views::Menu::CHECKBOX); } diff --git a/chrome/browser/views/bookmark_table_view.cc b/chrome/browser/views/bookmark_table_view.cc index 8a74777..7705d1b 100644 --- a/chrome/browser/views/bookmark_table_view.cc +++ b/chrome/browser/views/bookmark_table_view.cc @@ -28,7 +28,7 @@ namespace { // Height of the drop indicator used when dropping between rows. const int kDropHighlightHeight = 2; -int GetWidthOfColumn(const std::vector<views::TableColumn>& columns, +int GetWidthOfColumn(const std::vector<TableColumn>& columns, const std::vector<int> widths, int column_id) { for (size_t i = 0; i < columns.size(); ++i) { @@ -47,7 +47,7 @@ void BookmarkTableView::DropInfo::Scrolled() { BookmarkTableView::BookmarkTableView(Profile* profile, BookmarkTableModel* model) - : views::TableView(model, std::vector<views::TableColumn>(), + : views::TableView(model, std::vector<TableColumn>(), views::ICON_AND_TEXT, false, true, true), profile_(profile), show_path_column_(false) { @@ -362,15 +362,14 @@ RECT BookmarkTableView::GetDropBetweenHighlightRect(int index) { void BookmarkTableView::UpdateColumns() { PrefService* prefs = profile_->GetPrefs(); - views::TableColumn name_column = - views::TableColumn(IDS_BOOKMARK_TABLE_TITLE, views::TableColumn::LEFT, - -1); - views::TableColumn url_column = - views::TableColumn(IDS_BOOKMARK_TABLE_URL, views::TableColumn::LEFT, -1); - views::TableColumn path_column = - views::TableColumn(IDS_BOOKMARK_TABLE_PATH, views::TableColumn::LEFT, -1); - - std::vector<views::TableColumn> columns; + TableColumn name_column = + TableColumn(IDS_BOOKMARK_TABLE_TITLE, TableColumn::LEFT, -1); + TableColumn url_column = + TableColumn(IDS_BOOKMARK_TABLE_URL, TableColumn::LEFT, -1); + TableColumn path_column = + TableColumn(IDS_BOOKMARK_TABLE_PATH, TableColumn::LEFT, -1); + + std::vector<TableColumn> columns; if (show_path_column_) { int name_width = -1; int url_width = -1; diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index de96a8e..606a42c 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -48,14 +48,14 @@ class HungPagesTableModel : public views::GroupTableModel { virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); virtual SkBitmap GetIcon(int row); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); virtual void GetGroupRangeForItem(int item, views::GroupRange* range); private: typedef std::vector<TabContents*> TabContentsVector; TabContentsVector tab_contentses_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; DISALLOW_EVIL_CONSTRUCTORS(HungPagesTableModel); }; @@ -104,7 +104,7 @@ SkBitmap HungPagesTableModel::GetIcon(int row) { return tab_contentses_.at(row)->GetFavIcon(); } -void HungPagesTableModel::SetObserver(views::TableModelObserver* observer) { +void HungPagesTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -343,8 +343,8 @@ void HungRendererDialogView::Init() { info_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); hung_pages_table_model_.reset(new HungPagesTableModel); - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn()); + std::vector<TableColumn> columns; + columns.push_back(TableColumn()); hung_pages_table_ = new views::GroupTableView( hung_pages_table_model_.get(), columns, views::ICON_AND_TEXT, true, false, true); diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index d21b314..b5c1e56 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -37,7 +37,6 @@ using views::GridLayout; using views::NativeButton; -using views::TableColumn; // Group IDs used by TemplateURLTableModel. static const int kMainGroupID = 0; @@ -237,7 +236,7 @@ SkBitmap TemplateURLTableModel::GetIcon(int row) { return entries_[row]->GetIcon(); } -void TemplateURLTableModel::SetObserver(views::TableModelObserver* observer) { +void TemplateURLTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } diff --git a/chrome/browser/views/keyword_editor_view.h b/chrome/browser/views/keyword_editor_view.h index 8b093c7..1b70641 100644 --- a/chrome/browser/views/keyword_editor_view.h +++ b/chrome/browser/views/keyword_editor_view.h @@ -8,9 +8,9 @@ #include <Windows.h> #include <map> +#include "app/table_model.h" #include "chrome/browser/search_engines/template_url_model.h" #include "views/controls/button/button.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view_observer.h" #include "views/view.h" #include "views/window/dialog_delegate.h" @@ -40,7 +40,7 @@ class TemplateURLTableModel; // the favicon. The entries in the model are sorted such that non-generated // appear first (grouped together) and are followed by generated keywords. -class TemplateURLTableModel : public views::TableModel { +class TemplateURLTableModel : public TableModel { public: explicit TemplateURLTableModel(TemplateURLModel* template_url_model); @@ -54,7 +54,7 @@ class TemplateURLTableModel : public views::TableModel { virtual int RowCount(); virtual std::wstring GetText(int row, int column); virtual SkBitmap GetIcon(int row); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); virtual bool HasGroups(); virtual Groups GetGroups(); virtual int GetGroupID(int row); @@ -96,7 +96,7 @@ class TemplateURLTableModel : public views::TableModel { // Notification that a model entry has fetched its icon. void FavIconAvailable(ModelEntry* entry); - views::TableModelObserver* observer_; + TableModelObserver* observer_; // The entries. std::vector<ModelEntry*> entries_; diff --git a/chrome/browser/views/keyword_editor_view_unittest.cc b/chrome/browser/views/keyword_editor_view_unittest.cc index aeefc83..c23ee4e 100644 --- a/chrome/browser/views/keyword_editor_view_unittest.cc +++ b/chrome/browser/views/keyword_editor_view_unittest.cc @@ -2,18 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/table_model_observer.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/views/keyword_editor_view.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" -#include "views/controls/table/table_model_observer.h" // Base class for keyword editor tests. Creates a profile containing an // empty TemplateURLModel. class KeywordEditorViewTest : public testing::Test, - public views::TableModelObserver { + public TableModelObserver { public: virtual void SetUp() { model_changed_count_ = items_changed_count_ = added_count_ = diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 30b1e9d..ce410e8 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -10,6 +10,7 @@ #include "app/gfx/color_utils.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/table_model.h" #include "base/message_loop.h" #include "base/string_util.h" #include "base/time_format.h" @@ -23,7 +24,6 @@ #include "views/grid_layout.h" #include "views/controls/label.h" #include "views/controls/button/native_button.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view.h" #include "views/controls/textfield/textfield.h" #include "views/standard_layout.h" @@ -37,7 +37,7 @@ static const int kSearchFilterDelayMs = 500; /////////////////////////////////////////////////////////////////////////////// // CookiesTableModel -class CookiesTableModel : public views::TableModel { +class CookiesTableModel : public TableModel { public: explicit CookiesTableModel(Profile* profile); virtual ~CookiesTableModel() {} @@ -50,11 +50,11 @@ class CookiesTableModel : public views::TableModel { void RemoveCookies(int start_index, int remove_count); void RemoveAllShownCookies(); - // views::TableModel implementation: + // TableModel implementation: virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); virtual SkBitmap GetIcon(int row); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); virtual int CompareValues(int row1, int row2, int column_id); // Filter the cookies to only display matched results. @@ -74,7 +74,7 @@ class CookiesTableModel : public views::TableModel { CookieList all_cookies_; CookiePtrList shown_cookies_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; DISALLOW_COPY_AND_ASSIGN(CookiesTableModel); }; @@ -138,7 +138,7 @@ void CookiesTableModel::RemoveAllShownCookies() { } /////////////////////////////////////////////////////////////////////////////// -// CookiesTableModel, views::TableModel implementation: +// CookiesTableModel, TableModel implementation: int CookiesTableModel::RowCount() { return static_cast<int>(shown_cookies_.size()); @@ -180,7 +180,7 @@ SkBitmap CookiesTableModel::GetIcon(int row) { return *icon; } -void CookiesTableModel::SetObserver(views::TableModelObserver* observer) { +void CookiesTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -255,7 +255,7 @@ void CookiesTableModel::UpdateSearchResults(const std::wstring& filter) { class CookiesTableView : public views::TableView { public: CookiesTableView(CookiesTableModel* cookies_model, - std::vector<views::TableColumn> columns); + std::vector<TableColumn> columns); virtual ~CookiesTableView() {} // Removes the cookies associated with the selected rows in the TableView. @@ -270,7 +270,7 @@ class CookiesTableView : public views::TableView { CookiesTableView::CookiesTableView( CookiesTableModel* cookies_model, - std::vector<views::TableColumn> columns) + std::vector<TableColumn> columns) : views::TableView(cookies_model, columns, views::ICON_AND_TEXT, false, true, true), cookies_model_(cookies_model) { @@ -623,7 +623,7 @@ void CookiesView::ContentsChanged(views::Textfield* sender, bool CookiesView::HandleKeystroke(views::Textfield* sender, const views::Textfield::Keystroke& key) { - if (views::Textfield::IsKeystrokeEscape(key)) { + if (views::Textfield::IsKeystrokeEscape(key)) { ResetSearchQuery(); } else if (views::Textfield::IsKeystrokeEnter(key)) { search_update_factory_.RevokeAll(); @@ -711,12 +711,12 @@ void CookiesView::Init() { cookies_table_model_.reset(new CookiesTableModel(profile_)); info_view_ = new CookieInfoView; - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn(IDS_COOKIES_DOMAIN_COLUMN_HEADER, - views::TableColumn::LEFT, 200, 0.5f)); + std::vector<TableColumn> columns; + columns.push_back(TableColumn(IDS_COOKIES_DOMAIN_COLUMN_HEADER, + TableColumn::LEFT, 200, 0.5f)); columns.back().sortable = true; - columns.push_back(views::TableColumn(IDS_COOKIES_NAME_COLUMN_HEADER, - views::TableColumn::LEFT, 150, 0.5f)); + columns.push_back(TableColumn(IDS_COOKIES_NAME_COLUMN_HEADER, + TableColumn::LEFT, 150, 0.5f)); columns.back().sortable = true; cookies_table_ = new CookiesTableView(cookies_table_model_.get(), columns); cookies_table_->SetObserver(this); diff --git a/chrome/browser/views/options/exceptions_page_view.cc b/chrome/browser/views/options/exceptions_page_view.cc index f9d77c9..52de9eb 100644 --- a/chrome/browser/views/options/exceptions_page_view.cc +++ b/chrome/browser/views/options/exceptions_page_view.cc @@ -168,10 +168,10 @@ void ExceptionsPageView::SetupTable() { // Creates the different columns for the table. // The float resize values are the result of much tinkering. - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn( + std::vector<TableColumn> columns; + columns.push_back(TableColumn( IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, - views::TableColumn::LEFT, -1, 0.55f)); + TableColumn::LEFT, -1, 0.55f)); columns.back().sortable = true; table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY, true, true, true); diff --git a/chrome/browser/views/options/fonts_page_view.h b/chrome/browser/views/options/fonts_page_view.h index eec242a..c92df20 100644 --- a/chrome/browser/views/options/fonts_page_view.h +++ b/chrome/browser/views/options/fonts_page_view.h @@ -17,12 +17,12 @@ namespace views { class GroupboxView; class Label; class NativeButton; -class TableModel; class TableView; } -class FontDisplayView; class DefaultEncodingComboboxModel; +class FontDisplayView; +class TableModel; /////////////////////////////////////////////////////////////////////////////// // FontsPageView diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index 5d08722..dcf579f 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -171,7 +171,7 @@ void GeneralPageView::DefaultBrowserWorker::UpdateUI(bool is_default) { // CustomHomePagesTableModel is the model for the TableView showing the list // of pages the user wants opened on startup. -class CustomHomePagesTableModel : public views::TableModel { +class CustomHomePagesTableModel : public TableModel { public: explicit CustomHomePagesTableModel(Profile* profile); virtual ~CustomHomePagesTableModel() {} @@ -188,11 +188,11 @@ class CustomHomePagesTableModel : public views::TableModel { // Returns the set of urls this model contains. std::vector<GURL> GetURLs(); - // views::TableModel overrides: + // TableModel overrides: virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); virtual SkBitmap GetIcon(int row); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); private: // Each item in the model is represented as an Entry. Entry stores the URL @@ -236,7 +236,7 @@ class CustomHomePagesTableModel : public views::TableModel { // Profile used to load icons. Profile* profile_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; // Used in loading favicons. CancelableRequestConsumer fav_icon_consumer_; @@ -317,8 +317,7 @@ SkBitmap CustomHomePagesTableModel::GetIcon(int row) { return default_favicon_; } -void CustomHomePagesTableModel::SetObserver( - views::TableModelObserver* observer) { +void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -798,8 +797,8 @@ void GeneralPageView::InitStartupGroup() { startup_custom_pages_table_model_.reset( new CustomHomePagesTableModel(profile())); - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn()); + std::vector<TableColumn> columns; + columns.push_back(TableColumn()); startup_custom_pages_table_ = new views::TableView( startup_custom_pages_table_model_.get(), columns, views::ICON_AND_TEXT, true, false, true); diff --git a/chrome/browser/views/options/general_page_view.h b/chrome/browser/views/options/general_page_view.h index 3dcc66c..3faa421 100644 --- a/chrome/browser/views/options/general_page_view.h +++ b/chrome/browser/views/options/general_page_view.h @@ -19,13 +19,13 @@ class GroupboxView; class Label; class NativeButton; class RadioButton; -class TableModel; class TableView; class Textfield; } class CustomHomePagesTableModel; class OptionsGroupView; class SearchEngineListModel; +class TableModel; /////////////////////////////////////////////////////////////////////////////// // GeneralPageView diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc index d402b8e..ac08680 100644 --- a/chrome/browser/views/options/languages_page_view.cc +++ b/chrome/browser/views/options/languages_page_view.cc @@ -12,6 +12,8 @@ #include "app/gfx/font.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/table_model.h" +#include "app/table_model_observer.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/string_util.h" @@ -32,8 +34,6 @@ #include "unicode/uloc.h" #include "views/controls/button/radio_button.h" #include "views/controls/tabbed_pane.h" -#include "views/controls/table/table_model.h" -#include "views/controls/table/table_model_observer.h" #include "views/controls/table/table_view.h" #include "views/grid_layout.h" #include "views/standard_layout.h" @@ -314,7 +314,7 @@ void AddLanguageWindowView::Init() { AddChildView(accept_language_combobox_); } -class LanguageOrderTableModel : public views::TableModel { +class LanguageOrderTableModel : public TableModel { public: LanguageOrderTableModel(); @@ -340,10 +340,10 @@ class LanguageOrderTableModel : public views::TableModel { // Returns the set of languagess this model contains. std::string GetLanguageList() { return VectorToList(languages_); } - // views::TableModel overrides: + // TableModel overrides: virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); private: // This method converts a comma separated list to a vector of strings. @@ -357,7 +357,7 @@ class LanguageOrderTableModel : public views::TableModel { std::vector<std::string> languages_; std::string comma_separated_language_list_; - views::TableModelObserver* observer_; + TableModelObserver* observer_; DISALLOW_COPY_AND_ASSIGN(LanguageOrderTableModel); }; @@ -375,8 +375,7 @@ void LanguageOrderTableModel::SetAcceptLanguagesString( } } -void LanguageOrderTableModel::SetObserver( - views::TableModelObserver* observer) { +void LanguageOrderTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -569,8 +568,8 @@ void LanguagesPageView::InitControlLayout() { layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); // Add two columns - for table, and for button stack. - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn()); + std::vector<TableColumn> columns; + columns.push_back(TableColumn()); language_order_table_model_.reset(new LanguageOrderTableModel); language_order_table_ = new views::TableView( language_order_table_model_.get(), columns, diff --git a/chrome/browser/views/options/languages_page_view.h b/chrome/browser/views/options/languages_page_view.h index 168d67e..a16203b 100644 --- a/chrome/browser/views/options/languages_page_view.h +++ b/chrome/browser/views/options/languages_page_view.h @@ -16,13 +16,13 @@ namespace views { class Checkbox; class Label; class NativeButton; -class TableModel; class TableView; } +class AddLanguageView; class LanguageComboboxModel; class LanguageOrderTableModel; -class AddLanguageView; +class TableModel; /////////////////////////////////////////////////////////////////////////////// // LanguagesPageView diff --git a/chrome/browser/views/options/passwords_page_view.cc b/chrome/browser/views/options/passwords_page_view.cc index bc73703..e7337cb 100644 --- a/chrome/browser/views/options/passwords_page_view.cc +++ b/chrome/browser/views/options/passwords_page_view.cc @@ -97,8 +97,7 @@ int PasswordsTableModel::CompareValues(int row1, int row2, return TableModel::CompareValues(row1, row2, column_id); } -void PasswordsTableModel::SetObserver( - views::TableModelObserver* observer) { +void PasswordsTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -306,12 +305,12 @@ void PasswordsPageView::SetupTable() { // Creates the different columns for the table. // The float resize values are the result of much tinkering. - std::vector<views::TableColumn> columns; - columns.push_back(views::TableColumn(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, - views::TableColumn::LEFT, -1, 0.55f)); + std::vector<TableColumn> columns; + columns.push_back(TableColumn(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, + TableColumn::LEFT, -1, 0.55f)); columns.back().sortable = true; - columns.push_back(views::TableColumn( - IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN, views::TableColumn::LEFT, + columns.push_back(TableColumn( + IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN, TableColumn::LEFT, -1, 0.37f)); columns.back().sortable = true; table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY, diff --git a/chrome/browser/views/options/passwords_page_view.h b/chrome/browser/views/options/passwords_page_view.h index 907ffb4..7238f4c 100644 --- a/chrome/browser/views/options/passwords_page_view.h +++ b/chrome/browser/views/options/passwords_page_view.h @@ -8,6 +8,7 @@ #include <vector> #include "app/gfx/text_elider.h" +#include "app/table_model.h" #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "chrome/browser/views/options/options_page_view.h" @@ -15,7 +16,6 @@ #include "views/controls/button/native_button.h" #include "views/controls/label.h" #include "views/controls/table/table_view.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view_observer.h" #include "views/window/dialog_delegate.h" #include "views/window/window.h" @@ -29,9 +29,9 @@ class Profile; // allow the container view of TableView(i.e. PasswordsPageView and // ExceptionsPageView), to be notified of row count changes directly // from the TableModel. We have two different observers in -// PasswordsTableModel, namely views::TableModelObserver and +// PasswordsTableModel, namely TableModelObserver and // PasswordsTableModelObserver, rather than adding this event to -// views::TableModelObserver because only container view of +// TableModelObserver because only container view of // PasswordsTableModel cares about this event. class PasswordsTableModelObserver { public: @@ -60,7 +60,7 @@ class MultiLabelButtons : public views::NativeButton { /////////////////////////////////////////////////////////////////////////////// // PasswordsTableModel -class PasswordsTableModel : public views::TableModel, +class PasswordsTableModel : public TableModel, public WebDataServiceConsumer { public: explicit PasswordsTableModel(Profile* profile); @@ -70,7 +70,7 @@ class PasswordsTableModel : public views::TableModel, virtual int RowCount(); virtual std::wstring GetText(int row, int column); virtual int CompareValues(int row1, int row2, int column_id); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); // Delete the PasswordForm at specified row from the database (and remove // from view). @@ -116,7 +116,7 @@ class PasswordsTableModel : public views::TableModel, } // The TableView observing this model. - views::TableModelObserver* observer_; + TableModelObserver* observer_; // Dispatching row count events specific to this password manager table model // to this observer. diff --git a/chrome/browser/views/shelf_item_dialog.cc b/chrome/browser/views/shelf_item_dialog.cc index 7212c1d..ade3be7 100644 --- a/chrome/browser/views/shelf_item_dialog.cc +++ b/chrome/browser/views/shelf_item_dialog.cc @@ -7,6 +7,8 @@ #include "app/gfx/text_elider.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/table_model.h" +#include "app/table_model_observer.h" #include "base/gfx/png_decoder.h" #include "base/stl_util-inl.h" #include "base/string_util.h" @@ -21,8 +23,6 @@ #include "net/base/net_util.h" #include "views/background.h" #include "views/controls/label.h" -#include "views/controls/table/table_model.h" -#include "views/controls/table/table_model_observer.h" #include "views/controls/table/table_view.h" #include "views/controls/textfield/textfield.h" #include "views/focus/focus_manager.h" @@ -51,7 +51,7 @@ static SkBitmap* default_fav_icon = NULL; // How long we query entry points for. static const int kPossibleURLTimeScope = 30; -class PossibleURLModel : public views::TableModel { +class PossibleURLModel : public TableModel { public: PossibleURLModel() : profile_(NULL) { if (!default_fav_icon) { @@ -215,7 +215,7 @@ class PossibleURLModel : public views::TableModel { } } - virtual void SetObserver(views::TableModelObserver* observer) { + virtual void SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -237,7 +237,7 @@ class PossibleURLModel : public views::TableModel { Profile* profile_; // Our observer. - views::TableModelObserver* observer_; + TableModelObserver* observer_; // Our consumer for favicon requests. CancelableRequestConsumerT<size_t, NULL> consumer_; @@ -269,13 +269,13 @@ ShelfItemDialog::ShelfItemDialog(ShelfItemDialogDelegate* delegate, url_table_model_.reset(new PossibleURLModel()); - views::TableColumn col1(IDS_ASI_PAGE_COLUMN, views::TableColumn::LEFT, -1, + TableColumn col1(IDS_ASI_PAGE_COLUMN, TableColumn::LEFT, -1, 50); col1.sortable = true; - views::TableColumn col2(IDS_ASI_URL_COLUMN, views::TableColumn::LEFT, -1, + TableColumn col2(IDS_ASI_URL_COLUMN, TableColumn::LEFT, -1, 50); col2.sortable = true; - std::vector<views::TableColumn> cols; + std::vector<TableColumn> cols; cols.push_back(col1); cols.push_back(col2); diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 37a53e0..04d11c6e 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -159,23 +159,6 @@ namespace views { class AcceleratorHandler { }; -class TableModelObserver { - public: - virtual void OnModelChanged() = 0; - virtual void OnItemsChanged(int, int) = 0; - virtual void OnItemsAdded(int, int) = 0; - virtual void OnItemsRemoved(int, int) = 0; -}; - -class TableModel { - public: - int CompareValues(int row1, int row2, int column_id) { - NOTIMPLEMENTED(); - return 0; - } - virtual int RowCount() = 0; -}; - #if !defined(TOOLKIT_VIEWS) class MenuItemView { public: diff --git a/views/controls/table/group_table_view.h b/views/controls/table/group_table_view.h index c92587f..640776e 100644 --- a/views/controls/table/group_table_view.h +++ b/views/controls/table/group_table_view.h @@ -5,8 +5,8 @@ #ifndef VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ #define VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ +#include "app/table_model.h" #include "base/task.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view.h" // The GroupTableView adds grouping to the TableView class. diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 4e095cf..e0d0b55 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -16,13 +16,13 @@ #include "app/gfx/icon_util.h" #include "app/l10n_util_win.h" #include "app/resource_bundle.h" +#include "app/table_model.h" #include "base/string_util.h" #include "base/win_util.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColorFilter.h" #include "views/controls/native/native_view_host.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view_observer.h" namespace views { @@ -32,54 +32,11 @@ const int kListViewTextPadding = 15; // Additional column width necessary if column has icons. const int kListViewIconWidthAndPadding = 18; -// TableModel ----------------------------------------------------------------- +// TableView ------------------------------------------------------------------ // static const int TableView::kImageSize = 18; -// Used for sorting. -static Collator* collator = NULL; - -SkBitmap TableModel::GetIcon(int row) { - return SkBitmap(); -} - -int TableModel::CompareValues(int row1, int row2, int column_id) { - DCHECK(row1 >= 0 && row1 < RowCount() && - row2 >= 0 && row2 < RowCount()); - std::wstring value1 = GetText(row1, column_id); - std::wstring value2 = GetText(row2, column_id); - Collator* collator = GetCollator(); - - if (collator) { - UErrorCode compare_status = U_ZERO_ERROR; - UCollationResult compare_result = collator->compare( - static_cast<const UChar*>(value1.c_str()), - static_cast<int>(value1.length()), - static_cast<const UChar*>(value2.c_str()), - static_cast<int>(value2.length()), - compare_status); - DCHECK(U_SUCCESS(compare_status)); - return compare_result; - } - NOTREACHED(); - return 0; -} - -Collator* TableModel::GetCollator() { - if (!collator) { - UErrorCode create_status = U_ZERO_ERROR; - collator = Collator::createInstance(create_status); - if (!U_SUCCESS(create_status)) { - collator = NULL; - NOTREACHED(); - } - } - return collator; -} - -// TableView ------------------------------------------------------------------ - TableView::TableView(TableModel* model, const std::vector<TableColumn>& columns, TableTypes table_type, @@ -961,11 +918,7 @@ void TableView::SortItemsAndUpdateMapping() { // Sort the items. ListView_SortItems(list_view_, &TableView::SortFunc, this); - // Cleanup the collator. - if (collator) { - delete collator; - collator = NULL; - } + model_->ClearCollator(); // Update internal mapping to match how items were actually sorted. int row_count = RowCount(); diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h index 94198f8..b8bda67 100644 --- a/views/controls/table/table_view.h +++ b/views/controls/table/table_view.h @@ -15,13 +15,15 @@ typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW; #include <map> #include <vector> +#include "app/table_model_observer.h" #include "third_party/skia/include/core/SkColor.h" #if defined(OS_WIN) // TODO(port): remove the ifdef when native_control.h is ported. #include "views/controls/native_control.h" #endif // defined(OS_WIN) -#include "views/controls/table/table_model_observer.h" +struct TableColumn; +class TableModel; class SkBitmap; // A TableView is a view that displays multiple rows with any number of columns. @@ -51,8 +53,6 @@ namespace views { class ListView; class ListViewParent; class TableView; -struct TableColumn; -class TableModel; class TableViewObserver; // The cells in the first column of a table can contain: diff --git a/views/controls/table/table_view_unittest.cc b/views/controls/table/table_view_unittest.cc index c3d0a75..d79a5bc 100644 --- a/views/controls/table/table_view_unittest.cc +++ b/views/controls/table/table_view_unittest.cc @@ -4,10 +4,11 @@ #include <vector> +#include "app/table_model.h" +#include "app/table_model_observer.h" #include "base/message_loop.h" #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view.h" #include "views/window/window_delegate.h" #include "views/window/window_win.h" @@ -24,7 +25,7 @@ using views::TableView; // 0, 1 // 1, 1 // 2, 2 -class TestTableModel : public views::TableModel { +class TestTableModel : public TableModel { public: TestTableModel(); @@ -40,11 +41,11 @@ class TestTableModel : public views::TableModel { // TableModel virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); virtual int CompareValues(int row1, int row2, int column_id); private: - views::TableModelObserver* observer_; + TableModelObserver* observer_; // The data. std::vector<std::vector<int>> rows_; @@ -90,7 +91,7 @@ std::wstring TestTableModel::GetText(int row, int column_id) { return IntToWString(rows_[row][column_id]); } -void TestTableModel::SetObserver(views::TableModelObserver* observer) { +void TestTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -141,7 +142,7 @@ class TableViewTest : public testing::Test, views::WindowDelegate { void TableViewTest::SetUp() { OleInitialize(NULL); model_.reset(CreateModel()); - std::vector<views::TableColumn> columns; + std::vector<TableColumn> columns; columns.resize(2); columns[0].id = 0; columns[1].id = 1; diff --git a/views/views.gyp b/views/views.gyp index c0e63c8..2faa58a 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -148,9 +148,6 @@ 'controls/tabbed_pane.h', 'controls/table/group_table_view.cc', 'controls/table/group_table_view.h', - 'controls/table/table_model.cc', - 'controls/table/table_model.h', - 'controls/table/table_model_observer.h', 'controls/table/table_view.cc', 'controls/table/table_view.h', 'controls/table/table_view_observer.h', |