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.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 void Layer::Add(Layer* child) { | 152 void Layer::Add(Layer* child) { |
153 DCHECK(!child->compositor_); | 153 DCHECK(!child->compositor_); |
154 if (child->parent_) | 154 if (child->parent_) |
155 child->parent_->Remove(child); | 155 child->parent_->Remove(child); |
156 child->parent_ = this; | 156 child->parent_ = this; |
157 children_.push_back(child); | 157 children_.push_back(child); |
158 cc_layer_->AddChild(child->cc_layer_); | 158 cc_layer_->AddChild(child->cc_layer_); |
159 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 159 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
160 if (GetCompositor()) | 160 if (GetCompositor()) |
161 child->SendPendingThreadedAnimations(); | 161 child->SendPendingThreadedAnimations(); |
162 if (child->GetAnimator() && child->GetAnimator()->is_animating()) { | |
piman
2014/05/23 21:38:56
nit: GetAnimator() is non-trivial:
1- can we call
sadrul
2014/05/23 21:56:11
Done. Added Layer::IsAnimating() const { return an
| |
163 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | |
164 if (collection) | |
165 collection->StartAnimator(child->GetAnimator()); | |
166 } | |
162 } | 167 } |
163 | 168 |
164 void Layer::Remove(Layer* child) { | 169 void Layer::Remove(Layer* child) { |
165 // Current bounds are used to calculate offsets when layers are reparented. | 170 // Current bounds are used to calculate offsets when layers are reparented. |
166 // Stop (and complete) an ongoing animation to update the bounds immediately. | 171 // Stop (and complete) an ongoing animation to update the bounds immediately. |
167 if (child->GetAnimator()) { | 172 if (child->GetAnimator()) { |
168 child->GetAnimator()->StopAnimatingProperty( | 173 child->GetAnimator()->StopAnimatingProperty( |
169 ui::LayerAnimationElement::BOUNDS); | 174 ui::LayerAnimationElement::BOUNDS); |
175 if (child->GetAnimator()->is_animating()) { | |
176 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | |
177 if (collection) | |
178 collection->StopAnimator(child->GetAnimator()); | |
179 } | |
170 } | 180 } |
171 std::vector<Layer*>::iterator i = | 181 std::vector<Layer*>::iterator i = |
172 std::find(children_.begin(), children_.end(), child); | 182 std::find(children_.begin(), children_.end(), child); |
173 DCHECK(i != children_.end()); | 183 DCHECK(i != children_.end()); |
174 children_.erase(i); | 184 children_.erase(i); |
175 child->parent_ = NULL; | 185 child->parent_ = NULL; |
176 child->cc_layer_->RemoveFromParent(); | 186 child->cc_layer_->RemoveFromParent(); |
177 } | 187 } |
178 | 188 |
179 void Layer::StackAtTop(Layer* child) { | 189 void Layer::StackAtTop(Layer* child) { |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 } | 877 } |
868 | 878 |
869 pending_threaded_animations_.erase( | 879 pending_threaded_animations_.erase( |
870 cc::remove_if(&pending_threaded_animations_, | 880 cc::remove_if(&pending_threaded_animations_, |
871 pending_threaded_animations_.begin(), | 881 pending_threaded_animations_.begin(), |
872 pending_threaded_animations_.end(), | 882 pending_threaded_animations_.end(), |
873 HasAnimationId(animation_id)), | 883 HasAnimationId(animation_id)), |
874 pending_threaded_animations_.end()); | 884 pending_threaded_animations_.end()); |
875 } | 885 } |
876 | 886 |
887 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { | |
888 Compositor* compositor = GetCompositor(); | |
889 return compositor ? compositor->layer_animator_collection() : NULL; | |
890 } | |
891 | |
877 void Layer::SendPendingThreadedAnimations() { | 892 void Layer::SendPendingThreadedAnimations() { |
878 for (cc::ScopedPtrVector<cc::Animation>::iterator it = | 893 for (cc::ScopedPtrVector<cc::Animation>::iterator it = |
879 pending_threaded_animations_.begin(); | 894 pending_threaded_animations_.begin(); |
880 it != pending_threaded_animations_.end(); | 895 it != pending_threaded_animations_.end(); |
881 ++it) | 896 ++it) |
882 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); | 897 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); |
883 | 898 |
884 pending_threaded_animations_.clear(); | 899 pending_threaded_animations_.clear(); |
885 | 900 |
886 for (size_t i = 0; i < children_.size(); ++i) | 901 for (size_t i = 0; i < children_.size(); ++i) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_); | 940 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_); |
926 } | 941 } |
927 cc_layer_->SetBounds(size); | 942 cc_layer_->SetBounds(size); |
928 } | 943 } |
929 | 944 |
930 void Layer::RecomputePosition() { | 945 void Layer::RecomputePosition() { |
931 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); | 946 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); |
932 } | 947 } |
933 | 948 |
934 } // namespace ui | 949 } // namespace ui |
OLD | NEW |