Remove obsolete entries from .gitignore.
[chromium-blink-merge.git] / components / mus / server_view.h
blobafd82d850a6ec60a00c7529d9c7cba7e590b769a
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_MUS_SERVER_VIEW_H_
6 #define COMPONENTS_MUS_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/mus/ids.h"
17 #include "components/mus/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 mus {
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, public cc::SurfaceFactoryClient {
39 public:
40 ServerView(ServerViewDelegate* delegate, const ViewId& id);
41 ~ServerView() override;
43 void AddObserver(ServerViewObserver* observer);
44 void RemoveObserver(ServerViewObserver* observer);
46 // Binds the provided |request| to |this| object. If an interface is already
47 // bound to this ServerView then the old connection is closed first.
48 void Bind(mojo::InterfaceRequest<Surface> request,
49 mojo::SurfaceClientPtr client);
51 const ViewId& id() const { return id_; }
53 void Add(ServerView* child);
54 void Remove(ServerView* child);
55 void Reorder(ServerView* child,
56 ServerView* relative,
57 mojo::OrderDirection direction);
59 const gfx::Rect& bounds() const { return bounds_; }
60 void SetBounds(const gfx::Rect& bounds);
62 const ServerView* parent() const { return parent_; }
63 ServerView* parent() { return parent_; }
65 const ServerView* GetRoot() const;
66 ServerView* GetRoot() {
67 return const_cast<ServerView*>(
68 const_cast<const ServerView*>(this)->GetRoot());
71 std::vector<const ServerView*> GetChildren() const;
72 std::vector<ServerView*> GetChildren();
74 // Returns true if this contains |view| or is |view|.
75 bool Contains(const ServerView* view) const;
77 // Returns true if the window is visible. This does not consider visibility
78 // of any ancestors.
79 bool visible() const { return visible_; }
80 void SetVisible(bool value);
82 float opacity() const { return opacity_; }
83 void SetOpacity(float value);
85 const gfx::Transform& transform() const { return transform_; }
86 void SetTransform(const gfx::Transform& transform);
88 const std::map<std::string, std::vector<uint8_t>>& properties() const {
89 return properties_;
91 void SetProperty(const std::string& name, const std::vector<uint8_t>* value);
93 void SetTextInputState(const ui::TextInputState& state);
94 const ui::TextInputState& text_input_state() const {
95 return text_input_state_;
98 // Returns true if this view is attached to a root and all ancestors are
99 // visible.
100 bool IsDrawn() const;
102 void SetSurfaceId(cc::SurfaceId surface_id);
103 const cc::SurfaceId& surface_id() const { return surface_id_; }
105 const gfx::Size& last_submitted_frame_size() {
106 return last_submitted_frame_size_;
109 // mojo::Surface:
110 void SubmitCompositorFrame(
111 mojo::CompositorFramePtr frame,
112 const SubmitCompositorFrameCallback& callback) override;
114 #if !defined(NDEBUG)
115 std::string GetDebugWindowHierarchy() const;
116 void BuildDebugInfo(const std::string& depth, std::string* result) const;
117 #endif
119 private:
120 typedef std::vector<ServerView*> Views;
122 // SurfaceFactoryClient implementation.
123 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
125 // Implementation of removing a view. Doesn't send any notification.
126 void RemoveImpl(ServerView* view);
128 ServerViewDelegate* delegate_;
129 const ViewId id_;
130 ServerView* parent_;
131 Views children_;
132 bool visible_;
133 gfx::Rect bounds_;
134 cc::SurfaceId surface_id_;
135 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
136 scoped_ptr<cc::SurfaceFactory> surface_factory_;
137 float opacity_;
138 gfx::Transform transform_;
139 ui::TextInputState text_input_state_;
140 gfx::Size last_submitted_frame_size_;
142 std::map<std::string, std::vector<uint8_t>> properties_;
144 base::ObserverList<ServerViewObserver> observers_;
145 mojo::SurfaceClientPtr client_;
146 mojo::Binding<Surface> binding_;
148 DISALLOW_COPY_AND_ASSIGN(ServerView);
151 } // namespace mus
153 #endif // COMPONENTS_MUS_SERVER_VIEW_H_