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 COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_ | |
6 #define COMPONENTS_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_factory.h" | |
13 #include "cc/surfaces/surface_factory_client.h" | |
14 #include "cc/surfaces/surface_id.h" | |
15 #include "cc/surfaces/surface_id_allocator.h" | |
16 #include "components/view_manager/ids.h" | |
17 #include "components/view_manager/public/interfaces/view_tree.mojom.h" | |
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | |
19 #include "ui/gfx/geometry/rect.h" | |
20 #include "ui/gfx/transform.h" | |
21 #include "ui/platform_window/text_input_state.h" | |
22 | |
23 namespace view_manager { | |
24 | |
25 class ServerViewDelegate; | |
26 class ServerViewObserver; | |
27 | |
28 // Server side representation of a view. Delegate is informed of interesting | |
29 // events. | |
30 // | |
31 // It is assumed that all functions that mutate the tree have validated the | |
32 // mutation is possible before hand. For example, Reorder() assumes the supplied | |
33 // view is a child and not already in position. | |
34 // | |
35 // ServerViews do not own their children. If you delete a view that has children | |
36 // the children are implicitly removed. Similarly if a view has a parent and the | |
37 // view is deleted the deleted view is implicitly removed from the parent. | |
38 class ServerView : public mojo::Surface, | |
39 public cc::SurfaceFactoryClient { | |
40 public: | |
41 ServerView(ServerViewDelegate* delegate, const ViewId& id); | |
42 ~ServerView() override; | |
43 | |
44 void AddObserver(ServerViewObserver* observer); | |
45 void RemoveObserver(ServerViewObserver* observer); | |
46 | |
47 // Sets the access policy that is used the next time Embed() is called. | |
48 void set_pending_access_policy(uint32_t policy) { | |
49 pending_access_policy_ = policy; | |
50 } | |
51 | |
52 // Returns |pending_access_policy_| and resets it to the default. | |
53 uint32_t get_and_clear_pending_access_policy() { | |
54 const uint32_t policy = pending_access_policy_; | |
55 pending_access_policy_ = mojo::ViewTree::ACCESS_POLICY_DEFAULT; | |
56 return policy; | |
57 } | |
58 | |
59 // Binds the provided |request| to |this| object. If an interface is already | |
60 // bound to this ServerView then the old connection is closed first. | |
61 void Bind(mojo::InterfaceRequest<Surface> request, | |
62 mojo::SurfaceClientPtr client); | |
63 | |
64 const ViewId& id() const { return id_; } | |
65 | |
66 void Add(ServerView* child); | |
67 void Remove(ServerView* child); | |
68 void Reorder(ServerView* child, | |
69 ServerView* relative, | |
70 mojo::OrderDirection direction); | |
71 | |
72 const gfx::Rect& bounds() const { return bounds_; } | |
73 void SetBounds(const gfx::Rect& bounds); | |
74 | |
75 const ServerView* parent() const { return parent_; } | |
76 ServerView* parent() { return parent_; } | |
77 | |
78 const ServerView* GetRoot() const; | |
79 ServerView* GetRoot() { | |
80 return const_cast<ServerView*>( | |
81 const_cast<const ServerView*>(this)->GetRoot()); | |
82 } | |
83 | |
84 std::vector<const ServerView*> GetChildren() const; | |
85 std::vector<ServerView*> GetChildren(); | |
86 | |
87 // Returns true if this contains |view| or is |view|. | |
88 bool Contains(const ServerView* view) const; | |
89 | |
90 // Returns true if the window is visible. This does not consider visibility | |
91 // of any ancestors. | |
92 bool visible() const { return visible_; } | |
93 void SetVisible(bool value); | |
94 | |
95 float opacity() const { return opacity_; } | |
96 void SetOpacity(float value); | |
97 | |
98 const gfx::Transform& transform() const { return transform_; } | |
99 void SetTransform(const gfx::Transform& transform); | |
100 | |
101 const std::map<std::string, std::vector<uint8_t>>& properties() const { | |
102 return properties_; | |
103 } | |
104 void SetProperty(const std::string& name, const std::vector<uint8_t>* value); | |
105 | |
106 void SetTextInputState(const ui::TextInputState& state); | |
107 const ui::TextInputState& text_input_state() const { | |
108 return text_input_state_; | |
109 } | |
110 | |
111 // Returns true if this view is attached to a root and all ancestors are | |
112 // visible. | |
113 bool IsDrawn() const; | |
114 | |
115 void SetSurfaceId(cc::SurfaceId surface_id); | |
116 const cc::SurfaceId& surface_id() const { return surface_id_; } | |
117 | |
118 const gfx::Size& last_submitted_frame_size() { | |
119 return last_submitted_frame_size_; | |
120 } | |
121 | |
122 // mojo::Surface: | |
123 void SubmitCompositorFrame( | |
124 mojo::CompositorFramePtr frame, | |
125 const SubmitCompositorFrameCallback& callback) override; | |
126 | |
127 #if !defined(NDEBUG) | |
128 std::string GetDebugWindowHierarchy() const; | |
129 void BuildDebugInfo(const std::string& depth, std::string* result) const; | |
130 #endif | |
131 | |
132 private: | |
133 typedef std::vector<ServerView*> Views; | |
134 | |
135 // SurfaceFactoryClient implementation. | |
136 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
137 | |
138 // Implementation of removing a view. Doesn't send any notification. | |
139 void RemoveImpl(ServerView* view); | |
140 | |
141 ServerViewDelegate* delegate_; | |
142 const ViewId id_; | |
143 ServerView* parent_; | |
144 Views children_; | |
145 bool visible_; | |
146 gfx::Rect bounds_; | |
147 cc::SurfaceId surface_id_; | |
148 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | |
149 scoped_ptr<cc::SurfaceFactory> surface_factory_; | |
150 float opacity_; | |
151 gfx::Transform transform_; | |
152 uint32_t pending_access_policy_; | |
153 ui::TextInputState text_input_state_; | |
154 gfx::Size last_submitted_frame_size_; | |
155 | |
156 std::map<std::string, std::vector<uint8_t>> properties_; | |
157 | |
158 base::ObserverList<ServerViewObserver> observers_; | |
159 mojo::SurfaceClientPtr client_; | |
160 mojo::Binding<Surface> binding_; | |
161 | |
162 DISALLOW_COPY_AND_ASSIGN(ServerView); | |
163 }; | |
164 | |
165 } // namespace view_manager | |
166 | |
167 #endif // COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_ | |
OLD | NEW |