OLD | NEW |
| (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_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ | |
6 #define ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ | |
7 | |
8 #include "ash/ash_export.h" | |
9 #include "ash/devtools/ui_element_delegate.h" | |
10 #include "base/macros.h" | |
11 #include "components/ui_devtools/DOM.h" | |
12 #include "components/ui_devtools/devtools_base_agent.h" | |
13 #include "ui/aura/env_observer.h" | |
14 #include "ui/views/view.h" | |
15 #include "ui/views/widget/widget.h" | |
16 | |
17 namespace aura { | |
18 class Window; | |
19 } | |
20 | |
21 namespace ash { | |
22 namespace devtools { | |
23 | |
24 class UIElement; | |
25 | |
26 class ASH_EXPORT AshDevToolsDOMAgentObserver { | |
27 public: | |
28 virtual void OnNodeBoundsChanged(int node_id) = 0; | |
29 }; | |
30 | |
31 class ASH_EXPORT AshDevToolsDOMAgent | |
32 : public NON_EXPORTED_BASE(ui::devtools::UiDevToolsBaseAgent< | |
33 ui::devtools::protocol::DOM::Metainfo>), | |
34 public UIElementDelegate, | |
35 public aura::EnvObserver { | |
36 public: | |
37 AshDevToolsDOMAgent(); | |
38 ~AshDevToolsDOMAgent() override; | |
39 | |
40 // DOM::Backend: | |
41 ui::devtools::protocol::Response disable() override; | |
42 ui::devtools::protocol::Response getDocument( | |
43 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) override; | |
44 ui::devtools::protocol::Response highlightNode( | |
45 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | |
46 highlight_config, | |
47 ui::devtools::protocol::Maybe<int> node_id) override; | |
48 ui::devtools::protocol::Response hideHighlight() override; | |
49 | |
50 // UIElementDelegate: | |
51 void OnUIElementAdded(UIElement* parent, UIElement* child) override; | |
52 void OnUIElementReordered(UIElement* parent, UIElement* child) override; | |
53 void OnUIElementRemoved(UIElement* ui_element) override; | |
54 void OnUIElementBoundsChanged(UIElement* ui_element) override; | |
55 bool IsHighlightingWindow(aura::Window* window) override; | |
56 | |
57 void AddObserver(AshDevToolsDOMAgentObserver* observer); | |
58 void RemoveObserver(AshDevToolsDOMAgentObserver* observer); | |
59 UIElement* GetElementFromNodeId(int node_id); | |
60 UIElement* window_element_root() const { return window_element_root_; }; | |
61 const std::vector<aura::Window*>& root_windows() const { | |
62 return root_windows_; | |
63 }; | |
64 | |
65 private: | |
66 // EnvObserver: | |
67 void OnHostInitialized(aura::WindowTreeHost* host) override; | |
68 void OnWindowInitialized(aura::Window* window) override{}; | |
69 | |
70 // AshDevToolsDOMAgentObserver: | |
71 void OnNodeBoundsChanged(int node_id); | |
72 | |
73 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildInitialTree(); | |
74 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForUIElement( | |
75 UIElement* ui_element); | |
76 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForWindow( | |
77 UIElement* window_element_root, | |
78 aura::Window* window); | |
79 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForRootWidget( | |
80 UIElement* widget_element, | |
81 views::Widget* widget); | |
82 std::unique_ptr<ui::devtools::protocol::DOM::Node> BuildTreeForView( | |
83 UIElement* view_element, | |
84 views::View* view); | |
85 void RemoveDomNode(UIElement* ui_element); | |
86 void Reset(); | |
87 void InitializeHighlightingWidget(); | |
88 void UpdateHighlight( | |
89 const std::pair<aura::Window*, gfx::Rect>& window_and_bounds, | |
90 SkColor background, | |
91 SkColor border); | |
92 ui::devtools::protocol::Response HighlightNode( | |
93 std::unique_ptr<ui::devtools::protocol::DOM::HighlightConfig> | |
94 highlight_config, | |
95 int node_id); | |
96 | |
97 bool is_building_tree_; | |
98 UIElement* window_element_root_; | |
99 std::unordered_map<int, UIElement*> node_id_to_ui_element_; | |
100 std::unique_ptr<views::Widget> widget_for_highlighting_; | |
101 std::vector<aura::Window*> root_windows_; | |
102 base::ObserverList<AshDevToolsDOMAgentObserver> observers_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(AshDevToolsDOMAgent); | |
105 }; | |
106 | |
107 } // namespace devtools | |
108 } // namespace ash | |
109 | |
110 #endif // ASH_DEVTOOLS_ASH_DEVTOOLS_DOM_AGENT_H_ | |
OLD | NEW |