Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / mojo / services / public / cpp / view_manager / view.h
blob3f8ff98e9fa21fbffe9366347b5b2b5a3159beb2
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 MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_
8 #include <vector>
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"
19 class SkBitmap;
21 namespace mojo {
23 class ServiceProviderImpl;
24 class View;
25 class ViewManager;
26 class ViewObserver;
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;
36 static View* Create(ViewManager* view_manager);
38 // Destroys this view and all its children.
39 void Destroy();
41 // Configuration.
42 Id id() const { return id_; }
44 // Geometric disposition.
45 const gfx::Rect& bounds() { return bounds_; }
46 void SetBounds(const gfx::Rect& bounds);
48 // Visibility.
49 void SetVisible(bool value);
50 // TODO(sky): add accessor.
52 // Observation.
53 void AddObserver(ViewObserver* observer);
54 void RemoveObserver(ViewObserver* observer);
56 // Tree.
57 View* parent() { return parent_; }
58 const View* parent() const { return parent_; }
59 const Children& children() const { return children_; }
61 void AddChild(View* child);
62 void RemoveChild(View* child);
64 void Reorder(View* relative, OrderDirection direction);
65 void MoveToFront();
66 void MoveToBack();
68 bool Contains(View* child) const;
70 View* GetChildById(Id id);
72 // TODO(beng): temporary only.
73 void SetContents(const SkBitmap& contents);
74 void SetColor(SkColor color);
76 // Focus.
77 void SetFocus();
79 // Embedding.
80 void Embed(const String& url);
81 scoped_ptr<ServiceProvider> Embed(
82 const String& url,
83 scoped_ptr<ServiceProviderImpl> exported_services);
85 protected:
86 // This class is subclassed only by test classes that provide a public ctor.
87 View();
88 ~View();
90 private:
91 friend class ViewPrivate;
92 friend class ViewManagerClientImpl;
94 explicit View(ViewManager* manager);
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);
103 ViewManager* manager_;
104 Id id_;
105 View* parent_;
106 Children children_;
108 ObserverList<ViewObserver> observers_;
110 gfx::Rect bounds_;
112 DISALLOW_COPY_AND_ASSIGN(View);
115 } // namespace mojo
117 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_