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

Unified Diff: ash/devtools/ash_devtools_dom_agent.cc

Issue 2865713003: Remove ash dependency. (Closed)
Patch Set: use window coordinates to set bounds 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/devtools/ash_devtools_dom_agent.h ('k') | ash/devtools/ash_devtools_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/devtools/ash_devtools_dom_agent.cc
diff --git a/ash/devtools/ash_devtools_dom_agent.cc b/ash/devtools/ash_devtools_dom_agent.cc
index 24cac7f5ed0a1044d6839c703690e0e2a9ae3560..c2785faefd733c3e2d276aff06595c2e039dfca6 100644
--- a/ash/devtools/ash_devtools_dom_agent.cc
+++ b/ash/devtools/ash_devtools_dom_agent.cc
@@ -9,12 +9,14 @@
#include "ash/devtools/widget_element.h"
#include "ash/devtools/window_element.h"
#include "ash/public/cpp/shell_window_ids.h"
-#include "ash/root_window_controller.h"
-#include "ash/shell.h"
#include "components/ui_devtools/devtools_server.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/aura/client/screen_position_client.h"
+#include "ui/aura/env.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
+#include "ui/display/screen.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/view.h"
@@ -116,9 +118,12 @@ std::unique_ptr<DOM::Node> BuildDomNodeFromUIElement(UIElement* root) {
} // namespace
-AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) {}
+AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) {
+ aura::Env::GetInstance()->AddObserver(this);
+}
AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {
+ aura::Env::GetInstance()->RemoveObserver(this);
Reset();
}
@@ -209,6 +214,12 @@ UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) {
return node_id_to_ui_element_[node_id];
}
+void AshDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) {
+ root_windows_.push_back(host->window());
+ LOG(ERROR) << "host->window()->GetBoundsInScreen():"
+ << host->window()->GetBoundsInScreen().ToString();
+}
+
void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) {
for (auto& observer : observers_)
observer.OnNodeBoundsChanged(node_id);
@@ -223,7 +234,7 @@ AshDevToolsDOMAgent::BuildInitialTree() {
// but maybe a new different element type.
window_element_root_ = new WindowElement(nullptr, this, nullptr);
- for (aura::Window* window : Shell::GetAllRootWindows()) {
+ for (aura::Window* window : root_windows()) {
UIElement* window_element =
new WindowElement(window, this, window_element_root_);
@@ -328,7 +339,7 @@ void AshDevToolsDOMAgent::Reset() {
observers_.Clear();
}
-void AshDevToolsDOMAgent::InitializeHighlightingWidget() {
+void AshDevToolsDOMAgent::InitializeHighlightingWidget(int root_window_index) {
DCHECK(!widget_for_highlighting_);
widget_for_highlighting_.reset(new views::Widget);
views::Widget::InitParams params;
@@ -336,11 +347,13 @@ void AshDevToolsDOMAgent::InitializeHighlightingWidget() {
params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.opacity = views::Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW;
+ LOG(ERROR) << "root_window_index: " << root_window_index;
params.name = "HighlightingWidget";
- Shell::GetPrimaryRootWindowController()
- ->ConfigureWidgetInitParamsForContainer(widget_for_highlighting_.get(),
- kShellWindowId_OverlayContainer,
- &params);
+ params.parent = root_windows()[0];
+ DCHECK(root_windows().size());
+ // params.parent =
+ // root_windows()[root_window_index]->GetChildById(kShellWindowId_OverlayContainer);;
+ // params.parent = root_windows()[root_window_index];
params.keep_on_top = true;
params.accept_events = false;
widget_for_highlighting_->Init(params);
@@ -358,22 +371,58 @@ void AshDevToolsDOMAgent::UpdateHighlight(
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(
window_and_bounds.first);
- widget_for_highlighting_->GetNativeWindow()->SetBoundsInScreen(
- window_and_bounds.second, display);
+ aura::Window* root = window_and_bounds.first->GetRootWindow();
+ if (root != widget_for_highlighting_->GetNativeWindow()->GetRootWindow())
+ root->AddChild(widget_for_highlighting_->GetNativeWindow());
+
+ aura::client::ScreenPositionClient* screen_position_client =
+ aura::client::GetScreenPositionClient(
+ window_and_bounds.first->GetRootWindow());
+ gfx::Point origin_in_screen = window_and_bounds.first->bounds().origin();
+ screen_position_client->ConvertPointFromScreen(root, &origin_in_screen);
+
+ gfx::Rect origin_in_window(origin_in_screen,
+ window_and_bounds.first->bounds().size());
+ widget_for_highlighting_->GetNativeWindow()->SetBounds(origin_in_window);
sadrul 2017/05/26 20:09:56 gfx::Rect bounds = window_and_bounds.second; gfx::
thanhph 2017/05/28 00:04:25 Done. I use gfx::Rect bounds(window_and_bounds.sec
+
+ LOG(ERROR) << "name: widget_for_highlighting_->GetNativeWindow(): "
+ << widget_for_highlighting_->GetNativeWindow()
+ ->GetRootWindow()
+ ->GetDebugInfo();
+ LOG(ERROR) << "widget_for_highlighting_: "
+ << widget_for_highlighting_->GetNativeWindow()
+ ->GetBoundsInScreen()
+ .ToString();
}
ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode(
std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
highlight_config,
int node_id) {
- if (!widget_for_highlighting_)
- InitializeHighlightingWidget();
-
+ if (!widget_for_highlighting_) {
+ LOG(ERROR) << "AshDevToolsDOMAgent::HighlightNode - root_window().size(): "
+ << root_windows().size();
+ UIElement* ui_element = GetElementFromNodeId(node_id);
+ UIElement* child_element = nullptr;
+ while (ui_element->parent()) {
+ child_element = ui_element;
+ ui_element = ui_element->parent();
+ }
+ DCHECK_EQ(UIElementType::WINDOW, child_element->type());
+ aura::Window* window =
+ UIElement::GetBackingElement<aura::Window, WindowElement>(
+ child_element);
+ auto iter = std::find(root_windows().begin(), root_windows().end(), window);
+ DCHECK(iter != root_windows().end());
+ InitializeHighlightingWidget(std::distance(root_windows().begin(), iter));
+ }
std::pair<aura::Window*, gfx::Rect> window_and_bounds =
node_id_to_ui_element_.count(node_id)
? node_id_to_ui_element_[node_id]->GetNodeWindowAndBounds()
: std::make_pair<aura::Window*, gfx::Rect>(nullptr, gfx::Rect());
-
+ LOG(ERROR) << "bounds: " << window_and_bounds.second.ToString();
+ LOG(ERROR) << "widget_for_highlighting_: "
+ << widget_for_highlighting_->GetWindowBoundsInScreen().ToString();
if (!window_and_bounds.first) {
return ui::devtools::protocol::Response::Error(
"No node found with that id");
« no previous file with comments | « ash/devtools/ash_devtools_dom_agent.h ('k') | ash/devtools/ash_devtools_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698