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

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

Issue 2537163002: Hook up views/widgets to AshDevToolsDOMAgent (Closed)
Patch Set: sadruls comments Created 4 years 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 | « no previous file | ash/common/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_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 5 #ifndef ASH_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
6 #define ASH_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 6 #define ASH_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
7 7
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window_observer.h" 9 #include "ash/common/wm_window_observer.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.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/views/view.h" 13 #include "ui/views/view.h"
14 #include "ui/views/view_observer.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 #include "ui/views/widget/widget_removals_observer.h"
15 17
16 namespace ash { 18 namespace ash {
17 namespace devtools { 19 namespace devtools {
18 20
19 class ASH_EXPORT AshDevToolsDOMAgent 21 class ASH_EXPORT AshDevToolsDOMAgent
20 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent< 22 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent<
21 ui::devtools::protocol::DOM::Metainfo>), 23 ui::devtools::protocol::DOM::Metainfo>),
22 public WmWindowObserver { 24 public WmWindowObserver,
25 public views::WidgetRemovalsObserver,
26 public views::ViewObserver {
23 public: 27 public:
24 explicit AshDevToolsDOMAgent(ash::WmShell* shell); 28 explicit AshDevToolsDOMAgent(ash::WmShell* shell);
25 ~AshDevToolsDOMAgent() override; 29 ~AshDevToolsDOMAgent() override;
26 30
27 // DOM::Backend 31 // DOM::Backend
28 ui::devtools::protocol::Response disable() override; 32 ui::devtools::protocol::Response disable() override;
29 ui::devtools::protocol::Response getDocument( 33 ui::devtools::protocol::Response getDocument(
30 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override; 34 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override;
31 35
32 // WindowObserver 36 // WindowObserver
33 void OnWindowTreeChanging(WmWindow* window, 37 void OnWindowTreeChanging(WmWindow* window,
34 const TreeChangeParams& params) override; 38 const TreeChangeParams& params) override;
35 void OnWindowTreeChanged(WmWindow* window, 39 void OnWindowTreeChanged(WmWindow* window,
36 const TreeChangeParams& params) override; 40 const TreeChangeParams& params) override;
37 void OnWindowStackingChanged(WmWindow* window) override; 41 void OnWindowStackingChanged(WmWindow* window) override;
38 42
43 // views::WidgetRemovalsObserver
44 void OnWillRemoveView(views::Widget* widget, views::View* view) override;
45
46 // views::ViewObserver
47 void OnChildViewRemoved(views::View* view, views::View* parent) override;
48 void OnChildViewAdded(views::View* view) override;
49 void OnChildViewReordered(views::View*) override;
50
39 WmWindow* GetWindowFromNodeId(int nodeId); 51 WmWindow* GetWindowFromNodeId(int nodeId);
40 views::Widget* GetWidgetFromNodeId(int nodeId); 52 views::Widget* GetWidgetFromNodeId(int nodeId);
41 views::View* GetViewFromNodeId(int nodeId); 53 views::View* GetViewFromNodeId(int nodeId);
42 54
43 int GetNodeIdFromWindow(WmWindow* window); 55 int GetNodeIdFromWindow(WmWindow* window);
44 int GetNodeIdFromWidget(views::Widget* widget); 56 int GetNodeIdFromWidget(views::Widget* widget);
45 int GetNodeIdFromView(views::View* view); 57 int GetNodeIdFromView(views::View* view);
46 58
47 private: 59 private:
48 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree(); 60 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree();
49 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow( 61 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow(
50 WmWindow* window); 62 WmWindow* window);
51 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget( 63 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget(
52 views::Widget* widget); 64 views::Widget* widget);
53 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView( 65 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView(
54 views::View* view); 66 views::View* view);
55 67
56 void AddWindowTree(WmWindow* window); 68 void AddWindowTree(WmWindow* window);
57 // |remove_observer| ensures that we don't add a duplicate observer in any 69 // |remove_observer| ensures that we don't add a duplicate observer in any
58 // observer callback. For example, |remove_observer| is false when rebuilding 70 // observer callback. For example, |remove_observer| is false when rebuilding
59 // the tree in OnWindowStackingChanged so that the observer is not removed and 71 // the tree in OnWindowStackingChanged so that the observer is not removed and
60 // re-added, thus causing endless calls on the observer. 72 // re-added, thus causing endless calls on the observer.
61 void RemoveWindowTree(WmWindow* window, bool remove_observer); 73 void RemoveWindowTree(WmWindow* window, bool remove_observer);
62 void RemoveWindowNode(WmWindow* window, bool remove_observer); 74 void RemoveWindowNode(WmWindow* window, bool remove_observer);
63 75
76 // Don't need AddWidgetTree because |widget| will always be inside a window,
77 // so when windows are created, their widget nodes are created as well.
64 void RemoveWidgetTree(views::Widget* widget, bool remove_observer); 78 void RemoveWidgetTree(views::Widget* widget, bool remove_observer);
65 void RemoveWidgetNode(views::Widget* widget, bool remove_observer); 79 void RemoveWidgetNode(views::Widget* widget, bool remove_observer);
66 80
81 void AddViewTree(views::View* view);
67 void RemoveViewTree(views::View* view, 82 void RemoveViewTree(views::View* view,
68 views::View* parent, 83 views::View* parent,
69 bool remove_observer); 84 bool remove_observer);
70 void RemoveViewNode(views::View* view, 85 void RemoveViewNode(views::View* view,
71 views::View* parent, 86 views::View* parent,
72 bool remove_observer); 87 bool remove_observer);
73 88
74 void RemoveObserverFromAllWindows(); 89 void RemoveObservers();
75 void Reset(); 90 void Reset();
76 91
77 ash::WmShell* shell_; 92 ash::WmShell* shell_;
78 93
79 using WindowToNodeIdMap = std::unordered_map<WmWindow*, int>; 94 using WindowToNodeIdMap = std::unordered_map<WmWindow*, int>;
80 WindowToNodeIdMap window_to_node_id_map_; 95 WindowToNodeIdMap window_to_node_id_map_;
81 using NodeIdToWindowMap = std::unordered_map<int, WmWindow*>; 96 using NodeIdToWindowMap = std::unordered_map<int, WmWindow*>;
82 NodeIdToWindowMap node_id_to_window_map_; 97 NodeIdToWindowMap node_id_to_window_map_;
83 98
84 using WidgetToNodeIdMap = std::unordered_map<views::Widget*, int>; 99 using WidgetToNodeIdMap = std::unordered_map<views::Widget*, int>;
85 WidgetToNodeIdMap widget_to_node_id_map_; 100 WidgetToNodeIdMap widget_to_node_id_map_;
86 using NodeIdToWidgetMap = std::unordered_map<int, views::Widget*>; 101 using NodeIdToWidgetMap = std::unordered_map<int, views::Widget*>;
87 NodeIdToWidgetMap node_id_to_widget_map_; 102 NodeIdToWidgetMap node_id_to_widget_map_;
88 103
89 using ViewToNodeIdMap = std::unordered_map<views::View*, int>; 104 using ViewToNodeIdMap = std::unordered_map<views::View*, int>;
90 ViewToNodeIdMap view_to_node_id_map_; 105 ViewToNodeIdMap view_to_node_id_map_;
91 using NodeIdToViewMap = std::unordered_map<int, views::View*>; 106 using NodeIdToViewMap = std::unordered_map<int, views::View*>;
92 NodeIdToViewMap node_id_to_view_map_; 107 NodeIdToViewMap node_id_to_view_map_;
93 108
94 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent); 109 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent);
95 }; 110 };
96 111
97 } // namespace devtools 112 } // namespace devtools
98 } // namespace ash 113 } // namespace ash
99 114
100 #endif // ASH_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ 115 #endif // ASH_COMMON_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_
OLDNEW
« no previous file with comments | « no previous file | ash/common/devtools/ash_devtools_dom_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698