| 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 "ui/views/animation/ink_drop_animation.h" | 5 #include "ui/views/animation/ink_drop_animation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "ui/base/ui_base_switches.h" | 10 #include "ui/base/ui_base_switches.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 GetRootLayer()->SetVisible(true); | 61 GetRootLayer()->SetVisible(true); |
| 62 } | 62 } |
| 63 | 63 |
| 64 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, | 64 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, |
| 65 animation_observer); | 65 animation_observer); |
| 66 animation_observer->SetActive(); | 66 animation_observer->SetActive(); |
| 67 // |this| may be deleted! |animation_observer| might synchronously call | 67 // |this| may be deleted! |animation_observer| might synchronously call |
| 68 // AnimationEndedCallback which can delete |this|. | 68 // AnimationEndedCallback which can delete |this|. |
| 69 } | 69 } |
| 70 | 70 |
| 71 void InkDropAnimation::SnapToActivated() { |
| 72 AbortAllAnimations(); |
| 73 // |animation_observer| will be deleted when AnimationEndedCallback() returns |
| 74 // true. |
| 75 // TODO(bruthig): Implement a safer ownership model for the |
| 76 // |animation_observer|. |
| 77 ui::CallbackLayerAnimationObserver* animation_observer = |
| 78 new ui::CallbackLayerAnimationObserver( |
| 79 base::Bind(&InkDropAnimation::AnimationStartedCallback, |
| 80 base::Unretained(this), InkDropState::ACTIVATED), |
| 81 base::Bind(&InkDropAnimation::AnimationEndedCallback, |
| 82 base::Unretained(this), InkDropState::ACTIVATED)); |
| 83 GetRootLayer()->SetVisible(true); |
| 84 target_ink_drop_state_ = InkDropState::ACTIVATED; |
| 85 animation_observer->SetActive(); |
| 86 } |
| 87 |
| 71 void InkDropAnimation::HideImmediately() { | 88 void InkDropAnimation::HideImmediately() { |
| 72 AbortAllAnimations(); | 89 AbortAllAnimations(); |
| 73 SetStateToHidden(); | 90 SetStateToHidden(); |
| 74 target_ink_drop_state_ = InkDropState::HIDDEN; | 91 target_ink_drop_state_ = InkDropState::HIDDEN; |
| 75 } | 92 } |
| 76 | 93 |
| 77 void InkDropAnimation::AnimationStartedCallback( | 94 void InkDropAnimation::AnimationStartedCallback( |
| 78 InkDropState ink_drop_state, | 95 InkDropState ink_drop_state, |
| 79 const ui::CallbackLayerAnimationObserver& observer) { | 96 const ui::CallbackLayerAnimationObserver& observer) { |
| 80 observer_->InkDropAnimationStarted(ink_drop_state); | 97 observer_->InkDropAnimationStarted(ink_drop_state); |
| 81 } | 98 } |
| 82 | 99 |
| 83 bool InkDropAnimation::AnimationEndedCallback( | 100 bool InkDropAnimation::AnimationEndedCallback( |
| 84 InkDropState ink_drop_state, | 101 InkDropState ink_drop_state, |
| 85 const ui::CallbackLayerAnimationObserver& observer) { | 102 const ui::CallbackLayerAnimationObserver& observer) { |
| 86 if (ink_drop_state == InkDropState::HIDDEN) | 103 if (ink_drop_state == InkDropState::HIDDEN) |
| 87 SetStateToHidden(); | 104 SetStateToHidden(); |
| 88 observer_->InkDropAnimationEnded(ink_drop_state, | 105 observer_->InkDropAnimationEnded(ink_drop_state, |
| 89 observer.aborted_count() | 106 observer.aborted_count() |
| 90 ? InkDropAnimationObserver::PRE_EMPTED | 107 ? InkDropAnimationObserver::PRE_EMPTED |
| 91 : InkDropAnimationObserver::SUCCESS); | 108 : InkDropAnimationObserver::SUCCESS); |
| 92 // |this| may be deleted! | 109 // |this| may be deleted! |
| 93 return true; | 110 return true; |
| 94 } | 111 } |
| 95 | 112 |
| 96 } // namespace views | 113 } // namespace views |
| OLD | NEW |