Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: components/ui_devtools/devtools/ui_devtools_dom_agent.cc

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

Powered by Google App Engine
This is Rietveld 408576698