| 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_MUS_SERVER_VIEW_H_ | |
| 6 #define COMPONENTS_MUS_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/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" | |
| 22 | |
| 23 namespace mus { | |
| 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, public cc::SurfaceFactoryClient { | |
| 39 public: | |
| 40 ServerView(ServerViewDelegate* delegate, const ViewId& id); | |
| 41 ~ServerView() override; | |
| 42 | |
| 43 void AddObserver(ServerViewObserver* observer); | |
| 44 void RemoveObserver(ServerViewObserver* observer); | |
| 45 | |
| 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); | |
| 50 | |
| 51 const ViewId& id() const { return id_; } | |
| 52 | |
| 53 void Add(ServerView* child); | |
| 54 void Remove(ServerView* child); | |
| 55 void Reorder(ServerView* child, | |
| 56 ServerView* relative, | |
| 57 mojo::OrderDirection direction); | |
| 58 | |
| 59 const gfx::Rect& bounds() const { return bounds_; } | |
| 60 void SetBounds(const gfx::Rect& bounds); | |
| 61 | |
| 62 const ServerView* parent() const { return parent_; } | |
| 63 ServerView* parent() { return parent_; } | |
| 64 | |
| 65 const ServerView* GetRoot() const; | |
| 66 ServerView* GetRoot() { | |
| 67 return const_cast<ServerView*>( | |
| 68 const_cast<const ServerView*>(this)->GetRoot()); | |
| 69 } | |
| 70 | |
| 71 std::vector<const ServerView*> GetChildren() const; | |
| 72 std::vector<ServerView*> GetChildren(); | |
| 73 | |
| 74 // Returns true if this contains |view| or is |view|. | |
| 75 bool Contains(const ServerView* view) const; | |
| 76 | |
| 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); | |
| 81 | |
| 82 float opacity() const { return opacity_; } | |
| 83 void SetOpacity(float value); | |
| 84 | |
| 85 const gfx::Transform& transform() const { return transform_; } | |
| 86 void SetTransform(const gfx::Transform& transform); | |
| 87 | |
| 88 const std::map<std::string, std::vector<uint8_t>>& properties() const { | |
| 89 return properties_; | |
| 90 } | |
| 91 void SetProperty(const std::string& name, const std::vector<uint8_t>* value); | |
| 92 | |
| 93 void SetTextInputState(const ui::TextInputState& state); | |
| 94 const ui::TextInputState& text_input_state() const { | |
| 95 return text_input_state_; | |
| 96 } | |
| 97 | |
| 98 // Returns true if this view is attached to a root and all ancestors are | |
| 99 // visible. | |
| 100 bool IsDrawn() const; | |
| 101 | |
| 102 void SetSurfaceId(cc::SurfaceId surface_id); | |
| 103 const cc::SurfaceId& surface_id() const { return surface_id_; } | |
| 104 | |
| 105 const gfx::Size& last_submitted_frame_size() { | |
| 106 return last_submitted_frame_size_; | |
| 107 } | |
| 108 | |
| 109 ServerViewDelegate* delegate() { return delegate_; } | |
| 110 | |
| 111 // mojo::Surface: | |
| 112 void SubmitCompositorFrame( | |
| 113 mojo::CompositorFramePtr frame, | |
| 114 const SubmitCompositorFrameCallback& callback) override; | |
| 115 | |
| 116 #if !defined(NDEBUG) | |
| 117 std::string GetDebugWindowHierarchy() const; | |
| 118 void BuildDebugInfo(const std::string& depth, std::string* result) const; | |
| 119 #endif | |
| 120 | |
| 121 private: | |
| 122 typedef std::vector<ServerView*> Views; | |
| 123 | |
| 124 // SurfaceFactoryClient implementation. | |
| 125 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
| 126 | |
| 127 // Implementation of removing a view. Doesn't send any notification. | |
| 128 void RemoveImpl(ServerView* view); | |
| 129 | |
| 130 ServerViewDelegate* delegate_; | |
| 131 const ViewId id_; | |
| 132 ServerView* parent_; | |
| 133 Views children_; | |
| 134 bool visible_; | |
| 135 gfx::Rect bounds_; | |
| 136 cc::SurfaceId surface_id_; | |
| 137 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | |
| 138 scoped_ptr<cc::SurfaceFactory> surface_factory_; | |
| 139 float opacity_; | |
| 140 gfx::Transform transform_; | |
| 141 ui::TextInputState text_input_state_; | |
| 142 gfx::Size last_submitted_frame_size_; | |
| 143 | |
| 144 std::map<std::string, std::vector<uint8_t>> properties_; | |
| 145 | |
| 146 base::ObserverList<ServerViewObserver> observers_; | |
| 147 mojo::SurfaceClientPtr client_; | |
| 148 mojo::Binding<Surface> binding_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(ServerView); | |
| 151 }; | |
| 152 | |
| 153 } // namespace mus | |
| 154 | |
| 155 #endif // COMPONENTS_MUS_SERVER_VIEW_H_ | |
| OLD | NEW |