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