blob: 10abb56eecdcd4d36f9bb1bfb1a05411948d2aa7 [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
Illia Martyniukf688acd62018-04-02 19:26:075#ifndef COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_
6#define COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_
thanhph27d1ff52017-05-20 04:09:137
Illia Martyniukf688acd62018-04-02 19:26:078#include <memory>
Xiaohui Chenda1977a2018-10-16 20:13:029#include <string>
10#include <utility>
thanhph27d1ff52017-05-20 04:09:1311#include <vector>
12
thanhph27d1ff52017-05-20 04:09:1313#include "base/macros.h"
Illia Martyniukf688acd62018-04-02 19:26:0714#include "components/ui_devtools/devtools_export.h"
thanhph27d1ff52017-05-20 04:09:1315#include "ui/gfx/geometry/rect.h"
Leonard Grey601aae3f2018-01-19 17:45:5416#include "ui/gfx/native_widget_types.h"
thanhph27d1ff52017-05-20 04:09:1317
thanhph3f3968512017-06-21 00:37:2318namespace ui_devtools {
thanhph27d1ff52017-05-20 04:09:1319
20class UIElementDelegate;
21
Leonard Grey827f34d82018-02-13 23:25:2022namespace protocol {
23template <typename T>
24class Array;
25}
26
thanhph27d1ff52017-05-20 04:09:1327// UIElement type.
yiyix38f1e582018-09-06 21:23:4328enum UIElementType { WINDOW, WIDGET, VIEW, ROOT, FRAMESINK, SURFACE };
thanhph27d1ff52017-05-20 04:09:1329
Illia Martyniukf688acd62018-04-02 19:26:0730class UI_DEVTOOLS_EXPORT UIElement {
thanhph27d1ff52017-05-20 04:09:1331 public:
32 virtual ~UIElement();
Xiaohui Chenda1977a2018-10-16 20:13:0233 int node_id() const { return node_id_; }
thanhph27d1ff52017-05-20 04:09:1334 std::string GetTypeName() const;
Xiaohui Chenda1977a2018-10-16 20:13:0235 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 Gilhuly1e895c92018-12-03 19:52:4142 void set_owns_children(bool owns_children) { owns_children_ = owns_children; }
thanhph27d1ff52017-05-20 04:09:1343
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 Gilhuly8844de62018-11-21 15:45:0648 // Removes all elements from |children_|. Caller is responsible for destroying
49 // children.
50 void ClearChildren();
51
thanhph27d1ff52017-05-20 04:09:1352 // 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 Phamdabbb4dc2017-08-08 19:41:2259 template <class T>
60 int FindUIElementIdForBackendElement(T* element) const;
61
Leonard Grey827f34d82018-02-13 23:25:2062 // Return a vector of pairs of properties' names and values.
63 virtual std::vector<std::pair<std::string, std::string>> GetCustomProperties()
Thanh Pham5e4f231c2017-08-14 20:45:4664 const = 0;
thanhph27d1ff52017-05-20 04:09:1365 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 Lib847f9c2018-12-11 22:10:1970 // 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()
thanhph27d1ff52017-05-20 04:09:1373 const = 0;
Leonard Grey827f34d82018-02-13 23:25:2074 // 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;
thanhph27d1ff52017-05-20 04:09:1378
79 template <typename BackingT, typename T>
Thanh Phamdabbb4dc2017-08-08 19:41:2280 static BackingT* GetBackingElement(const UIElement* element) {
thanhph27d1ff52017-05-20 04:09:1381 return T::From(element);
Xiaohui Chenda1977a2018-10-16 20:13:0282 }
thanhph27d1ff52017-05-20 04:09:1383
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 Chenda1977a2018-10-16 20:13:0295 bool is_updating_ = false;
Sean Gilhuly1e895c92018-12-03 19:52:4196 bool owns_children_ = true;
thanhph27d1ff52017-05-20 04:09:1397
98 DISALLOW_COPY_AND_ASSIGN(UIElement);
99};
100
thanhph3f3968512017-06-21 00:37:23101} // namespace ui_devtools
thanhph27d1ff52017-05-20 04:09:13102
Illia Martyniukf688acd62018-04-02 19:26:07103#endif // COMPONENTS_UI_DEVTOOLS_UI_ELEMENT_H_