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

Side by Side Diff: ash/common/devtools/ash_devtools_dom_agent.cc

Issue 2495533005: Fix bug where removed (but not deleted) windows are not reflected in the tree properly (Closed)
Patch Set: Create new child instead of using existing child Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/common/devtools/ash_devtools_dom_agent.h" 5 #include "ash/common/devtools/ash_devtools_dom_agent.h"
6 6
7 #include "ash/common/wm_window.h" 7 #include "ash/common/wm_window.h"
8 #include "components/ui_devtools/devtools_server.h" 8 #include "components/ui_devtools/devtools_server.h"
9 #include "ui/views/view.h" 9 #include "ui/views/view.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 Reset(); 94 Reset();
95 return ui::devtools::protocol::Response::OK(); 95 return ui::devtools::protocol::Response::OK();
96 } 96 }
97 97
98 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( 98 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument(
99 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { 99 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) {
100 *out_root = BuildInitialTree(); 100 *out_root = BuildInitialTree();
101 return ui::devtools::protocol::Response::OK(); 101 return ui::devtools::protocol::Response::OK();
102 } 102 }
103 103
104 // Need to remove node in OnWindowDestroying because the window parent reference 104 // Handles removing windows.
105 // is gone in OnWindowDestroyed 105 void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window,
106 void AshDevToolsDOMAgent::OnWindowDestroying(WmWindow* window) { 106 const TreeChangeParams& params) {
107 RemoveWindowNode(window, window->GetParent()); 107 // Only trigger this when window == params.old_parent.
108 // Only removals are handled here. Removing a node can occur as a result of
109 // reorganizing a window or just destroying it. OnWindowTreeChanged
110 // is only called if there is a new_parent. The only case this method isn't
111 // called is when adding a node because old_parent is then null.
112 // Finally, We only trigger this 0 or 1 times as an old_parent will
113 // either exist and only call this callback once, or not at all.
114 if (window == params.old_parent)
115 RemoveWindowNode(params.target);
108 } 116 }
109 117
118 // Handles adding windows.
110 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, 119 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window,
111 const TreeChangeParams& params) { 120 const TreeChangeParams& params) {
112 // Only trigger this when window == root window. 121 // Only trigger this when window == params.new_parent.
113 // Removals are handled on OnWindowDestroying. 122 // If there is an old_parent + new_parent, then this window's node was
114 if (window != window->GetRootWindow() || !params.new_parent) 123 // removed in OnWindowTreeChanging and will now be added to the new_parent.
115 return; 124 // If there is only a new_parent, OnWindowTreeChanging is never called and
116 // If there is an old_parent + new_parent, then this window is being moved 125 // the window is only added here.
117 // which requires a remove followed by an add. If only new_parent 126 if (window == params.new_parent)
118 // exists, then a new window is being created so only add is called. 127 AddWindowNode(params.target);
119 if (params.old_parent)
120 RemoveWindowNode(params.target, params.old_parent);
121 AddWindowNode(params.target);
122 } 128 }
123 129
124 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { 130 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) {
125 RemoveWindowNode(window, window->GetParent()); 131 RemoveWindowNode(window);
126 AddWindowNode(window); 132 AddWindowNode(window);
127 } 133 }
128 134
129 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( 135 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
130 ash::WmWindow* window) { 136 ash::WmWindow* window) {
131 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 137 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
132 views::Widget* widget = window->GetInternalWidget(); 138 views::Widget* widget = window->GetInternalWidget();
133 if (widget) 139 if (widget)
134 children->addItem(BuildTreeForRootWidget(widget)); 140 children->addItem(BuildTreeForRootWidget(widget));
135 for (ash::WmWindow* child : window->GetChildren()) { 141 for (ash::WmWindow* child : window->GetChildren()) {
(...skipping 11 matching lines...) Expand all
147 std::unique_ptr<ui::devtools::protocol::DOM::Node> 153 std::unique_ptr<ui::devtools::protocol::DOM::Node>
148 AshDevToolsDOMAgent::BuildInitialTree() { 154 AshDevToolsDOMAgent::BuildInitialTree() {
149 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 155 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
150 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { 156 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
151 children->addItem(BuildTreeForWindow(window)); 157 children->addItem(BuildTreeForWindow(window));
152 } 158 }
153 return BuildNode("root", nullptr, std::move(children)); 159 return BuildNode("root", nullptr, std::move(children));
154 } 160 }
155 161
156 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) { 162 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) {
163 DCHECK(window_to_node_id_map_.count(window->GetParent()));
157 WmWindow* prev_sibling = FindPreviousSibling(window); 164 WmWindow* prev_sibling = FindPreviousSibling(window);
158 frontend()->childNodeInserted( 165 frontend()->childNodeInserted(
159 window_to_node_id_map_[window->GetParent()], 166 window_to_node_id_map_[window->GetParent()],
160 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0, 167 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0,
161 BuildTreeForWindow(window)); 168 BuildTreeForWindow(window));
162 } 169 }
163 170
164 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window, 171 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window) {
165 WmWindow* old_parent) { 172 WmWindow* parent = window->GetParent();
166 window->RemoveObserver(this); 173 DCHECK(parent);
174 DCHECK(window_to_node_id_map_.count(parent));
167 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window); 175 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window);
168 DCHECK(it != window_to_node_id_map_.end()); 176 DCHECK(it != window_to_node_id_map_.end());
169 177
170 int node_id = it->second; 178 int node_id = it->second;
171 int parent_id = old_parent ? window_to_node_id_map_[old_parent] : 0; 179 int parent_id = window_to_node_id_map_[parent];
172 180
181 window->RemoveObserver(this);
173 window_to_node_id_map_.erase(it); 182 window_to_node_id_map_.erase(it);
174 frontend()->childNodeRemoved(parent_id, node_id); 183 frontend()->childNodeRemoved(parent_id, node_id);
175 } 184 }
176 185
177 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { 186 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
178 for (auto& pair : window_to_node_id_map_) 187 for (auto& pair : window_to_node_id_map_)
179 pair.first->RemoveObserver(this); 188 pair.first->RemoveObserver(this);
180 } 189 }
181 190
182 void AshDevToolsDOMAgent::Reset() { 191 void AshDevToolsDOMAgent::Reset() {
183 RemoveObserverFromAllWindows(); 192 RemoveObserverFromAllWindows();
184 window_to_node_id_map_.clear(); 193 window_to_node_id_map_.clear();
185 node_ids = 1; 194 node_ids = 1;
186 } 195 }
187 196
188 } // namespace devtools 197 } // namespace devtools
189 } // namespace ash 198 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/devtools/ash_devtools_dom_agent.h ('k') | ash/common/devtools/ash_devtools_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698