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

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

Issue 2498593002: Revert of Fix bug where removed (but not deleted) windows are not reflected in the tree properly (Closed)
Patch Set: 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 // Handles removing windows. 104 // Need to remove node in OnWindowDestroying because the window parent reference
105 void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window, 105 // is gone in OnWindowDestroyed
106 const TreeChangeParams& params) { 106 void AshDevToolsDOMAgent::OnWindowDestroying(WmWindow* window) {
107 // Only trigger this when window == params.old_parent. 107 RemoveWindowNode(window, window->GetParent());
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);
116 } 108 }
117 109
118 // Handles adding windows.
119 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, 110 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window,
120 const TreeChangeParams& params) { 111 const TreeChangeParams& params) {
121 // Only trigger this when window == params.new_parent. 112 // Only trigger this when window == root window.
122 // If there is an old_parent + new_parent, then this window's node was 113 // Removals are handled on OnWindowDestroying.
123 // removed in OnWindowTreeChanging and will now be added to the new_parent. 114 if (window != window->GetRootWindow() || !params.new_parent)
124 // If there is only a new_parent, OnWindowTreeChanging is never called and 115 return;
125 // the window is only added here. 116 // If there is an old_parent + new_parent, then this window is being moved
126 if (window == params.new_parent) 117 // which requires a remove followed by an add. If only new_parent
127 AddWindowNode(params.target); 118 // exists, then a new window is being created so only add is called.
119 if (params.old_parent)
120 RemoveWindowNode(params.target, params.old_parent);
121 AddWindowNode(params.target);
128 } 122 }
129 123
130 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { 124 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) {
131 RemoveWindowNode(window); 125 RemoveWindowNode(window, window->GetParent());
132 AddWindowNode(window); 126 AddWindowNode(window);
133 } 127 }
134 128
135 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( 129 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
136 ash::WmWindow* window) { 130 ash::WmWindow* window) {
137 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 131 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
138 views::Widget* widget = window->GetInternalWidget(); 132 views::Widget* widget = window->GetInternalWidget();
139 if (widget) 133 if (widget)
140 children->addItem(BuildTreeForRootWidget(widget)); 134 children->addItem(BuildTreeForRootWidget(widget));
141 for (ash::WmWindow* child : window->GetChildren()) { 135 for (ash::WmWindow* child : window->GetChildren()) {
(...skipping 11 matching lines...) Expand all
153 std::unique_ptr<ui::devtools::protocol::DOM::Node> 147 std::unique_ptr<ui::devtools::protocol::DOM::Node>
154 AshDevToolsDOMAgent::BuildInitialTree() { 148 AshDevToolsDOMAgent::BuildInitialTree() {
155 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 149 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
156 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { 150 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
157 children->addItem(BuildTreeForWindow(window)); 151 children->addItem(BuildTreeForWindow(window));
158 } 152 }
159 return BuildNode("root", nullptr, std::move(children)); 153 return BuildNode("root", nullptr, std::move(children));
160 } 154 }
161 155
162 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) { 156 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) {
163 DCHECK(window_to_node_id_map_.count(window->GetParent()));
164 WmWindow* prev_sibling = FindPreviousSibling(window); 157 WmWindow* prev_sibling = FindPreviousSibling(window);
165 frontend()->childNodeInserted( 158 frontend()->childNodeInserted(
166 window_to_node_id_map_[window->GetParent()], 159 window_to_node_id_map_[window->GetParent()],
167 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0, 160 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0,
168 BuildTreeForWindow(window)); 161 BuildTreeForWindow(window));
169 } 162 }
170 163
171 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window) { 164 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window,
172 WmWindow* parent = window->GetParent(); 165 WmWindow* old_parent) {
173 DCHECK(parent); 166 window->RemoveObserver(this);
174 DCHECK(window_to_node_id_map_.count(parent));
175 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window); 167 WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window);
176 DCHECK(it != window_to_node_id_map_.end()); 168 DCHECK(it != window_to_node_id_map_.end());
177 169
178 int node_id = it->second; 170 int node_id = it->second;
179 int parent_id = window_to_node_id_map_[parent]; 171 int parent_id = old_parent ? window_to_node_id_map_[old_parent] : 0;
180 172
181 window->RemoveObserver(this);
182 window_to_node_id_map_.erase(it); 173 window_to_node_id_map_.erase(it);
183 frontend()->childNodeRemoved(parent_id, node_id); 174 frontend()->childNodeRemoved(parent_id, node_id);
184 } 175 }
185 176
186 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { 177 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
187 for (auto& pair : window_to_node_id_map_) 178 for (auto& pair : window_to_node_id_map_)
188 pair.first->RemoveObserver(this); 179 pair.first->RemoveObserver(this);
189 } 180 }
190 181
191 void AshDevToolsDOMAgent::Reset() { 182 void AshDevToolsDOMAgent::Reset() {
192 RemoveObserverFromAllWindows(); 183 RemoveObserverFromAllWindows();
193 window_to_node_id_map_.clear(); 184 window_to_node_id_map_.clear();
194 node_ids = 1; 185 node_ids = 1;
195 } 186 }
196 187
197 } // namespace devtools 188 } // namespace devtools
198 } // namespace ash 189 } // 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