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

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

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

Powered by Google App Engine
This is Rietveld 408576698