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 | |
Illia Martyniuk | f688acd6 | 2018-04-02 19:26:07 | [diff] [blame] | 5 | #ifndef COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_ |
| 6 | #define COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_ |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 7 | |
Illia Martyniuk | f688acd6 | 2018-04-02 19:26:07 | [diff] [blame] | 8 | #include <memory> |
Xiaohui Chen | da1977a | 2018-10-16 20:13:02 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 13 | #include "base/macros.h" |
Illia Martyniuk | f688acd6 | 2018-04-02 19:26:07 | [diff] [blame] | 14 | #include "components/ui_devtools/devtools_export.h" |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 15 | #include "ui/gfx/geometry/rect.h" |
Leonard Grey | 601aae3f | 2018-01-19 17:45:54 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 17 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 18 | namespace ui_devtools { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 19 | |
| 20 | class UIElementDelegate; |
| 21 | |
Leonard Grey | 827f34d8 | 2018-02-13 23:25:20 | [diff] [blame] | 22 | namespace protocol { |
| 23 | template <typename T> |
| 24 | class Array; |
| 25 | } |
| 26 | |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 27 | // UIElement type. |
yiyix | 38f1e58 | 2018-09-06 21:23:43 | [diff] [blame] | 28 | enum UIElementType { WINDOW, WIDGET, VIEW, ROOT, FRAMESINK, SURFACE }; |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 29 | |
Illia Martyniuk | f688acd6 | 2018-04-02 19:26:07 | [diff] [blame] | 30 | class UI_DEVTOOLS_EXPORT UIElement { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 31 | public: |
| 32 | virtual ~UIElement(); |
Xiaohui Chen | da1977a | 2018-10-16 20:13:02 | [diff] [blame] | 33 | int node_id() const { return node_id_; } |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 34 | std::string GetTypeName() const; |
Xiaohui Chen | da1977a | 2018-10-16 20:13:02 | [diff] [blame] | 35 | UIElement* parent() const { return parent_; } |
| 36 | void set_parent(UIElement* parent) { parent_ = parent; } |
| 37 | UIElementDelegate* delegate() const { return delegate_; } |
| 38 | UIElementType type() const { return type_; } |
| 39 | const std::vector<UIElement*>& children() const { return children_; } |
| 40 | bool is_updating() const { return is_updating_; } |
| 41 | void set_is_updating(bool is_updating) { is_updating_ = is_updating; } |
Sean Gilhuly | 1e895c9 | 2018-12-03 19:52:41 | [diff] [blame] | 42 | void set_owns_children(bool owns_children) { owns_children_ = owns_children; } |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 43 | |
| 44 | // |child| is inserted in front of |before|. If |before| is null, it |
| 45 | // is inserted at the end. Parent takes ownership of the added child. |
| 46 | void AddChild(UIElement* child, UIElement* before = nullptr); |
| 47 | |
Sean Gilhuly | 8844de6 | 2018-11-21 15:45:06 | [diff] [blame] | 48 | // Removes all elements from |children_|. Caller is responsible for destroying |
| 49 | // children. |
| 50 | void ClearChildren(); |
| 51 | |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 52 | // Remove |child| out of vector |children_| but |child| is not destroyed. |
| 53 | // The caller is responsible for destroying |child|. |
| 54 | void RemoveChild(UIElement* child); |
| 55 | |
| 56 | // Move |child| to position new_index in |children_|. |
| 57 | void ReorderChild(UIElement* child, int new_index); |
| 58 | |
Thanh Pham | dabbb4dc | 2017-08-08 19:41:22 | [diff] [blame] | 59 | template <class T> |
| 60 | int FindUIElementIdForBackendElement(T* element) const; |
| 61 | |
Leonard Grey | 827f34d8 | 2018-02-13 23:25:20 | [diff] [blame] | 62 | // Return a vector of pairs of properties' names and values. |
| 63 | virtual std::vector<std::pair<std::string, std::string>> GetCustomProperties() |
Thanh Pham | 5e4f231c | 2017-08-14 20:45:46 | [diff] [blame] | 64 | const = 0; |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 65 | virtual void GetBounds(gfx::Rect* bounds) const = 0; |
| 66 | virtual void SetBounds(const gfx::Rect& bounds) = 0; |
| 67 | virtual void GetVisible(bool* visible) const = 0; |
| 68 | virtual void SetVisible(bool visible) = 0; |
| 69 | |
Wei Li | b847f9c | 2018-12-11 22:10:19 | [diff] [blame^] | 70 | // If element exists, return its associated native window and its screen |
| 71 | // bounds. Otherwise, return null and empty bounds. |
| 72 | virtual std::pair<gfx::NativeWindow, gfx::Rect> GetNodeWindowAndScreenBounds() |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 73 | const = 0; |
Leonard Grey | 827f34d8 | 2018-02-13 23:25:20 | [diff] [blame] | 74 | // Get a list of interleaved keys and values of attributes to be displayed |
| 75 | // on the element in the dev tools hierarchy view. |
| 76 | virtual std::unique_ptr<protocol::Array<std::string>> GetAttributes() |
| 77 | const = 0; |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 78 | |
| 79 | template <typename BackingT, typename T> |
Thanh Pham | dabbb4dc | 2017-08-08 19:41:22 | [diff] [blame] | 80 | static BackingT* GetBackingElement(const UIElement* element) { |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 81 | return T::From(element); |
Xiaohui Chen | da1977a | 2018-10-16 20:13:02 | [diff] [blame] | 82 | } |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | UIElement(const UIElementType type, |
| 86 | UIElementDelegate* delegate, |
| 87 | UIElement* parent); |
| 88 | |
| 89 | private: |
| 90 | const int node_id_; |
| 91 | const UIElementType type_; |
| 92 | std::vector<UIElement*> children_; |
| 93 | UIElement* parent_; |
| 94 | UIElementDelegate* delegate_; |
Xiaohui Chen | da1977a | 2018-10-16 20:13:02 | [diff] [blame] | 95 | bool is_updating_ = false; |
Sean Gilhuly | 1e895c9 | 2018-12-03 19:52:41 | [diff] [blame] | 96 | bool owns_children_ = true; |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(UIElement); |
| 99 | }; |
| 100 | |
thanhph | 3f396851 | 2017-06-21 00:37:23 | [diff] [blame] | 101 | } // namespace ui_devtools |
thanhph | 27d1ff5 | 2017-05-20 04:09:13 | [diff] [blame] | 102 | |
Illia Martyniuk | f688acd6 | 2018-04-02 19:26:07 | [diff] [blame] | 103 | #endif // COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_ |