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

Side by Side Diff: ash/devtools/ash_devtools_dom_agent.h

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: address comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 5 #ifndef ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
6 #define ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 6 #define ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
7 7
8 #include "ash/ash_export.h" 8 #include "ash/ash_export.h"
9 #include "ash/devtools/ui_element_delegate.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/observer_list.h"
11 #include "components/ui_devtools/DOM.h" 11 #include "components/ui_devtools/DOM.h"
12 #include "components/ui_devtools/devtools_base_agent.h" 12 #include "components/ui_devtools/devtools_base_agent.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/views/view.h" 13 #include "ui/views/view.h"
15 #include "ui/views/view_observer.h"
16 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_observer.h"
18 #include "ui/views/widget/widget_removals_observer.h"
19 15
20 namespace aura { 16 namespace aura {
21 class Window; 17 class Window;
22 } 18 }
23 19
24 namespace ash { 20 namespace ash {
21 namespace devtools {
25 22
26 namespace devtools { 23 class UIElement;
27 24
28 class ASH_EXPORT AshDevToolsDOMAgentObserver { 25 class ASH_EXPORT AshDevToolsDOMAgentObserver {
29 public: 26 public:
30 virtual void OnWindowBoundsChanged(aura::Window* window) {} 27 virtual void OnNodeBoundsChanged(int node_id) = 0;
31 virtual void OnWidgetBoundsChanged(views::Widget* widget) {}
32 virtual void OnViewBoundsChanged(views::View* view) {}
33 }; 28 };
34 29
35 class ASH_EXPORT AshDevToolsDOMAgent 30 class ASH_EXPORT AshDevToolsDOMAgent
36 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent< 31 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent<
37 ui::devtools::protocol::DOM::Metainfo>), 32 ui::devtools::protocol::DOM::Metainfo>),
38 public aura::WindowObserver, 33 public UIElementDelegate {
39 public views::WidgetObserver,
40 public views::WidgetRemovalsObserver,
41 public views::ViewObserver {
42 public: 34 public:
43 AshDevToolsDOMAgent(); 35 AshDevToolsDOMAgent();
44 ~AshDevToolsDOMAgent() override; 36 ~AshDevToolsDOMAgent() override;
45 37
46 // DOM::Backend 38 // DOM::Backend:
47 ui::devtools::protocol::Response disable() override; 39 ui::devtools::protocol::Response disable() override;
48 ui::devtools::protocol::Response getDocument( 40 ui::devtools::protocol::Response getDocument(
49 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override; 41 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override;
50 ui::devtools::protocol::Response highlightNode( 42 ui::devtools::protocol::Response highlightNode(
51 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> 43 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
52 highlight_config, 44 highlight_config,
53 ui::devtools::protocol::Maybe<int> node_id) override; 45 ui::devtools::protocol::Maybe<int> node_id) override;
54 ui::devtools::protocol::Response hideHighlight() override; 46 ui::devtools::protocol::Response hideHighlight() override;
55 47
56 // WindowObserver 48 // UIElementDelegate:
57 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override; 49 void OnUIElementAdded(UIElement* parent, UIElement* child) override;
58 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override; 50 void OnUIElementReordered(UIElement* parent, UIElement* child) override;
59 void OnWindowStackingChanged(aura::Window* window) override; 51 bool OnUIElementRemoved(UIElement* ui_element) override;
60 void OnWindowBoundsChanged(aura::Window* window, 52 void OnUIElementBoundsChanged(UIElement* ui_element) override;
61 const gfx::Rect& old_bounds, 53 bool IsHighlightingWindow(aura::Window* window) override;
62 const gfx::Rect& new_bounds) override;
63
64 // views::WidgetRemovalsObserver
65 void OnWillRemoveView(views::Widget* widget, views::View* view) override;
66
67 // views::WidgetObserver
68 void OnWidgetBoundsChanged(views::Widget* widget,
69 const gfx::Rect& new_bounds) override;
70
71 // views::ViewObserver
72 void OnChildViewRemoved(views::View* parent, views::View* view) override;
73 void OnChildViewAdded(views::View* parent, views::View* view) override;
74 void OnChildViewReordered(views::View* parent, views::View*) override;
75 void OnViewBoundsChanged(views::View* view) override;
76
77 aura::Window* GetWindowFromNodeId(int nodeId);
78 views::Widget* GetWidgetFromNodeId(int nodeId);
79 views::View* GetViewFromNodeId(int nodeId);
80
81 int GetNodeIdFromWindow(aura::Window* window);
82 int GetNodeIdFromWidget(views::Widget* widget);
83 int GetNodeIdFromView(views::View* view);
84 54
85 void AddObserver(AshDevToolsDOMAgentObserver* observer); 55 void AddObserver(AshDevToolsDOMAgentObserver* observer);
86 void RemoveObserver(AshDevToolsDOMAgentObserver* observer); 56 void RemoveObserver(AshDevToolsDOMAgentObserver* observer);
57 UIElement* GetElementFromNodeId(int node_id);
58
59 UIElement* window_element_root() const { return window_element_root_; };
87 60
88 private: 61 private:
62 void OnNodeBoundsChanged(int node_id);
63
89 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree(); 64 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree();
65 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForUIElement(
66 UIElement* ui_element);
90 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow( 67 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow(
68 UIElement* window_element_root,
91 aura::Window* window); 69 aura::Window* window);
92 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget( 70 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget(
71 UIElement* widget_element,
93 views::Widget* widget); 72 views::Widget* widget);
94 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView( 73 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView(
74 UIElement* view_element,
95 views::View* view); 75 views::View* view);
96 76 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildDomNodeFromUIElement(
97 void AddWindowTree(aura::Window* window); 77 UIElement* root);
98 // |remove_observer| ensures that we don't add a duplicate observer in any 78 void RemoveDomNode(UIElement* ui_element);
99 // observer callback. For example, |remove_observer| is false when rebuilding
100 // the tree in OnWindowStackingChanged so that the observer is not removed and
101 // re-added, thus causing endless calls on the observer.
102 void RemoveWindowTree(aura::Window* window, bool remove_observer);
103 void RemoveWindowNode(aura::Window* window, bool remove_observer);
104
105 // Don't need AddWidgetTree because |widget| will always be inside a window,
106 // so when windows are created, their widget nodes are created as well.
107 void RemoveWidgetTree(views::Widget* widget, bool remove_observer);
108 void RemoveWidgetNode(views::Widget* widget, bool remove_observer);
109
110 void AddViewTree(views::View* view);
111 void RemoveViewTree(views::View* view,
112 views::View* parent,
113 bool remove_observer);
114 void RemoveViewNode(views::View* view,
115 views::View* parent,
116 bool remove_observer);
117
118 void DestroyHighlightingWidget();
119 void RemoveObservers();
120 void Reset(); 79 void Reset();
121
122 using WindowAndBoundsPair = std::pair<aura::Window*, gfx::Rect>;
123 WindowAndBoundsPair GetNodeWindowAndBounds(int node_id);
124 void InitializeHighlightingWidget(); 80 void InitializeHighlightingWidget();
125 void UpdateHighlight(const WindowAndBoundsPair& window_and_bounds, 81 void UpdateHighlight(
126 SkColor background, 82 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds,
127 SkColor border); 83 SkColor background,
84 SkColor border);
128 ui::devtools::protocol::Response HighlightNode( 85 ui::devtools::protocol::Response HighlightNode(
129 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> 86 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
130 highlight_config, 87 highlight_config,
131 int node_id); 88 int node_id);
132 bool IsHighlightingWindow(aura::Window* window);
133 89
90 bool is_building_tree_;
91 UIElement* window_element_root_;
92 std::unordered_map<int, UIElement*> node_id_to_ui_element_;
134 std::unique_ptr<views::Widget> widget_for_highlighting_; 93 std::unique_ptr<views::Widget> widget_for_highlighting_;
135
136 using WindowToNodeIdMap = std::unordered_map<aura::Window*, int>;
137 WindowToNodeIdMap window_to_node_id_map_;
138 using NodeIdToWindowMap = std::unordered_map<int, aura::Window*>;
139 NodeIdToWindowMap node_id_to_window_map_;
140
141 using WidgetToNodeIdMap = std::unordered_map<views::Widget*, int>;
142 WidgetToNodeIdMap widget_to_node_id_map_;
143 using NodeIdToWidgetMap = std::unordered_map<int, views::Widget*>;
144 NodeIdToWidgetMap node_id_to_widget_map_;
145
146 using ViewToNodeIdMap = std::unordered_map<views::View*, int>;
147 ViewToNodeIdMap view_to_node_id_map_;
148 using NodeIdToViewMap = std::unordered_map<int, views::View*>;
149 NodeIdToViewMap node_id_to_view_map_;
150
151 base::ObserverList<AshDevToolsDOMAgentObserver> observers_; 94 base::ObserverList<AshDevToolsDOMAgentObserver> observers_;
152 95
153 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent); 96 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent);
154 }; 97 };
155 98
156 } // namespace devtools 99 } // namespace devtools
157 } // namespace ash 100 } // namespace ash
158 101
159 #endif // ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 102 #endif // ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698