Inline NetLog IPv6 reachability events.
[chromium-blink-merge.git] / components / view_manager / server_view.h
blobb307ffd63b8dbb356257173ba9b7341273df9bfc
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_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
24 // events.
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.
33 class ServerView {
34 public:
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,
46 ServerView* relative,
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
68 // of any ancestors.
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 {
79 return properties_;
81 void SetProperty(const std::string& name, const std::vector<uint8_t>* value);
83 // Returns true if this view is attached to |root| and all ancestors are
84 // visible.
85 bool IsDrawn(const ServerView* root) const;
87 void SetSurfaceId(cc::SurfaceId surface_id);
88 const cc::SurfaceId& surface_id() const { return surface_id_; }
90 #if !defined(NDEBUG)
91 std::string GetDebugWindowHierarchy() const;
92 void BuildDebugInfo(const std::string& depth, std::string* result) const;
93 #endif
95 private:
96 typedef std::vector<ServerView*> Views;
98 // Implementation of removing a view. Doesn't send any notification.
99 void RemoveImpl(ServerView* view);
101 ServerViewDelegate* delegate_;
102 const ViewId id_;
103 ServerView* parent_;
104 Views children_;
105 bool visible_;
106 gfx::Rect bounds_;
107 cc::SurfaceId surface_id_;
108 float opacity_;
109 gfx::Transform transform_;
111 std::map<std::string, std::vector<uint8_t>> properties_;
113 ObserverList<ServerViewObserver> observers_;
115 DISALLOW_COPY_AND_ASSIGN(ServerView);
118 } // namespace view_manager
120 #endif // COMPONENTS_VIEW_MANAGER_SERVER_VIEW_H_