Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / components / view_manager / server_view.h
blob3ee4447ae3659cf4fc8673dac7f4befda50e998d
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.
5 #ifndef COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_
6 #define COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_
8 #include <vector>
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"
23 namespace view_manager {
25 class ServerViewDelegate;
26 class ServerViewObserver;
28 // Server side representation of a view. Delegate is informed of interesting
29 // events.
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.
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;
44 void AddObserver(ServerViewObserver* observer);
45 void RemoveObserver(ServerViewObserver* observer);
47 // Binds the provided |request| to |this| object. If an interface is already
48 // bound to this ServerView then the old connection is closed first.
49 void Bind(mojo::InterfaceRequest<Surface> request,
50 mojo::SurfaceClientPtr client);
52 const ViewId& id() const { return id_; }
54 void Add(ServerView* child);
55 void Remove(ServerView* child);
56 void Reorder(ServerView* child,
57 ServerView* relative,
58 mojo::OrderDirection direction);
60 const gfx::Rect& bounds() const { return bounds_; }
61 void SetBounds(const gfx::Rect& bounds);
63 const ServerView* parent() const { return parent_; }
64 ServerView* parent() { return parent_; }
66 const ServerView* GetRoot() const;
67 ServerView* GetRoot() {
68 return const_cast<ServerView*>(
69 const_cast<const ServerView*>(this)->GetRoot());
72 std::vector<const ServerView*> GetChildren() const;
73 std::vector<ServerView*> GetChildren();
75 // Returns true if this contains |view| or is |view|.
76 bool Contains(const ServerView* view) const;
78 // Returns true if the window is visible. This does not consider visibility
79 // of any ancestors.
80 bool visible() const { return visible_; }
81 void SetVisible(bool value);
83 float opacity() const { return opacity_; }
84 void SetOpacity(float value);
86 const gfx::Transform& transform() const { return transform_; }
87 void SetTransform(const gfx::Transform& transform);
89 const std::map<std::string, std::vector<uint8_t>>& properties() const {
90 return properties_;
92 void SetProperty(const std::string& name, const std::vector<uint8_t>* value);
94 void SetTextInputState(const ui::TextInputState& state);
95 const ui::TextInputState& text_input_state() const {
96 return text_input_state_;
99 // Returns true if this view is attached to a root and all ancestors are
100 // visible.
101 bool IsDrawn() const;
103 void SetSurfaceId(cc::SurfaceId surface_id);
104 const cc::SurfaceId& surface_id() const { return surface_id_; }
106 const gfx::Size& last_submitted_frame_size() {
107 return last_submitted_frame_size_;
110 // See mojom for for details.
111 void set_allows_reembed(bool value) { allows_reembed_ = value; }
112 bool allows_reembed() const { return allows_reembed_; }
114 // mojo::Surface:
115 void SubmitCompositorFrame(
116 mojo::CompositorFramePtr frame,
117 const SubmitCompositorFrameCallback& callback) override;
119 #if !defined(NDEBUG)
120 std::string GetDebugWindowHierarchy() const;
121 void BuildDebugInfo(const std::string& depth, std::string* result) const;
122 #endif
124 private:
125 typedef std::vector<ServerView*> Views;
127 // SurfaceFactoryClient implementation.
128 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
130 // Implementation of removing a view. Doesn't send any notification.
131 void RemoveImpl(ServerView* view);
133 ServerViewDelegate* delegate_;
134 const ViewId id_;
135 ServerView* parent_;
136 Views children_;
137 bool visible_;
138 gfx::Rect bounds_;
139 cc::SurfaceId surface_id_;
140 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
141 scoped_ptr<cc::SurfaceFactory> surface_factory_;
142 float opacity_;
143 gfx::Transform transform_;
144 bool allows_reembed_;
145 ui::TextInputState text_input_state_;
146 gfx::Size last_submitted_frame_size_;
148 std::map<std::string, std::vector<uint8_t>> properties_;
150 base::ObserverList<ServerViewObserver> observers_;
151 mojo::SurfaceClientPtr client_;
152 mojo::Binding<Surface> binding_;
154 DISALLOW_COPY_AND_ASSIGN(ServerView);
157 } // namespace view_manager
159 #endif // COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_