Chromium Code Reviews| 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_ripple.h" | 5 #include "ui/views/animation/ink_drop_ripple.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 24 matching lines...) Expand all Loading... | |
| 35 // two reasons. | 35 // two reasons. |
| 36 // 1. The attached observers must be notified of all animations started and | 36 // 1. The attached observers must be notified of all animations started and |
| 37 // ended. | 37 // ended. |
| 38 // 2. Not all state transitions is are valid, especially no-op transitions, | 38 // 2. Not all state transitions is are valid, especially no-op transitions, |
| 39 // and these should be detected by DCHECKs in AnimateStateChange(). | 39 // and these should be detected by DCHECKs in AnimateStateChange(). |
| 40 | 40 |
| 41 // |animation_observer| will be deleted when AnimationEndedCallback() returns | 41 // |animation_observer| will be deleted when AnimationEndedCallback() returns |
| 42 // true. | 42 // true. |
| 43 // TODO(bruthig): Implement a safer ownership model for the | 43 // TODO(bruthig): Implement a safer ownership model for the |
| 44 // |animation_observer|. | 44 // |animation_observer|. |
| 45 ui::CallbackLayerAnimationObserver* animation_observer = | 45 ui::CallbackLayerAnimationObserver* animation_observer = |
|
Evan Stade
2016/09/20 15:16:29
what happens to animation_observer when !GetRootLa
bruthig
2016/09/20 16:17:16
A test would be the best way to know for sure, but
| |
| 46 new ui::CallbackLayerAnimationObserver( | 46 new ui::CallbackLayerAnimationObserver( |
| 47 base::Bind(&InkDropRipple::AnimationStartedCallback, | 47 base::Bind(&InkDropRipple::AnimationStartedCallback, |
| 48 base::Unretained(this), ink_drop_state), | 48 base::Unretained(this), ink_drop_state), |
| 49 base::Bind(&InkDropRipple::AnimationEndedCallback, | 49 base::Bind(&InkDropRipple::AnimationEndedCallback, |
| 50 base::Unretained(this), ink_drop_state)); | 50 base::Unretained(this), ink_drop_state)); |
| 51 | 51 |
| 52 InkDropState old_ink_drop_state = target_ink_drop_state_; | 52 InkDropState old_ink_drop_state = target_ink_drop_state_; |
| 53 // Assign to |target_ink_drop_state_| before calling AnimateStateChange() so | 53 // Assign to |target_ink_drop_state_| before calling AnimateStateChange() so |
| 54 // that any observers notified as a side effect of the AnimateStateChange() | 54 // that any observers notified as a side effect of the AnimateStateChange() |
| 55 // will get the target InkDropState when calling GetInkDropState(). | 55 // will get the target InkDropState when calling GetInkDropState(). |
| 56 target_ink_drop_state_ = ink_drop_state; | 56 target_ink_drop_state_ = ink_drop_state; |
| 57 | 57 |
| 58 if (old_ink_drop_state == InkDropState::HIDDEN && | 58 if (GetRootLayer()) { |
| 59 target_ink_drop_state_ != InkDropState::HIDDEN) { | 59 if (old_ink_drop_state == InkDropState::HIDDEN && |
| 60 GetRootLayer()->SetVisible(true); | 60 target_ink_drop_state_ != InkDropState::HIDDEN) { |
| 61 GetRootLayer()->SetVisible(true); | |
| 62 } | |
| 63 | |
| 64 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, | |
| 65 animation_observer); | |
| 61 } | 66 } |
| 62 | |
| 63 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, | |
| 64 animation_observer); | |
| 65 animation_observer->SetActive(); | 67 animation_observer->SetActive(); |
| 66 // |this| may be deleted! |animation_observer| might synchronously call | 68 // |this| may be deleted! |animation_observer| might synchronously call |
| 67 // AnimationEndedCallback which can delete |this|. | 69 // AnimationEndedCallback which can delete |this|. |
| 68 } | 70 } |
| 69 | 71 |
| 70 void InkDropRipple::SnapToActivated() { | 72 void InkDropRipple::SnapToActivated() { |
| 71 AbortAllAnimations(); | 73 AbortAllAnimations(); |
| 72 // |animation_observer| will be deleted when AnimationEndedCallback() returns | 74 // |animation_observer| will be deleted when AnimationEndedCallback() returns |
| 73 // true. | 75 // true. |
| 74 // TODO(bruthig): Implement a safer ownership model for the | 76 // TODO(bruthig): Implement a safer ownership model for the |
| 75 // |animation_observer|. | 77 // |animation_observer|. |
| 76 ui::CallbackLayerAnimationObserver* animation_observer = | 78 ui::CallbackLayerAnimationObserver* animation_observer = |
| 77 new ui::CallbackLayerAnimationObserver( | 79 new ui::CallbackLayerAnimationObserver( |
| 78 base::Bind(&InkDropRipple::AnimationStartedCallback, | 80 base::Bind(&InkDropRipple::AnimationStartedCallback, |
| 79 base::Unretained(this), InkDropState::ACTIVATED), | 81 base::Unretained(this), InkDropState::ACTIVATED), |
| 80 base::Bind(&InkDropRipple::AnimationEndedCallback, | 82 base::Bind(&InkDropRipple::AnimationEndedCallback, |
| 81 base::Unretained(this), InkDropState::ACTIVATED)); | 83 base::Unretained(this), InkDropState::ACTIVATED)); |
| 82 GetRootLayer()->SetVisible(true); | 84 if (GetRootLayer()) |
| 85 GetRootLayer()->SetVisible(true); | |
| 83 target_ink_drop_state_ = InkDropState::ACTIVATED; | 86 target_ink_drop_state_ = InkDropState::ACTIVATED; |
| 84 animation_observer->SetActive(); | 87 animation_observer->SetActive(); |
| 85 } | 88 } |
| 86 | 89 |
| 90 bool InkDropRipple::IsVisible() { | |
| 91 return GetRootLayer() && GetRootLayer()->visible(); | |
| 92 } | |
| 93 | |
| 87 void InkDropRipple::HideImmediately() { | 94 void InkDropRipple::HideImmediately() { |
| 88 AbortAllAnimations(); | 95 AbortAllAnimations(); |
| 89 SetStateToHidden(); | 96 SetStateToHidden(); |
| 90 target_ink_drop_state_ = InkDropState::HIDDEN; | 97 target_ink_drop_state_ = InkDropState::HIDDEN; |
| 91 } | 98 } |
| 92 | 99 |
| 93 test::InkDropRippleTestApi* InkDropRipple::GetTestApi() { | 100 test::InkDropRippleTestApi* InkDropRipple::GetTestApi() { |
| 94 return nullptr; | 101 return nullptr; |
| 95 } | 102 } |
| 96 | 103 |
| 97 void InkDropRipple::AnimationStartedCallback( | 104 void InkDropRipple::AnimationStartedCallback( |
| 98 InkDropState ink_drop_state, | 105 InkDropState ink_drop_state, |
| 99 const ui::CallbackLayerAnimationObserver& observer) { | 106 const ui::CallbackLayerAnimationObserver& observer) { |
| 100 observer_->AnimationStarted(ink_drop_state); | 107 if (observer_) |
| 108 observer_->AnimationStarted(ink_drop_state); | |
| 101 } | 109 } |
| 102 | 110 |
| 103 bool InkDropRipple::AnimationEndedCallback( | 111 bool InkDropRipple::AnimationEndedCallback( |
| 104 InkDropState ink_drop_state, | 112 InkDropState ink_drop_state, |
| 105 const ui::CallbackLayerAnimationObserver& observer) { | 113 const ui::CallbackLayerAnimationObserver& observer) { |
| 106 if (ink_drop_state == InkDropState::HIDDEN) | 114 if (ink_drop_state == InkDropState::HIDDEN) |
| 107 SetStateToHidden(); | 115 SetStateToHidden(); |
| 108 observer_->AnimationEnded(ink_drop_state, | 116 if (observer_) { |
| 109 observer.aborted_count() | 117 observer_->AnimationEnded(ink_drop_state, |
| 110 ? InkDropAnimationEndedReason::PRE_EMPTED | 118 observer.aborted_count() |
| 111 : InkDropAnimationEndedReason::SUCCESS); | 119 ? InkDropAnimationEndedReason::PRE_EMPTED |
| 112 // |this| may be deleted! | 120 : InkDropAnimationEndedReason::SUCCESS); |
| 121 // |this| may be deleted! | |
| 122 } | |
| 113 return true; | 123 return true; |
| 114 } | 124 } |
| 115 | 125 |
| 116 } // namespace views | 126 } // namespace views |
| OLD | NEW |