• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PUBLIC_CPP_VIEW_MANAGER_NODE_H_
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_NODE_H_
7 
8 #include <vector>
9 
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "mojo/public/cpp/bindings/array.h"
13 #include "mojo/services/public/cpp/view_manager/types.h"
14 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mojom.h"
15 #include "ui/gfx/geometry/rect.h"
16 
17 namespace mojo {
18 namespace view_manager {
19 
20 class View;
21 class ViewManager;
22 class NodeObserver;
23 
24 // Nodes are owned by the ViewManager.
25 // TODO(beng): Right now, you'll have to implement a NodeObserver to track
26 //             destruction and NULL any pointers you have.
27 //             Investigate some kind of smart pointer or weak pointer for these.
28 class Node {
29  public:
30   typedef std::vector<Node*> Children;
31 
32   static Node* Create(ViewManager* view_manager);
33 
34   // Destroys this node and all its children.
35   void Destroy();
36 
37   // Configuration.
id()38   Id id() const { return id_; }
39 
40   // Geometric disposition.
bounds()41   const gfx::Rect& bounds() { return bounds_; }
42   void SetBounds(const gfx::Rect& bounds);
43 
44   // Observation.
45   void AddObserver(NodeObserver* observer);
46   void RemoveObserver(NodeObserver* observer);
47 
48   // Tree.
parent()49   Node* parent() { return parent_; }
parent()50   const Node* parent() const { return parent_; }
children()51   const Children& children() const { return children_; }
52 
53   void AddChild(Node* child);
54   void RemoveChild(Node* child);
55 
56   void Reorder(Node* relative, OrderDirection direction);
57   void MoveToFront();
58   void MoveToBack();
59 
60   bool Contains(Node* child) const;
61 
62   Node* GetChildById(Id id);
63 
64   // View.
65   void SetActiveView(View* view);
active_view()66   View* active_view() { return active_view_; }
67 
68   // Focus.
69   void SetFocus();
70 
71   // Embedding.
72   void Embed(const String& url);
73 
74  protected:
75   // This class is subclassed only by test classes that provide a public ctor.
76   Node();
77   ~Node();
78 
79  private:
80   friend class NodePrivate;
81 
82   explicit Node(ViewManager* manager);
83 
84   void LocalDestroy();
85   void LocalAddChild(Node* child);
86   void LocalRemoveChild(Node* child);
87   // Returns true if the order actually changed.
88   bool LocalReorder(Node* relative, OrderDirection direction);
89   void LocalSetActiveView(View* view);
90   void LocalSetBounds(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds);
91 
92   ViewManager* manager_;
93   Id id_;
94   Node* parent_;
95   Children children_;
96 
97   ObserverList<NodeObserver> observers_;
98 
99   gfx::Rect bounds_;
100   View* active_view_;
101 
102   DISALLOW_COPY_AND_ASSIGN(Node);
103 };
104 
105 }  // namespace view_manager
106 }  // namespace mojo
107 
108 #endif  // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_NODE_H_
109