Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: ash/devtools/ui_element.h

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
5 #ifndef ASH_DEVTOOLS_UI_ELEMENT_H_
6 #define ASH_DEVTOOLS_UI_ELEMENT_H_
7
8 #include <vector>
9
10 #include "ash/ash_export.h"
11 #include "base/macros.h"
12 #include "ui/aura/window.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/views/view.h"
15
16 namespace ash {
17 namespace devtools {
18
19 class UIElementDelegate;
20
21 // UIElement type.
22 enum UIElementType { WINDOW, WIDGET, VIEW };
23
24 class ASH_EXPORT UIElement {
25 public:
26 int node_id() const { return node_id_; };
27 std::string GetTypeName() const;
28 UIElement* parent() const { return parent_; };
29 UIElementDelegate* delegate() const { return delegate_; };
30 UIElementType type() const { return type_; };
31 const std::vector<UIElement*>& children() const { return children_; };
32
33 // |child| is inserted in front of |before|. If |before| is null, it
34 // is inserted at the end.
35 void AddChild(UIElement* child, UIElement* before = nullptr);
36
37 // Remove |child| out of vector |children_|.
38 bool RemoveChild(UIElement* child);
39
40 // Move |child| to position new_index in |children_|.
41 void ReorderChild(UIElement* child, int new_index);
42
43 virtual void Destroy() = 0;
44 virtual void GetBounds(gfx::Rect* bounds) const = 0;
45 virtual void SetBounds(const gfx::Rect& bounds) = 0;
46 virtual void GetVisible(bool* visible) const = 0;
47 virtual void SetVisible(bool visible) = 0;
48
49 // If element exists, return its associated native window and its bounds.
50 // Otherwise, return null and empty bounds.
51 virtual std::pair<aura::Window*, gfx::Rect> GetNodeWindowAndBounds()
52 const = 0;
53
54 template <typename BackingT, typename T>
55 static BackingT* GetBackingElement(UIElement* element) {
56 return T::From(element);
57 };
58
59 protected:
60 UIElement(const UIElementType type,
61 UIElementDelegate* delegate,
62 UIElement* parent);
63 virtual ~UIElement();
64
65 private:
66 const int node_id_;
67 std::vector<UIElement*> children_;
68 const UIElementType type_;
69 UIElement* parent_;
70 UIElementDelegate* delegate_;
71
72 DISALLOW_COPY_AND_ASSIGN(UIElement);
73 };
74
75 } // namespace devtools
76 } // namespace ash
77
78 #endif // ASH_DEVTOOLS_UI_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698