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"
17 #include "ui/platform_window/text_input_state.h"
19 namespace view_manager
{
21 class ServerViewDelegate
;
22 class ServerViewObserver
;
24 // Server side representation of a view. Delegate is informed of interesting
27 // It is assumed that all functions that mutate the tree have validated the
28 // mutation is possible before hand. For example, Reorder() assumes the supplied
29 // view is a child and not already in position.
31 // ServerViews do not own their children. If you delete a view that has children
32 // the children are implicitly removed. Similarly if a view has a parent and the
33 // view is deleted the deleted view is implicitly removed from the parent.
36 ServerView(ServerViewDelegate
* delegate
, const ViewId
& id
);
37 virtual ~ServerView();
39 void AddObserver(ServerViewObserver
* observer
);
40 void RemoveObserver(ServerViewObserver
* observer
);
42 const ViewId
& id() const { return id_
; }
44 void Add(ServerView
* child
);
45 void Remove(ServerView
* child
);
46 void Reorder(ServerView
* child
,
48 mojo::OrderDirection direction
);
50 const gfx::Rect
& bounds() const { return bounds_
; }
51 void SetBounds(const gfx::Rect
& bounds
);
53 const ServerView
* parent() const { return parent_
; }
54 ServerView
* parent() { return parent_
; }
56 const ServerView
* GetRoot() const;
57 ServerView
* GetRoot() {
58 return const_cast<ServerView
*>(
59 const_cast<const ServerView
*>(this)->GetRoot());
62 std::vector
<const ServerView
*> GetChildren() const;
63 std::vector
<ServerView
*> GetChildren();
65 // Returns true if this contains |view| or is |view|.
66 bool Contains(const ServerView
* view
) const;
68 // Returns true if the window is visible. This does not consider visibility
70 bool visible() const { return visible_
; }
71 void SetVisible(bool value
);
73 float opacity() const { return opacity_
; }
74 void SetOpacity(float value
);
76 const gfx::Transform
& transform() const { return transform_
; }
77 void SetTransform(const gfx::Transform
& transform
);
79 const std::map
<std::string
, std::vector
<uint8_t>>& properties() const {
82 void SetProperty(const std::string
& name
, const std::vector
<uint8_t>* value
);
84 void SetTextInputState(const ui::TextInputState
& state
);
85 const ui::TextInputState
& text_input_state() const {
86 return text_input_state_
;
89 // Returns true if this view is attached to a root and all ancestors are
93 void SetSurfaceId(cc::SurfaceId surface_id
);
94 const cc::SurfaceId
& surface_id() const { return surface_id_
; }
96 // See mojom for for details.
97 void set_allows_reembed(bool value
) { allows_reembed_
= value
; }
98 bool allows_reembed() const { return allows_reembed_
; }
101 std::string
GetDebugWindowHierarchy() const;
102 void BuildDebugInfo(const std::string
& depth
, std::string
* result
) const;
106 typedef std::vector
<ServerView
*> Views
;
108 // Implementation of removing a view. Doesn't send any notification.
109 void RemoveImpl(ServerView
* view
);
111 ServerViewDelegate
* delegate_
;
117 cc::SurfaceId surface_id_
;
119 gfx::Transform transform_
;
120 bool allows_reembed_
;
121 ui::TextInputState text_input_state_
;
123 std::map
<std::string
, std::vector
<uint8_t>> properties_
;
125 base::ObserverList
<ServerViewObserver
> observers_
;
127 DISALLOW_COPY_AND_ASSIGN(ServerView
);
130 } // namespace view_manager
132 #endif // COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_