summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/options
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/options')
-rw-r--r--chrome/browser/views/options/advanced_contents_view.cc3
-rw-r--r--chrome/browser/views/options/cookies_view.cc263
-rw-r--r--chrome/browser/views/options/cookies_view.h103
3 files changed, 131 insertions, 238 deletions
diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc
index 3359783..a6d62a1 100644
--- a/chrome/browser/views/options/advanced_contents_view.cc
+++ b/chrome/browser/views/options/advanced_contents_view.cc
@@ -656,7 +656,8 @@ void PrivacySection::InitControlLayout() {
allow_cookies_model_.get());
cookie_behavior_combobox_->set_listener(this);
show_cookies_button_ = new views::NativeButton(
- this, l10n_util::GetString(IDS_OPTIONS_COOKIES_SHOWCOOKIES));
+ this, l10n_util::GetString(
+ IDS_OPTIONS_COOKIES_SHOWCOOKIES_WEBSITE_PERMISSIONS));
GridLayout* layout = new GridLayout(contents_);
contents_->SetLayoutManager(layout);
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index 924480c..2fe5ac7 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -12,7 +12,7 @@
#include "base/i18n/time_formatting.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "chrome/browser/cookies_table_model.h"
+#include "chrome/browser/cookies_tree_model.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
@@ -21,7 +21,7 @@
#include "views/grid_layout.h"
#include "views/controls/label.h"
#include "views/controls/button/native_button.h"
-#include "views/controls/table/table_view.h"
+#include "views/controls/tree/tree_view.h"
#include "views/controls/textfield/textfield.h"
#include "views/standard_layout.h"
@@ -29,116 +29,42 @@
views::Window* CookiesView::instance_ = NULL;
static const int kCookieInfoViewBorderSize = 1;
static const int kCookieInfoViewInsetSize = 3;
-static const int kSearchFilterDelayMs = 500;
+
///////////////////////////////////////////////////////////////////////////////
-// CookiesTableView
+// CookiesTreeView
// Overridden to handle Delete key presses
-class CookiesTableView : public views::TableView {
+class CookiesTreeView : public views::TreeView {
public:
- CookiesTableView(CookiesTableModel* cookies_model,
- std::vector<TableColumn> columns);
- virtual ~CookiesTableView() {}
+ explicit CookiesTreeView(CookiesTreeModel* cookies_model);
+ virtual ~CookiesTreeView() {}
- // Removes the cookies associated with the selected rows in the TableView.
- void RemoveSelectedCookies();
+ // Removes the items associated with the selected node in the TreeView
+ void RemoveSelectedItems();
private:
- // Our model, as a CookiesTableModel.
- CookiesTableModel* cookies_model_;
+ // Our model, as a CookiesTreeModel.
+ CookiesTreeModel* cookies_model_;
- DISALLOW_COPY_AND_ASSIGN(CookiesTableView);
+ DISALLOW_COPY_AND_ASSIGN(CookiesTreeView);
};
-CookiesTableView::CookiesTableView(
- CookiesTableModel* cookies_model,
- std::vector<TableColumn> columns)
- : views::TableView(cookies_model, columns, views::ICON_AND_TEXT, false,
- true, true),
- cookies_model_(cookies_model) {
+CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model)
+ : cookies_model_(cookies_model) {
+ SetModel(cookies_model_);
+ SetRootShown(false);
+ SetEditable(false);
}
-void CookiesTableView::RemoveSelectedCookies() {
- // It's possible that we don't have anything selected.
- if (SelectedRowCount() <= 0)
- return;
-
- if (SelectedRowCount() == cookies_model_->RowCount()) {
- cookies_model_->RemoveAllShownCookies();
- return;
- }
-
- // Remove the selected cookies. This iterates over the rows backwards, which
- // is required when calling RemoveCookies, see bug 2994.
- int last_selected_view_row = -1;
- int remove_count = 0;
- for (views::TableView::iterator i = SelectionBegin();
- i != SelectionEnd(); ++i) {
- int selected_model_row = *i;
- ++remove_count;
- if (last_selected_view_row == -1) {
- // Store the view row since the view to model mapping changes when
- // we delete.
- last_selected_view_row = model_to_view(selected_model_row);
- }
- cookies_model_->RemoveCookies(selected_model_row, 1);
+void CookiesTreeView::RemoveSelectedItems() {
+ TreeModelNode* selected_node = GetSelectedNode();
+ if (selected_node) {
+ cookies_model_->DeleteCookieNode(static_cast<CookieTreeCookieNode*>(
+ GetSelectedNode()));
}
-
- // Select the next row after the last row deleted (unless removing last row).
- DCHECK(RowCount() > 0 && last_selected_view_row != -1);
- Select(view_to_model(std::min(RowCount() - 1,
- last_selected_view_row - remove_count + 1)));
}
-///////////////////////////////////////////////////////////////////////////////
-// CookieInfoView
-//
-// Responsible for displaying a tabular grid of Cookie information.
-class CookieInfoView : public views::View {
- public:
- CookieInfoView();
- virtual ~CookieInfoView();
-
- // Update the display from the specified CookieNode.
- void SetCookie(const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie_node);
-
- // Clears the cookie display to indicate that no or multiple cookies are
- // selected.
- void ClearCookieDisplay();
-
- // Enables or disables the cookie proerty text fields.
- void EnableCookieDisplay(bool enabled);
-
- protected:
- // views::View overrides:
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
-
- private:
- // Set up the view layout
- void Init();
-
- // Individual property labels
- views::Label* name_label_;
- views::Textfield* name_value_field_;
- views::Label* content_label_;
- views::Textfield* content_value_field_;
- views::Label* domain_label_;
- views::Textfield* domain_value_field_;
- views::Label* path_label_;
- views::Textfield* path_value_field_;
- views::Label* send_for_label_;
- views::Textfield* send_for_value_field_;
- views::Label* created_label_;
- views::Textfield* created_value_field_;
- views::Label* expires_label_;
- views::Textfield* expires_value_field_;
-
- DISALLOW_COPY_AND_ASSIGN(CookieInfoView);
-};
///////////////////////////////////////////////////////////////////////////////
// CookieInfoView, public:
@@ -347,12 +273,7 @@ void CookiesView::ShowCookiesWindow(Profile* profile) {
}
CookiesView::~CookiesView() {
- cookies_table_->SetModel(NULL);
-}
-
-void CookiesView::UpdateSearchResults() {
- cookies_table_model_->UpdateSearchResults(search_field_->text());
- remove_all_button_->SetEnabled(cookies_table_model_->RowCount() > 0);
+ cookies_tree_->SetModel(NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -361,67 +282,18 @@ void CookiesView::UpdateSearchResults() {
void CookiesView::ButtonPressed(
views::Button* sender, const views::Event& event) {
if (sender == remove_button_) {
- cookies_table_->RemoveSelectedCookies();
+ cookies_tree_->RemoveSelectedItems();
} else if (sender == remove_all_button_) {
- // Delete all the Cookies shown.
- cookies_table_model_->RemoveAllShownCookies();
- UpdateForEmptyState();
- } else if (sender == clear_search_button_) {
- ResetSearchQuery();
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// CookiesView, views::TableViewObserver implementation:
-void CookiesView::OnSelectionChanged() {
- int selected_row_count = cookies_table_->SelectedRowCount();
- if (selected_row_count == 1) {
- int selected_index = cookies_table_->FirstSelectedRow();
- if (selected_index >= 0 &&
- selected_index < cookies_table_model_->RowCount()) {
- info_view_->SetCookie(cookies_table_model_->GetDomainAt(selected_index),
- cookies_table_model_->GetCookieAt(selected_index));
- }
- } else {
- info_view_->ClearCookieDisplay();
- }
- remove_button_->SetEnabled(selected_row_count != 0);
- if (cookies_table_->RowCount() == 0)
+ cookies_tree_model_->DeleteAllCookies();
UpdateForEmptyState();
-}
-
-void CookiesView::OnTableViewDelete(views::TableView* table_view) {
- cookies_table_->RemoveSelectedCookies();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// 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 {
- return l10n_util::GetString(IDS_COOKIES_WINDOW_TITLE);
+ return l10n_util::GetString(IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE);
}
void CookiesView::WindowClosing() {
@@ -468,50 +340,49 @@ void CookiesView::ViewHierarchyChanged(bool is_add,
}
///////////////////////////////////////////////////////////////////////////////
+// CookiesView, views::TreeViewController overrides:
+
+void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) {
+ CookieTreeNode::DetailedInfo detailed_info =
+ static_cast<CookieTreeNode*>(tree_view->GetSelectedNode())->
+ GetDetailedInfo();
+ if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) {
+ info_view_->SetCookie(detailed_info.cookie->first,
+ detailed_info.cookie->second);
+ } else {
+ info_view_->ClearCookieDisplay();
+ }
+}
+
+void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) {
+ if (keycode == base::VKEY_DELETE)
+ cookies_tree_->RemoveSelectedItems();
+}
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, private:
CookiesView::CookiesView(Profile* profile)
- : search_label_(NULL),
- search_field_(NULL),
- clear_search_button_(NULL),
+ :
description_label_(NULL),
- cookies_table_(NULL),
+ cookies_tree_(NULL),
info_view_(NULL),
remove_button_(NULL),
remove_all_button_(NULL),
- profile_(profile),
- ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) {
+ profile_(profile) {
+}
+
+views::View* CookiesView::GetInitiallyFocusedView() {
+ return cookies_tree_;
}
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);
-
- cookies_table_model_.reset(new CookiesTableModel(profile_));
+ cookies_tree_model_.reset(new CookiesTreeModel(profile_));
info_view_ = new CookieInfoView;
- 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(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);
- // Make the table initially sorted by domain.
- views::TableView::SortDescriptors sort;
- sort.push_back(
- views::TableView::SortDescriptor(IDS_COOKIES_DOMAIN_COLUMN_HEADER,
- true));
- cookies_table_->SetSortDescriptors(sort);
+ cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get());
remove_button_ = new views::NativeButton(
this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL));
remove_all_button_ = new views::NativeButton(
@@ -539,16 +410,16 @@ 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_);
+
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(1, single_column_layout_id);
- layout->AddView(cookies_table_);
+ layout->AddView(cookies_tree_);
+ cookies_tree_->ExpandAll();
+
+ cookies_tree_->SetController(this);
+
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
layout->AddView(info_view_);
@@ -557,18 +428,8 @@ void CookiesView::Init() {
View* parent = GetParent();
parent->AddChildView(remove_button_);
parent->AddChildView(remove_all_button_);
-
- if (cookies_table_->RowCount() > 0) {
- cookies_table_->Select(0);
- } else {
+ if (!cookies_tree_model_.get()->GetRoot()->GetChildCount())
UpdateForEmptyState();
- }
-}
-
-void CookiesView::ResetSearchQuery() {
- search_field_->SetText(EmptyWString());
- clear_search_button_->SetEnabled(false);
- UpdateSearchResults();
}
void CookiesView::UpdateForEmptyState() {
diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h
index 23e28ba..7932b45 100644
--- a/chrome/browser/views/options/cookies_view.h
+++ b/chrome/browser/views/options/cookies_view.h
@@ -5,9 +5,12 @@
#ifndef CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H_
#define CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H_
+#include <string>
+
#include "base/task.h"
+#include "net/base/cookie_monster.h"
#include "views/controls/button/button.h"
-#include "views/controls/table/table_view_observer.h"
+#include "views/controls/tree/tree_view.h"
#include "views/controls/textfield/textfield.h"
#include "views/view.h"
#include "views/window/dialog_delegate.h"
@@ -17,53 +20,42 @@ namespace views {
class Label;
class NativeButton;
-class TableView;
} // namespace views
+
class CookieInfoView;
-class CookiesTableModel;
-class CookiesTableView;
+class CookiesTreeModel;
+class CookiesTreeView;
class Profile;
class Timer;
+
class CookiesView : public views::View,
public views::DialogDelegate,
public views::ButtonListener,
- public views::TableViewObserver,
- public views::Textfield::Controller {
+ public views::TreeViewController {
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);
- // views::TableViewObserver implementation.
- virtual void OnSelectionChanged();
+ // views::TreeViewController implementation.
+ virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view);
- // Invoked when the user presses the delete key. Deletes the selected
- // cookies.
- virtual void OnTableViewDelete(views::TableView* table_view);
-
- // 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::TreeViewController implementation.
+ virtual void OnTreeViewKeyDown(base::KeyboardCode keycode);
// views::WindowDelegate implementation.
virtual int GetDialogButtons() const {
return MessageBoxFlags::DIALOGBUTTON_CANCEL;
}
- virtual views::View* GetInitiallyFocusedView() {
- return search_field_;
- }
+ virtual views::View* GetInitiallyFocusedView();
+
virtual bool CanResize() const { return true; }
virtual std::wstring GetWindowTitle() const;
virtual void WindowClosing();
@@ -86,32 +78,22 @@ 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_;
- CookiesTableView* cookies_table_;
+ CookiesTreeView* cookies_tree_;
CookieInfoView* info_view_;
views::NativeButton* remove_button_;
views::NativeButton* remove_all_button_;
- // The Cookies Table model
- scoped_ptr<CookiesTableModel> cookies_table_model_;
+ // The Cookies Tree model
+ scoped_ptr<CookiesTreeModel> cookies_tree_model_;
// 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_;
@@ -119,4 +101,53 @@ class CookiesView : public views::View,
DISALLOW_COPY_AND_ASSIGN(CookiesView);
};
+///////////////////////////////////////////////////////////////////////////////
+// CookieInfoView
+//
+// Responsible for displaying a tabular grid of Cookie information.
+class CookieInfoView : public views::View {
+ public:
+ CookieInfoView();
+ virtual ~CookieInfoView();
+
+ // Update the display from the specified CookieNode.
+ void SetCookie(const std::string& domain,
+ const net::CookieMonster::CanonicalCookie& cookie_node);
+
+ // Clears the cookie display to indicate that no or multiple cookies are
+ // selected.
+ void ClearCookieDisplay();
+
+ // Enables or disables the cookie proerty text fields.
+ void EnableCookieDisplay(bool enabled);
+
+ protected:
+ // views::View overrides:
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child);
+
+ private:
+ // Set up the view layout
+ void Init();
+
+ // Individual property labels
+ views::Label* name_label_;
+ views::Textfield* name_value_field_;
+ views::Label* content_label_;
+ views::Textfield* content_value_field_;
+ views::Label* domain_label_;
+ views::Textfield* domain_value_field_;
+ views::Label* path_label_;
+ views::Textfield* path_value_field_;
+ views::Label* send_for_label_;
+ views::Textfield* send_for_value_field_;
+ views::Label* created_label_;
+ views::Textfield* created_value_field_;
+ views::Label* expires_label_;
+ views::Textfield* expires_value_field_;
+
+ DISALLOW_COPY_AND_ASSIGN(CookieInfoView);
+};
+
#endif // CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H_