Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / services / public / cpp / view_manager / view.h
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_VIEW_H_
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_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/public/interfaces/application/service_provider.mojom.h"
14 #include "mojo/services/public/cpp/view_manager/types.h"
15 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mojom.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/gfx/geometry/rect.h"
18
19 class SkBitmap;
20
21 namespace mojo {
22
23 class ServiceProviderImpl;
24 class View;
25 class ViewManager;
26 class ViewObserver;
27
28 // Views are owned by the ViewManager.
29 // TODO(beng): Right now, you'll have to implement a ViewObserver to track
30 //             destruction and NULL any pointers you have.
31 //             Investigate some kind of smart pointer or weak pointer for these.
32 class View {
33  public:
34   typedef std::vector<View*> Children;
35
36   static View* Create(ViewManager* view_manager);
37
38   // Destroys this view and all its children.
39   void Destroy();
40
41   // Configuration.
42   Id id() const { return id_; }
43
44   // Geometric disposition.
45   const gfx::Rect& bounds() { return bounds_; }
46   void SetBounds(const gfx::Rect& bounds);
47
48   // Visibility.
49   void SetVisible(bool value);
50   // TODO(sky): add accessor.
51
52   // Observation.
53   void AddObserver(ViewObserver* observer);
54   void RemoveObserver(ViewObserver* observer);
55
56   // Tree.
57   View* parent() { return parent_; }
58   const View* parent() const { return parent_; }
59   const Children& children() const { return children_; }
60
61   void AddChild(View* child);
62   void RemoveChild(View* child);
63
64   void Reorder(View* relative, OrderDirection direction);
65   void MoveToFront();
66   void MoveToBack();
67
68   bool Contains(View* child) const;
69
70   View* GetChildById(Id id);
71
72   // TODO(beng): temporary only.
73   void SetContents(const SkBitmap& contents);
74   void SetColor(SkColor color);
75
76   // Focus.
77   void SetFocus();
78
79   // Embedding.
80   void Embed(const String& url);
81   scoped_ptr<ServiceProvider> Embed(
82       const String& url,
83       scoped_ptr<ServiceProviderImpl> exported_services);
84
85  protected:
86   // This class is subclassed only by test classes that provide a public ctor.
87   View();
88   ~View();
89
90  private:
91   friend class ViewPrivate;
92   friend class ViewManagerClientImpl;
93
94   explicit View(ViewManager* manager);
95
96   void LocalDestroy();
97   void LocalAddChild(View* child);
98   void LocalRemoveChild(View* child);
99   // Returns true if the order actually changed.
100   bool LocalReorder(View* relative, OrderDirection direction);
101   void LocalSetBounds(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds);
102
103   ViewManager* manager_;
104   Id id_;
105   View* parent_;
106   Children children_;
107
108   ObserverList<ViewObserver> observers_;
109
110   gfx::Rect bounds_;
111
112   DISALLOW_COPY_AND_ASSIGN(View);
113 };
114
115 }  // namespace mojo
116
117 #endif  // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_