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 #include "ui/compositor/layer_owner.h" | 5 #include "ui/compositor/layer_owner.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "ui/compositor/layer_owner_delegate.h" | 9 #include "ui/compositor/layer_owner_delegate.h" |
8 | 10 |
9 namespace ui { | 11 namespace ui { |
10 | 12 |
11 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) { | 13 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) { |
12 } | 14 } |
13 | 15 |
14 LayerOwner::~LayerOwner() { | 16 LayerOwner::~LayerOwner() { |
15 } | 17 } |
16 | 18 |
17 void LayerOwner::SetLayer(Layer* layer) { | 19 void LayerOwner::SetLayer(Layer* layer) { |
18 DCHECK(!OwnsLayer()); | 20 DCHECK(!OwnsLayer()); |
19 layer_owner_.reset(layer); | 21 layer_owner_.reset(layer); |
20 layer_ = layer; | 22 layer_ = layer; |
21 layer_->owner_ = this; | 23 layer_->owner_ = this; |
22 } | 24 } |
23 | 25 |
24 scoped_ptr<Layer> LayerOwner::AcquireLayer() { | 26 scoped_ptr<Layer> LayerOwner::AcquireLayer() { |
25 if (layer_owner_) | 27 if (layer_owner_) |
26 layer_owner_->owner_ = NULL; | 28 layer_owner_->owner_ = NULL; |
27 return layer_owner_.Pass(); | 29 return std::move(layer_owner_); |
28 } | 30 } |
29 | 31 |
30 scoped_ptr<Layer> LayerOwner::RecreateLayer() { | 32 scoped_ptr<Layer> LayerOwner::RecreateLayer() { |
31 scoped_ptr<ui::Layer> old_layer(AcquireLayer()); | 33 scoped_ptr<ui::Layer> old_layer(AcquireLayer()); |
32 if (!old_layer) | 34 if (!old_layer) |
33 return old_layer.Pass(); | 35 return old_layer; |
34 | 36 |
35 LayerDelegate* old_delegate = old_layer->delegate(); | 37 LayerDelegate* old_delegate = old_layer->delegate(); |
36 old_layer->set_delegate(NULL); | 38 old_layer->set_delegate(NULL); |
37 | 39 |
38 const gfx::Rect layer_bounds(old_layer->bounds()); | 40 const gfx::Rect layer_bounds(old_layer->bounds()); |
39 Layer* new_layer = new ui::Layer(old_layer->type()); | 41 Layer* new_layer = new ui::Layer(old_layer->type()); |
40 SetLayer(new_layer); | 42 SetLayer(new_layer); |
41 new_layer->SetVisible(old_layer->GetTargetVisibility()); | 43 new_layer->SetVisible(old_layer->GetTargetVisibility()); |
42 new_layer->SetOpacity(old_layer->GetTargetOpacity()); | 44 new_layer->SetOpacity(old_layer->GetTargetOpacity()); |
43 new_layer->SetBounds(layer_bounds); | 45 new_layer->SetBounds(layer_bounds); |
(...skipping 28 matching lines...) Expand all Loading... |
72 new_layer->Add(child); | 74 new_layer->Add(child); |
73 } | 75 } |
74 | 76 |
75 // Install the delegate last so that the delegate isn't notified as we copy | 77 // Install the delegate last so that the delegate isn't notified as we copy |
76 // state to the new layer. | 78 // state to the new layer. |
77 new_layer->set_delegate(old_delegate); | 79 new_layer->set_delegate(old_delegate); |
78 | 80 |
79 if (layer_owner_delegate_) | 81 if (layer_owner_delegate_) |
80 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer); | 82 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer); |
81 | 83 |
82 return old_layer.Pass(); | 84 return old_layer; |
83 } | 85 } |
84 | 86 |
85 void LayerOwner::DestroyLayer() { | 87 void LayerOwner::DestroyLayer() { |
86 layer_ = NULL; | 88 layer_ = NULL; |
87 layer_owner_.reset(); | 89 layer_owner_.reset(); |
88 } | 90 } |
89 | 91 |
90 bool LayerOwner::OwnsLayer() const { | 92 bool LayerOwner::OwnsLayer() const { |
91 return !!layer_owner_; | 93 return !!layer_owner_; |
92 } | 94 } |
93 | 95 |
94 } // namespace ui | 96 } // namespace ui |
OLD | NEW |