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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/ui_devtools/devtools/ui_devtools_dom_agent.cc
diff --git a/ash/devtools/ash_devtools_dom_agent.cc b/components/ui_devtools/devtools/ui_devtools_dom_agent.cc
similarity index 84%
rename from ash/devtools/ash_devtools_dom_agent.cc
rename to components/ui_devtools/devtools/ui_devtools_dom_agent.cc
index 83bc4065f733c6264db983e7b612b817d7fd5ac2..7507bdaee181eda795fa63e1504e283e256e82a0 100644
--- a/ash/devtools/ash_devtools_dom_agent.cc
+++ b/components/ui_devtools/devtools/ui_devtools_dom_agent.cc
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/devtools/ash_devtools_dom_agent.h"
+#include "components/ui_devtools/devtools/ui_devtools_dom_agent.h"
-#include "ash/devtools/ui_element.h"
-#include "ash/devtools/view_element.h"
-#include "ash/devtools/widget_element.h"
-#include "ash/devtools/window_element.h"
#include "ash/public/cpp/shell_window_ids.h"
+
+#include "components/ui_devtools/devtools/ui_element.h"
+#include "components/ui_devtools/devtools/view_element.h"
+#include "components/ui_devtools/devtools/widget_element.h"
+#include "components/ui_devtools/devtools/window_element.h"
#include "components/ui_devtools/devtools_server.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/env.h"
@@ -22,10 +23,9 @@
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"
-namespace ash {
+namespace ui {
namespace devtools {
namespace {
-
using namespace ui::devtools::protocol;
// TODO(mhashmi): Make ids reusable
@@ -116,41 +116,40 @@ std::unique_ptr<DOM::Node> BuildDomNodeFromUIElement(UIElement* root) {
} // namespace
-AshDevToolsDOMAgent::AshDevToolsDOMAgent() : is_building_tree_(false) {
+UIDevToolsDOMAgent::UIDevToolsDOMAgent() : is_building_tree_(false) {
aura::Env::GetInstance()->AddObserver(this);
}
-AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {
+UIDevToolsDOMAgent::~UIDevToolsDOMAgent() {
aura::Env::GetInstance()->RemoveObserver(this);
Reset();
}
-ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() {
+ui::devtools::protocol::Response UIDevToolsDOMAgent::disable() {
Reset();
return ui::devtools::protocol::Response::OK();
}
-ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument(
+ui::devtools::protocol::Response UIDevToolsDOMAgent::getDocument(
std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) {
*out_root = BuildInitialTree();
return ui::devtools::protocol::Response::OK();
}
-ui::devtools::protocol::Response AshDevToolsDOMAgent::highlightNode(
+ui::devtools::protocol::Response UIDevToolsDOMAgent::highlightNode(
std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
highlight_config,
ui::devtools::protocol::Maybe<int> node_id) {
return HighlightNode(std::move(highlight_config), node_id.fromJust());
}
-ui::devtools::protocol::Response AshDevToolsDOMAgent::hideHighlight() {
+ui::devtools::protocol::Response UIDevToolsDOMAgent::hideHighlight() {
if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible())
widget_for_highlighting_->Hide();
return ui::devtools::protocol::Response::OK();
}
-void AshDevToolsDOMAgent::OnUIElementAdded(UIElement* parent,
- UIElement* child) {
+void UIDevToolsDOMAgent::OnUIElementAdded(UIElement* parent, UIElement* child) {
if (!parent) {
node_id_to_ui_element_[child->node_id()] = child;
return;
@@ -168,8 +167,12 @@ void AshDevToolsDOMAgent::OnUIElementAdded(UIElement* parent,
BuildTreeForUIElement(child));
}
-void AshDevToolsDOMAgent::OnUIElementReordered(UIElement* parent,
- UIElement* child) {
+void UIDevToolsDOMAgent::OnUIElementReordered(UIElement* parent,
+ UIElement* child) {
+ if (child->type() == UIElementType::WINDOW &&
+ IsHighlightingWindow(
+ UIElement::GetBackingElement<aura::Window, WindowElement>(child)))
+ return;
DCHECK(node_id_to_ui_element_.count(parent->node_id()));
const auto& children = parent->children();
@@ -181,47 +184,46 @@ void AshDevToolsDOMAgent::OnUIElementReordered(UIElement* parent,
BuildDomNodeFromUIElement(child));
}
-void AshDevToolsDOMAgent::OnUIElementRemoved(UIElement* ui_element) {
+void UIDevToolsDOMAgent::OnUIElementRemoved(UIElement* ui_element) {
DCHECK(node_id_to_ui_element_.count(ui_element->node_id()));
RemoveDomNode(ui_element);
node_id_to_ui_element_.erase(ui_element->node_id());
}
-void AshDevToolsDOMAgent::OnUIElementBoundsChanged(UIElement* ui_element) {
+void UIDevToolsDOMAgent::OnUIElementBoundsChanged(UIElement* ui_element) {
for (auto& observer : observers_)
observer.OnNodeBoundsChanged(ui_element->node_id());
}
-bool AshDevToolsDOMAgent::IsHighlightingWindow(aura::Window* window) {
+bool UIDevToolsDOMAgent::IsHighlightingWindow(aura::Window* window) {
return widget_for_highlighting_ &&
GetWidgetFromWindow(window) == widget_for_highlighting_.get();
}
-void AshDevToolsDOMAgent::AddObserver(AshDevToolsDOMAgentObserver* observer) {
+void UIDevToolsDOMAgent::AddObserver(UIDevToolsDOMAgentObserver* observer) {
observers_.AddObserver(observer);
}
-void AshDevToolsDOMAgent::RemoveObserver(
- AshDevToolsDOMAgentObserver* observer) {
+void UIDevToolsDOMAgent::RemoveObserver(UIDevToolsDOMAgentObserver* observer) {
observers_.RemoveObserver(observer);
}
-UIElement* AshDevToolsDOMAgent::GetElementFromNodeId(int node_id) {
+UIElement* UIDevToolsDOMAgent::GetElementFromNodeId(int node_id) {
return node_id_to_ui_element_[node_id];
}
-void AshDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) {
+void UIDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) {
root_windows_.push_back(host->window());
}
-void AshDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) {
+void UIDevToolsDOMAgent::OnNodeBoundsChanged(int node_id) {
for (auto& observer : observers_)
observer.OnNodeBoundsChanged(node_id);
}
std::unique_ptr<ui::devtools::protocol::DOM::Node>
-AshDevToolsDOMAgent::BuildInitialTree() {
+UIDevToolsDOMAgent::BuildInitialTree() {
is_building_tree_ = true;
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -243,7 +245,7 @@ AshDevToolsDOMAgent::BuildInitialTree() {
}
std::unique_ptr<ui::devtools::protocol::DOM::Node>
-AshDevToolsDOMAgent::BuildTreeForUIElement(UIElement* ui_element) {
+UIDevToolsDOMAgent::BuildTreeForUIElement(UIElement* ui_element) {
if (ui_element->type() == UIElementType::WINDOW) {
return BuildTreeForWindow(
ui_element,
@@ -260,7 +262,7 @@ AshDevToolsDOMAgent::BuildTreeForUIElement(UIElement* ui_element) {
return nullptr;
}
-std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
+std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForWindow(
UIElement* window_element_root,
aura::Window* window) {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -285,7 +287,7 @@ std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
return node;
}
-std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget(
+std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForRootWidget(
UIElement* widget_element,
views::Widget* widget) {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -302,7 +304,7 @@ std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget(
return node;
}
-std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView(
+std::unique_ptr<DOM::Node> UIDevToolsDOMAgent::BuildTreeForView(
UIElement* view_element,
views::View* view) {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -319,14 +321,14 @@ std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView(
return node;
}
-void AshDevToolsDOMAgent::RemoveDomNode(UIElement* ui_element) {
+void UIDevToolsDOMAgent::RemoveDomNode(UIElement* ui_element) {
for (auto* child_element : ui_element->children())
RemoveDomNode(child_element);
frontend()->childNodeRemoved(ui_element->parent()->node_id(),
ui_element->node_id());
}
-void AshDevToolsDOMAgent::Reset() {
+void UIDevToolsDOMAgent::Reset() {
is_building_tree_ = false;
widget_for_highlighting_.reset();
window_element_root_->Destroy();
@@ -334,7 +336,7 @@ void AshDevToolsDOMAgent::Reset() {
observers_.Clear();
}
-void AshDevToolsDOMAgent::InitializeHighlightingWidget() {
+void UIDevToolsDOMAgent::InitializeHighlightingWidget() {
DCHECK(!widget_for_highlighting_);
widget_for_highlighting_.reset(new views::Widget);
views::Widget::InitParams params;
@@ -346,14 +348,15 @@ void AshDevToolsDOMAgent::InitializeHighlightingWidget() {
params.parent = nullptr;
if (!root_windows().empty()) {
params.parent =
- root_windows()[0]->GetChildById(kShellWindowId_OverlayContainer);
+ root_windows()[0]->GetChildById(ash::kShellWindowId_OverlayContainer);
+ DCHECK(params.parent);
}
params.keep_on_top = true;
params.accept_events = false;
widget_for_highlighting_->Init(params);
}
-void AshDevToolsDOMAgent::UpdateHighlight(
+void UIDevToolsDOMAgent::UpdateHighlight(
const std::pair<aura::Window*, gfx::Rect>& window_and_bounds,
SkColor background,
SkColor border) {
@@ -369,7 +372,7 @@ void AshDevToolsDOMAgent::UpdateHighlight(
window_and_bounds.second, display);
}
-ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode(
+ui::devtools::protocol::Response UIDevToolsDOMAgent::HighlightNode(
std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
highlight_config,
int node_id) {
@@ -398,4 +401,4 @@ ui::devtools::protocol::Response AshDevToolsDOMAgent::HighlightNode(
}
} // namespace devtools
-} // namespace ash
+} // namespace ui
« 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