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