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

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: . 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(thanhph): Use UIElement* as input argument instead.
31 virtual void OnWidgetBoundsChanged(views::Widget* widget) {} 28 virtual void OnNodeBoundsChanged(int node_id) = 0;
32 virtual void OnViewBoundsChanged(views::View* view) {}
33 }; 29 };
34 30
35 class ASH_EXPORT AshDevToolsDOMAgent 31 class ASH_EXPORT AshDevToolsDOMAgent
36 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent< 32 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent<
37 ui::devtools::protocol::DOM::Metainfo>), 33 ui::devtools::protocol::DOM::Metainfo>),
38 public aura::WindowObserver, 34 public UIElementDelegate {
39 public views::WidgetObserver,
40 public views::WidgetRemovalsObserver,
41 public views::ViewObserver {
42 public: 35 public:
43 AshDevToolsDOMAgent(); 36 AshDevToolsDOMAgent();
44 ~AshDevToolsDOMAgent() override; 37 ~AshDevToolsDOMAgent() override;
45 38
46 // DOM::Backend 39 // DOM::Backend:
47 ui::devtools::protocol::Response disable() override; 40 ui::devtools::protocol::Response disable() override;
48 ui::devtools::protocol::Response getDocument( 41 ui::devtools::protocol::Response getDocument(
49 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override; 42 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override;
50 ui::devtools::protocol::Response highlightNode( 43 ui::devtools::protocol::Response highlightNode(
51 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> 44 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
52 highlight_config, 45 highlight_config,
53 ui::devtools::protocol::Maybe<int> node_id) override; 46 ui::devtools::protocol::Maybe<int> node_id) override;
54 ui::devtools::protocol::Response hideHighlight() override; 47 ui::devtools::protocol::Response hideHighlight() override;
55 48
56 // WindowObserver 49 // UIElementDelegate:
57 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override; 50 void OnUIElementAdded(UIElement* parent, UIElement* child) override;
58 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override; 51 void OnUIElementReordered(UIElement* parent, UIElement* child) override;
59 void OnWindowStackingChanged(aura::Window* window) override; 52 void OnUIElementRemoved(UIElement* ui_element) override;
60 void OnWindowBoundsChanged(aura::Window* window, 53 void OnUIElementBoundsChanged(UIElement* ui_element) override;
61 const gfx::Rect& old_bounds, 54 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 55
85 void AddObserver(AshDevToolsDOMAgentObserver* observer); 56 void AddObserver(AshDevToolsDOMAgentObserver* observer);
86 void RemoveObserver(AshDevToolsDOMAgentObserver* observer); 57 void RemoveObserver(AshDevToolsDOMAgentObserver* observer);
58 UIElement* GetElementFromNodeId(int node_id);
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 void RemoveDomNode(UIElement* ui_element);
97 void AddWindowTree(aura::Window* window);
98 // |remove_observer| ensures that we don't add a duplicate observer in any
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(); 77 void Reset();
121
122 using WindowAndBoundsPair = std::pair<aura::Window*, gfx::Rect>;
123 WindowAndBoundsPair GetNodeWindowAndBounds(int node_id);
124 void InitializeHighlightingWidget(); 78 void InitializeHighlightingWidget();
125 void UpdateHighlight(const WindowAndBoundsPair& window_and_bounds, 79 void UpdateHighlight(
126 SkColor background, 80 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds,
127 SkColor border); 81 SkColor background,
82 SkColor border);
128 ui::devtools::protocol::Response HighlightNode( 83 ui::devtools::protocol::Response HighlightNode(
129 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> 84 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig>
130 highlight_config, 85 highlight_config,
131 int node_id); 86 int node_id);
132 bool IsHighlightingWindow(aura::Window* window);
133 87
88 bool is_building_tree_;
89 UIElement* window_element_root_;
90 std::unordered_map<int, UIElement*> node_id_to_ui_element_;
134 std::unique_ptr<views::Widget> widget_for_highlighting_; 91 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_; 92 base::ObserverList<AshDevToolsDOMAgentObserver> observers_;
152 93
153 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent); 94 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent);
154 }; 95 };
155 96
156 } // namespace devtools 97 } // namespace devtools
157 } // namespace ash 98 } // namespace ash
158 99
159 #endif // ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 100 #endif // ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
OLDNEW
« 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