blob: 56dc1f79e3121f7880916c5102ba0c8cf4dece9d [file] [log] [blame]
thanhph27d1ff52017-05-20 04:09:131// 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
thanhph3f3968512017-06-21 00:37:235#ifndef COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_
6#define COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_
thanhph27d1ff52017-05-20 04:09:137
8#include <vector>
9
thanhph27d1ff52017-05-20 04:09:1310#include "base/macros.h"
thanhph27d1ff52017-05-20 04:09:1311#include "ui/gfx/geometry/rect.h"
Leonard Grey601aae3f2018-01-19 17:45:5412#include "ui/gfx/native_widget_types.h"
thanhph27d1ff52017-05-20 04:09:1313#include "ui/views/view.h"
14
thanhph3f3968512017-06-21 00:37:2315namespace ui_devtools {
thanhph27d1ff52017-05-20 04:09:1316
17class UIElementDelegate;
18
Leonard Grey827f34d82018-02-13 23:25:2019namespace protocol {
20template <typename T>
21class Array;
22}
23
thanhph27d1ff52017-05-20 04:09:1324// UIElement type.
25enum UIElementType { WINDOW, WIDGET, VIEW };
26
thanhph3f3968512017-06-21 00:37:2327class UIElement {
thanhph27d1ff52017-05-20 04:09:1328 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 Phamdabbb4dc2017-08-08 19:41:2248 template <class T>
49 int FindUIElementIdForBackendElement(T* element) const;
50
Leonard Grey827f34d82018-02-13 23:25:2051 // Return a vector of pairs of properties' names and values.
52 virtual std::vector<std::pair<std::string, std::string>> GetCustomProperties()
Thanh Pham5e4f231c2017-08-14 20:45:4653 const = 0;
thanhph27d1ff52017-05-20 04:09:1354 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 Grey601aae3f2018-01-19 17:45:5461 virtual std::pair<gfx::NativeWindow, gfx::Rect> GetNodeWindowAndBounds()
thanhph27d1ff52017-05-20 04:09:1362 const = 0;
Leonard Grey827f34d82018-02-13 23:25:2063 // 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;
thanhph27d1ff52017-05-20 04:09:1367
68 template <typename BackingT, typename T>
Thanh Phamdabbb4dc2017-08-08 19:41:2269 static BackingT* GetBackingElement(const UIElement* element) {
thanhph27d1ff52017-05-20 04:09:1370 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
thanhph3f3968512017-06-21 00:37:2388} // namespace ui_devtools
thanhph27d1ff52017-05-20 04:09:1389
thanhph3f3968512017-06-21 00:37:2390#endif // COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_