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

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

Issue 435024: Adds back the ability to filter cookies by origin in the cookies options view... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/views/options/cookies_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 11 matching lines...) Expand all
22 #include "views/controls/label.h" 22 #include "views/controls/label.h"
23 #include "views/controls/button/native_button.h" 23 #include "views/controls/button/native_button.h"
24 #include "views/controls/tree/tree_view.h" 24 #include "views/controls/tree/tree_view.h"
25 #include "views/controls/textfield/textfield.h" 25 #include "views/controls/textfield/textfield.h"
26 #include "views/standard_layout.h" 26 #include "views/standard_layout.h"
27 27
28 // static 28 // static
29 views::Window* CookiesView::instance_ = NULL; 29 views::Window* CookiesView::instance_ = NULL;
30 static const int kCookieInfoViewBorderSize = 1; 30 static const int kCookieInfoViewBorderSize = 1;
31 static const int kCookieInfoViewInsetSize = 3; 31 static const int kCookieInfoViewInsetSize = 3;
32 static const int kSearchFilterDelayMs = 500;
32 33
33 34
34 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
35 // CookiesTreeView 36 // CookiesTreeView
36 // Overridden to handle Delete key presses 37 // Overridden to handle Delete key presses
37 38
38 class CookiesTreeView : public views::TreeView { 39 class CookiesTreeView : public views::TreeView {
39 public: 40 public:
40 explicit CookiesTreeView(CookiesTreeModel* cookies_model); 41 explicit CookiesTreeView(CookiesTreeModel* cookies_model);
41 virtual ~CookiesTreeView() {} 42 virtual ~CookiesTreeView() {}
42 43
43 // Removes the items associated with the selected node in the TreeView 44 // Removes the items associated with the selected node in the TreeView
44 void RemoveSelectedItems(); 45 void RemoveSelectedItems();
45 46
46 private: 47 private:
47 // Our model, as a CookiesTreeModel.
48 CookiesTreeModel* cookies_model_;
49
50 DISALLOW_COPY_AND_ASSIGN(CookiesTreeView); 48 DISALLOW_COPY_AND_ASSIGN(CookiesTreeView);
51 }; 49 };
52 50
53 CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) 51 CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) {
54 : cookies_model_(cookies_model) { 52 SetModel(cookies_model);
55 SetModel(cookies_model_);
56 SetRootShown(false); 53 SetRootShown(false);
57 SetEditable(false); 54 SetEditable(false);
58 } 55 }
59 56
60 void CookiesTreeView::RemoveSelectedItems() { 57 void CookiesTreeView::RemoveSelectedItems() {
61 TreeModelNode* selected_node = GetSelectedNode(); 58 TreeModelNode* selected_node = GetSelectedNode();
62 if (selected_node) { 59 if (selected_node) {
63 cookies_model_->DeleteCookieNode(static_cast<CookieTreeCookieNode*>( 60 static_cast<CookiesTreeModel*>(model())->DeleteCookieNode(
64 GetSelectedNode())); 61 static_cast<CookieTreeCookieNode*>(GetSelectedNode()));
65 } 62 }
66 } 63 }
67 64
68 65
69 /////////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////////
70 // CookieInfoView, public: 67 // CookieInfoView, public:
71 68
72 CookieInfoView::CookieInfoView() 69 CookieInfoView::CookieInfoView()
73 : name_label_(NULL), 70 : name_label_(NULL),
74 name_value_field_(NULL), 71 name_value_field_(NULL),
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 /////////////////////////////////////////////////////////////////////////////// 276 ///////////////////////////////////////////////////////////////////////////////
280 // CookiesView, views::Buttonlistener implementation: 277 // CookiesView, views::Buttonlistener implementation:
281 278
282 void CookiesView::ButtonPressed( 279 void CookiesView::ButtonPressed(
283 views::Button* sender, const views::Event& event) { 280 views::Button* sender, const views::Event& event) {
284 if (sender == remove_button_) { 281 if (sender == remove_button_) {
285 cookies_tree_->RemoveSelectedItems(); 282 cookies_tree_->RemoveSelectedItems();
286 } else if (sender == remove_all_button_) { 283 } else if (sender == remove_all_button_) {
287 cookies_tree_model_->DeleteAllCookies(); 284 cookies_tree_model_->DeleteAllCookies();
288 UpdateForEmptyState(); 285 UpdateForEmptyState();
286 } else if (sender == clear_search_button_) {
287 ResetSearchQuery();
289 } 288 }
290 } 289 }
291 290
292 /////////////////////////////////////////////////////////////////////////////// 291 ///////////////////////////////////////////////////////////////////////////////
292 // CookiesView, views::Textfield::Controller implementation:
293
294 void CookiesView::ContentsChanged(views::Textfield* sender,
295 const std::wstring& new_contents) {
296 clear_search_button_->SetEnabled(!search_field_->text().empty());
297 search_update_factory_.RevokeAll();
298 MessageLoop::current()->PostDelayedTask(FROM_HERE,
299 search_update_factory_.NewRunnableMethod(
300 &CookiesView::UpdateSearchResults), kSearchFilterDelayMs);
301 }
302
303 bool CookiesView::HandleKeystroke(views::Textfield* sender,
304 const views::Textfield::Keystroke& key) {
305 if (key.GetKeyboardCode() == base::VKEY_ESCAPE) {
306 ResetSearchQuery();
307 } else if (key.GetKeyboardCode() == base::VKEY_RETURN) {
308 search_update_factory_.RevokeAll();
309 UpdateSearchResults();
310 }
311 return false;
312 }
313
314 ///////////////////////////////////////////////////////////////////////////////
293 // CookiesView, views::DialogDelegate implementation: 315 // CookiesView, views::DialogDelegate implementation:
294 316
295 std::wstring CookiesView::GetWindowTitle() const { 317 std::wstring CookiesView::GetWindowTitle() const {
296 return l10n_util::GetString(IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); 318 return l10n_util::GetString(IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE);
297 } 319 }
298 320
299 void CookiesView::WindowClosing() { 321 void CookiesView::WindowClosing() {
300 instance_ = NULL; 322 instance_ = NULL;
301 } 323 }
302 324
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) { 379 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) {
358 if (keycode == base::VKEY_DELETE) 380 if (keycode == base::VKEY_DELETE)
359 cookies_tree_->RemoveSelectedItems(); 381 cookies_tree_->RemoveSelectedItems();
360 } 382 }
361 383
362 /////////////////////////////////////////////////////////////////////////////// 384 ///////////////////////////////////////////////////////////////////////////////
363 // CookiesView, private: 385 // CookiesView, private:
364 386
365 CookiesView::CookiesView(Profile* profile) 387 CookiesView::CookiesView(Profile* profile)
366 : 388 :
389 search_label_(NULL),
390 search_field_(NULL),
391 clear_search_button_(NULL),
367 description_label_(NULL), 392 description_label_(NULL),
368 cookies_tree_(NULL), 393 cookies_tree_(NULL),
369 info_view_(NULL), 394 info_view_(NULL),
370 remove_button_(NULL), 395 remove_button_(NULL),
371 remove_all_button_(NULL), 396 remove_all_button_(NULL),
372 profile_(profile) { 397 profile_(profile),
398 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) {
373 } 399 }
374 400
375 views::View* CookiesView::GetInitiallyFocusedView() { 401
376 return cookies_tree_; 402 void CookiesView::UpdateSearchResults() {
403 cookies_tree_model_->UpdateSearchResults(search_field_->text());
404 remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()->
405 GetTotalNodeCount() > 1);
377 } 406 }
378 407
379 void CookiesView::Init() { 408 void CookiesView::Init() {
409 search_label_ = new views::Label(
410 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL));
411 search_field_ = new views::Textfield;
412 search_field_->SetController(this);
413 clear_search_button_ = new views::NativeButton(
414 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL));
415 clear_search_button_->SetEnabled(false);
380 description_label_ = new views::Label( 416 description_label_ = new views::Label(
381 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); 417 l10n_util::GetString(IDS_COOKIES_INFO_LABEL));
382 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 418 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
383 cookies_tree_model_.reset(new CookiesTreeModel(profile_)); 419 cookies_tree_model_.reset(new CookiesTreeModel(profile_));
384 info_view_ = new CookieInfoView; 420 info_view_ = new CookieInfoView;
385 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); 421 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get());
386 remove_button_ = new views::NativeButton( 422 remove_button_ = new views::NativeButton(
387 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL)); 423 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL));
388 remove_all_button_ = new views::NativeButton( 424 remove_all_button_ = new views::NativeButton(
389 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL)); 425 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL));
(...skipping 13 matching lines...) Expand all
403 GridLayout::USE_PREF, 0, 0); 439 GridLayout::USE_PREF, 0, 0);
404 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); 440 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
405 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, 441 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
406 GridLayout::USE_PREF, 0, 0); 442 GridLayout::USE_PREF, 0, 0);
407 443
408 const int single_column_layout_id = 1; 444 const int single_column_layout_id = 1;
409 column_set = layout->AddColumnSet(single_column_layout_id); 445 column_set = layout->AddColumnSet(single_column_layout_id);
410 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 446 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
411 GridLayout::USE_PREF, 0, 0); 447 GridLayout::USE_PREF, 0, 0);
412 448
449 layout->StartRow(0, five_column_layout_id);
450 layout->AddView(search_label_);
451 layout->AddView(search_field_);
452 layout->AddView(clear_search_button_);
453 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
454
413 layout->StartRow(0, single_column_layout_id); 455 layout->StartRow(0, single_column_layout_id);
414 layout->AddView(description_label_); 456 layout->AddView(description_label_);
415 457
416 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 458 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
417 layout->StartRow(1, single_column_layout_id); 459 layout->StartRow(1, single_column_layout_id);
418 cookies_tree_->set_lines_at_root(true); 460 cookies_tree_->set_lines_at_root(true);
419 cookies_tree_->set_auto_expand_children(true); 461 cookies_tree_->set_auto_expand_children(true);
420 layout->AddView(cookies_tree_); 462 layout->AddView(cookies_tree_);
421 463
422 cookies_tree_->SetController(this); 464 cookies_tree_->SetController(this);
423 465
424 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 466 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
425 layout->StartRow(0, single_column_layout_id); 467 layout->StartRow(0, single_column_layout_id);
426 layout->AddView(info_view_); 468 layout->AddView(info_view_);
427 469
428 // Add the Remove/Remove All buttons to the ClientView 470 // Add the Remove/Remove All buttons to the ClientView
429 View* parent = GetParent(); 471 View* parent = GetParent();
430 parent->AddChildView(remove_button_); 472 parent->AddChildView(remove_button_);
431 parent->AddChildView(remove_all_button_); 473 parent->AddChildView(remove_all_button_);
432 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) 474 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount())
433 UpdateForEmptyState(); 475 UpdateForEmptyState();
434 } 476 }
435 477
478 void CookiesView::ResetSearchQuery() {
479 search_field_->SetText(EmptyWString());
480 clear_search_button_->SetEnabled(false);
481 UpdateSearchResults();
482 }
483
436 void CookiesView::UpdateForEmptyState() { 484 void CookiesView::UpdateForEmptyState() {
437 info_view_->ClearCookieDisplay(); 485 info_view_->ClearCookieDisplay();
438 remove_button_->SetEnabled(false); 486 remove_button_->SetEnabled(false);
439 remove_all_button_->SetEnabled(false); 487 remove_all_button_->SetEnabled(false);
440 } 488 }
OLDNEW
« no previous file with comments | « chrome/browser/views/options/cookies_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698