OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_NODE_H_ | |
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_NODE_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/observer_list.h" | |
12 #include "mojo/public/cpp/bindings/array.h" | |
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
14 #include "mojo/services/public/cpp/view_manager/types.h" | |
15 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mo
jom.h" | |
16 #include "third_party/skia/include/core/SkColor.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 | |
19 class SkBitmap; | |
20 | |
21 namespace mojo { | |
22 | |
23 class ServiceProviderImpl; | |
24 class View; | |
25 class ViewManager; | |
26 class NodeObserver; | |
27 | |
28 // Nodes are owned by the ViewManager. | |
29 // TODO(beng): Right now, you'll have to implement a NodeObserver to track | |
30 // destruction and NULL any pointers you have. | |
31 // Investigate some kind of smart pointer or weak pointer for these. | |
32 class Node { | |
33 public: | |
34 typedef std::vector<Node*> Children; | |
35 | |
36 static Node* Create(ViewManager* view_manager); | |
37 | |
38 // Destroys this node and all its children. | |
39 void Destroy(); | |
40 | |
41 // Configuration. | |
42 Id id() const { return id_; } | |
43 | |
44 // Geometric disposition. | |
45 const gfx::Rect& bounds() { return bounds_; } | |
46 void SetBounds(const gfx::Rect& bounds); | |
47 | |
48 // Visibility. | |
49 void SetVisible(bool value); | |
50 // TODO(sky): add accessor. | |
51 | |
52 // Observation. | |
53 void AddObserver(NodeObserver* observer); | |
54 void RemoveObserver(NodeObserver* observer); | |
55 | |
56 // Tree. | |
57 Node* parent() { return parent_; } | |
58 const Node* parent() const { return parent_; } | |
59 const Children& children() const { return children_; } | |
60 | |
61 void AddChild(Node* child); | |
62 void RemoveChild(Node* child); | |
63 | |
64 void Reorder(Node* relative, OrderDirection direction); | |
65 void MoveToFront(); | |
66 void MoveToBack(); | |
67 | |
68 bool Contains(Node* child) const; | |
69 | |
70 Node* GetChildById(Id id); | |
71 | |
72 // TODO(beng): temporary only. | |
73 void SetContents(const SkBitmap& contents); | |
74 void SetColor(SkColor color); | |
75 | |
76 // Focus. | |
77 void SetFocus(); | |
78 | |
79 // Embedding. | |
80 void Embed(const String& url); | |
81 scoped_ptr<ServiceProvider> Embed( | |
82 const String& url, | |
83 scoped_ptr<ServiceProviderImpl> exported_services); | |
84 | |
85 protected: | |
86 // This class is subclassed only by test classes that provide a public ctor. | |
87 Node(); | |
88 ~Node(); | |
89 | |
90 private: | |
91 friend class NodePrivate; | |
92 friend class ViewManagerClientImpl; | |
93 | |
94 explicit Node(ViewManager* manager); | |
95 | |
96 void LocalDestroy(); | |
97 void LocalAddChild(Node* child); | |
98 void LocalRemoveChild(Node* child); | |
99 // Returns true if the order actually changed. | |
100 bool LocalReorder(Node* relative, OrderDirection direction); | |
101 void LocalSetBounds(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds); | |
102 | |
103 ViewManager* manager_; | |
104 Id id_; | |
105 Node* parent_; | |
106 Children children_; | |
107 | |
108 ObserverList<NodeObserver> observers_; | |
109 | |
110 gfx::Rect bounds_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(Node); | |
113 }; | |
114 | |
115 } // namespace mojo | |
116 | |
117 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_NODE_H_ | |
OLD | NEW |