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_
10 #include "base/logging.h"
11 #include "base/observer_list.h"
12 #include "cc/surfaces/surface_id.h"
13 #include "components/view_manager/ids.h"
14 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/transform.h"
18 namespace view_manager
{
20 class ServerViewDelegate
;
21 class ServerViewObserver
;
23 // Server side representation of a view. Delegate is informed of interesting
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.
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.
35 ServerView(ServerViewDelegate
* delegate
, const ViewId
& id
);
36 virtual ~ServerView();
38 void AddObserver(ServerViewObserver
* observer
);
39 void RemoveObserver(ServerViewObserver
* observer
);
41 const ViewId
& id() const { return id_
; }
43 void Add(ServerView
* child
);
44 void Remove(ServerView
* child
);
45 void Reorder(ServerView
* child
,
47 mojo::OrderDirection direction
);
49 const gfx::Rect
& bounds() const { return bounds_
; }
50 void SetBounds(const gfx::Rect
& bounds
);
52 const ServerView
* parent() const { return parent_
; }
53 ServerView
* parent() { return parent_
; }
55 const ServerView
* GetRoot() const;
56 ServerView
* GetRoot() {
57 return const_cast<ServerView
*>(
58 const_cast<const ServerView
*>(this)->GetRoot());
61 std::vector
<const ServerView
*> GetChildren() const;
62 std::vector
<ServerView
*> GetChildren();
64 // Returns true if this contains |view| or is |view|.
65 bool Contains(const ServerView
* view
) const;
67 // Returns true if the window is visible. This does not consider visibility
69 bool visible() const { return visible_
; }
70 void SetVisible(bool value
);
72 float opacity() const { return opacity_
; }
73 void SetOpacity(float value
);
75 const gfx::Transform
& transform() const { return transform_
; }
76 void SetTransform(const gfx::Transform
& transform
);
78 const std::map
<std::string
, std::vector
<uint8_t>>& properties() const {
81 void SetProperty(const std::string
& name
, const std::vector
<uint8_t>* value
);
83 // Returns true if this view is attached to a root and all ancestors are
87 void SetSurfaceId(cc::SurfaceId surface_id
);
88 const cc::SurfaceId
& surface_id() const { return surface_id_
; }
90 // See mojom for for details.
91 void set_allows_reembed(bool value
) { allows_reembed_
= value
; }
92 bool allows_reembed() const { return allows_reembed_
; }
95 std::string
GetDebugWindowHierarchy() const;
96 void BuildDebugInfo(const std::string
& depth
, std::string
* result
) const;
100 typedef std::vector
<ServerView
*> Views
;
102 // Implementation of removing a view. Doesn't send any notification.
103 void RemoveImpl(ServerView
* view
);
105 ServerViewDelegate
* delegate_
;
111 cc::SurfaceId surface_id_
;
113 gfx::Transform transform_
;
114 bool allows_reembed_
;
116 std::map
<std::string
, std::vector
<uint8_t>> properties_
;
118 base::ObserverList
<ServerViewObserver
> observers_
;
120 DISALLOW_COPY_AND_ASSIGN(ServerView
);
123 } // namespace view_manager
125 #endif // COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_