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_animation_controller_impl.h" | 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
| 10 #include "ui/views/animation/ink_drop_host.h" | 10 #include "ui/views/animation/ink_drop_host.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( | 53 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( |
| 54 InkDropHost* ink_drop_host) | 54 InkDropHost* ink_drop_host) |
| 55 : ink_drop_host_(ink_drop_host), | 55 : ink_drop_host_(ink_drop_host), |
| 56 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), | 56 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
| 57 can_destroy_after_hidden_animation_(true), | |
| 58 hover_after_animation_timer_(nullptr) { | 57 hover_after_animation_timer_(nullptr) { |
| 59 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer"); | 58 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer"); |
| 60 ink_drop_host_->AddInkDropLayer(root_layer_.get()); | 59 ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { | 62 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |
| 64 // Explicitly destroy the InkDropAnimation so that this still exists if | 63 // Explicitly destroy the InkDropAnimation so that this still exists if |
| 65 // views::InkDropAnimationObserver methods are called on this. | 64 // views::InkDropAnimationObserver methods are called on this. |
| 66 DestroyInkDropAnimation(); | 65 DestroyInkDropAnimation(); |
| 67 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); | 66 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); |
| 68 } | 67 } |
| 69 | 68 |
| 70 InkDropState InkDropAnimationControllerImpl::GetTargetInkDropState() const { | 69 InkDropState InkDropAnimationControllerImpl::GetTargetInkDropState() const { |
| 71 if (!ink_drop_animation_) | 70 if (!ink_drop_animation_) |
| 72 return InkDropState::HIDDEN; | 71 return InkDropState::HIDDEN; |
| 73 return ink_drop_animation_->GetTargetInkDropState(); | 72 return ink_drop_animation_->GetTargetInkDropState(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 bool InkDropAnimationControllerImpl::IsVisible() const { | 75 bool InkDropAnimationControllerImpl::IsVisible() const { |
| 77 return ink_drop_animation_ && ink_drop_animation_->IsVisible(); | 76 return ink_drop_animation_ && ink_drop_animation_->IsVisible(); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void InkDropAnimationControllerImpl::AnimateToState( | 79 void InkDropAnimationControllerImpl::AnimateToState( |
| 81 InkDropState ink_drop_state) { | 80 InkDropState ink_drop_state) { |
| 82 if (!ink_drop_animation_) | 81 if (!ink_drop_animation_) |
| 83 CreateInkDropAnimation(); | 82 CreateInkDropAnimation(); |
| 84 | 83 |
| 85 // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to | |
| 86 // know if it is safe to destroy the |ink_drop_animation_| and it is not safe | |
| 87 // when the notification is raised within a call to | |
| 88 // InkDropAnimation::AnimateToState(). | |
| 89 base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation( | |
| 90 &can_destroy_after_hidden_animation_, false); | |
| 91 | |
| 92 if (ink_drop_state != views::InkDropState::HIDDEN) { | 84 if (ink_drop_state != views::InkDropState::HIDDEN) { |
| 93 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( | 85 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( |
| 94 kHoverFadeOutBeforeAnimationDurationInMs)); | 86 kHoverFadeOutBeforeAnimationDurationInMs)); |
| 95 } | 87 } |
| 96 | 88 |
| 97 // Make sure the ink drop starts from the HIDDEN state it was going to auto | 89 // Make sure the ink drop starts from the HIDDEN state it was going to auto |
| 98 // transition to it. | 90 // transition to it. |
| 99 if (ink_drop_animation_->GetTargetInkDropState() == InkDropState::HIDDEN || | 91 if (ink_drop_animation_->GetTargetInkDropState() == InkDropState::HIDDEN || |
| 100 ShouldAnimateToHidden(ink_drop_animation_->GetTargetInkDropState())) { | 92 ShouldAnimateToHidden(ink_drop_animation_->GetTargetInkDropState())) { |
| 101 ink_drop_animation_->HideImmediately(); | 93 ink_drop_animation_->HideImmediately(); |
| 102 } | 94 } |
| 103 ink_drop_animation_->AnimateToState(ink_drop_state); | 95 ink_drop_animation_->AnimateToState(ink_drop_state); |
|
bruthig
2016/02/23 22:48:09
Here would be a good spot to note that |ink_drop_a
Evan Stade
2016/02/24 00:31:57
I don't think it's super helpful because the crash
bruthig
2016/02/24 15:46:55
Acknowledged.
| |
| 104 } | 96 } |
| 105 | 97 |
| 106 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { | 98 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { |
| 107 SetHoveredInternal(is_hovered, | 99 SetHoveredInternal(is_hovered, |
| 108 is_hovered ? base::TimeDelta::FromMilliseconds( | 100 is_hovered ? base::TimeDelta::FromMilliseconds( |
| 109 kHoverFadeInFromUserInputDurationInMs) | 101 kHoverFadeInFromUserInputDurationInMs) |
| 110 : base::TimeDelta::FromMilliseconds( | 102 : base::TimeDelta::FromMilliseconds( |
| 111 kHoverFadeOutFromUserInputDurationInMs)); | 103 kHoverFadeOutFromUserInputDurationInMs)); |
| 112 } | 104 } |
| 113 | 105 |
| 114 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { | 106 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { |
| 115 DestroyInkDropAnimation(); | 107 DestroyInkDropAnimation(); |
| 116 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation(); | 108 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation(); |
| 117 ink_drop_animation_->AddObserver(this); | 109 ink_drop_animation_->set_observer(this); |
| 118 root_layer_->Add(ink_drop_animation_->GetRootLayer()); | 110 root_layer_->Add(ink_drop_animation_->GetRootLayer()); |
| 119 } | 111 } |
| 120 | 112 |
| 121 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { | 113 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { |
| 122 if (!ink_drop_animation_) | 114 if (!ink_drop_animation_) |
| 123 return; | 115 return; |
| 124 root_layer_->Remove(ink_drop_animation_->GetRootLayer()); | 116 root_layer_->Remove(ink_drop_animation_->GetRootLayer()); |
| 125 ink_drop_animation_->RemoveObserver(this); | |
| 126 ink_drop_animation_.reset(); | 117 ink_drop_animation_.reset(); |
| 127 } | 118 } |
| 128 | 119 |
| 129 void InkDropAnimationControllerImpl::CreateInkDropHover() { | 120 void InkDropAnimationControllerImpl::CreateInkDropHover() { |
| 130 DestroyInkDropHover(); | 121 DestroyInkDropHover(); |
| 131 | 122 |
| 132 hover_ = ink_drop_host_->CreateInkDropHover(); | 123 hover_ = ink_drop_host_->CreateInkDropHover(); |
| 133 if (!hover_) | 124 if (!hover_) |
| 134 return; | 125 return; |
| 135 root_layer_->Add(hover_->layer()); | 126 root_layer_->Add(hover_->layer()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 152 | 143 |
| 153 void InkDropAnimationControllerImpl::InkDropAnimationEnded( | 144 void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
| 154 InkDropState ink_drop_state, | 145 InkDropState ink_drop_state, |
| 155 InkDropAnimationEndedReason reason) { | 146 InkDropAnimationEndedReason reason) { |
| 156 if (reason != SUCCESS) | 147 if (reason != SUCCESS) |
| 157 return; | 148 return; |
| 158 if (ShouldAnimateToHidden(ink_drop_state)) { | 149 if (ShouldAnimateToHidden(ink_drop_state)) { |
| 159 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); | 150 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); |
| 160 } else if (ink_drop_state == views::InkDropState::HIDDEN) { | 151 } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
| 161 StartHoverAfterAnimationTimer(); | 152 StartHoverAfterAnimationTimer(); |
| 162 if (can_destroy_after_hidden_animation_) { | 153 // TODO(bruthig): Investigate whether creating and destroying |
| 163 // TODO(bruthig): Investigate whether creating and destroying | 154 // InkDropAnimations is expensive and consider creating an |
| 164 // InkDropAnimations is expensive and consider creating an | 155 // InkDropAnimationPool. See www.crbug.com/522175. |
| 165 // InkDropAnimationPool. See www.crbug.com/522175. | 156 DestroyInkDropAnimation(); |
| 166 DestroyInkDropAnimation(); | |
| 167 } | |
| 168 } | 157 } |
| 169 } | 158 } |
| 170 | 159 |
| 171 void InkDropAnimationControllerImpl::SetHoveredInternal( | 160 void InkDropAnimationControllerImpl::SetHoveredInternal( |
| 172 bool is_hovered, | 161 bool is_hovered, |
| 173 base::TimeDelta animation_duration) { | 162 base::TimeDelta animation_duration) { |
| 174 StopHoverAfterAnimationTimer(); | 163 StopHoverAfterAnimationTimer(); |
| 175 | 164 |
| 176 if (IsHoverFadingInOrVisible() == is_hovered) | 165 if (IsHoverFadingInOrVisible() == is_hovered) |
| 177 return; | 166 return; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 203 hover_after_animation_timer_.reset(); | 192 hover_after_animation_timer_.reset(); |
| 204 } | 193 } |
| 205 | 194 |
| 206 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { | 195 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { |
| 207 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( | 196 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( |
| 208 kHoverFadeInAfterAnimationDurationInMs)); | 197 kHoverFadeInAfterAnimationDurationInMs)); |
| 209 hover_after_animation_timer_.reset(); | 198 hover_after_animation_timer_.reset(); |
| 210 } | 199 } |
| 211 | 200 |
| 212 } // namespace views | 201 } // namespace views |
| OLD | NEW |