 Chromium Code Reviews
 Chromium Code Reviews Issue 2001843002:
  Use ink drop hover for focus states on toolbar buttons and location  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2001843002:
  Use ink drop hover for focus states on toolbar buttons and location  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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_impl.h" | 5 #include "ui/views/animation/ink_drop_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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } | 
| 49 } | 49 } | 
| 50 | 50 | 
| 51 } // namespace | 51 } // namespace | 
| 52 | 52 | 
| 53 InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host) | 53 InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host) | 
| 54 : ink_drop_host_(ink_drop_host), | 54 : ink_drop_host_(ink_drop_host), | 
| 55 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), | 55 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), | 
| 56 root_layer_added_to_host_(false), | 56 root_layer_added_to_host_(false), | 
| 57 is_hovered_(false), | 57 is_hovered_(false), | 
| 58 is_focused_(false), | |
| 58 hover_after_ripple_timer_(nullptr) { | 59 hover_after_ripple_timer_(nullptr) { | 
| 59 root_layer_->set_name("InkDropImpl:RootLayer"); | 60 root_layer_->set_name("InkDropImpl:RootLayer"); | 
| 60 } | 61 } | 
| 61 | 62 | 
| 62 InkDropImpl::~InkDropImpl() { | 63 InkDropImpl::~InkDropImpl() { | 
| 63 // Explicitly destroy the InkDropRipple so that this still exists if | 64 // Explicitly destroy the InkDropRipple so that this still exists if | 
| 64 // views::InkDropRippleObserver methods are called on this. | 65 // views::InkDropRippleObserver methods are called on this. | 
| 65 DestroyInkDropRipple(); | 66 DestroyInkDropRipple(); | 
| 66 DestroyInkDropHover(); | 67 DestroyInkDropHover(); | 
| 67 } | 68 } | 
| 68 | 69 | 
| 69 InkDropState InkDropImpl::GetTargetInkDropState() const { | 70 InkDropState InkDropImpl::GetTargetInkDropState() const { | 
| 70 if (!ink_drop_ripple_) | 71 if (!ink_drop_ripple_) | 
| 71 return InkDropState::HIDDEN; | 72 return InkDropState::HIDDEN; | 
| 72 return ink_drop_ripple_->target_ink_drop_state(); | 73 return ink_drop_ripple_->target_ink_drop_state(); | 
| 73 } | 74 } | 
| 74 | 75 | 
| 75 bool InkDropImpl::IsVisible() const { | 76 bool InkDropImpl::IsVisible() const { | 
| 76 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible(); | 77 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible(); | 
| 77 } | 78 } | 
| 78 | 79 | 
| 79 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { | 80 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { | 
| 80 DestroyHiddenTargetedAnimations(); | 81 DestroyHiddenTargetedAnimations(); | 
| 81 if (!ink_drop_ripple_) | 82 if (!ink_drop_ripple_) | 
| 82 CreateInkDropRipple(); | 83 CreateInkDropRipple(); | 
| 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 SetHighlight(false, base::TimeDelta::FromMilliseconds( | 
| 86 kHoverFadeOutBeforeRippleDurationInMs), | 87 kHoverFadeOutBeforeRippleDurationInMs), | 
| 87 true); | 88 true); | 
| 88 } | 89 } | 
| 89 | 90 | 
| 90 ink_drop_ripple_->AnimateToState(ink_drop_state); | 91 ink_drop_ripple_->AnimateToState(ink_drop_state); | 
| 91 } | 92 } | 
| 92 | 93 | 
| 93 void InkDropImpl::SnapToActivated() { | 94 void InkDropImpl::SnapToActivated() { | 
| 94 DestroyHiddenTargetedAnimations(); | 95 DestroyHiddenTargetedAnimations(); | 
| 95 if (!ink_drop_ripple_) | 96 if (!ink_drop_ripple_) | 
| 96 CreateInkDropRipple(); | 97 CreateInkDropRipple(); | 
| 97 | 98 | 
| 98 SetHoveredInternal(false, base::TimeDelta(), false); | 99 SetHighlight(false, base::TimeDelta(), false); | 
| 99 | 100 | 
| 100 ink_drop_ripple_->SnapToActivated(); | 101 ink_drop_ripple_->SnapToActivated(); | 
| 101 } | 102 } | 
| 102 | 103 | 
| 103 void InkDropImpl::SetHovered(bool is_hovered) { | 104 void InkDropImpl::SetHovered(bool is_hovered) { | 
| 104 is_hovered_ = is_hovered; | 105 is_hovered_ = is_hovered; | 
| 105 SetHoveredInternal(is_hovered, | 106 SetHighlight(ShouldHighlight(), | 
| 106 is_hovered ? base::TimeDelta::FromMilliseconds( | 107 ShouldHighlight() ? base::TimeDelta::FromMilliseconds( | 
| 107 kHoverFadeInFromUserInputDurationInMs) | 108 kHoverFadeInFromUserInputDurationInMs) | 
| 108 : base::TimeDelta::FromMilliseconds( | 109 : base::TimeDelta::FromMilliseconds( | 
| 109 kHoverFadeOutFromUserInputDurationInMs), | 110 kHoverFadeOutFromUserInputDurationInMs), | 
| 110 false); | 111 false); | 
| 112 } | |
| 113 | |
| 114 void InkDropImpl::SetFocused(bool is_focused) { | |
| 115 NOTIMPLEMENTED() << " DAS BLUNT"; | |
| 
bruthig
2016/05/26 19:04:36
is this wanted?
 
Evan Stade
2016/05/26 19:06:55
must have been a stray cosmic ray
 | |
| 116 is_focused_ = is_focused; | |
| 117 SetHighlight(ShouldHighlight(), base::TimeDelta(), false); | |
| 111 } | 118 } | 
| 112 | 119 | 
| 113 void InkDropImpl::DestroyHiddenTargetedAnimations() { | 120 void InkDropImpl::DestroyHiddenTargetedAnimations() { | 
| 114 if (ink_drop_ripple_ && | 121 if (ink_drop_ripple_ && | 
| 115 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || | 122 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || | 
| 116 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { | 123 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { | 
| 117 DestroyInkDropRipple(); | 124 DestroyInkDropRipple(); | 
| 118 } | 125 } | 
| 119 } | 126 } | 
| 120 | 127 | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 208 } | 
| 202 | 209 | 
| 203 void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type, | 210 void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type, | 
| 204 InkDropAnimationEndedReason reason) { | 211 InkDropAnimationEndedReason reason) { | 
| 205 if (animation_type == InkDropHover::FADE_OUT && | 212 if (animation_type == InkDropHover::FADE_OUT && | 
| 206 reason == InkDropAnimationEndedReason::SUCCESS) { | 213 reason == InkDropAnimationEndedReason::SUCCESS) { | 
| 207 DestroyInkDropHover(); | 214 DestroyInkDropHover(); | 
| 208 } | 215 } | 
| 209 } | 216 } | 
| 210 | 217 | 
| 211 void InkDropImpl::SetHoveredInternal(bool is_hovered, | 218 void InkDropImpl::SetHighlight(bool should_highlight, | 
| 212 base::TimeDelta animation_duration, | 219 base::TimeDelta animation_duration, | 
| 213 bool explode) { | 220 bool explode) { | 
| 214 StopHoverAfterRippleTimer(); | 221 StopHoverAfterRippleTimer(); | 
| 215 | 222 | 
| 216 if (IsHoverFadingInOrVisible() == is_hovered) | 223 if (IsHoverFadingInOrVisible() == should_highlight) | 
| 217 return; | 224 return; | 
| 218 | 225 | 
| 219 if (is_hovered) { | 226 if (should_highlight) { | 
| 220 CreateInkDropHover(); | 227 CreateInkDropHover(); | 
| 221 if (hover_ && !IsVisible()) | 228 if (hover_ && !IsVisible()) | 
| 222 hover_->FadeIn(animation_duration); | 229 hover_->FadeIn(animation_duration); | 
| 223 } else { | 230 } else { | 
| 224 hover_->FadeOut(animation_duration, explode); | 231 hover_->FadeOut(animation_duration, explode); | 
| 225 } | 232 } | 
| 226 } | 233 } | 
| 227 | 234 | 
| 235 bool InkDropImpl::ShouldHighlight() const { | |
| 236 return is_focused_ || is_hovered_; | |
| 237 } | |
| 238 | |
| 228 void InkDropImpl::StartHoverAfterRippleTimer() { | 239 void InkDropImpl::StartHoverAfterRippleTimer() { | 
| 229 StopHoverAfterRippleTimer(); | 240 StopHoverAfterRippleTimer(); | 
| 230 | 241 | 
| 231 if (!hover_after_ripple_timer_) | 242 if (!hover_after_ripple_timer_) | 
| 232 hover_after_ripple_timer_.reset(new base::OneShotTimer); | 243 hover_after_ripple_timer_.reset(new base::OneShotTimer); | 
| 233 | 244 | 
| 234 hover_after_ripple_timer_->Start( | 245 hover_after_ripple_timer_->Start( | 
| 235 FROM_HERE, | 246 FROM_HERE, | 
| 236 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs), | 247 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs), | 
| 237 base::Bind(&InkDropImpl::HoverAfterRippleTimerFired, | 248 base::Bind(&InkDropImpl::HoverAfterRippleTimerFired, | 
| 238 base::Unretained(this))); | 249 base::Unretained(this))); | 
| 239 } | 250 } | 
| 240 | 251 | 
| 241 void InkDropImpl::StopHoverAfterRippleTimer() { | 252 void InkDropImpl::StopHoverAfterRippleTimer() { | 
| 242 if (hover_after_ripple_timer_) | 253 if (hover_after_ripple_timer_) | 
| 243 hover_after_ripple_timer_.reset(); | 254 hover_after_ripple_timer_.reset(); | 
| 244 } | 255 } | 
| 245 | 256 | 
| 246 void InkDropImpl::HoverAfterRippleTimerFired() { | 257 void InkDropImpl::HoverAfterRippleTimerFired() { | 
| 247 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( | 258 SetHighlight(true, base::TimeDelta::FromMilliseconds( | 
| 248 kHoverFadeInAfterRippleDurationInMs), | 259 kHoverFadeInAfterRippleDurationInMs), | 
| 249 true); | 260 true); | 
| 250 hover_after_ripple_timer_.reset(); | 261 hover_after_ripple_timer_.reset(); | 
| 251 } | 262 } | 
| 252 | 263 | 
| 253 } // namespace views | 264 } // namespace views | 
| OLD | NEW |