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

Unified Diff: ash/devtools/ash_devtools_dom_agent.h

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . 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_css_agent.cc ('k') | ash/devtools/ash_devtools_dom_agent.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.h
diff --git a/ash/devtools/ash_devtools_dom_agent.h b/ash/devtools/ash_devtools_dom_agent.h
index 80e2404a627113b89069205e5ce04b72d805a3c0..91074fb1452c5cc60b6171821c8b172a82c646bf 100644
--- a/ash/devtools/ash_devtools_dom_agent.h
+++ b/ash/devtools/ash_devtools_dom_agent.h
@@ -6,44 +6,37 @@
#define ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
#include "ash/ash_export.h"
+#include "ash/devtools/ui_element_delegate.h"
#include "base/macros.h"
-#include "base/observer_list.h"
#include "components/ui_devtools/DOM.h"
#include "components/ui_devtools/devtools_base_agent.h"
-#include "ui/aura/window_observer.h"
#include "ui/views/view.h"
-#include "ui/views/view_observer.h"
#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_observer.h"
-#include "ui/views/widget/widget_removals_observer.h"
namespace aura {
class Window;
}
namespace ash {
-
namespace devtools {
+class UIElement;
+
class ASH_EXPORT AshDevToolsDOMAgentObserver {
public:
- virtual void OnWindowBoundsChanged(aura::Window* window) {}
- virtual void OnWidgetBoundsChanged(views::Widget* widget) {}
- virtual void OnViewBoundsChanged(views::View* view) {}
+ // TODO(thanhph): Use UIElement* as input argument instead.
+ virtual void OnNodeBoundsChanged(int node_id) = 0;
};
class ASH_EXPORT AshDevToolsDOMAgent
: public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent<
ui::devtools::protocol::DOM::Metainfo>),
- public aura::WindowObserver,
- public views::WidgetObserver,
- public views::WidgetRemovalsObserver,
- public views::ViewObserver {
+ public UIElementDelegate {
public:
AshDevToolsDOMAgent();
~AshDevToolsDOMAgent() override;
- // DOM::Backend
+ // DOM::Backend:
ui::devtools::protocol::Response disable() override;
ui::devtools::protocol::Response getDocument(
std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override;
@@ -53,101 +46,49 @@ class ASH_EXPORT AshDevToolsDOMAgent
ui::devtools::protocol::Maybe<int> node_id) override;
ui::devtools::protocol::Response hideHighlight() override;
- // WindowObserver
- void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override;
- void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
- void OnWindowStackingChanged(aura::Window* window) override;
- void OnWindowBoundsChanged(aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
-
- // views::WidgetRemovalsObserver
- void OnWillRemoveView(views::Widget* widget, views::View* view) override;
-
- // views::WidgetObserver
- void OnWidgetBoundsChanged(views::Widget* widget,
- const gfx::Rect& new_bounds) override;
-
- // views::ViewObserver
- void OnChildViewRemoved(views::View* parent, views::View* view) override;
- void OnChildViewAdded(views::View* parent, views::View* view) override;
- void OnChildViewReordered(views::View* parent, views::View*) override;
- void OnViewBoundsChanged(views::View* view) override;
-
- aura::Window* GetWindowFromNodeId(int nodeId);
- views::Widget* GetWidgetFromNodeId(int nodeId);
- views::View* GetViewFromNodeId(int nodeId);
-
- int GetNodeIdFromWindow(aura::Window* window);
- int GetNodeIdFromWidget(views::Widget* widget);
- int GetNodeIdFromView(views::View* view);
+ // UIElementDelegate:
+ void OnUIElementAdded(UIElement* parent, UIElement* child) override;
+ void OnUIElementReordered(UIElement* parent, UIElement* child) override;
+ void OnUIElementRemoved(UIElement* ui_element) override;
+ void OnUIElementBoundsChanged(UIElement* ui_element) override;
+ bool IsHighlightingWindow(aura::Window* window) override;
void AddObserver(AshDevToolsDOMAgentObserver* observer);
void RemoveObserver(AshDevToolsDOMAgentObserver* observer);
+ UIElement* GetElementFromNodeId(int node_id);
+ UIElement* window_element_root() const { return window_element_root_; };
private:
+ void OnNodeBoundsChanged(int node_id);
+
std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree();
+ std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForUIElement(
+ UIElement* ui_element);
std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow(
+ UIElement* window_element_root,
aura::Window* window);
std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget(
+ UIElement* widget_element,
views::Widget* widget);
std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView(
+ UIElement* view_element,
views::View* view);
-
- void AddWindowTree(aura::Window* window);
- // |remove_observer| ensures that we don't add a duplicate observer in any
- // observer callback. For example, |remove_observer| is false when rebuilding
- // the tree in OnWindowStackingChanged so that the observer is not removed and
- // re-added, thus causing endless calls on the observer.
- void RemoveWindowTree(aura::Window* window, bool remove_observer);
- void RemoveWindowNode(aura::Window* window, bool remove_observer);
-
- // Don't need AddWidgetTree because |widget| will always be inside a window,
- // so when windows are created, their widget nodes are created as well.
- void RemoveWidgetTree(views::Widget* widget, bool remove_observer);
- void RemoveWidgetNode(views::Widget* widget, bool remove_observer);
-
- void AddViewTree(views::View* view);
- void RemoveViewTree(views::View* view,
- views::View* parent,
- bool remove_observer);
- void RemoveViewNode(views::View* view,
- views::View* parent,
- bool remove_observer);
-
- void DestroyHighlightingWidget();
- void RemoveObservers();
+ void RemoveDomNode(UIElement* ui_element);
void Reset();
-
- using WindowAndBoundsPair = std::pair<aura::Window*, gfx::Rect>;
- WindowAndBoundsPair GetNodeWindowAndBounds(int node_id);
void InitializeHighlightingWidget();
- void UpdateHighlight(const WindowAndBoundsPair& window_and_bounds,
- SkColor background,
- SkColor border);
+ void UpdateHighlight(
+ const std::pair<aura::Window*, gfx::Rect>& window_and_bounds,
+ SkColor background,
+ SkColor border);
ui::devtools::protocol::Response HighlightNode(
std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
highlight_config,
int node_id);
- bool IsHighlightingWindow(aura::Window* window);
+ bool is_building_tree_;
+ UIElement* window_element_root_;
+ std::unordered_map<int, UIElement*> node_id_to_ui_element_;
std::unique_ptr<views::Widget> widget_for_highlighting_;
-
- using WindowToNodeIdMap = std::unordered_map<aura::Window*, int>;
- WindowToNodeIdMap window_to_node_id_map_;
- using NodeIdToWindowMap = std::unordered_map<int, aura::Window*>;
- NodeIdToWindowMap node_id_to_window_map_;
-
- using WidgetToNodeIdMap = std::unordered_map<views::Widget*, int>;
- WidgetToNodeIdMap widget_to_node_id_map_;
- using NodeIdToWidgetMap = std::unordered_map<int, views::Widget*>;
- NodeIdToWidgetMap node_id_to_widget_map_;
-
- using ViewToNodeIdMap = std::unordered_map<views::View*, int>;
- ViewToNodeIdMap view_to_node_id_map_;
- using NodeIdToViewMap = std::unordered_map<int, views::View*>;
- NodeIdToViewMap node_id_to_view_map_;
-
base::ObserverList<AshDevToolsDOMAgentObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent);
« no previous file with comments | « ash/devtools/ash_devtools_css_agent.cc ('k') | ash/devtools/ash_devtools_dom_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698