OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/animation/animation_host.h" | 5 #include "cc/animation/animation_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void AnimationHost::RegisterPlayerForElement(ElementId element_id, | 122 void AnimationHost::RegisterPlayerForElement(ElementId element_id, |
123 AnimationPlayer* player) { | 123 AnimationPlayer* player) { |
124 DCHECK(element_id); | 124 DCHECK(element_id); |
125 DCHECK(player); | 125 DCHECK(player); |
126 | 126 |
127 scoped_refptr<ElementAnimations> element_animations = | 127 scoped_refptr<ElementAnimations> element_animations = |
128 GetElementAnimationsForElementId(element_id); | 128 GetElementAnimationsForElementId(element_id); |
129 if (!element_animations) { | 129 if (!element_animations) { |
130 element_animations = ElementAnimations::Create(); | 130 element_animations = ElementAnimations::Create(); |
131 element_animations->SetElementId(element_id); | 131 element_animations->SetElementId(element_id); |
132 element_to_animations_map_[element_animations->element_id()] = | 132 element_to_animations_map_[element_animations->element_id().id] = |
133 element_animations; | 133 element_animations; |
134 } | 134 } |
135 | 135 |
136 if (element_animations->animation_host() != this) { | 136 if (element_animations->animation_host() != this) { |
137 element_animations->SetAnimationHost(this); | 137 element_animations->SetAnimationHost(this); |
138 element_animations->InitAffectedElementTypes(); | 138 element_animations->InitAffectedElementTypes(); |
139 } | 139 } |
140 | 140 |
141 element_animations->AddPlayer(player); | 141 element_animations->AddPlayer(player); |
142 } | 142 } |
143 | 143 |
144 void AnimationHost::UnregisterPlayerForElement(ElementId element_id, | 144 void AnimationHost::UnregisterPlayerForElement(ElementId element_id, |
145 AnimationPlayer* player) { | 145 AnimationPlayer* player) { |
146 DCHECK(element_id); | 146 DCHECK(element_id); |
147 DCHECK(player); | 147 DCHECK(player); |
148 | 148 |
149 scoped_refptr<ElementAnimations> element_animations = | 149 scoped_refptr<ElementAnimations> element_animations = |
150 GetElementAnimationsForElementId(element_id); | 150 GetElementAnimationsForElementId(element_id); |
151 DCHECK(element_animations); | 151 DCHECK(element_animations); |
152 element_animations->RemovePlayer(player); | 152 element_animations->RemovePlayer(player); |
153 | 153 |
154 if (element_animations->IsEmpty()) { | 154 if (element_animations->IsEmpty()) { |
155 element_animations->ClearAffectedElementTypes(); | 155 element_animations->ClearAffectedElementTypes(); |
156 element_to_animations_map_.erase(element_animations->element_id()); | 156 element_to_animations_map_.erase(element_animations->element_id().id); |
157 element_animations->SetAnimationHost(nullptr); | 157 element_animations->SetAnimationHost(nullptr); |
158 } | 158 } |
159 | 159 |
160 RemoveFromTicking(player); | 160 RemoveFromTicking(player); |
161 } | 161 } |
162 | 162 |
163 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { | 163 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { |
164 if (mutator_host_client_ == client) | 164 if (mutator_host_client_ == client) |
165 return; | 165 return; |
166 | 166 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 host_impl->GetTimelineById(timeline->id()); | 233 host_impl->GetTimelineById(timeline->id()); |
234 if (timeline_impl) | 234 if (timeline_impl) |
235 timeline->PushPropertiesTo(timeline_impl); | 235 timeline->PushPropertiesTo(timeline_impl); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 // Sync properties for created ElementAnimations. | 239 // Sync properties for created ElementAnimations. |
240 for (auto& kv : element_to_animations_map_) { | 240 for (auto& kv : element_to_animations_map_) { |
241 const auto& element_animations = kv.second; | 241 const auto& element_animations = kv.second; |
242 if (element_animations->needs_push_properties()) { | 242 if (element_animations->needs_push_properties()) { |
| 243 ElementId element_id; |
| 244 element_id.id = kv.first; |
243 auto element_animations_impl = | 245 auto element_animations_impl = |
244 host_impl->GetElementAnimationsForElementId(kv.first); | 246 host_impl->GetElementAnimationsForElementId(element_id); |
245 if (element_animations_impl) | 247 if (element_animations_impl) |
246 element_animations->PushPropertiesTo( | 248 element_animations->PushPropertiesTo( |
247 std::move(element_animations_impl)); | 249 std::move(element_animations_impl)); |
248 } | 250 } |
249 } | 251 } |
250 | 252 |
251 // Update the impl-only scroll offset animations. | 253 // Update the impl-only scroll offset animations. |
252 scroll_offset_animations_->PushPropertiesTo( | 254 scroll_offset_animations_->PushPropertiesTo( |
253 host_impl->scroll_offset_animations_impl_.get()); | 255 host_impl->scroll_offset_animations_impl_.get()); |
254 } | 256 } |
255 | 257 |
256 scoped_refptr<ElementAnimations> | 258 scoped_refptr<ElementAnimations> |
257 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { | 259 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { |
258 if (!element_id) | 260 if (!element_id) |
259 return nullptr; | 261 return nullptr; |
260 auto iter = element_to_animations_map_.find(element_id); | 262 auto iter = element_to_animations_map_.find(element_id.id); |
261 return iter == element_to_animations_map_.end() ? nullptr : iter->second; | 263 return iter == element_to_animations_map_.end() ? nullptr : iter->second; |
262 } | 264 } |
263 | 265 |
264 void AnimationHost::SetSupportsScrollAnimations( | 266 void AnimationHost::SetSupportsScrollAnimations( |
265 bool supports_scroll_animations) { | 267 bool supports_scroll_animations) { |
266 supports_scroll_animations_ = supports_scroll_animations; | 268 supports_scroll_animations_ = supports_scroll_animations; |
267 } | 269 } |
268 | 270 |
269 bool AnimationHost::SupportsScrollAnimations() const { | 271 bool AnimationHost::SupportsScrollAnimations() const { |
270 return supports_scroll_animations_; | 272 return supports_scroll_animations_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 base::WrapUnique(static_cast<AnimationEvents*>(mutator_events.release())); | 325 base::WrapUnique(static_cast<AnimationEvents*>(mutator_events.release())); |
324 | 326 |
325 for (size_t event_index = 0; event_index < events->events_.size(); | 327 for (size_t event_index = 0; event_index < events->events_.size(); |
326 ++event_index) { | 328 ++event_index) { |
327 ElementId element_id = events->events_[event_index].element_id; | 329 ElementId element_id = events->events_[event_index].element_id; |
328 | 330 |
329 // Use the map of all ElementAnimations, not just ticking players, since | 331 // Use the map of all ElementAnimations, not just ticking players, since |
330 // non-ticking Players may still receive events for impl-only animations. | 332 // non-ticking Players may still receive events for impl-only animations. |
331 const ElementToAnimationsMap& all_element_animations = | 333 const ElementToAnimationsMap& all_element_animations = |
332 element_to_animations_map_; | 334 element_to_animations_map_; |
333 auto iter = all_element_animations.find(element_id); | 335 auto iter = all_element_animations.find(element_id.id); |
334 if (iter != all_element_animations.end()) { | 336 if (iter != all_element_animations.end()) { |
335 switch (events->events_[event_index].type) { | 337 switch (events->events_[event_index].type) { |
336 case AnimationEvent::STARTED: | 338 case AnimationEvent::STARTED: |
337 (*iter).second->NotifyAnimationStarted(events->events_[event_index]); | 339 (*iter).second->NotifyAnimationStarted(events->events_[event_index]); |
338 break; | 340 break; |
339 | 341 |
340 case AnimationEvent::FINISHED: | 342 case AnimationEvent::FINISHED: |
341 (*iter).second->NotifyAnimationFinished(events->events_[event_index]); | 343 (*iter).second->NotifyAnimationFinished(events->events_[event_index]); |
342 break; | 344 break; |
343 | 345 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 const { | 576 const { |
575 return ticking_players_; | 577 return ticking_players_; |
576 } | 578 } |
577 | 579 |
578 const AnimationHost::ElementToAnimationsMap& | 580 const AnimationHost::ElementToAnimationsMap& |
579 AnimationHost::element_animations_for_testing() const { | 581 AnimationHost::element_animations_for_testing() const { |
580 return element_to_animations_map_; | 582 return element_to_animations_map_; |
581 } | 583 } |
582 | 584 |
583 } // namespace cc | 585 } // namespace cc |
OLD | NEW |