Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/views/options/cookies_view.cc

Issue 126184: Move TableModel out of views/ and into app/.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: addressed comments, build fixes Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/views/options/cookies_view.h" 5 #include "chrome/browser/views/options/cookies_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/gfx/color_utils.h" 10 #include "app/gfx/color_utils.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "app/table_model.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/time_format.h" 16 #include "base/time_format.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
18 #include "grit/locale_settings.h" 19 #include "grit/locale_settings.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "net/base/cookie_monster.h" 21 #include "net/base/cookie_monster.h"
21 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
22 #include "views/border.h" 23 #include "views/border.h"
23 #include "views/grid_layout.h" 24 #include "views/grid_layout.h"
24 #include "views/controls/label.h" 25 #include "views/controls/label.h"
25 #include "views/controls/button/native_button.h" 26 #include "views/controls/button/native_button.h"
26 #include "views/controls/table/table_model.h"
27 #include "views/controls/table/table_view.h" 27 #include "views/controls/table/table_view.h"
28 #include "views/controls/textfield/textfield.h" 28 #include "views/controls/textfield/textfield.h"
29 #include "views/standard_layout.h" 29 #include "views/standard_layout.h"
30 30
31 // static 31 // static
32 views::Window* CookiesView::instance_ = NULL; 32 views::Window* CookiesView::instance_ = NULL;
33 static const int kCookieInfoViewBorderSize = 1; 33 static const int kCookieInfoViewBorderSize = 1;
34 static const int kCookieInfoViewInsetSize = 3; 34 static const int kCookieInfoViewInsetSize = 3;
35 static const int kSearchFilterDelayMs = 500; 35 static const int kSearchFilterDelayMs = 500;
36 36
37 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
38 // CookiesTableModel 38 // CookiesTableModel
39 39
40 class CookiesTableModel : public views::TableModel { 40 class CookiesTableModel : public TableModel {
41 public: 41 public:
42 explicit CookiesTableModel(Profile* profile); 42 explicit CookiesTableModel(Profile* profile);
43 virtual ~CookiesTableModel() {} 43 virtual ~CookiesTableModel() {}
44 44
45 // Returns information about the Cookie at the specified index. 45 // Returns information about the Cookie at the specified index.
46 std::string GetDomainAt(int index); 46 std::string GetDomainAt(int index);
47 net::CookieMonster::CanonicalCookie& GetCookieAt(int index); 47 net::CookieMonster::CanonicalCookie& GetCookieAt(int index);
48 48
49 // Remove the specified cookies from the Cookie Monster and update the view. 49 // Remove the specified cookies from the Cookie Monster and update the view.
50 void RemoveCookies(int start_index, int remove_count); 50 void RemoveCookies(int start_index, int remove_count);
51 void RemoveAllShownCookies(); 51 void RemoveAllShownCookies();
52 52
53 // views::TableModel implementation: 53 // TableModel implementation:
54 virtual int RowCount(); 54 virtual int RowCount();
55 virtual std::wstring GetText(int row, int column_id); 55 virtual std::wstring GetText(int row, int column_id);
56 virtual SkBitmap GetIcon(int row); 56 virtual SkBitmap GetIcon(int row);
57 virtual void SetObserver(views::TableModelObserver* observer); 57 virtual void SetObserver(TableModelObserver* observer);
58 virtual int CompareValues(int row1, int row2, int column_id); 58 virtual int CompareValues(int row1, int row2, int column_id);
59 59
60 // Filter the cookies to only display matched results. 60 // Filter the cookies to only display matched results.
61 void UpdateSearchResults(const std::wstring& filter); 61 void UpdateSearchResults(const std::wstring& filter);
62 62
63 private: 63 private:
64 void LoadCookies(); 64 void LoadCookies();
65 void DoFilter(); 65 void DoFilter();
66 66
67 std::wstring filter_; 67 std::wstring filter_;
68 68
69 // The profile from which this model sources cookies. 69 // The profile from which this model sources cookies.
70 Profile* profile_; 70 Profile* profile_;
71 71
72 typedef net::CookieMonster::CookieList CookieList; 72 typedef net::CookieMonster::CookieList CookieList;
73 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; 73 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList;
74 CookieList all_cookies_; 74 CookieList all_cookies_;
75 CookiePtrList shown_cookies_; 75 CookiePtrList shown_cookies_;
76 76
77 views::TableModelObserver* observer_; 77 TableModelObserver* observer_;
78 78
79 DISALLOW_COPY_AND_ASSIGN(CookiesTableModel); 79 DISALLOW_COPY_AND_ASSIGN(CookiesTableModel);
80 }; 80 };
81 81
82 /////////////////////////////////////////////////////////////////////////////// 82 ///////////////////////////////////////////////////////////////////////////////
83 // CookiesTableModel, public: 83 // CookiesTableModel, public:
84 84
85 CookiesTableModel::CookiesTableModel(Profile* profile) 85 CookiesTableModel::CookiesTableModel(Profile* profile)
86 : profile_(profile) { 86 : profile_(profile) {
87 LoadCookies(); 87 LoadCookies();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // all_cookies as dead instead of deleting, but this should be fine for now. 131 // all_cookies as dead instead of deleting, but this should be fine for now.
132 DoFilter(); 132 DoFilter();
133 observer_->OnItemsRemoved(start_index, remove_count); 133 observer_->OnItemsRemoved(start_index, remove_count);
134 } 134 }
135 135
136 void CookiesTableModel::RemoveAllShownCookies() { 136 void CookiesTableModel::RemoveAllShownCookies() {
137 RemoveCookies(0, RowCount()); 137 RemoveCookies(0, RowCount());
138 } 138 }
139 139
140 /////////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////////
141 // CookiesTableModel, views::TableModel implementation: 141 // CookiesTableModel, TableModel implementation:
142 142
143 int CookiesTableModel::RowCount() { 143 int CookiesTableModel::RowCount() {
144 return static_cast<int>(shown_cookies_.size()); 144 return static_cast<int>(shown_cookies_.size());
145 } 145 }
146 146
147 std::wstring CookiesTableModel::GetText(int row, int column_id) { 147 std::wstring CookiesTableModel::GetText(int row, int column_id) {
148 DCHECK(row >= 0 && row < RowCount()); 148 DCHECK(row >= 0 && row < RowCount());
149 switch (column_id) { 149 switch (column_id) {
150 case IDS_COOKIES_DOMAIN_COLUMN_HEADER: 150 case IDS_COOKIES_DOMAIN_COLUMN_HEADER:
151 { 151 {
(...skipping 21 matching lines...) Expand all
173 NOTREACHED(); 173 NOTREACHED();
174 return L""; 174 return L"";
175 } 175 }
176 176
177 SkBitmap CookiesTableModel::GetIcon(int row) { 177 SkBitmap CookiesTableModel::GetIcon(int row) {
178 static SkBitmap* icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( 178 static SkBitmap* icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
179 IDR_COOKIE_ICON); 179 IDR_COOKIE_ICON);
180 return *icon; 180 return *icon;
181 } 181 }
182 182
183 void CookiesTableModel::SetObserver(views::TableModelObserver* observer) { 183 void CookiesTableModel::SetObserver(TableModelObserver* observer) {
184 observer_ = observer; 184 observer_ = observer;
185 } 185 }
186 186
187 int CookiesTableModel::CompareValues(int row1, int row2, int column_id) { 187 int CookiesTableModel::CompareValues(int row1, int row2, int column_id) {
188 if (column_id == IDS_COOKIES_DOMAIN_COLUMN_HEADER) { 188 if (column_id == IDS_COOKIES_DOMAIN_COLUMN_HEADER) {
189 // Sort ignore the '.' prefix for domain cookies. 189 // Sort ignore the '.' prefix for domain cookies.
190 net::CookieMonster::CookieListPair* cp1 = shown_cookies_[row1]; 190 net::CookieMonster::CookieListPair* cp1 = shown_cookies_[row1];
191 net::CookieMonster::CookieListPair* cp2 = shown_cookies_[row2]; 191 net::CookieMonster::CookieListPair* cp2 = shown_cookies_[row2];
192 bool is1domain = !cp1->first.empty() && cp1->first[0] == '.'; 192 bool is1domain = !cp1->first.empty() && cp1->first[0] == '.';
193 bool is2domain = !cp2->first.empty() && cp2->first[0] == '.'; 193 bool is2domain = !cp2->first.empty() && cp2->first[0] == '.';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 observer_->OnModelChanged(); 248 observer_->OnModelChanged();
249 } 249 }
250 250
251 /////////////////////////////////////////////////////////////////////////////// 251 ///////////////////////////////////////////////////////////////////////////////
252 // CookiesTableView 252 // CookiesTableView
253 // Overridden to handle Delete key presses 253 // Overridden to handle Delete key presses
254 254
255 class CookiesTableView : public views::TableView { 255 class CookiesTableView : public views::TableView {
256 public: 256 public:
257 CookiesTableView(CookiesTableModel* cookies_model, 257 CookiesTableView(CookiesTableModel* cookies_model,
258 std::vector<views::TableColumn> columns); 258 std::vector<TableColumn> columns);
259 virtual ~CookiesTableView() {} 259 virtual ~CookiesTableView() {}
260 260
261 // Removes the cookies associated with the selected rows in the TableView. 261 // Removes the cookies associated with the selected rows in the TableView.
262 void RemoveSelectedCookies(); 262 void RemoveSelectedCookies();
263 263
264 private: 264 private:
265 // Our model, as a CookiesTableModel. 265 // Our model, as a CookiesTableModel.
266 CookiesTableModel* cookies_model_; 266 CookiesTableModel* cookies_model_;
267 267
268 DISALLOW_COPY_AND_ASSIGN(CookiesTableView); 268 DISALLOW_COPY_AND_ASSIGN(CookiesTableView);
269 }; 269 };
270 270
271 CookiesTableView::CookiesTableView( 271 CookiesTableView::CookiesTableView(
272 CookiesTableModel* cookies_model, 272 CookiesTableModel* cookies_model,
273 std::vector<views::TableColumn> columns) 273 std::vector<TableColumn> columns)
274 : views::TableView(cookies_model, columns, views::ICON_AND_TEXT, false, 274 : views::TableView(cookies_model, columns, views::ICON_AND_TEXT, false,
275 true, true), 275 true, true),
276 cookies_model_(cookies_model) { 276 cookies_model_(cookies_model) {
277 } 277 }
278 278
279 void CookiesTableView::RemoveSelectedCookies() { 279 void CookiesTableView::RemoveSelectedCookies() {
280 // It's possible that we don't have anything selected. 280 // It's possible that we don't have anything selected.
281 if (SelectedRowCount() <= 0) 281 if (SelectedRowCount() <= 0)
282 return; 282 return;
283 283
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 void CookiesView::ContentsChanged(views::Textfield* sender, 616 void CookiesView::ContentsChanged(views::Textfield* sender,
617 const std::wstring& new_contents) { 617 const std::wstring& new_contents) {
618 search_update_factory_.RevokeAll(); 618 search_update_factory_.RevokeAll();
619 MessageLoop::current()->PostDelayedTask(FROM_HERE, 619 MessageLoop::current()->PostDelayedTask(FROM_HERE,
620 search_update_factory_.NewRunnableMethod( 620 search_update_factory_.NewRunnableMethod(
621 &CookiesView::UpdateSearchResults), kSearchFilterDelayMs); 621 &CookiesView::UpdateSearchResults), kSearchFilterDelayMs);
622 } 622 }
623 623
624 bool CookiesView::HandleKeystroke(views::Textfield* sender, 624 bool CookiesView::HandleKeystroke(views::Textfield* sender,
625 const views::Textfield::Keystroke& key) { 625 const views::Textfield::Keystroke& key) {
626 if (views::Textfield::IsKeystrokeEscape(key)) { 626 if (views::Textfield::IsKeystrokeEscape(key)) {
627 ResetSearchQuery(); 627 ResetSearchQuery();
628 } else if (views::Textfield::IsKeystrokeEnter(key)) { 628 } else if (views::Textfield::IsKeystrokeEnter(key)) {
629 search_update_factory_.RevokeAll(); 629 search_update_factory_.RevokeAll();
630 UpdateSearchResults(); 630 UpdateSearchResults();
631 } 631 }
632 return false; 632 return false;
633 } 633 }
634 634
635 /////////////////////////////////////////////////////////////////////////////// 635 ///////////////////////////////////////////////////////////////////////////////
636 // CookiesView, views::DialogDelegate implementation: 636 // CookiesView, views::DialogDelegate implementation:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 search_field_ = new views::Textfield; 704 search_field_ = new views::Textfield;
705 search_field_->SetController(this); 705 search_field_->SetController(this);
706 clear_search_button_ = new views::NativeButton( 706 clear_search_button_ = new views::NativeButton(
707 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); 707 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL));
708 description_label_ = new views::Label( 708 description_label_ = new views::Label(
709 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); 709 l10n_util::GetString(IDS_COOKIES_INFO_LABEL));
710 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 710 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
711 711
712 cookies_table_model_.reset(new CookiesTableModel(profile_)); 712 cookies_table_model_.reset(new CookiesTableModel(profile_));
713 info_view_ = new CookieInfoView; 713 info_view_ = new CookieInfoView;
714 std::vector<views::TableColumn> columns; 714 std::vector<TableColumn> columns;
715 columns.push_back(views::TableColumn(IDS_COOKIES_DOMAIN_COLUMN_HEADER, 715 columns.push_back(TableColumn(IDS_COOKIES_DOMAIN_COLUMN_HEADER,
716 views::TableColumn::LEFT, 200, 0.5f)); 716 TableColumn::LEFT, 200, 0.5f));
717 columns.back().sortable = true; 717 columns.back().sortable = true;
718 columns.push_back(views::TableColumn(IDS_COOKIES_NAME_COLUMN_HEADER, 718 columns.push_back(TableColumn(IDS_COOKIES_NAME_COLUMN_HEADER,
719 views::TableColumn::LEFT, 150, 0.5f)); 719 TableColumn::LEFT, 150, 0.5f));
720 columns.back().sortable = true; 720 columns.back().sortable = true;
721 cookies_table_ = new CookiesTableView(cookies_table_model_.get(), columns); 721 cookies_table_ = new CookiesTableView(cookies_table_model_.get(), columns);
722 cookies_table_->SetObserver(this); 722 cookies_table_->SetObserver(this);
723 // Make the table initially sorted by domain. 723 // Make the table initially sorted by domain.
724 views::TableView::SortDescriptors sort; 724 views::TableView::SortDescriptors sort;
725 sort.push_back( 725 sort.push_back(
726 views::TableView::SortDescriptor(IDS_COOKIES_DOMAIN_COLUMN_HEADER, 726 views::TableView::SortDescriptor(IDS_COOKIES_DOMAIN_COLUMN_HEADER,
727 true)); 727 true));
728 cookies_table_->SetSortDescriptors(sort); 728 cookies_table_->SetSortDescriptors(sort);
729 remove_button_ = new views::NativeButton( 729 remove_button_ = new views::NativeButton(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 void CookiesView::ResetSearchQuery() { 782 void CookiesView::ResetSearchQuery() {
783 search_field_->SetText(EmptyWString()); 783 search_field_->SetText(EmptyWString());
784 UpdateSearchResults(); 784 UpdateSearchResults();
785 } 785 }
786 786
787 void CookiesView::UpdateForEmptyState() { 787 void CookiesView::UpdateForEmptyState() {
788 info_view_->ClearCookieDisplay(); 788 info_view_->ClearCookieDisplay();
789 remove_button_->SetEnabled(false); 789 remove_button_->SetEnabled(false);
790 remove_all_button_->SetEnabled(false); 790 remove_all_button_->SetEnabled(false);
791 } 791 }
OLDNEW
« no previous file with comments | « chrome/browser/views/keyword_editor_view_unittest.cc ('k') | chrome/browser/views/options/exceptions_page_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698