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" | 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" | 12 #include "components/ui_devtools/devtools_server.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/aura/client/screen_position_client.h" |
| 15 #include "ui/aura/env.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_tree_host.h" |
17 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" |
18 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
19 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
20 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
22 #include "ui/wm/core/window_util.h" | 24 #include "ui/wm/core/window_util.h" |
23 | 25 |
24 namespace ash { | 26 namespace ash { |
25 namespace devtools { | 27 namespace devtools { |
26 namespace { | 28 namespace { |
27 | 29 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 .setNodeType(kDomElementNodeType) | 111 .setNodeType(kDomElementNodeType) |
110 .setAttributes(GetAttributes(root)) | 112 .setAttributes(GetAttributes(root)) |
111 .build(); | 113 .build(); |
112 node->setChildNodeCount(children->length()); | 114 node->setChildNodeCount(children->length()); |
113 node->setChildren(std::move(children)); | 115 node->setChildren(std::move(children)); |
114 return node; | 116 return node; |
115 } | 117 } |
116 | 118 |
117 } // namespace | 119 } // namespace |
118 | 120 |
119 AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) {} | 121 AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) { |
| 122 aura::Env::GetInstance()->AddObserver(this); |
| 123 } |
120 | 124 |
121 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { | 125 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { |
| 126 aura::Env::GetInstance()->RemoveObserver(this); |
122 Reset(); | 127 Reset(); |
123 } | 128 } |
124 | 129 |
125 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { | 130 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { |
126 Reset(); | 131 Reset(); |
127 return ui::devtools::protocol::Response::OK(); | 132 return ui::devtools::protocol::Response::OK(); |
128 } | 133 } |
129 | 134 |
130 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( | 135 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( |
131 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { | 136 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 207 |
203 void AshDevToolsDOMAgent::RemoveObserver( | 208 void AshDevToolsDOMAgent::RemoveObserver( |
204 AshDevToolsDOMAgentObserver* observer) { | 209 AshDevToolsDOMAgentObserver* observer) { |
205 observers_.RemoveObserver(observer); | 210 observers_.RemoveObserver(observer); |
206 } | 211 } |
207 | 212 |
208 UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) { | 213 UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) { |
209 return node_id_to_ui_element_[node_id]; | 214 return node_id_to_ui_element_[node_id]; |
210 } | 215 } |
211 | 216 |
| 217 void AshDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) { |
| 218 root_windows_.push_back(host->window()); |
| 219 } |
| 220 |
212 void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { | 221 void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { |
213 for (auto& observer : observers_) | 222 for (auto& observer : observers_) |
214 observer.OnNodeBoundsChanged(node_id); | 223 observer.OnNodeBoundsChanged(node_id); |
215 } | 224 } |
216 | 225 |
217 std::unique_ptr<ui::devtools::protocol::DOM::Node> | 226 std::unique_ptr<ui::devtools::protocol::DOM::Node> |
218 AshDevToolsDOMAgent::BuildInitialTree() { | 227 AshDevToolsDOMAgent::BuildInitialTree() { |
219 is_building_tree_ = true; | 228 is_building_tree_ = true; |
220 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 229 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
221 | 230 |
222 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement | 231 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement |
223 // but maybe a new different element type. | 232 // but maybe a new different element type. |
224 window_element_root_ = | 233 window_element_root_ = |
225 base::MakeUnique<WindowElement>(nullptr, this, nullptr); | 234 base::MakeUnique<WindowElement>(nullptr, this, nullptr); |
226 | 235 |
227 for (aura::Window* window : Shell::GetAllRootWindows()) { | 236 for (aura::Window* window : root_windows()) { |
228 UIElement* window_element = | 237 UIElement* window_element = |
229 new WindowElement(window, this, window_element_root_.get()); | 238 new WindowElement(window, this, window_element_root_.get()); |
230 | 239 |
231 children->addItem(BuildTreeForUIElement(window_element)); | 240 children->addItem(BuildTreeForUIElement(window_element)); |
232 window_element_root_->AddChild(window_element); | 241 window_element_root_->AddChild(window_element); |
233 } | 242 } |
234 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( | 243 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( |
235 "root", nullptr, std::move(children), window_element_root_->node_id()); | 244 "root", nullptr, std::move(children), window_element_root_->node_id()); |
236 is_building_tree_ = false; | 245 is_building_tree_ = false; |
237 return root_node; | 246 return root_node; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 340 |
332 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { | 341 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { |
333 DCHECK(!widget_for_highlighting_); | 342 DCHECK(!widget_for_highlighting_); |
334 widget_for_highlighting_.reset(new views::Widget); | 343 widget_for_highlighting_.reset(new views::Widget); |
335 views::Widget::InitParams params; | 344 views::Widget::InitParams params; |
336 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 345 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
337 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 346 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
338 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 347 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
339 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; | 348 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; |
340 params.name = "HighlightingWidget"; | 349 params.name = "HighlightingWidget"; |
341 Shell::GetPrimaryRootWindowController() | |
342 ->ConfigureWidgetInitParamsForContainer(widget_for_highlighting_.get(), | |
343 kShellWindowId_OverlayContainer, | |
344 ¶ms); | |
345 params.keep_on_top = true; | 350 params.keep_on_top = true; |
346 params.accept_events = false; | 351 params.accept_events = false; |
347 widget_for_highlighting_->Init(params); | 352 widget_for_highlighting_->Init(params); |
348 } | 353 } |
349 | 354 |
350 void AshDevToolsDOMAgent::UpdateHighlight( | 355 void AshDevToolsDOMAgent::UpdateHighlight( |
351 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, | 356 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, |
352 SkColor background, | 357 SkColor background, |
353 SkColor border) { | 358 SkColor border) { |
354 constexpr int kBorderThickness = 1; | 359 constexpr int kBorderThickness = 1; |
355 views::View* root_view = widget_for_highlighting_->GetRootView(); | 360 views::View* root_view = widget_for_highlighting_->GetRootView(); |
356 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); | 361 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); |
357 root_view->set_background( | 362 root_view->set_background( |
358 views::Background::CreateSolidBackground(background)); | 363 views::Background::CreateSolidBackground(background)); |
359 display::Display display = | 364 display::Display display = |
360 display::Screen::GetScreen()->GetDisplayNearestWindow( | 365 display::Screen::GetScreen()->GetDisplayNearestWindow( |
361 window_and_bounds.first); | 366 window_and_bounds.first); |
362 widget_for_highlighting_->GetNativeWindow()->SetBoundsInScreen( | 367 aura::Window* root = window_and_bounds.first->GetRootWindow(); |
363 window_and_bounds.second, display); | 368 if (root != widget_for_highlighting_->GetNativeWindow()->GetRootWindow()) |
| 369 root->AddChild(widget_for_highlighting_->GetNativeWindow()); |
| 370 |
| 371 aura::client::ScreenPositionClient* screen_position_client = |
| 372 aura::client::GetScreenPositionClient(root); |
| 373 |
| 374 gfx::Rect bounds(window_and_bounds.second); |
| 375 gfx::Point origin = bounds.origin(); |
| 376 screen_position_client->ConvertPointFromScreen(root, &origin); |
| 377 bounds.set_origin(origin); |
| 378 widget_for_highlighting_->GetNativeWindow()->SetBounds(bounds); |
364 } | 379 } |
365 | 380 |
366 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( | 381 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( |
367 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | 382 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> |
368 highlight_config, | 383 highlight_config, |
369 int node_id) { | 384 int node_id) { |
370 if (!widget_for_highlighting_) | 385 if (!widget_for_highlighting_) |
371 InitializeHighlightingWidget(); | 386 InitializeHighlightingWidget(); |
372 | 387 |
373 std::pair<aura::Window*, gfx::Rect> window_and_bounds = | 388 std::pair<aura::Window*, gfx::Rect> window_and_bounds = |
(...skipping 12 matching lines...) Expand all Loading... |
386 UpdateHighlight(window_and_bounds, content_color, border_color); | 401 UpdateHighlight(window_and_bounds, content_color, border_color); |
387 | 402 |
388 if (!widget_for_highlighting_->IsVisible()) | 403 if (!widget_for_highlighting_->IsVisible()) |
389 widget_for_highlighting_->Show(); | 404 widget_for_highlighting_->Show(); |
390 | 405 |
391 return ui::devtools::protocol::Response::OK(); | 406 return ui::devtools::protocol::Response::OK(); |
392 } | 407 } |
393 | 408 |
394 } // namespace devtools | 409 } // namespace devtools |
395 } // namespace ash | 410 } // namespace ash |
OLD | NEW |