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 SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ | |
6 #define SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/observer_list.h" | |
12 #include "cc/surfaces/surface_id.h" | |
13 #include "mojo/services/view_manager/interfaces/view_manager.mojom.h" | |
14 #include "services/view_manager/ids.h" | |
15 #include "ui/gfx/geometry/rect.h" | |
16 #include "ui/gfx/transform.h" | |
17 | |
18 namespace view_manager { | |
19 | |
20 class ServerViewDelegate; | |
21 class ServerViewObserver; | |
22 | |
23 // Server side representation of a view. Delegate is informed of interesting | |
24 // events. | |
25 // | |
26 // It is assumed that all functions that mutate the tree have validated the | |
27 // mutation is possible before hand. For example, Reorder() assumes the supplied | |
28 // view is a child and not already in position. | |
29 // | |
30 // ServerViews do not own their children. If you delete a view that has children | |
31 // the children are implicitly removed. Similarly if a view has a parent and the | |
32 // view is deleted the deleted view is implicitly removed from the parent. | |
33 class ServerView { | |
34 public: | |
35 ServerView(ServerViewDelegate* delegate, const ViewId& id); | |
36 virtual ~ServerView(); | |
37 | |
38 void AddObserver(ServerViewObserver* observer); | |
39 void RemoveObserver(ServerViewObserver* observer); | |
40 | |
41 const ViewId& id() const { return id_; } | |
42 | |
43 void Add(ServerView* child); | |
44 void Remove(ServerView* child); | |
45 void Reorder(ServerView* child, | |
46 ServerView* relative, | |
47 mojo::OrderDirection direction); | |
48 | |
49 const gfx::Rect& bounds() const { return bounds_; } | |
50 void SetBounds(const gfx::Rect& bounds); | |
51 | |
52 const ServerView* parent() const { return parent_; } | |
53 ServerView* parent() { return parent_; } | |
54 | |
55 const ServerView* GetRoot() const; | |
56 ServerView* GetRoot() { | |
57 return const_cast<ServerView*>( | |
58 const_cast<const ServerView*>(this)->GetRoot()); | |
59 } | |
60 | |
61 std::vector<const ServerView*> GetChildren() const; | |
62 std::vector<ServerView*> GetChildren(); | |
63 | |
64 // Returns true if this contains |view| or is |view|. | |
65 bool Contains(const ServerView* view) const; | |
66 | |
67 // Returns true if the window is visible. This does not consider visibility | |
68 // of any ancestors. | |
69 bool visible() const { return visible_; } | |
70 void SetVisible(bool value); | |
71 | |
72 float opacity() const { return opacity_; } | |
73 void SetOpacity(float value); | |
74 | |
75 const gfx::Transform& transform() const { return transform_; } | |
76 void SetTransform(const gfx::Transform& transform); | |
77 | |
78 const std::map<std::string, std::vector<uint8_t>>& properties() const { | |
79 return properties_; | |
80 } | |
81 void SetProperty(const std::string& name, const std::vector<uint8_t>* value); | |
82 | |
83 // Returns true if this view is attached to |root| and all ancestors are | |
84 // visible. | |
85 bool IsDrawn(const ServerView* root) const; | |
86 | |
87 void SetSurfaceId(cc::SurfaceId surface_id); | |
88 const cc::SurfaceId& surface_id() const { return surface_id_; } | |
89 | |
90 #if !defined(NDEBUG) | |
91 std::string GetDebugWindowHierarchy() const; | |
92 void BuildDebugInfo(const std::string& depth, std::string* result) const; | |
93 #endif | |
94 | |
95 private: | |
96 typedef std::vector<ServerView*> Views; | |
97 | |
98 // Implementation of removing a view. Doesn't send any notification. | |
99 void RemoveImpl(ServerView* view); | |
100 | |
101 ServerViewDelegate* delegate_; | |
102 const ViewId id_; | |
103 ServerView* parent_; | |
104 Views children_; | |
105 bool visible_; | |
106 gfx::Rect bounds_; | |
107 cc::SurfaceId surface_id_; | |
108 float opacity_; | |
109 gfx::Transform transform_; | |
110 | |
111 std::map<std::string, std::vector<uint8_t>> properties_; | |
112 | |
113 base::ObserverList<ServerViewObserver> observers_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(ServerView); | |
116 }; | |
117 | |
118 } // namespace view_manager | |
119 | |
120 #endif // SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ | |
OLD | NEW |