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 "components/ui_devtools/views/ui_devtools_dom_agent.h" |
| 6 | 6 |
| 7 #include "ash/devtools/ui_element.h" | |
| 8 #include "ash/devtools/view_element.h" | |
| 9 #include "ash/devtools/widget_element.h" | |
| 10 #include "ash/devtools/window_element.h" | |
| 11 #include "ash/public/cpp/shell_window_ids.h" | |
| 12 #include "components/ui_devtools/devtools_server.h" | 7 #include "components/ui_devtools/devtools_server.h" |
| 8 #include "components/ui_devtools/views/ui_element.h" | |
| 9 #include "components/ui_devtools/views/view_element.h" | |
| 10 #include "components/ui_devtools/views/widget_element.h" | |
| 11 #include "components/ui_devtools/views/window_element.h" | |
| 13 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/aura/client/screen_position_client.h" | 13 #include "ui/aura/client/screen_position_client.h" |
| 15 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 18 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
| 20 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
| 21 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
| 22 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 23 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 24 #include "ui/wm/core/window_util.h" | 23 #include "ui/wm/core/window_util.h" |
| 25 | 24 |
| 26 namespace ash { | 25 namespace ui { |
| 27 namespace devtools { | 26 namespace devtools { |
| 28 namespace { | 27 namespace { |
| 29 | 28 |
| 30 using namespace ui::devtools::protocol; | 29 using namespace ui::devtools::protocol; |
| 31 // TODO(mhashmi): Make ids reusable | 30 // TODO(mhashmi): Make ids reusable |
| 32 | 31 |
| 33 std::unique_ptr<DOM::Node> BuildNode( | 32 std::unique_ptr<DOM::Node> BuildNode( |
| 34 const std::string& name, | 33 const std::string& name, |
| 35 std::unique_ptr<Array<std::string>> attributes, | 34 std::unique_ptr<Array<std::string>> attributes, |
| 36 std::unique_ptr<Array<DOM::Node>> children, | 35 std::unique_ptr<Array<DOM::Node>> children, |
| 37 int node_ids) { | 36 int node_ids) { |
| 38 constexpr int kDomElementNodeType = 1; | 37 constexpr int kDomElementNodeType = 1; |
| 39 std::unique_ptr<DOM::Node> node = DOM::Node::create() | 38 std::unique_ptr<DOM::Node> node = DOM::Node::create() |
| 40 .setNodeId(node_ids) | 39 .setNodeId(node_ids) |
| 41 .setNodeName(name) | 40 .setNodeName(name) |
| 42 .setNodeType(kDomElementNodeType) | 41 .setNodeType(kDomElementNodeType) |
| 43 .setAttributes(std::move(attributes)) | 42 .setAttributes(std::move(attributes)) |
| 44 .build(); | 43 .build(); |
| 45 node->setChildNodeCount(children->length()); | 44 node->setChildNodeCount(static_cast<int>(children->length())); |
| 46 node->setChildren(std::move(children)); | 45 node->setChildren(std::move(children)); |
| 47 return node; | 46 return node; |
| 48 } | 47 } |
| 49 | 48 |
| 50 // TODO(thanhph): Move this function to UIElement::GetAttributes(). | 49 // TODO(thanhph): Move this function to UIElement::GetAttributes(). |
| 51 std::unique_ptr<Array<std::string>> GetAttributes(UIElement* ui_element) { | 50 std::unique_ptr<Array<std::string>> GetAttributes(UIElement* ui_element) { |
| 52 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); | 51 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); |
| 53 attributes->addItem("name"); | 52 attributes->addItem("name"); |
| 54 switch (ui_element->type()) { | 53 switch (ui_element->type()) { |
| 55 case UIElementType::WINDOW: { | 54 case UIElementType::WINDOW: { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 for (auto* it : root->children()) | 103 for (auto* it : root->children()) |
| 105 children->addItem(BuildDomNodeFromUIElement(it)); | 104 children->addItem(BuildDomNodeFromUIElement(it)); |
| 106 | 105 |
| 107 constexpr int kDomElementNodeType = 1; | 106 constexpr int kDomElementNodeType = 1; |
| 108 std::unique_ptr<DOM::Node> node = DOM::Node::create() | 107 std::unique_ptr<DOM::Node> node = DOM::Node::create() |
| 109 .setNodeId(root->node_id()) | 108 .setNodeId(root->node_id()) |
| 110 .setNodeName(root->GetTypeName()) | 109 .setNodeName(root->GetTypeName()) |
| 111 .setNodeType(kDomElementNodeType) | 110 .setNodeType(kDomElementNodeType) |
| 112 .setAttributes(GetAttributes(root)) | 111 .setAttributes(GetAttributes(root)) |
| 113 .build(); | 112 .build(); |
| 114 node->setChildNodeCount(children->length()); | 113 node->setChildNodeCount(static_cast<int>(children->length())); |
| 115 node->setChildren(std::move(children)); | 114 node->setChildren(std::move(children)); |
| 116 return node; | 115 return node; |
| 117 } | 116 } |
| 118 | 117 |
| 119 } // namespace | 118 } // namespace |
| 120 | 119 |
| 121 AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) { | 120 UIDevToolsDOMAgent::UIDevToolsDOMAgent() : is_building_tree_(false) { |
| 122 aura::Env::GetInstance()->AddObserver(this); | 121 aura::Env::GetInstance()->AddObserver(this); |
| 123 } | 122 } |
| 124 | 123 |
| 125 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { | 124 UIDevToolsDOMAgent::~UIDevToolsDOMAgent() { |
| 126 aura::Env::GetInstance()->RemoveObserver(this); | 125 aura::Env::GetInstance()->RemoveObserver(this); |
| 127 Reset(); | 126 Reset(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { | 129 ui::devtools::protocol::Response UIDevToolsDOMAgent::disable() { |
| 131 Reset(); | 130 Reset(); |
| 132 return ui::devtools::protocol::Response::OK(); | 131 return ui::devtools::protocol::Response::OK(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( | 134 ui::devtools::protocol::Response UIDevToolsDOMAgent::getDocument( |
| 136 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { | 135 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { |
| 137 *out_root = BuildInitialTree(); | 136 *out_root = BuildInitialTree(); |
| 138 return ui::devtools::protocol::Response::OK(); | 137 return ui::devtools::protocol::Response::OK(); |
| 139 } | 138 } |
| 140 | 139 |
| 141 ui::devtools::protocol::Response AshDevToolsDOMAgent::highlightNode( | 140 ui::devtools::protocol::Response UIDevToolsDOMAgent::highlightNode( |
| 142 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | 141 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> |
| 143 highlight_config, | 142 highlight_config, |
| 144 ui::devtools::protocol::Maybe<int> node_id) { | 143 ui::devtools::protocol::Maybe<int> node_id) { |
| 145 return HighlightNode(std::move(highlight_config), node_id.fromJust()); | 144 return HighlightNode(std::move(highlight_config), node_id.fromJust()); |
| 146 } | 145 } |
| 147 | 146 |
| 148 ui::devtools::protocol::Response AshDevToolsDOMAgent::hideHighlight() { | 147 ui::devtools::protocol::Response UIDevToolsDOMAgent::hideHighlight() { |
| 149 if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible()) | 148 if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible()) |
| 150 widget_for_highlighting_->Hide(); | 149 widget_for_highlighting_->Hide(); |
| 151 return ui::devtools::protocol::Response::OK(); | 150 return ui::devtools::protocol::Response::OK(); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void AshDevToolsDOMAgent::OnUIElementAdded(UIElement* parent, | 153 void UIDevToolsDOMAgent::OnUIElementAdded(UIElement* parent, UIElement* child) { |
| 155 UIElement* child) { | |
| 156 // When parent is null, only need to update |node_id_to_ui_element_|. | 154 // When parent is null, only need to update |node_id_to_ui_element_|. |
| 157 if (!parent) { | 155 if (!parent) { |
| 158 node_id_to_ui_element_[child->node_id()] = child; | 156 node_id_to_ui_element_[child->node_id()] = child; |
| 159 return; | 157 return; |
| 160 } | 158 } |
| 161 // If tree is being built, don't add child to dom tree again. | 159 // If tree is being built, don't add child to dom tree again. |
| 162 if (is_building_tree_) | 160 if (is_building_tree_) |
| 163 return; | 161 return; |
| 164 DCHECK(node_id_to_ui_element_.count(parent->node_id())); | 162 DCHECK(node_id_to_ui_element_.count(parent->node_id())); |
| 165 | 163 |
| 166 const auto& children = parent->children(); | 164 const auto& children = parent->children(); |
| 167 auto iter = std::find(children.begin(), children.end(), child); | 165 auto iter = std::find(children.begin(), children.end(), child); |
| 168 int prev_node_id = | 166 int prev_node_id = |
| 169 (iter == children.end() - 1) ? 0 : (*std::next(iter))->node_id(); | 167 (iter == children.end() - 1) ? 0 : (*std::next(iter))->node_id(); |
| 170 frontend()->childNodeInserted(parent->node_id(), prev_node_id, | 168 frontend()->childNodeInserted(parent->node_id(), prev_node_id, |
| 171 BuildTreeForUIElement(child)); | 169 BuildTreeForUIElement(child)); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void AshDevToolsDOMAgent::OnUIElementReordered(UIElement* parent, | 172 void UIDevToolsDOMAgent::OnUIElementReordered(UIElement* parent, |
| 175 UIElement* child) { | 173 UIElement* child) { |
| 176 DCHECK(node_id_to_ui_element_.count(parent->node_id())); | 174 DCHECK(node_id_to_ui_element_.count(parent->node_id())); |
| 177 | 175 |
| 178 const auto& children = parent->children(); | 176 const auto& children = parent->children(); |
| 179 auto iter = std::find(children.begin(), children.end(), child); | 177 auto iter = std::find(children.begin(), children.end(), child); |
| 180 int prev_node_id = | 178 int prev_node_id = |
| 181 (iter == children.begin()) ? 0 : (*std::prev(iter))->node_id(); | 179 (iter == children.begin()) ? 0 : (*std::prev(iter))->node_id(); |
| 182 RemoveDomNode(child); | 180 RemoveDomNode(child); |
| 183 frontend()->childNodeInserted(parent->node_id(), prev_node_id, | 181 frontend()->childNodeInserted(parent->node_id(), prev_node_id, |
| 184 BuildDomNodeFromUIElement(child)); | 182 BuildDomNodeFromUIElement(child)); |
| 185 } | 183 } |
| 186 | 184 |
| 187 void AshDevToolsDOMAgent::OnUIElementRemoved(UIElement* ui_element) { | 185 void UIDevToolsDOMAgent::OnUIElementRemoved(UIElement* ui_element) { |
| 188 DCHECK(node_id_to_ui_element_.count(ui_element->node_id())); | 186 DCHECK(node_id_to_ui_element_.count(ui_element->node_id())); |
| 189 | 187 |
| 190 RemoveDomNode(ui_element); | 188 RemoveDomNode(ui_element); |
| 191 node_id_to_ui_element_.erase(ui_element->node_id()); | 189 node_id_to_ui_element_.erase(ui_element->node_id()); |
| 192 } | 190 } |
| 193 | 191 |
| 194 void AshDevToolsDOMAgent::OnUIElementBoundsChanged(UIElement* ui_element) { | 192 void UIDevToolsDOMAgent::OnUIElementBoundsChanged(UIElement* ui_element) { |
| 195 for (auto& observer : observers_) | 193 for (auto& observer : observers_) |
| 196 observer.OnNodeBoundsChanged(ui_element->node_id()); | 194 observer.OnNodeBoundsChanged(ui_element->node_id()); |
| 197 } | 195 } |
| 198 | 196 |
| 199 bool AshDevToolsDOMAgent::IsHighlightingWindow(aura::Window* window) { | 197 bool UIDevToolsDOMAgent::IsHighlightingWindow(aura::Window* window) { |
| 200 return widget_for_highlighting_ && | 198 return widget_for_highlighting_ && |
| 201 GetWidgetFromWindow(window) == widget_for_highlighting_.get(); | 199 GetWidgetFromWindow(window) == widget_for_highlighting_.get(); |
| 202 } | 200 } |
| 203 | 201 |
| 204 void AshDevToolsDOMAgent::AddObserver(AshDevToolsDOMAgentObserver* observer) { | 202 void UIDevToolsDOMAgent::AddObserver(UIDevToolsDOMAgentObserver* observer) { |
| 205 observers_.AddObserver(observer); | 203 observers_.AddObserver(observer); |
| 206 } | 204 } |
| 207 | 205 |
| 208 void AshDevToolsDOMAgent::RemoveObserver( | 206 void UIDevToolsDOMAgent::RemoveObserver(UIDevToolsDOMAgentObserver* observer) { |
| 209 AshDevToolsDOMAgentObserver* observer) { | |
| 210 observers_.RemoveObserver(observer); | 207 observers_.RemoveObserver(observer); |
| 211 } | 208 } |
| 212 | 209 |
| 213 UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) { | 210 UIElement* UIDevToolsDOMAgent::GetElementFromNodeId(int node_id) { |
| 214 return node_id_to_ui_element_[node_id]; | 211 return node_id_to_ui_element_[node_id]; |
| 215 } | 212 } |
| 216 | 213 |
| 217 void AshDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) { | 214 void UIDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) { |
| 218 root_windows_.push_back(host->window()); | 215 root_windows_.push_back(host->window()); |
| 219 } | 216 } |
| 220 | 217 |
| 221 void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { | 218 void UIDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) { |
| 222 for (auto& observer : observers_) | 219 for (auto& observer : observers_) |
| 223 observer.OnNodeBoundsChanged(node_id); | 220 observer.OnNodeBoundsChanged(node_id); |
| 224 } | 221 } |
| 225 | 222 |
| 226 std::unique_ptr<ui::devtools::protocol::DOM::Node> | 223 std::unique_ptr<ui::devtools::protocol::DOM::Node> |
| 227 AshDevToolsDOMAgent::BuildInitialTree() { | 224 UIDevToolsDOMAgent::BuildInitialTree() { |
| 228 is_building_tree_ = true; | 225 is_building_tree_ = true; |
| 229 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 226 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 230 | 227 |
| 231 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement | 228 // TODO(thanhph): Root of UIElement tree shoudn't be WindowElement |
| 232 // but maybe a new different element type. | 229 // but maybe a new different element type. |
| 233 window_element_root_ = | 230 window_element_root_ = |
| 234 base::MakeUnique<WindowElement>(nullptr, this, nullptr); | 231 base::MakeUnique<WindowElement>(nullptr, this, nullptr); |
| 235 | 232 |
| 236 for (aura::Window* window : root_windows()) { | 233 for (aura::Window* window : root_windows()) { |
| 237 UIElement* window_element = | 234 UIElement* window_element = |
| 238 new WindowElement(window, this, window_element_root_.get()); | 235 new WindowElement(window, this, window_element_root_.get()); |
| 239 | 236 |
| 240 children->addItem(BuildTreeForUIElement(window_element)); | 237 children->addItem(BuildTreeForUIElement(window_element)); |
| 241 window_element_root_->AddChild(window_element); | 238 window_element_root_->AddChild(window_element); |
| 242 } | 239 } |
| 243 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( | 240 std::unique_ptr<ui::devtools::protocol::DOM::Node> root_node = BuildNode( |
| 244 "root", nullptr, std::move(children), window_element_root_->node_id()); | 241 "root", nullptr, std::move(children), window_element_root_->node_id()); |
| 245 is_building_tree_ = false; | 242 is_building_tree_ = false; |
| 246 return root_node; | 243 return root_node; |
| 247 } | 244 } |
| 248 | 245 |
| 249 std::unique_ptr<ui::devtools::protocol::DOM::Node> | 246 std::unique_ptr<ui::devtools::protocol::DOM::Node> |
| 250 AshDevToolsDOMAgent::BuildTreeForUIElement(UIElement* ui_element) { | 247 UIDevToolsDOMAgent::BuildTreeForUIElement(UIElement* ui_element) { |
| 251 if (ui_element->type() == UIElementType::WINDOW) { | 248 if (ui_element->type() == UIElementType::WINDOW) { |
| 252 return BuildTreeForWindow( | 249 return BuildTreeForWindow( |
| 253 ui_element, | 250 ui_element, |
| 254 UIElement::GetBackingElement<aura::Window, WindowElement>(ui_element)); | 251 UIElement::GetBackingElement<aura::Window, WindowElement>(ui_element)); |
| 255 } else if (ui_element->type() == UIElementType::WIDGET) { | 252 } else if (ui_element->type() == UIElementType::WIDGET) { |
| 256 return BuildTreeForRootWidget( | 253 return BuildTreeForRootWidget( |
| 257 ui_element, | 254 ui_element, |
| 258 UIElement::GetBackingElement<views::Widget, WidgetElement>(ui_element)); | 255 UIElement::GetBackingElement<views::Widget, WidgetElement>(ui_element)); |
| 259 } else if (ui_element->type() == UIElementType::VIEW) { | 256 } else if (ui_element->type() == UIElementType::VIEW) { |
| 260 return BuildTreeForView( | 257 return BuildTreeForView( |
| 261 ui_element, | 258 ui_element, |
| 262 UIElement::GetBackingElement<views::View, ViewElement>(ui_element)); | 259 UIElement::GetBackingElement<views::View, ViewElement>(ui_element)); |
| 263 } | 260 } |
| 264 return nullptr; | 261 return nullptr; |
| 265 } | 262 } |
| 266 | 263 |
| 267 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( | 264 std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForWindow( |
| 268 UIElement* window_element_root, | 265 UIElement* window_element_root, |
| 269 aura::Window* window) { | 266 aura::Window* window) { |
| 270 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 267 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 271 views::Widget* widget = GetWidgetFromWindow(window); | 268 views::Widget* widget = GetWidgetFromWindow(window); |
| 272 if (widget) { | 269 if (widget) { |
| 273 UIElement* widget_element = | 270 UIElement* widget_element = |
| 274 new WidgetElement(widget, this, window_element_root); | 271 new WidgetElement(widget, this, window_element_root); |
| 275 | 272 |
| 276 children->addItem(BuildTreeForRootWidget(widget_element, widget)); | 273 children->addItem(BuildTreeForRootWidget(widget_element, widget)); |
| 277 window_element_root->AddChild(widget_element); | 274 window_element_root->AddChild(widget_element); |
| 278 } | 275 } |
| 279 for (aura::Window* child : window->children()) { | 276 for (aura::Window* child : window->children()) { |
| 280 UIElement* window_element = | 277 UIElement* window_element = |
| 281 new WindowElement(child, this, window_element_root); | 278 new WindowElement(child, this, window_element_root); |
| 282 | 279 |
| 283 children->addItem(BuildTreeForWindow(window_element, child)); | 280 children->addItem(BuildTreeForWindow(window_element, child)); |
| 284 window_element_root->AddChild(window_element); | 281 window_element_root->AddChild(window_element); |
| 285 } | 282 } |
| 286 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | 283 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 287 BuildNode("Window", GetAttributes(window_element_root), | 284 BuildNode("Window", GetAttributes(window_element_root), |
| 288 std::move(children), window_element_root->node_id()); | 285 std::move(children), window_element_root->node_id()); |
| 289 return node; | 286 return node; |
| 290 } | 287 } |
| 291 | 288 |
| 292 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget( | 289 std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForRootWidget( |
| 293 UIElement* widget_element, | 290 UIElement* widget_element, |
| 294 views::Widget* widget) { | 291 views::Widget* widget) { |
| 295 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 292 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 296 | 293 |
| 297 UIElement* view_element = | 294 UIElement* view_element = |
| 298 new ViewElement(widget->GetRootView(), this, widget_element); | 295 new ViewElement(widget->GetRootView(), this, widget_element); |
| 299 | 296 |
| 300 children->addItem(BuildTreeForView(view_element, widget->GetRootView())); | 297 children->addItem(BuildTreeForView(view_element, widget->GetRootView())); |
| 301 widget_element->AddChild(view_element); | 298 widget_element->AddChild(view_element); |
| 302 | 299 |
| 303 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | 300 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 304 BuildNode("Widget", GetAttributes(widget_element), std::move(children), | 301 BuildNode("Widget", GetAttributes(widget_element), std::move(children), |
| 305 widget_element->node_id()); | 302 widget_element->node_id()); |
| 306 return node; | 303 return node; |
| 307 } | 304 } |
| 308 | 305 |
| 309 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView( | 306 std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForView( |
| 310 UIElement* view_element, | 307 UIElement* view_element, |
| 311 views::View* view) { | 308 views::View* view) { |
| 312 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 309 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 313 | 310 |
| 314 for (auto* child : view->GetChildrenInZOrder()) { | 311 for (auto* child : view->GetChildrenInZOrder()) { |
| 315 UIElement* view_element_child = new ViewElement(child, this, view_element); | 312 UIElement* view_element_child = new ViewElement(child, this, view_element); |
| 316 | 313 |
| 317 children->addItem(BuildTreeForView(view_element_child, child)); | 314 children->addItem(BuildTreeForView(view_element_child, child)); |
| 318 view_element->AddChild(view_element_child); | 315 view_element->AddChild(view_element_child); |
| 319 } | 316 } |
| 320 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | 317 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 321 BuildNode("View", GetAttributes(view_element), std::move(children), | 318 BuildNode("View", GetAttributes(view_element), std::move(children), |
| 322 view_element->node_id()); | 319 view_element->node_id()); |
| 323 return node; | 320 return node; |
| 324 } | 321 } |
| 325 | 322 |
| 326 void AshDevToolsDOMAgent::RemoveDomNode(UIElement* ui_element) { | 323 void UIDevToolsDOMAgent::RemoveDomNode(UIElement* ui_element) { |
| 327 for (auto* child_element : ui_element->children()) | 324 for (auto* child_element : ui_element->children()) |
| 328 RemoveDomNode(child_element); | 325 RemoveDomNode(child_element); |
| 329 frontend()->childNodeRemoved(ui_element->parent()->node_id(), | 326 frontend()->childNodeRemoved(ui_element->parent()->node_id(), |
| 330 ui_element->node_id()); | 327 ui_element->node_id()); |
| 331 } | 328 } |
| 332 | 329 |
| 333 void AshDevToolsDOMAgent::Reset() { | 330 void UIDevToolsDOMAgent::Reset() { |
| 334 is_building_tree_ = false; | 331 is_building_tree_ = false; |
| 335 widget_for_highlighting_.reset(); | 332 widget_for_highlighting_.reset(); |
| 336 window_element_root_.reset(); | 333 window_element_root_.reset(); |
| 337 node_id_to_ui_element_.clear(); | 334 node_id_to_ui_element_.clear(); |
| 338 observers_.Clear(); | 335 observers_.Clear(); |
| 339 } | 336 } |
| 340 | 337 |
| 341 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { | 338 void UIDevToolsDOMAgent::InitializeHighlightingWidget() { |
| 342 DCHECK(!widget_for_highlighting_); | 339 DCHECK(!widget_for_highlighting_); |
| 343 widget_for_highlighting_.reset(new views::Widget); | 340 widget_for_highlighting_.reset(new views::Widget); |
| 344 views::Widget::InitParams params; | 341 views::Widget::InitParams params; |
| 345 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 342 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 346 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 343 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 347 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 344 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 348 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; | 345 params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW; |
| 349 params.name = "HighlightingWidget"; | 346 params.name = "HighlightingWidget"; |
| 347 params.parent = root_windows()[0]; | |
|
sadrul
2017/06/14 03:25:57
This should be going away soon (https://bugs.chrom
thanhph
2017/06/14 15:26:37
Acknowledged.
| |
| 350 params.keep_on_top = true; | 348 params.keep_on_top = true; |
| 351 params.accept_events = false; | 349 params.accept_events = false; |
| 352 widget_for_highlighting_->Init(params); | 350 widget_for_highlighting_->Init(params); |
| 353 } | 351 } |
| 354 | 352 |
| 355 void AshDevToolsDOMAgent::UpdateHighlight( | 353 void UIDevToolsDOMAgent::UpdateHighlight( |
| 356 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, | 354 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, |
| 357 SkColor background, | 355 SkColor background, |
| 358 SkColor border) { | 356 SkColor border) { |
| 359 constexpr int kBorderThickness = 1; | 357 constexpr int kBorderThickness = 1; |
| 360 views::View* root_view = widget_for_highlighting_->GetRootView(); | 358 views::View* root_view = widget_for_highlighting_->GetRootView(); |
| 361 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); | 359 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); |
| 362 root_view->SetBackground(views::CreateSolidBackground(background)); | 360 root_view->SetBackground(views::CreateSolidBackground(background)); |
| 363 display::Display display = | 361 display::Display display = |
| 364 display::Screen::GetScreen()->GetDisplayNearestWindow( | 362 display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 365 window_and_bounds.first); | 363 window_and_bounds.first); |
| 366 aura::Window* root = window_and_bounds.first->GetRootWindow(); | 364 aura::Window* root = window_and_bounds.first->GetRootWindow(); |
| 367 if (root != widget_for_highlighting_->GetNativeWindow()->GetRootWindow()) | 365 if (root != widget_for_highlighting_->GetNativeWindow()->GetRootWindow()) |
| 368 root->AddChild(widget_for_highlighting_->GetNativeWindow()); | 366 root->AddChild(widget_for_highlighting_->GetNativeWindow()); |
| 369 | 367 |
| 370 aura::client::ScreenPositionClient* screen_position_client = | 368 aura::client::ScreenPositionClient* screen_position_client = |
| 371 aura::client::GetScreenPositionClient(root); | 369 aura::client::GetScreenPositionClient(root); |
| 372 | 370 |
| 373 gfx::Rect bounds(window_and_bounds.second); | 371 gfx::Rect bounds(window_and_bounds.second); |
| 374 gfx::Point origin = bounds.origin(); | 372 gfx::Point origin = bounds.origin(); |
| 375 screen_position_client->ConvertPointFromScreen(root, &origin); | 373 screen_position_client->ConvertPointFromScreen(root, &origin); |
| 376 bounds.set_origin(origin); | 374 bounds.set_origin(origin); |
| 377 widget_for_highlighting_->GetNativeWindow()->SetBounds(bounds); | 375 widget_for_highlighting_->GetNativeWindow()->SetBounds(bounds); |
| 378 } | 376 } |
| 379 | 377 |
| 380 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( | 378 ui::devtools::protocol::Response UIDevToolsDOMAgent::HighlightNode( |
| 381 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | 379 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> |
| 382 highlight_config, | 380 highlight_config, |
| 383 int node_id) { | 381 int node_id) { |
| 384 if (!widget_for_highlighting_) | 382 if (!widget_for_highlighting_) |
| 385 InitializeHighlightingWidget(); | 383 InitializeHighlightingWidget(); |
| 386 | 384 |
| 387 std::pair<aura::Window*, gfx::Rect> window_and_bounds = | 385 std::pair<aura::Window*, gfx::Rect> window_and_bounds = |
| 388 node_id_to_ui_element_.count(node_id) | 386 node_id_to_ui_element_.count(node_id) |
| 389 ? node_id_to_ui_element_[node_id]->GetNodeWindowAndBounds() | 387 ? node_id_to_ui_element_[node_id]->GetNodeWindowAndBounds() |
| 390 : std::make_pair<aura::Window*, gfx::Rect>(nullptr, gfx::Rect()); | 388 : std::make_pair<aura::Window*, gfx::Rect>(nullptr, gfx::Rect()); |
| 391 | 389 |
| 392 if (!window_and_bounds.first) { | 390 if (!window_and_bounds.first) { |
| 393 return ui::devtools::protocol::Response::Error( | 391 return ui::devtools::protocol::Response::Error( |
| 394 "No node found with that id"); | 392 "No node found with that id"); |
| 395 } | 393 } |
| 396 SkColor border_color = | 394 SkColor border_color = |
| 397 RGBAToSkColor(highlight_config->getBorderColor(nullptr)); | 395 RGBAToSkColor(highlight_config->getBorderColor(nullptr)); |
| 398 SkColor content_color = | 396 SkColor content_color = |
| 399 RGBAToSkColor(highlight_config->getContentColor(nullptr)); | 397 RGBAToSkColor(highlight_config->getContentColor(nullptr)); |
| 400 UpdateHighlight(window_and_bounds, content_color, border_color); | 398 UpdateHighlight(window_and_bounds, content_color, border_color); |
| 401 | 399 |
| 402 if (!widget_for_highlighting_->IsVisible()) | 400 if (!widget_for_highlighting_->IsVisible()) |
| 403 widget_for_highlighting_->Show(); | 401 widget_for_highlighting_->Show(); |
| 404 | 402 |
| 405 return ui::devtools::protocol::Response::OK(); | 403 return ui::devtools::protocol::Response::OK(); |
| 406 } | 404 } |
| 407 | 405 |
| 408 } // namespace devtools | 406 } // namespace devtools |
| 409 } // namespace ash | 407 } // namespace ui |
| OLD | NEW |