blob: 1df61821190e01b55608aca5328366c9ab37adb0 [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"
11#include "ui/aura/window.h"
12#include "ui/gfx/geometry/rect.h"
13#include "ui/views/view.h"
14
thanhph3f3968512017-06-21 00:37:2315namespace ui_devtools {
thanhph27d1ff52017-05-20 04:09:1316
17class UIElementDelegate;
18
19// UIElement type.
20enum UIElementType { WINDOW, WIDGET, VIEW };
21
thanhph3f3968512017-06-21 00:37:2322class UIElement {
thanhph27d1ff52017-05-20 04:09:1323 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 Phamdabbb4dc2017-08-08 19:41:2243 template <class T>
44 int FindUIElementIdForBackendElement(T* element) const;
45
Thanh Pham5e4f231c2017-08-14 20:45:4646 // Return a vector of pairs of attributes' names and values.
47 virtual std::vector<std::pair<std::string, std::string>> GetCustomAttributes()
48 const = 0;
thanhph27d1ff52017-05-20 04:09:1349 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 Phamdabbb4dc2017-08-08 19:41:2260 static BackingT* GetBackingElement(const UIElement* element) {
thanhph27d1ff52017-05-20 04:09:1361 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
thanhph3f3968512017-06-21 00:37:2379} // namespace ui_devtools
thanhph27d1ff52017-05-20 04:09:1380
thanhph3f3968512017-06-21 00:37:2381#endif // COMPONENTS_UI_DEVTOOLS_VIEWS_UI_ELEMENT_H_