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

Side by Side Diff: ash/devtools/ash_devtools_dom_agent.cc

Issue 2865713003: Remove ash dependency. (Closed)
Patch Set: rebase 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 "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
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
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
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() 350 params.parent = nullptr;
sadrul 2017/05/29 16:48:45 Don't need to set this.
342 ->ConfigureWidgetInitParamsForContainer(widget_for_highlighting_.get(),
343 kShellWindowId_OverlayContainer,
344 &params);
345 params.keep_on_top = true; 351 params.keep_on_top = true;
346 params.accept_events = false; 352 params.accept_events = false;
347 widget_for_highlighting_->Init(params); 353 widget_for_highlighting_->Init(params);
348 } 354 }
349 355
350 void AshDevToolsDOMAgent::UpdateHighlight( 356 void AshDevToolsDOMAgent::UpdateHighlight(
351 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, 357 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds,
352 SkColor background, 358 SkColor background,
353 SkColor border) { 359 SkColor border) {
354 constexpr int kBorderThickness = 1; 360 constexpr int kBorderThickness = 1;
355 views::View* root_view = widget_for_highlighting_->GetRootView(); 361 views::View* root_view = widget_for_highlighting_->GetRootView();
356 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); 362 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border));
357 root_view->set_background( 363 root_view->set_background(
358 views::Background::CreateSolidBackground(background)); 364 views::Background::CreateSolidBackground(background));
359 display::Display display = 365 display::Display display =
360 display::Screen::GetScreen()->GetDisplayNearestWindow( 366 display::Screen::GetScreen()->GetDisplayNearestWindow(
361 window_and_bounds.first); 367 window_and_bounds.first);
362 widget_for_highlighting_->GetNativeWindow()->SetBoundsInScreen( 368 aura::Window* root = window_and_bounds.first->GetRootWindow();
363 window_and_bounds.second, display); 369 if (root != widget_for_highlighting_->GetNativeWindow()->GetRootWindow())
370 root->AddChild(widget_for_highlighting_->GetNativeWindow());
371
372 aura::client::ScreenPositionClient* screen_position_client =
373 aura::client::GetScreenPositionClient(
374 window_and_bounds.first->GetRootWindow());
sadrul 2017/05/29 16:48:45 Use |root|
375
376 gfx::Rect bounds(window_and_bounds.second);
377 gfx::Point origin = bounds.origin();
378 screen_position_client->ConvertPointFromScreen(root, &origin);
379 bounds.set_origin(origin);
380 widget_for_highlighting_->GetNativeWindow()->SetBounds(bounds);
364 } 381 }
365 382
366 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( 383 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode(
367 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> 384 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
368 highlight_config, 385 highlight_config,
369 int node_id) { 386 int node_id) {
370 if (!widget_for_highlighting_) 387 if (!widget_for_highlighting_)
371 InitializeHighlightingWidget(); 388 InitializeHighlightingWidget();
372 389
373 std::pair<aura::Window*, gfx::Rect> window_and_bounds = 390 std::pair<aura::Window*, gfx::Rect> window_and_bounds =
(...skipping 12 matching lines...) Expand all
386 UpdateHighlight(window_and_bounds, content_color, border_color); 403 UpdateHighlight(window_and_bounds, content_color, border_color);
387 404
388 if (!widget_for_highlighting_->IsVisible()) 405 if (!widget_for_highlighting_->IsVisible())
389 widget_for_highlighting_->Show(); 406 widget_for_highlighting_->Show();
390 407
391 return ui::devtools::protocol::Response::OK(); 408 return ui::devtools::protocol::Response::OK();
392 } 409 }
393 410
394 } // namespace devtools 411 } // namespace devtools
395 } // namespace ash 412 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698