| 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/common/devtools/ash_devtools_dom_agent.h" | 5 #include "ash/common/devtools/ash_devtools_dom_agent.h" |
| 6 | 6 |
| 7 #include "ash/common/wm_lookup.h" | |
| 8 #include "ash/common/wm_window.h" | 7 #include "ash/common/wm_window.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 11 #include "components/ui_devtools/devtools_server.h" | 10 #include "components/ui_devtools/devtools_server.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/display/display.h" | 12 #include "ui/display/display.h" |
| 14 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
| 15 #include "ui/views/border.h" | 14 #include "ui/views/border.h" |
| 16 | 15 |
| 17 namespace ash { | 16 namespace ash { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 RemoveWidgetNode(widget, remove_observer); | 358 RemoveWidgetNode(widget, remove_observer); |
| 360 } | 359 } |
| 361 | 360 |
| 362 void AshDevToolsDOMAgent::RemoveWidgetNode(views::Widget* widget, | 361 void AshDevToolsDOMAgent::RemoveWidgetNode(views::Widget* widget, |
| 363 bool remove_observer) { | 362 bool remove_observer) { |
| 364 WidgetToNodeIdMap::iterator widget_to_node_id_it = | 363 WidgetToNodeIdMap::iterator widget_to_node_id_it = |
| 365 widget_to_node_id_map_.find(widget); | 364 widget_to_node_id_map_.find(widget); |
| 366 DCHECK(widget_to_node_id_it != widget_to_node_id_map_.end()); | 365 DCHECK(widget_to_node_id_it != widget_to_node_id_map_.end()); |
| 367 | 366 |
| 368 int node_id = widget_to_node_id_it->second; | 367 int node_id = widget_to_node_id_it->second; |
| 369 int parent_id = | 368 int parent_id = GetNodeIdFromWindow(WmWindow::Get(widget->GetNativeWindow())); |
| 370 GetNodeIdFromWindow(WmLookup::Get()->GetWindowForWidget(widget)); | |
| 371 | 369 |
| 372 if (remove_observer) | 370 if (remove_observer) |
| 373 widget->RemoveRemovalsObserver(this); | 371 widget->RemoveRemovalsObserver(this); |
| 374 | 372 |
| 375 NodeIdToWidgetMap::iterator node_id_to_widget_it = | 373 NodeIdToWidgetMap::iterator node_id_to_widget_it = |
| 376 node_id_to_widget_map_.find(node_id); | 374 node_id_to_widget_map_.find(node_id); |
| 377 DCHECK(node_id_to_widget_it != node_id_to_widget_map_.end()); | 375 DCHECK(node_id_to_widget_it != node_id_to_widget_map_.end()); |
| 378 | 376 |
| 379 widget_to_node_id_map_.erase(widget_to_node_id_it); | 377 widget_to_node_id_map_.erase(widget_to_node_id_it); |
| 380 node_id_to_widget_map_.erase(node_id_to_widget_it); | 378 node_id_to_widget_map_.erase(node_id_to_widget_it); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 445 } |
| 448 | 446 |
| 449 AshDevToolsDOMAgent::WindowAndBoundsPair | 447 AshDevToolsDOMAgent::WindowAndBoundsPair |
| 450 AshDevToolsDOMAgent::GetNodeWindowAndBounds(int node_id) { | 448 AshDevToolsDOMAgent::GetNodeWindowAndBounds(int node_id) { |
| 451 WmWindow* window = GetWindowFromNodeId(node_id); | 449 WmWindow* window = GetWindowFromNodeId(node_id); |
| 452 if (window) | 450 if (window) |
| 453 return std::make_pair(window, window->GetBoundsInScreen()); | 451 return std::make_pair(window, window->GetBoundsInScreen()); |
| 454 | 452 |
| 455 views::Widget* widget = GetWidgetFromNodeId(node_id); | 453 views::Widget* widget = GetWidgetFromNodeId(node_id); |
| 456 if (widget) { | 454 if (widget) { |
| 457 return std::make_pair(WmLookup::Get()->GetWindowForWidget(widget), | 455 return std::make_pair(WmWindow::Get(widget->GetNativeWindow()), |
| 458 widget->GetWindowBoundsInScreen()); | 456 widget->GetWindowBoundsInScreen()); |
| 459 } | 457 } |
| 460 | 458 |
| 461 views::View* view = GetViewFromNodeId(node_id); | 459 views::View* view = GetViewFromNodeId(node_id); |
| 462 if (view) { | 460 if (view) { |
| 463 gfx::Rect bounds = view->GetBoundsInScreen(); | 461 gfx::Rect bounds = view->GetBoundsInScreen(); |
| 464 return std::make_pair( | 462 return std::make_pair(WmWindow::Get(view->GetWidget()->GetNativeWindow()), |
| 465 WmLookup::Get()->GetWindowForWidget(view->GetWidget()), bounds); | 463 bounds); |
| 466 } | 464 } |
| 467 | 465 |
| 468 return std::make_pair(nullptr, gfx::Rect()); | 466 return std::make_pair(nullptr, gfx::Rect()); |
| 469 } | 467 } |
| 470 | 468 |
| 471 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { | 469 void AshDevToolsDOMAgent::InitializeHighlightingWidget() { |
| 472 DCHECK(!widget_for_highlighting_); | 470 DCHECK(!widget_for_highlighting_); |
| 473 widget_for_highlighting_.reset(new views::Widget); | 471 widget_for_highlighting_.reset(new views::Widget); |
| 474 views::Widget::InitParams params; | 472 views::Widget::InitParams params; |
| 475 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 473 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 488 | 486 |
| 489 void AshDevToolsDOMAgent::UpdateHighlight( | 487 void AshDevToolsDOMAgent::UpdateHighlight( |
| 490 const WindowAndBoundsPair& window_and_bounds, | 488 const WindowAndBoundsPair& window_and_bounds, |
| 491 SkColor background, | 489 SkColor background, |
| 492 SkColor border) { | 490 SkColor border) { |
| 493 constexpr int kBorderThickness = 1; | 491 constexpr int kBorderThickness = 1; |
| 494 views::View* root_view = widget_for_highlighting_->GetRootView(); | 492 views::View* root_view = widget_for_highlighting_->GetRootView(); |
| 495 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); | 493 root_view->SetBorder(views::CreateSolidBorder(kBorderThickness, border)); |
| 496 root_view->set_background( | 494 root_view->set_background( |
| 497 views::Background::CreateSolidBackground(background)); | 495 views::Background::CreateSolidBackground(background)); |
| 498 WmLookup::Get() | 496 WmWindow::Get(widget_for_highlighting_->GetNativeWindow()) |
| 499 ->GetWindowForWidget(widget_for_highlighting_.get()) | |
| 500 ->SetBoundsInScreen(window_and_bounds.second, | 497 ->SetBoundsInScreen(window_and_bounds.second, |
| 501 window_and_bounds.first->GetDisplayNearestWindow()); | 498 window_and_bounds.first->GetDisplayNearestWindow()); |
| 502 } | 499 } |
| 503 | 500 |
| 504 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( | 501 ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode( |
| 505 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | 502 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> |
| 506 highlight_config, | 503 highlight_config, |
| 507 int node_id) { | 504 int node_id) { |
| 508 if (!widget_for_highlighting_) | 505 if (!widget_for_highlighting_) |
| 509 InitializeHighlightingWidget(); | 506 InitializeHighlightingWidget(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 526 return ui::devtools::protocol::Response::OK(); | 523 return ui::devtools::protocol::Response::OK(); |
| 527 } | 524 } |
| 528 | 525 |
| 529 bool AshDevToolsDOMAgent::IsHighlightingWindow(WmWindow* window) { | 526 bool AshDevToolsDOMAgent::IsHighlightingWindow(WmWindow* window) { |
| 530 return widget_for_highlighting_ && | 527 return widget_for_highlighting_ && |
| 531 GetWidgetFromWmWindow(window) == widget_for_highlighting_.get(); | 528 GetWidgetFromWmWindow(window) == widget_for_highlighting_.get(); |
| 532 } | 529 } |
| 533 | 530 |
| 534 } // namespace devtools | 531 } // namespace devtools |
| 535 } // namespace ash | 532 } // namespace ash |
| OLD | NEW |