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