Commit e4ae34da authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

[UiDevTools] Introduce new UiElement subclass to serve as the root of the DOM tree.

This is more prep for Mac support. The current root is a WindowElement which is
backed by aura::Window.

Bug: 769352
Change-Id: Ie7e05fb528f9f54fc07bc5ce96397715e0e34f1e
Reviewed-on: https://chromium-review.googlesource.com/876307
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537341}
parent 0aca50f1
......@@ -17,6 +17,8 @@ source_set("views") {
"dom_agent.h",
"overlay_agent.cc",
"overlay_agent.h",
"root_element.cc",
"root_element.h",
"ui_element.cc",
"ui_element.h",
"ui_element_delegate.h",
......
......@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/ui_devtools/views/overlay_agent.h"
#include "components/ui_devtools/views/root_element.h"
#include "components/ui_devtools/views/ui_element.h"
#include "components/ui_devtools/views/view_element.h"
#include "components/ui_devtools/views/widget_element.h"
......@@ -536,7 +537,7 @@ int DOMAgent::FindElementIdTargetedByPoint(
views::Widget::GetWidgetForNativeWindow(targeted_window);
if (!targeted_widget) {
#if defined(USE_AURA)
return window_element_root_->FindUIElementIdForBackendElement<aura::Window>(
return element_root_->FindUIElementIdForBackendElement<aura::Window>(
targeted_window);
#else
return 0;
......@@ -554,7 +555,7 @@ int DOMAgent::FindElementIdTargetedByPoint(
views::View* targeted_view =
root_view->GetEventHandlerForPoint(point_in_targeted_window);
DCHECK(targeted_view);
return window_element_root_->FindUIElementIdForBackendElement<views::View>(
return element_root_->FindUIElementIdForBackendElement<views::View>(
targeted_view);
}
......@@ -607,7 +608,7 @@ void DOMAgent::ShowDistancesInHighlightOverlay(int pinned_id, int element_id) {
int DOMAgent::GetParentIdOfNodeId(int node_id) const {
DCHECK(node_id_to_ui_element_.count(node_id));
const UIElement* element = node_id_to_ui_element_.at(node_id);
if (element->parent() && element->parent() != window_element_root_.get())
if (element->parent() && element->parent() != element_root_.get())
return element->parent()->node_id();
return 0;
}
......@@ -764,20 +765,17 @@ std::unique_ptr<DOM::Node> DOMAgent::BuildInitialTree() {
is_building_tree_ = true;
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
// TODO(thanhph): Root of UIElement tree shoudn't be WindowElement
// but maybe a new different element type.
window_element_root_ =
std::make_unique<WindowElement>(nullptr, this, nullptr);
element_root_ = base::MakeUnique<RootElement>(this);
for (aura::Window* window : root_windows()) {
UIElement* window_element =
new WindowElement(window, this, window_element_root_.get());
new WindowElement(window, this, element_root_.get());
children->addItem(BuildTreeForUIElement(window_element));
window_element_root_->AddChild(window_element);
element_root_->AddChild(window_element);
}
std::unique_ptr<DOM::Node> root_node = BuildNode(
"root", nullptr, std::move(children), window_element_root_->node_id());
std::unique_ptr<DOM::Node> root_node =
BuildNode("root", nullptr, std::move(children), element_root_->node_id());
is_building_tree_ = false;
return root_node;
}
......@@ -869,7 +867,7 @@ void DOMAgent::Reset() {
is_building_tree_ = false;
render_text_.reset();
layer_for_highlighting_.reset();
window_element_root_.reset();
element_root_.reset();
node_id_to_ui_element_.clear();
observers_.Clear();
}
......
......@@ -70,7 +70,7 @@ class DOMAgent : public UiDevToolsBaseAgent<protocol::DOM::Metainfo>,
void AddObserver(DOMAgentObserver* observer);
void RemoveObserver(DOMAgentObserver* observer);
UIElement* GetElementFromNodeId(int node_id);
UIElement* window_element_root() const { return window_element_root_.get(); };
UIElement* element_root() const { return element_root_.get(); };
const std::vector<gfx::NativeWindow>& root_windows() const {
return root_windows_;
};
......@@ -127,7 +127,7 @@ class DOMAgent : public UiDevToolsBaseAgent<protocol::DOM::Metainfo>,
bool show_size_on_canvas_ = false;
HighlightRectsConfiguration highlight_rect_config_;
bool is_swap_ = false;
std::unique_ptr<UIElement> window_element_root_;
std::unique_ptr<UIElement> element_root_;
std::unordered_map<int, UIElement*> node_id_to_ui_element_;
// TODO(thanhph): |layer_for_highlighting_| should be owned by the overlay
......
......@@ -45,7 +45,7 @@ protocol::Response OverlayAgent::hideHighlight() {
void OverlayAgent::OnMouseEvent(ui::MouseEvent* event) {
// Make sure the element tree has been populated before processing
// mouse events.
if (!dom_agent_->window_element_root())
if (!dom_agent_->element_root())
return;
// Show parent of the pinned element with id |pinned_id_| when mouse scrolls
......@@ -92,7 +92,7 @@ void OverlayAgent::OnMouseEvent(ui::MouseEvent* event) {
}
void OverlayAgent::OnKeyEvent(ui::KeyEvent* event) {
if (!dom_agent_->window_element_root())
if (!dom_agent_->element_root())
return;
// Exit inspect mode by pressing ESC key.
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ui_devtools/views/root_element.h"
#include "components/ui_devtools/Protocol.h"
#include "components/ui_devtools/views/ui_element_delegate.h"
namespace ui_devtools {
RootElement::RootElement(UIElementDelegate* ui_element_delegate)
: UIElement(UIElementType::ROOT, ui_element_delegate, nullptr) {}
RootElement::~RootElement() {}
std::vector<std::pair<std::string, std::string>>
RootElement::GetCustomProperties() const {
NOTREACHED();
return {};
}
void RootElement::GetBounds(gfx::Rect* bounds) const {
NOTREACHED();
}
void RootElement::SetBounds(const gfx::Rect& bounds) {
NOTREACHED();
}
void RootElement::GetVisible(bool* visible) const {
NOTREACHED();
}
void RootElement::SetVisible(bool visible) {
NOTREACHED();
}
std::unique_ptr<protocol::Array<std::string>> RootElement::GetAttributes()
const {
NOTREACHED();
return nullptr;
}
std::pair<gfx::NativeWindow, gfx::Rect> RootElement::GetNodeWindowAndBounds()
const {
NOTREACHED();
return {};
}
} // namespace ui_devtools
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_UI_DEVTOOLS_VIEWS_ROOT_ELEMENT_H_
#define COMPONENTS_UI_DEVTOOLS_VIEWS_ROOT_ELEMENT_H_
#include "base/macros.h"
#include "components/ui_devtools/views/ui_element.h"
namespace ui_devtools {
class RootElement : public UIElement {
public:
explicit RootElement(UIElementDelegate* ui_element_delegate);
~RootElement() override;
// UIElement:
std::vector<std::pair<std::string, std::string>> GetCustomProperties()
const override;
void GetBounds(gfx::Rect* bounds) const override;
void SetBounds(const gfx::Rect& bounds) override;
void GetVisible(bool* visible) const override;
void SetVisible(bool visible) override;
std::unique_ptr<protocol::Array<std::string>> GetAttributes() const override;
std::pair<gfx::NativeWindow, gfx::Rect> GetNodeWindowAndBounds()
const override;
private:
DISALLOW_COPY_AND_ASSIGN(RootElement);
};
} // namespace ui_devtools
#endif // COMPONENTS_UI_DEVTOOLS_VIEWS_ROOT_ELEMENT_H_
......@@ -27,6 +27,8 @@ UIElement::~UIElement() {
std::string UIElement::GetTypeName() const {
switch (type_) {
case UIElementType::ROOT:
return "Root";
case UIElementType::WINDOW:
return "Window";
case UIElementType::WIDGET:
......
......@@ -22,7 +22,7 @@ class Array;
}
// UIElement type.
enum UIElementType { WINDOW, WIDGET, VIEW };
enum UIElementType { WINDOW, WIDGET, VIEW, ROOT };
class UIElement {
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment