| OLD | NEW |
| 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_lookup.h" | 7 #include "ash/common/wm_lookup.h" |
| 8 #include "ash/common/wm_window.h" | 8 #include "ash/common/wm_window.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return HighlightNode(std::move(highlight_config), node_id.fromJust()); | 131 return HighlightNode(std::move(highlight_config), node_id.fromJust()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 ui::devtools::protocol::Response AshDevToolsDOMAgent::hideHighlight() { | 134 ui::devtools::protocol::Response AshDevToolsDOMAgent::hideHighlight() { |
| 135 if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible()) | 135 if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible()) |
| 136 widget_for_highlighting_->Hide(); | 136 widget_for_highlighting_->Hide(); |
| 137 return ui::devtools::protocol::Response::OK(); | 137 return ui::devtools::protocol::Response::OK(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Handles removing windows. | 140 // Handles removing windows. |
| 141 void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window, | 141 void AshDevToolsDOMAgent::OnWindowHierarchyChanging( |
| 142 const TreeChangeParams& params) { | 142 const HierarchyChangeParams& params) { |
| 143 // Only trigger this when window == params.old_parent. | 143 // Only trigger this when params.receiver == params.old_parent. |
| 144 // Only removals are handled here. Removing a node can occur as a result of | 144 // Only removals are handled here. Removing a node can occur as a result of |
| 145 // reorganizing a window or just destroying it. OnWindowTreeChanged | 145 // reorganizing a window or just destroying it. OnWindowHierarchyChanged |
| 146 // is only called if there is a new_parent. The only case this method isn't | 146 // is only called if there is a new_parent. The only case this method isn't |
| 147 // called is when adding a node because old_parent is then null. | 147 // called is when adding a node because old_parent is then null. |
| 148 // Finally, We only trigger this 0 or 1 times as an old_parent will | 148 // Finally, We only trigger this 0 or 1 times as an old_parent will |
| 149 // either exist and only call this callback once, or not at all. | 149 // either exist and only call this callback once, or not at all. |
| 150 if (window == params.old_parent) | 150 if (params.receiver == params.old_parent) |
| 151 RemoveWindowTree(params.target, true); | 151 RemoveWindowTree(WmWindow::Get(params.target), true); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Handles adding windows. | 154 // Handles adding windows. |
| 155 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, | 155 void AshDevToolsDOMAgent::OnWindowHierarchyChanged( |
| 156 const TreeChangeParams& params) { | 156 const HierarchyChangeParams& params) { |
| 157 // Only trigger this when window == params.new_parent. | 157 // Only trigger this when params.receiver == params.new_parent. |
| 158 // If there is an old_parent + new_parent, then this window's node was | 158 // If there is an old_parent + new_parent, then this window's node was |
| 159 // removed in OnWindowTreeChanging and will now be added to the new_parent. | 159 // removed in OnWindowHierarchyChanging and will now be added to the |
| 160 // If there is only a new_parent, OnWindowTreeChanging is never called and | 160 // new_parent. If there is only a new_parent, OnWindowHierarchyChanging is |
| 161 // the window is only added here. | 161 // never called and the window is only added here. |
| 162 if (window == params.new_parent) | 162 if (params.receiver == params.new_parent) |
| 163 AddWindowTree(params.target); | 163 AddWindowTree(WmWindow::Get(params.target)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { | 166 void AshDevToolsDOMAgent::OnWindowStackingChanged(aura::Window* window) { |
| 167 RemoveWindowTree(window, false); | 167 RemoveWindowTree(WmWindow::Get(window), false); |
| 168 AddWindowTree(window); | 168 AddWindowTree(WmWindow::Get(window)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void AshDevToolsDOMAgent::OnWindowBoundsChanged(WmWindow* window, | 171 void AshDevToolsDOMAgent::OnWindowBoundsChanged(aura::Window* window, |
| 172 const gfx::Rect& old_bounds, | 172 const gfx::Rect& old_bounds, |
| 173 const gfx::Rect& new_bounds) { | 173 const gfx::Rect& new_bounds) { |
| 174 for (auto& observer : observers_) | 174 for (auto& observer : observers_) |
| 175 observer.OnWindowBoundsChanged(window); | 175 observer.OnWindowBoundsChanged(WmWindow::Get(window)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void AshDevToolsDOMAgent::OnWillRemoveView(views::Widget* widget, | 178 void AshDevToolsDOMAgent::OnWillRemoveView(views::Widget* widget, |
| 179 views::View* view) { | 179 views::View* view) { |
| 180 if (view == widget->GetRootView()) | 180 if (view == widget->GetRootView()) |
| 181 RemoveViewTree(view, nullptr, true); | 181 RemoveViewTree(view, nullptr, true); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void AshDevToolsDOMAgent::OnWidgetBoundsChanged(views::Widget* widget, | 184 void AshDevToolsDOMAgent::OnWidgetBoundsChanged(views::Widget* widget, |
| 185 const gfx::Rect& new_bounds) { | 185 const gfx::Rect& new_bounds) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 views::Widget* widget = GetWidgetFromWmWindow(window); | 260 views::Widget* widget = GetWidgetFromWmWindow(window); |
| 261 if (widget) | 261 if (widget) |
| 262 children->addItem(BuildTreeForRootWidget(widget)); | 262 children->addItem(BuildTreeForRootWidget(widget)); |
| 263 for (ash::WmWindow* child : window->GetChildren()) { | 263 for (ash::WmWindow* child : window->GetChildren()) { |
| 264 if (!IsHighlightingWindow(child)) | 264 if (!IsHighlightingWindow(child)) |
| 265 children->addItem(BuildTreeForWindow(child)); | 265 children->addItem(BuildTreeForWindow(child)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | 268 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 269 BuildNode("Window", GetAttributes(window), std::move(children)); | 269 BuildNode("Window", GetAttributes(window), std::move(children)); |
| 270 if (!window->HasObserver(this)) | 270 if (!window->aura_window()->HasObserver(this)) |
| 271 window->AddObserver(this); | 271 window->aura_window()->AddObserver(this); |
| 272 window_to_node_id_map_[window] = node->getNodeId(); | 272 window_to_node_id_map_[window] = node->getNodeId(); |
| 273 node_id_to_window_map_[node->getNodeId()] = window; | 273 node_id_to_window_map_[node->getNodeId()] = window; |
| 274 return node; | 274 return node; |
| 275 } | 275 } |
| 276 | 276 |
| 277 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget( | 277 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget( |
| 278 views::Widget* widget) { | 278 views::Widget* widget) { |
| 279 DCHECK(!widget_to_node_id_map_.count(widget)); | 279 DCHECK(!widget_to_node_id_map_.count(widget)); |
| 280 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 280 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 281 children->addItem(BuildTreeForView(widget->GetRootView())); | 281 children->addItem(BuildTreeForView(widget->GetRootView())); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 DCHECK(window_to_node_id_it != window_to_node_id_map_.end()); | 337 DCHECK(window_to_node_id_it != window_to_node_id_map_.end()); |
| 338 | 338 |
| 339 int node_id = window_to_node_id_it->second; | 339 int node_id = window_to_node_id_it->second; |
| 340 int parent_id = GetNodeIdFromWindow(window->GetParent()); | 340 int parent_id = GetNodeIdFromWindow(window->GetParent()); |
| 341 | 341 |
| 342 NodeIdToWindowMap::iterator node_id_to_window_it = | 342 NodeIdToWindowMap::iterator node_id_to_window_it = |
| 343 node_id_to_window_map_.find(node_id); | 343 node_id_to_window_map_.find(node_id); |
| 344 DCHECK(node_id_to_window_it != node_id_to_window_map_.end()); | 344 DCHECK(node_id_to_window_it != node_id_to_window_map_.end()); |
| 345 | 345 |
| 346 if (remove_observer) | 346 if (remove_observer) |
| 347 window->RemoveObserver(this); | 347 window->aura_window()->RemoveObserver(this); |
| 348 | 348 |
| 349 node_id_to_window_map_.erase(node_id_to_window_it); | 349 node_id_to_window_map_.erase(node_id_to_window_it); |
| 350 window_to_node_id_map_.erase(window_to_node_id_it); | 350 window_to_node_id_map_.erase(window_to_node_id_it); |
| 351 frontend()->childNodeRemoved(parent_id, node_id); | 351 frontend()->childNodeRemoved(parent_id, node_id); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void AshDevToolsDOMAgent::RemoveWidgetTree(views::Widget* widget, | 354 void AshDevToolsDOMAgent::RemoveWidgetTree(views::Widget* widget, |
| 355 bool remove_observer) { | 355 bool remove_observer) { |
| 356 DCHECK(widget); | 356 DCHECK(widget); |
| 357 if (widget->GetRootView()) | 357 if (widget->GetRootView()) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 node_id_to_view_map_.find(node_id); | 420 node_id_to_view_map_.find(node_id); |
| 421 DCHECK(node_id_to_view_it != node_id_to_view_map_.end()); | 421 DCHECK(node_id_to_view_it != node_id_to_view_map_.end()); |
| 422 | 422 |
| 423 view_to_node_id_map_.erase(view_to_node_id_it); | 423 view_to_node_id_map_.erase(view_to_node_id_it); |
| 424 node_id_to_view_map_.erase(node_id_to_view_it); | 424 node_id_to_view_map_.erase(node_id_to_view_it); |
| 425 frontend()->childNodeRemoved(parent_id, node_id); | 425 frontend()->childNodeRemoved(parent_id, node_id); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void AshDevToolsDOMAgent::RemoveObservers() { | 428 void AshDevToolsDOMAgent::RemoveObservers() { |
| 429 for (auto& pair : window_to_node_id_map_) | 429 for (auto& pair : window_to_node_id_map_) |
| 430 pair.first->RemoveObserver(this); | 430 pair.first->aura_window()->RemoveObserver(this); |
| 431 for (auto& pair : widget_to_node_id_map_) | 431 for (auto& pair : widget_to_node_id_map_) |
| 432 pair.first->RemoveRemovalsObserver(this); | 432 pair.first->RemoveRemovalsObserver(this); |
| 433 for (auto& pair : view_to_node_id_map_) | 433 for (auto& pair : view_to_node_id_map_) |
| 434 pair.first->RemoveObserver(this); | 434 pair.first->RemoveObserver(this); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void AshDevToolsDOMAgent::Reset() { | 437 void AshDevToolsDOMAgent::Reset() { |
| 438 RemoveObservers(); | 438 RemoveObservers(); |
| 439 widget_for_highlighting_.reset(); | 439 widget_for_highlighting_.reset(); |
| 440 window_to_node_id_map_.clear(); | 440 window_to_node_id_map_.clear(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return ui::devtools::protocol::Response::OK(); | 526 return ui::devtools::protocol::Response::OK(); |
| 527 } | 527 } |
| 528 | 528 |
| 529 bool AshDevToolsDOMAgent::IsHighlightingWindow(WmWindow* window) { | 529 bool AshDevToolsDOMAgent::IsHighlightingWindow(WmWindow* window) { |
| 530 return widget_for_highlighting_ && | 530 return widget_for_highlighting_ && |
| 531 GetWidgetFromWmWindow(window) == widget_for_highlighting_.get(); | 531 GetWidgetFromWmWindow(window) == widget_for_highlighting_.get(); |
| 532 } | 532 } |
| 533 | 533 |
| 534 } // namespace devtools | 534 } // namespace devtools |
| 535 } // namespace ash | 535 } // namespace ash |
| OLD | NEW |