1// Copyright (c) 2012 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 UI_COMPOSITOR_LAYER_OWNER_H_ 6#define UI_COMPOSITOR_LAYER_OWNER_H_ 7 8#include "base/compiler_specific.h" 9#include "base/memory/scoped_ptr.h" 10#include "ui/compositor/compositor_export.h" 11#include "ui/compositor/layer.h" 12 13namespace ui { 14class LayerOwnerDelegate; 15 16class COMPOSITOR_EXPORT LayerOwner { 17 public: 18 LayerOwner(); 19 virtual ~LayerOwner(); 20 21 void SetLayer(Layer* layer); 22 23 // Releases the owning reference to its layer, and returns it. 24 // This is used when you need to animate the presentation of the owner just 25 // prior to destroying it. The Owner can be destroyed soon after calling this 26 // function, and the caller is then responsible for disposing of the layer 27 // once any animation completes. Note that layer() will remain valid until the 28 // end of ~LayerOwner(). 29 scoped_ptr<Layer> AcquireLayer(); 30 31 // Asks the owner to recreate the layer, returning the old Layer. NULL is 32 // returned if there is no existing layer, or recreate is not supported. 33 // 34 // This does not recurse. Existing children of the layer are moved to the new 35 // layer. 36 scoped_ptr<Layer> RecreateLayer(); 37 38 ui::Layer* layer() { return layer_; } 39 const ui::Layer* layer() const { return layer_; } 40 41 void set_layer_owner_delegate(LayerOwnerDelegate* delegate) { 42 layer_owner_delegate_ = delegate; 43 } 44 45 protected: 46 void DestroyLayer(); 47 48 bool OwnsLayer() const; 49 50 private: 51 // The LayerOwner owns its layer unless ownership is relinquished via a call 52 // to AcquireLayer(). After that moment |layer_| will still be valid but 53 // |layer_owner_| will be NULL. The reason for releasing ownership is that 54 // the client may wish to animate the layer beyond the lifetime of the owner, 55 // e.g. fading it out when it is destroyed. 56 scoped_ptr<Layer> layer_owner_; 57 Layer* layer_; 58 59 LayerOwnerDelegate* layer_owner_delegate_; 60 61 DISALLOW_COPY_AND_ASSIGN(LayerOwner); 62}; 63 64} // namespace ui 65 66#endif // UI_COMPOSITOR_LAYER_OWNER_H_ 67