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

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

Issue 2476353002: Fix bug where removed (but not deleted) windows are not reflected in the tree properly (Closed)
Patch Set: rebase 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 // Also want to ignore rearranges or additions. Only removals are handled
109 // here. This is because OnWindowTreeChanged is only called if there is a
110 // new_parent. If there is no new_parent, we have to handle the removal
111 // of the node here. We only trigger this 0 or 1 times as an old_parent will
112 // either exist and only call this callback once, or not at all.
113 if (window == params.old_parent)
sadrul 2016/11/09 16:09:26 Should you check that params.new_parent is nullptr
Sarmad Hashmi 2016/11/09 17:51:30 Updated comment. This handles the removing when re
114 RemoveWindowNode(params.target, params.old_parent);
108 } 115 }
109 116
117 // Handles adding windows.
110 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, 118 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window,
111 const TreeChangeParams& params) { 119 const TreeChangeParams& params) {
112 // Only trigger this when window == root window. 120 // Only trigger this when window == params.new_parent.
113 // Removals are handled on OnWindowDestroying. 121 // If there is an old_parent + new_parent, then this window's node was
114 if (window != window->GetRootWindow() || !params.new_parent) 122 // removed in OnWindowTreeChanging and will now be added to the new_parent.
115 return; 123 // 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 124 // the window is only added here.
117 // which requires a remove followed by an add. If only new_parent 125 if (window == params.new_parent)
118 // exists, then a new window is being created so only add is called. 126 AddWindowNode(params.target);
119 if (params.old_parent)
120 RemoveWindowNode(params.target, params.old_parent);
121 AddWindowNode(params.target);
122 } 127 }
123 128
124 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { 129 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) {
125 RemoveWindowNode(window, window->GetParent()); 130 RemoveWindowNode(window, window->GetParent());
126 AddWindowNode(window); 131 AddWindowNode(window);
127 } 132 }
128 133
129 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( 134 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
130 ash::WmWindow* window) { 135 ash::WmWindow* window) {
131 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 136 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
(...skipping 15 matching lines...) Expand all
147 std::unique_ptr<ui::devtools::protocol::DOM::Node> 152 std::unique_ptr<ui::devtools::protocol::DOM::Node>
148 AshDevToolsDOMAgent::BuildInitialTree() { 153 AshDevToolsDOMAgent::BuildInitialTree() {
149 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 154 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
150 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { 155 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
151 children->addItem(BuildTreeForWindow(window)); 156 children->addItem(BuildTreeForWindow(window));
152 } 157 }
153 return BuildNode("root", nullptr, std::move(children)); 158 return BuildNode("root", nullptr, std::move(children));
154 } 159 }
155 160
156 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) { 161 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) {
162 DCHECK(window_to_node_id_map_.count(window->GetParent()));
157 WmWindow* prev_sibling = FindPreviousSibling(window); 163 WmWindow* prev_sibling = FindPreviousSibling(window);
158 frontend()->childNodeInserted( 164 frontend()->childNodeInserted(
159 window_to_node_id_map_[window->GetParent()], 165 window_to_node_id_map_[window->GetParent()],
160 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0, 166 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0,
161 BuildTreeForWindow(window)); 167 BuildTreeForWindow(window));
162 } 168 }
163 169
164 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window, 170 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window,
165 WmWindow* old_parent) { 171 WmWindow* old_parent) {
sadrul 2016/11/09 16:09:26 Can you add a DCHECK that old_parent is non-null h
Sarmad Hashmi 2016/11/09 17:51:30 Done.
166 window->RemoveObserver(this); 172 window->RemoveObserver(this);
167 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window); 173 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window);
168 DCHECK(it != window_to_node_id_map_.end()); 174 DCHECK(it != window_to_node_id_map_.end());
169 175
170 int node_id = it->second; 176 int node_id = it->second;
171 int parent_id = old_parent ? window_to_node_id_map_[old_parent] : 0; 177 int parent_id = 0;
178 if (window != window->GetRootWindow()) {
sadrul 2016/11/09 16:09:26 Is |window| ever the root-window here, i.e. are th
Sarmad Hashmi 2016/11/09 17:51:30 Ah, thanks for catching this. Done. I'm going to d
179 DCHECK(old_parent);
180 DCHECK(window_to_node_id_map_.count(old_parent));
181 parent_id = window_to_node_id_map_[old_parent];
182 }
172 183
173 window_to_node_id_map_.erase(it); 184 window_to_node_id_map_.erase(it);
174 frontend()->childNodeRemoved(parent_id, node_id); 185 frontend()->childNodeRemoved(parent_id, node_id);
175 } 186 }
176 187
177 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { 188 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
178 for (auto& pair : window_to_node_id_map_) 189 for (auto& pair : window_to_node_id_map_)
179 pair.first->RemoveObserver(this); 190 pair.first->RemoveObserver(this);
180 } 191 }
181 192
182 void AshDevToolsDOMAgent::Reset() { 193 void AshDevToolsDOMAgent::Reset() {
183 RemoveObserverFromAllWindows(); 194 RemoveObserverFromAllWindows();
184 window_to_node_id_map_.clear(); 195 window_to_node_id_map_.clear();
185 node_ids = 1; 196 node_ids = 1;
186 } 197 }
187 198
188 } // namespace devtools 199 } // namespace devtools
189 } // namespace ash 200 } // 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