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