summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 16:31:50 +0000
committerian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 16:31:50 +0000
commit7daa3e9d198fb002767cfd590559149ca375aeec (patch)
treef8385c345127f6f4b2d679c30b65a74c11512bcf /chrome/browser/views
parent752e451f811b4b20ea7049051be44f28fe4d7581 (diff)
downloadchromium_src-7daa3e9d198fb002767cfd590559149ca375aeec.zip
chromium_src-7daa3e9d198fb002767cfd590559149ca375aeec.tar.gz
chromium_src-7daa3e9d198fb002767cfd590559149ca375aeec.tar.bz2
Adds back the ability to filter cookies by origin in the cookies options view.
BUG=27657 TEST=Typing "google" in the search field pulls up origins containing "google" in their name Review URL: http://codereview.chromium.org/435024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/options/cookies_view.cc70
-rw-r--r--chrome/browser/views/options/cookies_view.h26
2 files changed, 83 insertions, 13 deletions
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index b287582..1388c82 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -29,6 +29,7 @@
views::Window* CookiesView::instance_ = NULL;
static const int kCookieInfoViewBorderSize = 1;
static const int kCookieInfoViewInsetSize = 3;
+static const int kSearchFilterDelayMs = 500;
///////////////////////////////////////////////////////////////////////////////
@@ -44,15 +45,11 @@ class CookiesTreeView : public views::TreeView {
void RemoveSelectedItems();
private:
- // Our model, as a CookiesTreeModel.
- CookiesTreeModel* cookies_model_;
-
DISALLOW_COPY_AND_ASSIGN(CookiesTreeView);
};
-CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model)
- : cookies_model_(cookies_model) {
- SetModel(cookies_model_);
+CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) {
+ SetModel(cookies_model);
SetRootShown(false);
SetEditable(false);
}
@@ -60,8 +57,8 @@ CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model)
void CookiesTreeView::RemoveSelectedItems() {
TreeModelNode* selected_node = GetSelectedNode();
if (selected_node) {
- cookies_model_->DeleteCookieNode(static_cast<CookieTreeCookieNode*>(
- GetSelectedNode()));
+ static_cast<CookiesTreeModel*>(model())->DeleteCookieNode(
+ static_cast<CookieTreeCookieNode*>(GetSelectedNode()));
}
}
@@ -286,10 +283,35 @@ void CookiesView::ButtonPressed(
} else if (sender == remove_all_button_) {
cookies_tree_model_->DeleteAllCookies();
UpdateForEmptyState();
+ } else if (sender == clear_search_button_) {
+ ResetSearchQuery();
}
}
///////////////////////////////////////////////////////////////////////////////
+// CookiesView, views::Textfield::Controller implementation:
+
+void CookiesView::ContentsChanged(views::Textfield* sender,
+ const std::wstring& new_contents) {
+ clear_search_button_->SetEnabled(!search_field_->text().empty());
+ search_update_factory_.RevokeAll();
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ search_update_factory_.NewRunnableMethod(
+ &CookiesView::UpdateSearchResults), kSearchFilterDelayMs);
+}
+
+bool CookiesView::HandleKeystroke(views::Textfield* sender,
+ const views::Textfield::Keystroke& key) {
+ if (key.GetKeyboardCode() == base::VKEY_ESCAPE) {
+ ResetSearchQuery();
+ } else if (key.GetKeyboardCode() == base::VKEY_RETURN) {
+ search_update_factory_.RevokeAll();
+ UpdateSearchResults();
+ }
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, views::DialogDelegate implementation:
std::wstring CookiesView::GetWindowTitle() const {
@@ -364,19 +386,33 @@ void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) {
CookiesView::CookiesView(Profile* profile)
:
+ search_label_(NULL),
+ search_field_(NULL),
+ clear_search_button_(NULL),
description_label_(NULL),
cookies_tree_(NULL),
info_view_(NULL),
remove_button_(NULL),
remove_all_button_(NULL),
- profile_(profile) {
+ profile_(profile),
+ ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) {
}
-views::View* CookiesView::GetInitiallyFocusedView() {
- return cookies_tree_;
+
+void CookiesView::UpdateSearchResults() {
+ cookies_tree_model_->UpdateSearchResults(search_field_->text());
+ remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()->
+ GetTotalNodeCount() > 1);
}
void CookiesView::Init() {
+ search_label_ = new views::Label(
+ l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL));
+ search_field_ = new views::Textfield;
+ search_field_->SetController(this);
+ clear_search_button_ = new views::NativeButton(
+ this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL));
+ clear_search_button_->SetEnabled(false);
description_label_ = new views::Label(
l10n_util::GetString(IDS_COOKIES_INFO_LABEL));
description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
@@ -410,6 +446,12 @@ void CookiesView::Init() {
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(0, five_column_layout_id);
+ layout->AddView(search_label_);
+ layout->AddView(search_field_);
+ layout->AddView(clear_search_button_);
+ layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
+
layout->StartRow(0, single_column_layout_id);
layout->AddView(description_label_);
@@ -433,6 +475,12 @@ void CookiesView::Init() {
UpdateForEmptyState();
}
+void CookiesView::ResetSearchQuery() {
+ search_field_->SetText(EmptyWString());
+ clear_search_button_->SetEnabled(false);
+ UpdateSearchResults();
+}
+
void CookiesView::UpdateForEmptyState() {
info_view_->ClearCookieDisplay();
remove_button_->SetEnabled(false);
diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h
index 7932b45..d7c1b23 100644
--- a/chrome/browser/views/options/cookies_view.h
+++ b/chrome/browser/views/options/cookies_view.h
@@ -34,13 +34,17 @@ class Timer;
class CookiesView : public views::View,
public views::DialogDelegate,
public views::ButtonListener,
- public views::TreeViewController {
+ public views::TreeViewController,
+ public views::Textfield::Controller {
public:
// Show the Cookies Window, creating one if necessary.
static void ShowCookiesWindow(Profile* profile);
virtual ~CookiesView();
+ // Updates the display to show only the search results.
+ void UpdateSearchResults();
+
// views::ButtonListener implementation.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
@@ -50,11 +54,19 @@ class CookiesView : public views::View,
// views::TreeViewController implementation.
virtual void OnTreeViewKeyDown(base::KeyboardCode keycode);
+ // views::Textfield::Controller implementation.
+ virtual void ContentsChanged(views::Textfield* sender,
+ const std::wstring& new_contents);
+ virtual bool HandleKeystroke(views::Textfield* sender,
+ const views::Textfield::Keystroke& key);
+
// views::WindowDelegate implementation.
virtual int GetDialogButtons() const {
return MessageBoxFlags::DIALOGBUTTON_CANCEL;
}
- virtual views::View* GetInitiallyFocusedView();
+ virtual views::View* GetInitiallyFocusedView() {
+ return search_field_;
+ }
virtual bool CanResize() const { return true; }
virtual std::wstring GetWindowTitle() const;
@@ -78,10 +90,16 @@ class CookiesView : public views::View,
// Initialize the dialog contents and layout.
void Init();
+ // Resets the display to what it would be if there were no search query.
+ void ResetSearchQuery();
+
// Update the UI when there are no cookies.
void UpdateForEmptyState();
// Assorted dialog controls
+ views::Label* search_label_;
+ views::Textfield* search_field_;
+ views::NativeButton* clear_search_button_;
views::Label* description_label_;
CookiesTreeView* cookies_tree_;
CookieInfoView* info_view_;
@@ -94,6 +112,10 @@ class CookiesView : public views::View,
// The Profile for which Cookies are displayed
Profile* profile_;
+ // A factory to construct Runnable Methods so that we can be called back to
+ // re-evaluate the model after the search query string changes.
+ ScopedRunnableMethodFactory<CookiesView> search_update_factory_;
+
// Our containing window. If this is non-NULL there is a visible Cookies
// window somewhere.
static views::Window* instance_;