thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 1 | // Copyright 2017 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 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 5 | #ifndef COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_ |
| 6 | #define COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_ |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 7 | |
| 8 | #include <vector> |
| 9 | |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "ui/aura/window.h" |
| 12 | #include "ui/gfx/geometry/rect.h" |
| 13 | #include "ui/views/view.h" |
| 14 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 15 | namespace ui_devtools { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 16 | |
| 17 | class UIElementDelegate; |
| 18 | |
| 19 | // UIElement type. |
| 20 | enum UIElementType { WINDOW, WIDGET, VIEW }; |
| 21 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 22 | class UIElement { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 23 | public: |
| 24 | virtual ~UIElement(); |
| 25 | int node_id() const { return node_id_; }; |
| 26 | std::string GetTypeName() const; |
| 27 | UIElement* parent() const { return parent_; }; |
| 28 | UIElementDelegate* delegate() const { return delegate_; }; |
| 29 | UIElementType type() const { return type_; }; |
| 30 | const std::vector<UIElement*>& children() const { return children_; }; |
| 31 | |
| 32 | // |child| is inserted in front of |before|. If |before| is null, it |
| 33 | // is inserted at the end. Parent takes ownership of the added child. |
| 34 | void AddChild(UIElement* child, UIElement* before = nullptr); |
| 35 | |
| 36 | // Remove |child| out of vector |children_| but |child| is not destroyed. |
| 37 | // The caller is responsible for destroying |child|. |
| 38 | void RemoveChild(UIElement* child); |
| 39 | |
| 40 | // Move |child| to position new_index in |children_|. |
| 41 | void ReorderChild(UIElement* child, int new_index); |
| 42 | |
Thanh Pham | dabbb4dc | 2017-08-08 19:41:22 | [diff] [blame] | 43 | template <class T> |
| 44 | int FindUIElementIdForBackendElement(T* element) const; |
| 45 | |
Thanh Pham | 5e4f231c | 2017-08-14 20:45:46 | [diff] [blame^] | 46 | // Return a vector of pairs of attributes' names and values. |
| 47 | virtual std::vector<std::pair<std::string, std::string>> GetCustomAttributes() |
| 48 | const = 0; |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 49 | virtual void GetBounds(gfx::Rect* bounds) const = 0; |
| 50 | virtual void SetBounds(const gfx::Rect& bounds) = 0; |
| 51 | virtual void GetVisible(bool* visible) const = 0; |
| 52 | virtual void SetVisible(bool visible) = 0; |
| 53 | |
| 54 | // If element exists, return its associated native window and its bounds. |
| 55 | // Otherwise, return null and empty bounds. |
| 56 | virtual std::pair<aura::Window*, gfx::Rect> GetNodeWindowAndBounds() |
| 57 | const = 0; |
| 58 | |
| 59 | template <typename BackingT, typename T> |
Thanh Pham | dabbb4dc | 2017-08-08 19:41:22 | [diff] [blame] | 60 | static BackingT* GetBackingElement(const UIElement* element) { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 61 | return T::From(element); |
| 62 | }; |
| 63 | |
| 64 | protected: |
| 65 | UIElement(const UIElementType type, |
| 66 | UIElementDelegate* delegate, |
| 67 | UIElement* parent); |
| 68 | |
| 69 | private: |
| 70 | const int node_id_; |
| 71 | const UIElementType type_; |
| 72 | std::vector<UIElement*> children_; |
| 73 | UIElement* parent_; |
| 74 | UIElementDelegate* delegate_; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(UIElement); |
| 77 | }; |
| 78 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 79 | } // namespace ui_devtools |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 80 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 81 | #endif // COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_ |