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