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 MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ 7 8 #include <vector> 9 10 #include "base/logging.h" 11 #include "cc/surfaces/surface_id.h" 12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 13 #include "mojo/services/view_manager/ids.h" 14 #include "mojo/services/view_manager/view_manager_export.h" 15 #include "ui/gfx/geometry/rect.h" 16 17 namespace mojo { 18 namespace service { 19 20 class ServerViewDelegate; 21 22 // Server side representation of a view. Delegate is informed of interesting 23 // events. 24 // 25 // It is assumed that all functions that mutate the tree have validated the 26 // mutation is possible before hand. For example, Reorder() assumes the supplied 27 // view is a child and not already in position. 28 class MOJO_VIEW_MANAGER_EXPORT ServerView { 29 public: 30 ServerView(ServerViewDelegate* delegate, const ViewId& id); 31 virtual ~ServerView(); 32 id()33 const ViewId& id() const { return id_; } 34 35 void Add(ServerView* child); 36 void Remove(ServerView* child); 37 void Reorder(ServerView* child, 38 ServerView* relative, 39 OrderDirection direction); 40 bounds()41 const gfx::Rect& bounds() const { return bounds_; } 42 void SetBounds(const gfx::Rect& bounds); 43 parent()44 const ServerView* parent() const { return parent_; } parent()45 ServerView* parent() { return parent_; } 46 47 const ServerView* GetRoot() const; GetRoot()48 ServerView* GetRoot() { 49 return const_cast<ServerView*>( 50 const_cast<const ServerView*>(this)->GetRoot()); 51 } 52 53 std::vector<const ServerView*> GetChildren() const; 54 std::vector<ServerView*> GetChildren(); 55 56 // Returns true if this contains |view| or is |view|. 57 bool Contains(const ServerView* view) const; 58 59 // Returns true if the window is visible. This does not consider visibility 60 // of any ancestors. visible()61 bool visible() const { return visible_; } 62 void SetVisible(bool value); 63 64 // Returns true if this view is attached to |root| and all ancestors are 65 // visible. 66 bool IsDrawn(const ServerView* root) const; 67 68 void SetSurfaceId(cc::SurfaceId surface_id); surface_id()69 const cc::SurfaceId surface_id() const { return surface_id_; } 70 71 private: 72 typedef std::vector<ServerView*> Views; 73 74 // Implementation of removing a view. Doesn't send any notification. 75 void RemoveImpl(ServerView* view); 76 77 ServerViewDelegate* delegate_; 78 const ViewId id_; 79 ServerView* parent_; 80 Views children_; 81 bool visible_; 82 gfx::Rect bounds_; 83 cc::SurfaceId surface_id_; 84 85 DISALLOW_COPY_AND_ASSIGN(ServerView); 86 }; 87 88 } // namespace service 89 } // namespace mojo 90 91 #endif // MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_H_ 92