Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/scroll_offset_animations.h" | 5 #include "cc/animation/scroll_offset_animations.h" |
| 6 | 6 |
| 7 #include "cc/animation/animation_host.h" | 7 #include "cc/animation/animation_host.h" |
| 8 | 8 |
| 9 namespace cc { | 9 namespace cc { |
| 10 | 10 |
| 11 ScrollOffsetAnimationUpdate::ScrollOffsetAnimationUpdate(Type type, | 11 ScrollOffsetAnimationUpdate::ScrollOffsetAnimationUpdate(ElementId element_id) |
| 12 ElementId element_id) | 12 : element_id_(element_id) {} |
|
ajuma
2016/05/24 23:25:09
takeover_ needs to be initialized here
ymalik
2016/05/25 16:09:05
Thanks! Done.
| |
| 13 : type_(type), element_id_(element_id) {} | |
| 14 | 13 |
| 15 ScrollOffsetAnimations::ScrollOffsetAnimations(AnimationHost* animation_host) | 14 ScrollOffsetAnimations::ScrollOffsetAnimations(AnimationHost* animation_host) |
| 16 : animation_host_(animation_host) {} | 15 : animation_host_(animation_host) {} |
| 17 | 16 |
| 18 ScrollOffsetAnimations::~ScrollOffsetAnimations() {} | 17 ScrollOffsetAnimations::~ScrollOffsetAnimations() {} |
| 19 | 18 |
| 20 void ScrollOffsetAnimations::AddUpdate(ScrollOffsetAnimationUpdate update) { | 19 ScrollOffsetAnimationUpdate ScrollOffsetAnimations::GetUpdateForElementId( |
| 21 queue_.push_back(update); | 20 ElementId element_id) const { |
| 21 DCHECK(element_id); | |
| 22 auto iter = element_to_update_map_.find(element_id); | |
| 23 return iter == element_to_update_map_.end() | |
| 24 ? ScrollOffsetAnimationUpdate(element_id) | |
| 25 : iter->second; | |
| 26 } | |
| 27 | |
| 28 void ScrollOffsetAnimations::AddAdjustmentUpdate(ElementId element_id, | |
| 29 gfx::Vector2dF adjustment) { | |
| 30 DCHECK(element_id); | |
| 31 ScrollOffsetAnimationUpdate update = GetUpdateForElementId(element_id); | |
| 32 update.adjustment_ += adjustment; | |
| 33 element_to_update_map_.insert(std::make_pair(element_id, update)); | |
|
skobes
2016/05/24 23:50:50
Hmm, I think unordered_map::insert will not replac
ymalik
2016/05/25 16:09:05
Good catch. Done!
| |
| 34 animation_host_->SetNeedsCommit(); | |
| 35 } | |
| 36 | |
| 37 void ScrollOffsetAnimations::AddTakeoverUpdate(ElementId element_id) { | |
| 38 DCHECK(element_id); | |
| 39 ScrollOffsetAnimationUpdate update = GetUpdateForElementId(element_id); | |
| 40 update.takeover_ = true; | |
| 41 element_to_update_map_.insert(std::make_pair(element_id, update)); | |
| 22 animation_host_->SetNeedsCommit(); | 42 animation_host_->SetNeedsCommit(); |
| 23 } | 43 } |
| 24 | 44 |
| 25 bool ScrollOffsetAnimations::HasUpdatesForTesting() const { | 45 bool ScrollOffsetAnimations::HasUpdatesForTesting() const { |
| 26 return !queue_.empty(); | 46 return !element_to_update_map_.empty(); |
| 27 } | 47 } |
| 28 | 48 |
| 29 void ScrollOffsetAnimations::PushPropertiesTo( | 49 void ScrollOffsetAnimations::PushPropertiesTo( |
| 30 ScrollOffsetAnimationsImpl* animations) { | 50 ScrollOffsetAnimationsImpl* animations) { |
| 31 DCHECK(animations); | 51 DCHECK(animations); |
| 32 if (queue_.empty()) | 52 if (element_to_update_map_.empty()) |
| 33 return; | 53 return; |
| 34 | 54 |
| 35 for (auto& update : queue_) { | 55 for (auto& kv : element_to_update_map_) { |
| 36 switch (update.type_) { | 56 const auto& update = kv.second; |
| 37 case ScrollOffsetAnimationUpdate::Type::SCROLL_OFFSET_CHANGED: | 57 if (update.takeover_) |
| 38 animations->ScrollAnimationApplyAdjustment(update.element_id_, | 58 animations->ScrollAnimationAbort(true /*needs_completion*/); |
| 39 update.adjustment_); | 59 else |
| 40 } | 60 animations->ScrollAnimationApplyAdjustment(update.element_id_, |
| 61 update.adjustment_); | |
| 41 } | 62 } |
| 42 queue_.clear(); | 63 element_to_update_map_.clear(); |
| 43 } | 64 } |
| 44 | 65 |
| 45 } // namespace cc | 66 } // namespace cc |
| OLD | NEW |