| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_COMPOSITOR_LAYER_OWNER_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_OWNER_H_ |
| 6 #define UI_COMPOSITOR_LAYER_OWNER_H_ | 6 #define UI_COMPOSITOR_LAYER_OWNER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/compositor/compositor_export.h" | 10 #include "ui/compositor/compositor_export.h" |
| 11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 class COMPOSITOR_EXPORT LayerOwner { | 15 class COMPOSITOR_EXPORT LayerOwner { |
| 16 public: | 16 public: |
| 17 LayerOwner(); | 17 LayerOwner(); |
| 18 virtual ~LayerOwner(); | 18 virtual ~LayerOwner(); |
| 19 | 19 |
| 20 void SetLayer(Layer* layer); |
| 21 |
| 20 // Releases the owning reference to its layer, and returns it. | 22 // Releases the owning reference to its layer, and returns it. |
| 21 // This is used when you need to animate the presentation of the owner just | 23 // This is used when you need to animate the presentation of the owner just |
| 22 // prior to destroying it. The Owner can be destroyed soon after calling this | 24 // prior to destroying it. The Owner can be destroyed soon after calling this |
| 23 // function, and the caller is then responsible for disposing of the layer | 25 // function, and the caller is then responsible for disposing of the layer |
| 24 // once any animation completes. Note that layer() will remain valid until the | 26 // once any animation completes. Note that layer() will remain valid until the |
| 25 // end of ~LayerOwner(). | 27 // end of ~LayerOwner(). |
| 26 Layer* AcquireLayer() WARN_UNUSED_RESULT; | 28 Layer* AcquireLayer() WARN_UNUSED_RESULT; |
| 27 | 29 |
| 28 ui::Layer* layer() { return layer_; } | 30 ui::Layer* layer() { return layer_; } |
| 29 const ui::Layer* layer() const { return layer_; } | 31 const ui::Layer* layer() const { return layer_; } |
| 30 | 32 |
| 31 protected: | 33 protected: |
| 34 void DestroyLayer(); |
| 35 |
| 36 bool OwnsLayer() const; |
| 37 |
| 38 private: |
| 32 // The LayerOwner owns its layer unless ownership is relinquished via a call | 39 // The LayerOwner owns its layer unless ownership is relinquished via a call |
| 33 // to AcquireLayer(). After that moment |layer_| will still be valid but | 40 // to AcquireLayer(). After that moment |layer_| will still be valid but |
| 34 // |layer_owner_| will be NULL. The reason for releasing ownership is that | 41 // |layer_owner_| will be NULL. The reason for releasing ownership is that |
| 35 // the client may wish to animate the layer beyond the lifetime of the owner, | 42 // the client may wish to animate the layer beyond the lifetime of the owner, |
| 36 // e.g. fading it out when it is destroyed. | 43 // e.g. fading it out when it is destroyed. |
| 37 scoped_ptr<Layer> layer_owner_; | 44 scoped_ptr<Layer> layer_owner_; |
| 38 Layer* layer_; | 45 Layer* layer_; |
| 39 | 46 |
| 40 private: | |
| 41 DISALLOW_COPY_AND_ASSIGN(LayerOwner); | 47 DISALLOW_COPY_AND_ASSIGN(LayerOwner); |
| 42 }; | 48 }; |
| 43 | 49 |
| 44 } // namespace ui | 50 } // namespace ui |
| 45 | 51 |
| 46 #endif // UI_COMPOSITOR_LAYER_OWNER_H_ | 52 #endif // UI_COMPOSITOR_LAYER_OWNER_H_ |
| OLD | NEW |