summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 20:20:06 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 20:20:06 +0000
commitc8d7021f04a3430705fc7ccd9672fc83d6533caf (patch)
tree01364eacccef175a384d0c663180404f5a095949 /views
parent672c023de1bad91d83ce4b107b9500025be7bec9 (diff)
downloadchromium_src-c8d7021f04a3430705fc7ccd9672fc83d6533caf.zip
chromium_src-c8d7021f04a3430705fc7ccd9672fc83d6533caf.tar.gz
chromium_src-c8d7021f04a3430705fc7ccd9672fc83d6533caf.tar.bz2
Show details about allowed and blocked cookies in a tabbed pane. Also reworks
the UI to show allowed and blocked cookies in differnt tabs. This implement only addresses the windows build. BUG=63650 TEST=Block all cookies, and visit a site that uses cookies. Click on the broken cookie icon that appears in the URL bar, and then click to see the cookies for this page. The UI now shows the allowed and blocked cookies in separate tabs, with an area below showing information about specific cookies selected in the tree control. Review URL: http://codereview.chromium.org/6639013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/tree/tree_view.cc93
-rw-r--r--views/controls/tree/tree_view.h15
2 files changed, 83 insertions, 25 deletions
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index 3f6b8bf..b0f850ff 100644
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -45,19 +45,13 @@ TreeView::TreeView()
ALLOW_THIS_IN_INITIALIZER_LIST(wrapper_(this)),
original_handler_(NULL),
drag_enabled_(false),
+ observer_added_(false),
has_custom_icons_(false),
image_list_(NULL) {
}
TreeView::~TreeView() {
- if (model_)
- model_->RemoveObserver(this);
- // Both param_to_details_map_ and node_to_details_map_ have the same value,
- // as such only need to delete from one.
- STLDeleteContainerPairSecondPointers(id_to_details_map_.begin(),
- id_to_details_map_.end());
- if (image_list_)
- ImageList_Destroy(image_list_);
+ Cleanup();
}
AccessibilityTypes::Role TreeView::GetAccessibleRole() {
@@ -73,12 +67,13 @@ void TreeView::SetModel(TreeModel* model) {
return;
if (model_ && tree_view_)
DeleteRootItems();
- if (model_)
- model_->RemoveObserver(this);
+
+ RemoveObserverFromModel();
+
model_ = model;
if (tree_view_ && model_) {
CreateRootItems();
- model_->AddObserver(this);
+ AddObserverToModel();
HIMAGELIST last_image_list = image_list_;
image_list_ = CreateImageList();
TreeView_SetImageList(tree_view_, image_list_, TVSIL_NORMAL);
@@ -345,7 +340,7 @@ HWND TreeView::CreateNativeControl(HWND parent_container) {
if (model_) {
CreateRootItems();
- model_->AddObserver(this);
+ AddObserverToModel();
image_list_ = CreateImageList();
TreeView_SetImageList(tree_view_, image_list_, TVSIL_NORMAL);
}
@@ -364,22 +359,36 @@ LRESULT TreeView::OnNotify(int w_param, LPNMHDR l_param) {
// in the maps is NULL.
DCHECK(model_);
NMTVDISPINFO* info = reinterpret_cast<NMTVDISPINFO*>(l_param);
- const NodeDetails* details =
- GetNodeDetailsByID(static_cast<int>(info->item.lParam));
- if (info->item.mask & TVIF_CHILDREN)
- info->item.cChildren = model_->GetChildCount(details->node);
- if (info->item.mask & TVIF_TEXT) {
- std::wstring text = details->node->GetTitle();
- DCHECK(info->item.cchTextMax);
- // Adjust the string direction if such adjustment is required.
- base::i18n::AdjustStringForLocaleDirection(&text);
+ // WARNING: its possible for Windows to send a TVN_GETDISPINFO message
+ // after the WM_DESTROY time of the native control. Since the details
+ // map will be cleaned up on OnDestroy(), don't try to access it in
+ // this case.
+ if (!id_to_details_map_.empty()) {
+ const NodeDetails* details =
+ GetNodeDetailsByID(static_cast<int>(info->item.lParam));
+ if (info->item.mask & TVIF_CHILDREN)
+ info->item.cChildren = model_->GetChildCount(details->node);
+ if (info->item.mask & TVIF_TEXT) {
+ std::wstring text = details->node->GetTitle();
+ DCHECK(info->item.cchTextMax);
- wcsncpy_s(info->item.pszText, info->item.cchTextMax, text.c_str(),
- _TRUNCATE);
+ // Adjust the string direction if such adjustment is required.
+ base::i18n::AdjustStringForLocaleDirection(&text);
+
+ wcsncpy_s(info->item.pszText, info->item.cchTextMax, text.c_str(),
+ _TRUNCATE);
+ }
+ // Instructs windows to cache the values for this node.
+ info->item.mask |= TVIF_DI_SETITEM;
+ } else {
+ if (info->item.mask & TVIF_CHILDREN)
+ info->item.cChildren = 0;
+
+ if (info->item.mask & TVIF_TEXT)
+ wcsncpy_s(info->item.pszText, info->item.cchTextMax, L"", _TRUNCATE);
}
- // Instructs windows to cache the values for this node.
- info->item.mask |= TVIF_DI_SETITEM;
+
// Return value ignored.
return 0;
}
@@ -454,6 +463,10 @@ LRESULT TreeView::OnNotify(int w_param, LPNMHDR l_param) {
return 0;
}
+void TreeView::OnDestroy() {
+ Cleanup();
+}
+
bool TreeView::OnKeyDown(ui::KeyboardCode virtual_key_code) {
if (virtual_key_code == VK_F2) {
if (!GetEditingNode()) {
@@ -515,6 +528,36 @@ HTREEITEM TreeView::GetTreeItemForNode(TreeModelNode* node) {
return details ? details->tree_item : NULL;
}
+void TreeView::Cleanup() {
+ RemoveObserverFromModel();
+
+ // Both node_to_details_map_ and node_to_details_map_ have the same value,
+ // as such only need to delete from one.
+ STLDeleteContainerPairSecondPointers(id_to_details_map_.begin(),
+ id_to_details_map_.end());
+ id_to_details_map_.clear();
+ node_to_details_map_.clear();
+
+ if (image_list_) {
+ ImageList_Destroy(image_list_);
+ image_list_ = NULL;
+ }
+}
+
+void TreeView::AddObserverToModel() {
+ if (model_ && !observer_added_) {
+ model_->AddObserver(this);
+ observer_added_ = true;
+ }
+}
+
+void TreeView::RemoveObserverFromModel() {
+ if (model_ && observer_added_) {
+ model_->RemoveObserver(this);
+ observer_added_ = false;
+ }
+}
+
void TreeView::DeleteRootItems() {
HTREEITEM root = TreeView_GetRoot(tree_view_);
if (root) {
diff --git a/views/controls/tree/tree_view.h b/views/controls/tree/tree_view.h
index d4d0771..c15207f 100644
--- a/views/controls/tree/tree_view.h
+++ b/views/controls/tree/tree_view.h
@@ -178,6 +178,9 @@ class TreeView : public NativeControl, ui::TreeModelObserver {
// Handles a variety of potential TreeView messages.
virtual LRESULT OnNotify(int w_param, LPNMHDR l_param);
+ // Invoked when the native control send a WM_DESTROY message to its parent.
+ virtual void OnDestroy();
+
// We pay attention to key down for two reasons: to circumvent VK_ENTER from
// toggling the expaned state when processes_enter_ is false, and to have F2
// start editting.
@@ -221,6 +224,15 @@ class TreeView : public NativeControl, ui::TreeModelObserver {
bool loaded_children;
};
+ // Cleanup all resources used by treeview.
+ void Cleanup();
+
+ // Make sure the tree view is observing the tree model.
+ void AddObserverToModel();
+
+ // Make sure the tree view is no longer observing the tree model.
+ void RemoveObserverFromModel();
+
// Deletes the root items from the treeview. This is used when the model
// changes.
void DeleteRootItems();
@@ -316,6 +328,9 @@ class TreeView : public NativeControl, ui::TreeModelObserver {
bool drag_enabled_;
+ // Has an observer been added to the model?
+ bool observer_added_;
+
// Did the model return a non-empty set of icons from GetIcons?
bool has_custom_icons_;