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_
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"
23 class ServiceProviderImpl
;
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.
34 typedef std::vector
<View
*> Children
;
36 static View
* Create(ViewManager
* view_manager
);
38 // Destroys this view and all its children.
42 Id
id() const { return id_
; }
44 // Geometric disposition.
45 const gfx::Rect
& bounds() { return bounds_
; }
46 void SetBounds(const gfx::Rect
& bounds
);
49 void SetVisible(bool value
);
50 // TODO(sky): add accessor.
53 void AddObserver(ViewObserver
* observer
);
54 void RemoveObserver(ViewObserver
* observer
);
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
);
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
);
80 void Embed(const String
& url
);
81 scoped_ptr
<ServiceProvider
> Embed(
83 scoped_ptr
<ServiceProviderImpl
> exported_services
);
86 // This class is subclassed only by test classes that provide a public ctor.
91 friend class ViewPrivate
;
92 friend class ViewManagerClientImpl
;
94 explicit View(ViewManager
* manager
);
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_
;
108 ObserverList
<ViewObserver
> observers_
;
112 DISALLOW_COPY_AND_ASSIGN(View
);
117 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_H_