Commit 784ce4bc authored by Illia Martyniuk's avatar Illia Martyniuk Committed by Commit Bot

DevTools: Refactoring node highlighting

Moving all the highlighting logic from DOM Agent to Overlay agent.

Bug: 775348
Change-Id: I5ae4fc7bc178566147f306d9ac5c04834e683c0c
Reviewed-on: https://chromium-review.googlesource.com/964704Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarYi Xu <yiyix@chromium.org>
Commit-Queue: Illia Martyniuk <illiam@google.com>
Cr-Commit-Position: refs/heads/master@{#544168}
parent 617dbe32
This diff is collapsed.
......@@ -9,8 +9,6 @@
#include "components/ui_devtools/devtools_base_agent.h"
#include "components/ui_devtools/views/ui_element_delegate.h"
#include "ui/aura/env_observer.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -18,25 +16,8 @@ namespace aura {
class Window;
}
namespace gfx {
class RenderText;
}
namespace ui_devtools {
enum HighlightRectsConfiguration {
NO_DRAW,
R1_CONTAINS_R2,
R1_HORIZONTAL_FULL_LEFT_R2,
R1_TOP_FULL_LEFT_R2,
R1_BOTTOM_FULL_LEFT_R2,
R1_TOP_PARTIAL_LEFT_R2,
R1_BOTTOM_PARTIAL_LEFT_R2,
R1_INTERSECTS_R2
};
enum RectSide { TOP_SIDE, LEFT_SIDE, RIGHT_SIDE, BOTTOM_SIDE };
class UIElement;
class DOMAgentObserver {
......@@ -46,8 +27,7 @@ class DOMAgentObserver {
class DOMAgent : public UiDevToolsBaseAgent<protocol::DOM::Metainfo>,
public UIElementDelegate,
public aura::EnvObserver,
public ui::LayerDelegate {
public aura::EnvObserver {
public:
DOMAgent();
~DOMAgent() override;
......@@ -74,32 +54,12 @@ class DOMAgent : public UiDevToolsBaseAgent<protocol::DOM::Metainfo>,
const std::vector<gfx::NativeWindow>& root_windows() const {
return root_windows_;
};
HighlightRectsConfiguration highlight_rect_config() const {
return highlight_rect_config_;
};
protocol::Response HighlightNode(int node_id, bool show_size = false);
// Return the id of the UI element targeted by an event located at |p|, where
// |p| is in the local coodinate space of |root_window|. The function
// first searches for the targeted window, then the targeted widget (if one
// exists), then the targeted view (if one exists). Return 0 if no valid
// target is found.
int FindElementIdTargetedByPoint(const gfx::Point& p,
gfx::NativeWindow root_window) const;
// Shows the distances between the nodes identified by |pinned_id| and
// |element_id| in the highlight overlay.
void ShowDistancesInHighlightOverlay(int pinned_id, int element_id);
// Returns parent id of the element with id |node_id|. Returns 0 if parent
// does not exist.
int GetParentIdOfNodeId(int node_id) const;
private:
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override;
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override {}
// aura::EnvObserver:
void OnWindowInitialized(aura::Window* window) override {}
......@@ -119,23 +79,13 @@ class DOMAgent : public UiDevToolsBaseAgent<protocol::DOM::Metainfo>,
views::View* view);
void RemoveDomNode(UIElement* ui_element);
void Reset();
void UpdateHighlight(
const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds);
std::unique_ptr<gfx::RenderText> render_text_;
bool is_building_tree_;
bool show_size_on_canvas_ = false;
HighlightRectsConfiguration highlight_rect_config_;
bool is_swap_ = false;
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
// agent.
std::unique_ptr<ui::Layer> layer_for_highlighting_;
std::vector<aura::Window*> root_windows_;
gfx::Rect hovered_rect_;
gfx::Rect pinned_rect_;
base::ObserverList<DOMAgentObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(DOMAgent);
......
......@@ -7,12 +7,32 @@
#include "components/ui_devtools/Overlay.h"
#include "components/ui_devtools/views/dom_agent.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class RenderText;
}
namespace ui_devtools {
enum HighlightRectsConfiguration {
NO_DRAW,
R1_CONTAINS_R2,
R1_HORIZONTAL_FULL_LEFT_R2,
R1_TOP_FULL_LEFT_R2,
R1_BOTTOM_FULL_LEFT_R2,
R1_TOP_PARTIAL_LEFT_R2,
R1_BOTTOM_PARTIAL_LEFT_R2,
R1_INTERSECTS_R2
};
enum RectSide { TOP_SIDE, LEFT_SIDE, RIGHT_SIDE, BOTTOM_SIDE };
class OverlayAgent : public UiDevToolsBaseAgent<protocol::Overlay::Metainfo>,
public ui::EventHandler {
public ui::EventHandler,
public ui::LayerDelegate {
public:
explicit OverlayAgent(DOMAgent* dom_agent);
~OverlayAgent() override;
......@@ -29,12 +49,46 @@ class OverlayAgent : public UiDevToolsBaseAgent<protocol::Overlay::Metainfo>,
protocol::Maybe<int> node_id) override;
protocol::Response hideHighlight() override;
HighlightRectsConfiguration highlight_rect_config() const {
return highlight_rect_config_;
};
// Return the id of the UI element targeted by an event located at |p|, where
// |p| is in the local coodinate space of |root_window|. The function
// first searches for the targeted window, then the targeted widget (if one
// exists), then the targeted view (if one exists). Return 0 if no valid
// target is found.
int FindElementIdTargetedByPoint(const gfx::Point& p,
gfx::NativeWindow root_window) const;
// Shows the distances between the nodes identified by |pinned_id| and
// |element_id| in the highlight overlay.
void ShowDistancesInHighlightOverlay(int pinned_id, int element_id);
private:
// ui:EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnKeyEvent(ui::KeyEvent* event) override;
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override;
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override {}
protocol::Response HighlightNode(int node_id, bool show_size = false);
void UpdateHighlight(
const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds);
DOMAgent* const dom_agent_;
std::unique_ptr<gfx::RenderText> render_text_;
bool show_size_on_canvas_ = false;
HighlightRectsConfiguration highlight_rect_config_;
bool is_swap_ = false;
std::unique_ptr<ui::Layer> layer_for_highlighting_;
gfx::Rect hovered_rect_;
gfx::Rect pinned_rect_;
int pinned_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(OverlayAgent);
......
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