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/devtools/ash_devtools_dom_agent.h" | 5 #include "ash/devtools/ash_devtools_dom_agent.h" |
6 | 6 |
7 #include "ash/devtools/ui_element.h" | 7 #include "ash/devtools/ui_element.h" |
8 #include "ash/devtools/view_element.h" | 8 #include "ash/devtools/view_element.h" |
9 #include "ash/devtools/widget_element.h" | 9 #include "ash/devtools/widget_element.h" |
10 #include "ash/devtools/window_element.h" | 10 #include "ash/devtools/window_element.h" |
11 #include "ash/public/cpp/shell_window_ids.h" | |
12 #include "ash/root_window_controller.h" | |
13 #include "ash/shell.h" | |
14 #include "components/ui_devtools/devtools_server.h" | 11 #include "components/ui_devtools/devtools_server.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
13 #include "ui/aura/env.h" | |
16 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_tree_host.h" | |
17 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
17 #include "ui/display/screen.h" | |
18 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
19 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
20 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 #include "ui/wm/core/window_util.h" | 22 #include "ui/wm/core/window_util.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 namespace devtools { | 25 namespace devtools { |
26 namespace { | 26 namespace { |
27 | 27 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 .setNodeType(kDomElementNodeType) | 109 .setNodeType(kDomElementNodeType) |
110 .setAttributes(GetAttributes(root)) | 110 .setAttributes(GetAttributes(root)) |
111 .build(); | 111 .build(); |
112 node->setChildNodeCount(children->length()); | 112 node->setChildNodeCount(children->length()); |
113 node->setChildren(std::move(children)); | 113 node->setChildren(std::move(children)); |
114 return node; | 114 return node; |
115 } | 115 } |
116 | 116 |
117 } // namespace | 117 } // namespace |
118 | 118 |
119 AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) {} | 119 AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) { |
120 aura::Env::GetInstance()->AddObserver(this); | |
121 } | |
120 | 122 |
121 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { | 123 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { |
124 aura::Env::GetInstance()->RemoveObserver(this); | |
122 Reset(); | 125 Reset(); |
123 } | 126 } |
124 | 127 |
125 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { | 128 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { |
126 Reset(); | 129 Reset(); |
127 return ui::devtools::protocol::Response::OK(); | 130 return ui::devtools::protocol::Response::OK(); |
128 } | 131 } |
129 | 132 |
130 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( | 133 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( |
131 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { | 134 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 | 205 |
203 void AshDevToolsDOMAgent::RemoveObserver( | 206 void AshDevToolsDOMAgent::RemoveObserver( |
204 AshDevToolsDOMAgentObserver* observer) { | 207 AshDevToolsDOMAgentObserver* observer) { |
205 observers_.RemoveObserver(observer); | 208 observers_.RemoveObserver(observer); |
206 } | 209 } |
207 | 210 |
208 UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) { | 211 UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) { |
209 return node_id_to_ui_element_[node_id]; | 212 return node_id_to_ui_element_[node_id]; |
210 } | 213 } |
211 | 214 |
215 void AshDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) { | |
216 root_windows_.push_back(host->window()); | |
217 } | |
218 | |
212 void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { | 219 void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { |
213 for (auto& observer : observers_) | 220 for (auto& observer : observers_) |
214 observer.OnNodeBoundsChanged(node_id); | 221 observer.OnNodeBoundsChanged(node_id); |
215 } | 222 } |
216 | 223 |
217 std::unique_ptr<ui::devtools::protocol::DOM::Node> | 224 std::unique_ptr<ui::devtools::protocol::DOM::Node> |
218 AshDevToolsDOMAgent::BuildInitialTree() { | 225 AshDevToolsDOMAgent::BuildInitialTree() { |
219 is_building_tree_ = true; | 226 is_building_tree_ = true; |
220 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 227 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
221 | 228 |
222 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement | 229 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement |
223 // but maybe a new different element type. | 230 // but maybe a new different element type. |
224 window_element_root_ = new WindowElement(nullptr, this, nullptr); | 231 window_element_root_ = new WindowElement(nullptr, this, nullptr); |
225 | 232 |
226 for (aura::Window* window : Shell::GetAllRootWindows()) { | 233 for (aura::Window* window : root_windows()) { |
227 UIElement* window_element = | 234 UIElement* window_element = |
228 new WindowElement(window, this, window_element_root_); | 235 new WindowElement(window, this, window_element_root_); |
229 | 236 |
230 children->addItem(BuildTreeForUIElement(window_element)); | 237 children->addItem(BuildTreeForUIElement(window_element)); |
231 window_element_root_->AddChild(window_element); | 238 window_element_root_->AddChild(window_element); |
232 } | 239 } |
233 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( | 240 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( |
234 "root", nullptr, std::move(children), window_element_root_->node_id()); | 241 "root", nullptr, std::move(children), window_element_root_->node_id()); |
235 is_building_tree_ = false; | 242 is_building_tree_ = false; |
236 return root_node; | 243 return root_node; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 337 |
331 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { | 338 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { |
332 DCHECK(!widget_for_highlighting_); | 339 DCHECK(!widget_for_highlighting_); |
333 widget_for_highlighting_.reset(new views::Widget); | 340 widget_for_highlighting_.reset(new views::Widget); |
334 views::Widget::InitParams params; | 341 views::Widget::InitParams params; |
335 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 342 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
336 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 343 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
337 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 344 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
338 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; | 345 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; |
339 params.name = "HighlightingWidget"; | 346 params.name = "HighlightingWidget"; |
340 Shell::GetPrimaryRootWindowController() | 347 DCHECK(root_windows().size()); |
341 ->ConfigureWidgetInitParamsForContainer(widget_for_highlighting_.get(), | 348 params.parent = root_windows()[0]; |
sadrul
2017/05/25 04:21:03
Add a TODO here that we would want to find the cor
thanhph
2017/05/28 00:04:25
We don't need this anymore.
| |
342 kShellWindowId_OverlayContainer, | |
343 ¶ms); | |
344 params.keep_on_top = true; | 349 params.keep_on_top = true; |
345 params.accept_events = false; | 350 params.accept_events = false; |
346 widget_for_highlighting_->Init(params); | 351 widget_for_highlighting_->Init(params); |
347 } | 352 } |
348 | 353 |
349 void AshDevToolsDOMAgent::UpdateHighlight( | 354 void AshDevToolsDOMAgent::UpdateHighlight( |
350 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, | 355 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, |
351 SkColor background, | 356 SkColor background, |
352 SkColor border) { | 357 SkColor border) { |
353 constexpr int kBorderThickness = 1; | 358 constexpr int kBorderThickness = 1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 UpdateHighlight(window_and_bounds, content_color, border_color); | 390 UpdateHighlight(window_and_bounds, content_color, border_color); |
386 | 391 |
387 if (!widget_for_highlighting_->IsVisible()) | 392 if (!widget_for_highlighting_->IsVisible()) |
388 widget_for_highlighting_->Show(); | 393 widget_for_highlighting_->Show(); |
389 | 394 |
390 return ui::devtools::protocol::Response::OK(); | 395 return ui::devtools::protocol::Response::OK(); |
391 } | 396 } |
392 | 397 |
393 } // namespace devtools | 398 } // namespace devtools |
394 } // namespace ash | 399 } // namespace ash |
OLD | NEW |