Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: ui/views/animation/ink_drop_animation_controller_impl.cc

Issue 1757993004: Added ink drop hover/ripple to menu hosting bookmark buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed sky@ & varkha@ comments. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 is_hovered_(false),
57 hover_after_animation_timer_(nullptr) { 58 hover_after_animation_timer_(nullptr) {
58 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer"); 59 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer");
59 ink_drop_host_->AddInkDropLayer(root_layer_.get()); 60 ink_drop_host_->AddInkDropLayer(root_layer_.get());
60 } 61 }
61 62
62 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { 63 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() {
63 // Explicitly destroy the InkDropAnimation so that this still exists if 64 // Explicitly destroy the InkDropAnimation so that this still exists if
64 // views::InkDropAnimationObserver methods are called on this. 65 // views::InkDropAnimationObserver methods are called on this.
65 DestroyInkDropAnimation(); 66 DestroyInkDropAnimation();
66 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 67 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
(...skipping 12 matching lines...) Expand all
79 void InkDropAnimationControllerImpl::AnimateToState( 80 void InkDropAnimationControllerImpl::AnimateToState(
80 InkDropState ink_drop_state) { 81 InkDropState ink_drop_state) {
81 if (!ink_drop_animation_) 82 if (!ink_drop_animation_)
82 CreateInkDropAnimation(); 83 CreateInkDropAnimation();
83 84
84 if (ink_drop_state != views::InkDropState::HIDDEN) { 85 if (ink_drop_state != views::InkDropState::HIDDEN) {
85 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( 86 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds(
86 kHoverFadeOutBeforeAnimationDurationInMs)); 87 kHoverFadeOutBeforeAnimationDurationInMs));
87 } 88 }
88 89
89 // Make sure the ink drop starts from the HIDDEN state it was going to auto 90 CompleteHiddenTargetedAnimations();
90 // transition to it.
91 if (ink_drop_animation_->target_ink_drop_state() == InkDropState::HIDDEN ||
92 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state())) {
93 ink_drop_animation_->HideImmediately();
94 }
95 ink_drop_animation_->AnimateToState(ink_drop_state); 91 ink_drop_animation_->AnimateToState(ink_drop_state);
96 } 92 }
97 93
94 void InkDropAnimationControllerImpl::SnapToActivated() {
95 if (!ink_drop_animation_)
96 CreateInkDropAnimation();
97
98 SetHoveredInternal(false, base::TimeDelta());
99
100 CompleteHiddenTargetedAnimations();
101 ink_drop_animation_->SnapToActivated();
102 }
103
98 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { 104 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) {
105 is_hovered_ = is_hovered;
99 SetHoveredInternal(is_hovered, 106 SetHoveredInternal(is_hovered,
100 is_hovered ? base::TimeDelta::FromMilliseconds( 107 is_hovered ? base::TimeDelta::FromMilliseconds(
101 kHoverFadeInFromUserInputDurationInMs) 108 kHoverFadeInFromUserInputDurationInMs)
102 : base::TimeDelta::FromMilliseconds( 109 : base::TimeDelta::FromMilliseconds(
103 kHoverFadeOutFromUserInputDurationInMs)); 110 kHoverFadeOutFromUserInputDurationInMs));
104 } 111 }
105 112
113 void InkDropAnimationControllerImpl::CompleteHiddenTargetedAnimations() {
114 if (ink_drop_animation_->target_ink_drop_state() == InkDropState::HIDDEN ||
115 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state())) {
116 ink_drop_animation_->HideImmediately();
117 }
118 }
119
106 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { 120 void InkDropAnimationControllerImpl::CreateInkDropAnimation() {
107 DestroyInkDropAnimation(); 121 DestroyInkDropAnimation();
108 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation(); 122 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation();
109 ink_drop_animation_->set_observer(this); 123 ink_drop_animation_->set_observer(this);
110 root_layer_->Add(ink_drop_animation_->GetRootLayer()); 124 root_layer_->Add(ink_drop_animation_->GetRootLayer());
111 } 125 }
112 126
113 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { 127 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() {
114 if (!ink_drop_animation_) 128 if (!ink_drop_animation_)
115 return; 129 return;
(...skipping 26 matching lines...) Expand all
142 } 156 }
143 157
144 void InkDropAnimationControllerImpl::InkDropAnimationEnded( 158 void InkDropAnimationControllerImpl::InkDropAnimationEnded(
145 InkDropState ink_drop_state, 159 InkDropState ink_drop_state,
146 InkDropAnimationEndedReason reason) { 160 InkDropAnimationEndedReason reason) {
147 if (reason != SUCCESS) 161 if (reason != SUCCESS)
148 return; 162 return;
149 if (ShouldAnimateToHidden(ink_drop_state)) { 163 if (ShouldAnimateToHidden(ink_drop_state)) {
150 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); 164 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
151 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 165 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
152 StartHoverAfterAnimationTimer(); 166 if (is_hovered_)
167 StartHoverAfterAnimationTimer();
153 // TODO(bruthig): Investigate whether creating and destroying 168 // TODO(bruthig): Investigate whether creating and destroying
154 // InkDropAnimations is expensive and consider creating an 169 // InkDropAnimations is expensive and consider creating an
155 // InkDropAnimationPool. See www.crbug.com/522175. 170 // InkDropAnimationPool. See www.crbug.com/522175.
156 DestroyInkDropAnimation(); 171 DestroyInkDropAnimation();
157 } 172 }
158 } 173 }
159 174
160 void InkDropAnimationControllerImpl::SetHoveredInternal( 175 void InkDropAnimationControllerImpl::SetHoveredInternal(
161 bool is_hovered, 176 bool is_hovered,
162 base::TimeDelta animation_duration) { 177 base::TimeDelta animation_duration) {
(...skipping 29 matching lines...) Expand all
192 hover_after_animation_timer_.reset(); 207 hover_after_animation_timer_.reset();
193 } 208 }
194 209
195 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { 210 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() {
196 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( 211 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds(
197 kHoverFadeInAfterAnimationDurationInMs)); 212 kHoverFadeInAfterAnimationDurationInMs));
198 hover_after_animation_timer_.reset(); 213 hover_after_animation_timer_.reset();
199 } 214 }
200 215
201 } // namespace views 216 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698