Chromium Code Reviews| Index: ui/views/animation/ink_drop_impl.cc |
| diff --git a/ui/views/animation/ink_drop_impl.cc b/ui/views/animation/ink_drop_impl.cc |
| index c252d325fb0893d7fdee6f6d11d11caacf0f4670..212b5de41b8a0814ba42c0c90a64d73fe7283811 100644 |
| --- a/ui/views/animation/ink_drop_impl.cc |
| +++ b/ui/views/animation/ink_drop_impl.cc |
| @@ -15,21 +15,27 @@ namespace views { |
| namespace { |
| -// The duration, in milliseconds, of the highlight state fade in animation when |
| -// it is triggered by user input. |
| -const int kHighlightFadeInFromUserInputDurationMs = 250; |
| - |
| -// The duration, in milliseconds, of the highlight state fade out animation when |
| -// it is triggered by user input. |
| -const int kHighlightFadeOutFromUserInputDurationMs = 250; |
| - |
| -// The duration, in milliseconds, of the highlight state fade in animation when |
| -// it is triggered by an ink drop ripple animation ending. |
| -const int kHighlightFadeInAfterRippleDurationMs = 250; |
| - |
| -// The duration, in milliseconds, of the highlight state fade out animation when |
| -// it is triggered by an ink drop ripple animation starting. |
| -const int kHighlightFadeOutBeforeRippleDurationMs = 120; |
| +// The duration, in milliseconds for the highlight state fade in/out animations |
| +// when it is triggered by a hover changed event. |
| +const int kHighlightFadeInOnHoverChangeDurationMs = 250; |
| +const int kHighlightFadeOutOnHoverChangeDurationMs = 250; |
| + |
| +// The duration, in milliseconds for the highlight state fade in/out animations |
| +// when it is triggered by a focus changed event. |
| +const int kHighlightFadeInOnFocusChangeDurationMs = 0; |
| +const int kHighlightFadeOutOnFocusChangeDurationMs = 0; |
| + |
| +// The duration, in milliseconds, for showing/hiding the highlight when |
| +// triggered by ripple visibility changes for the HIDE_ON_RIPPLE |
| +// AutoHighlightMode. |
| +const int kHighlightFadeInOnRippleHidingDurationMs = 250; |
| +const int kHighlightFadeOutOnRippleShowingDurationMs = 120; |
| + |
| +// The duration, in milliseconds, for showing/hiding the highlight when |
| +// triggered by ripple visibility changes for the SHOW_ON_RIPPLE |
| +// AutoHighlightMode. |
| +const int kHighlightFadeInOnRippleShowingDurationMs = 250; |
| +const int kHighlightFadeOutOnRippleHidingDurationMs = 120; |
| // The amount of time in milliseconds that |highlight_| should delay after a |
| // ripple animation before fading in, for highlight due to mouse hover. |
| @@ -50,13 +56,570 @@ bool ShouldAnimateToHidden(InkDropState ink_drop_state) { |
| } // namespace |
| +// Creates the different HighlightStates instances. |
| +class InkDropImpl::HighlightStateFactory { |
| + public: |
| + HighlightStateFactory(AutoHighlightMode highlight_mode, |
| + InkDropImpl* ink_drop); |
| + |
| + // Returns the initial state. |
| + std::unique_ptr<InkDropImpl::HighlightState> CreateStartState(); |
| + |
| + std::unique_ptr<InkDropImpl::HighlightState> CreateHiddenState( |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + std::unique_ptr<InkDropImpl::HighlightState> CreateVisibleState( |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + InkDropImpl* ink_drop() { return ink_drop_; } |
| + |
| + private: |
| + // Defines which state machine flavors to use. |
| + AutoHighlightMode highlight_mode_; |
| + |
| + // The ink drop to invoke highlight changes on. |
| + InkDropImpl* ink_drop_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HighlightStateFactory); |
| +}; |
| + |
| +// Base HighlightState defining functions to handle all input that may affects |
| +// the highlight state. |
|
sky
2016/11/02 02:52:11
Please document what the expectation is for subcla
bruthig
2016/11/04 18:50:36
Done.
|
| +class InkDropImpl::HighlightState { |
| + public: |
| + virtual ~HighlightState() {} |
| + |
| + // Called when |this| becomes the current state. Allows subclasses to perform |
| + // any work that should not be done in the constructor. |
| + virtual void Enter() {} |
| + |
| + // Called just before |this| is removed as the current state. Allows |
| + // subclasses to perform any work that should not be done in the destructor. |
| + virtual void Exit() {} |
| + |
| + // Called when the value of InkDropImpl::show_highlight_on_hover_ changes. |
| + virtual void ShowOnHoverChanged() {} |
|
sky
2016/11/02 02:52:11
optional: is there a reason you aren't making thes
bruthig
2016/11/04 18:50:37
Done.
|
| + |
| + // Called when the value of InkDropImpl::is_hovered_ changes. |
| + virtual void OnHoverChanged() {} |
| + |
| + // Called when the value of InkDropImpl::show_highlight_on_focus_ changes. |
| + virtual void ShowOnFocusChanged() {} |
| + |
| + // Called when the value of InkDropImpl::is_focused_ changes. |
| + virtual void OnFocusChanged() {} |
| + |
| + // Called when an ink drop ripple animation is started. |
| + virtual void AnimationStarted(InkDropState ink_drop_state) {} |
| + |
| + // Called when an ink drop ripple animation has ended. |
| + virtual void AnimationEnded(InkDropState ink_drop_state, |
| + InkDropAnimationEndedReason reason) {} |
| + |
| + protected: |
| + explicit HighlightState(HighlightStateFactory* state_factory) |
| + : state_factory_(state_factory) {} |
| + |
| + HighlightStateFactory* state_factory() { return state_factory_; } |
| + |
| + // Returns the ink drop that has |this| as the current state. |
| + InkDropImpl* GetInkDrop(); |
| + |
| + private: |
| + // Used by |this| to create the new states to transition to. |
| + HighlightStateFactory* state_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HighlightState); |
| +}; |
| + |
| +// HighlightState definition |
| + |
| +InkDropImpl* InkDropImpl::HighlightState::GetInkDrop() { |
| + return state_factory_->ink_drop(); |
| +} |
| + |
| +// |
| +// AutoHighlightMode::NONE states |
| +// |
| + |
| +// Animates the highlight to hidden upon entering this state. Transitions to a |
| +// visible state based on hover/focus changes. |
| +class InkDropImpl::NoAutoHighlightHiddenState |
| + : public InkDropImpl::HighlightState { |
| + public: |
| + NoAutoHighlightHiddenState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::HighlightState: |
| + void Enter() override; |
| + void ShowOnHoverChanged() override; |
| + void OnHoverChanged() override; |
| + void ShowOnFocusChanged() override; |
| + void OnFocusChanged() override; |
| + |
| + private: |
| + // Handles all changes to the hover/focus status. |
| + void HandleHoverAndFocusChangeChanges(int animation_duration_ms); |
| + |
| + // The fade out animation duration. |
| + base::TimeDelta animation_duration_; |
| + |
| + // True when the highlight should explode while fading out. |
| + bool explode_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NoAutoHighlightHiddenState); |
| +}; |
| + |
| +// Animates the highlight to visible upon entering this state. Transitions to a |
| +// hidden state based on hover/focus changes. |
| +class InkDropImpl::NoAutoHighlightVisibleState |
| + : public InkDropImpl::HighlightState { |
| + public: |
| + NoAutoHighlightVisibleState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::HighlightState: |
| + void Enter() override; |
| + void ShowOnHoverChanged() override; |
| + void OnHoverChanged() override; |
| + void ShowOnFocusChanged() override; |
| + void OnFocusChanged() override; |
| + |
| + private: |
| + // Handles all changes to the hover/focus status. |
| + void HandleHoverAndFocusChangeChanges(int animation_duration_ms); |
| + |
| + // The fade in animation duration. |
| + base::TimeDelta animation_duration_; |
| + |
| + // True when the highlight should explode while fading in. |
| + bool explode_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NoAutoHighlightVisibleState); |
| +}; |
| + |
| +// NoAutoHighlightHiddenState definition |
| + |
| +InkDropImpl::NoAutoHighlightHiddenState::NoAutoHighlightHiddenState( |
| + HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::HighlightState(state_factory), |
| + animation_duration_(animation_duration), |
| + explode_(explode) {} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::Enter() { |
| + GetInkDrop()->SetHighlight(false, animation_duration_, explode_); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::ShowOnHoverChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeInOnHoverChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::OnHoverChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeInOnHoverChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::ShowOnFocusChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeInOnFocusChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::OnFocusChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeInOnFocusChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightHiddenState::HandleHoverAndFocusChangeChanges( |
| + int animation_duration_ms) { |
| + if (GetInkDrop()->ShouldHighlight()) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateVisibleState( |
| + base::TimeDelta::FromMilliseconds(animation_duration_ms), false)); |
| + } |
| +} |
| + |
| +// NoAutoHighlightVisibleState definition |
| + |
| +InkDropImpl::NoAutoHighlightVisibleState::NoAutoHighlightVisibleState( |
| + HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::HighlightState(state_factory), |
| + animation_duration_(animation_duration), |
| + explode_(explode) {} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::Enter() { |
| + GetInkDrop()->SetHighlight(true, animation_duration_, explode_); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::ShowOnHoverChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnHoverChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::OnHoverChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnHoverChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::ShowOnFocusChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnFocusChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::OnFocusChanged() { |
| + HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnFocusChangeDurationMs); |
| +} |
| + |
| +void InkDropImpl::NoAutoHighlightVisibleState::HandleHoverAndFocusChangeChanges( |
| + int animation_duration_ms) { |
| + if (!GetInkDrop()->ShouldHighlight()) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateHiddenState( |
| + base::TimeDelta::FromMilliseconds(animation_duration_ms), false)); |
| + } |
| +} |
| + |
| +// |
| +// AutoHighlightMode::HIDE_ON_RIPPLE states |
| +// |
| + |
| +// Extends the base hidden state to re-show the highlight after the ripple |
| +// becomes hidden. |
| +class InkDropImpl::HideHighlightOnRippleHiddenState |
| + : public InkDropImpl::NoAutoHighlightHiddenState { |
| + public: |
| + HideHighlightOnRippleHiddenState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::NoAutoHighlightHiddenState: |
| + void ShowOnHoverChanged() override; |
| + void OnHoverChanged() override; |
| + void ShowOnFocusChanged() override; |
| + void OnFocusChanged() override; |
| + void AnimationStarted(InkDropState ink_drop_state) override; |
| + void AnimationEnded(InkDropState ink_drop_state, |
| + InkDropAnimationEndedReason reason) override; |
| + |
| + private: |
| + // Starts the |highlight_after_ripple_timer_|. This will stop the current |
| + // |highlight_after_ripple_timer_| instance if it exists. |
| + void StartHighlightAfterRippleTimer(); |
| + |
| + // Callback for when the |highlight_after_ripple_timer_| fires. |
| + void HighlightAfterRippleTimerFired(); |
| + |
| + // The timer used to delay the highlight fade in after an ink drop ripple |
| + // animation. |
| + std::unique_ptr<base::Timer> highlight_after_ripple_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HideHighlightOnRippleHiddenState); |
| +}; |
| + |
| +// Extends the base visible state to hide the highlight when the ripple becomes |
| +// visible. |
| +class InkDropImpl::HideHighlightOnRippleVisibleState |
| + : public InkDropImpl::NoAutoHighlightVisibleState { |
| + public: |
| + HideHighlightOnRippleVisibleState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::NoAutoHighlightVisibleState: |
| + void AnimationStarted(InkDropState ink_drop_state) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HideHighlightOnRippleVisibleState); |
| +}; |
| + |
| +// HideHighlightOnRippleHiddenState definition |
| + |
| +InkDropImpl::HideHighlightOnRippleHiddenState::HideHighlightOnRippleHiddenState( |
| + HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::NoAutoHighlightHiddenState(state_factory, |
| + animation_duration, |
| + explode), |
| + highlight_after_ripple_timer_(nullptr) { |
| + LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::ShowOnHoverChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightHiddenState::ShowOnHoverChanged(); |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::OnHoverChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightHiddenState::OnHoverChanged(); |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::ShowOnFocusChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightHiddenState::ShowOnFocusChanged(); |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::OnFocusChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightHiddenState::OnFocusChanged(); |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::AnimationStarted( |
| + InkDropState ink_drop_state) { |
| + if (ink_drop_state == views::InkDropState::DEACTIVATED && |
| + GetInkDrop()->is_focused_) { |
| + GetInkDrop()->ink_drop_ripple_->HideImmediately(); |
| + GetInkDrop()->SetHighlightState( |
| + state_factory()->CreateVisibleState(base::TimeDelta(), false)); |
| + } |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState::AnimationEnded( |
| + InkDropState ink_drop_state, |
| + InkDropAnimationEndedReason reason) { |
| + if (ink_drop_state == InkDropState::HIDDEN) { |
| + // Re-highlight, as necessary. For hover, there's a delay; for focus, jump |
| + // straight into the animation. |
| + if (GetInkDrop()->ShouldHighlightBasedOnFocus()) { |
| + GetInkDrop()->SetHighlightState( |
| + state_factory()->CreateVisibleState(base::TimeDelta(), false)); |
| + return; |
| + } else { |
| + StartHighlightAfterRippleTimer(); |
| + } |
| + } |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState:: |
| + StartHighlightAfterRippleTimer() { |
| + highlight_after_ripple_timer_.reset(new base::OneShotTimer); |
| + highlight_after_ripple_timer_->Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayMs), |
| + base::Bind(&InkDropImpl::HideHighlightOnRippleHiddenState:: |
| + HighlightAfterRippleTimerFired, |
| + base::Unretained(this))); |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleHiddenState:: |
| + HighlightAfterRippleTimerFired() { |
| + highlight_after_ripple_timer_.reset(); |
| + if (GetInkDrop()->GetTargetInkDropState() == InkDropState::HIDDEN && |
| + GetInkDrop()->ShouldHighlight()) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateVisibleState( |
| + base::TimeDelta::FromMilliseconds( |
| + kHighlightFadeInOnRippleHidingDurationMs), |
| + true)); |
| + } |
| +} |
| + |
| +// HideHighlightOnRippleVisibleState definition |
| + |
| +InkDropImpl::HideHighlightOnRippleVisibleState:: |
| + HideHighlightOnRippleVisibleState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::NoAutoHighlightVisibleState(state_factory, |
| + animation_duration, |
| + explode) { |
| + LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
| +} |
| + |
| +void InkDropImpl::HideHighlightOnRippleVisibleState::AnimationStarted( |
| + InkDropState ink_drop_state) { |
| + if (ink_drop_state != InkDropState::HIDDEN) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateHiddenState( |
| + base::TimeDelta::FromMilliseconds( |
| + kHighlightFadeOutOnRippleShowingDurationMs), |
| + true)); |
| + } |
| +} |
| + |
| +// |
| +// AutoHighlightMode::SHOW_ON_RIPPLE states |
| +// |
| + |
| +// Extends the base hidden state to show the highlight when the ripple becomes |
| +// visible. |
| +class InkDropImpl::ShowHighlightOnRippleHiddenState |
| + : public InkDropImpl::NoAutoHighlightHiddenState { |
| + public: |
| + ShowHighlightOnRippleHiddenState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::NoAutoHighlightHiddenState: |
| + void AnimationStarted(InkDropState ink_drop_state) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ShowHighlightOnRippleHiddenState); |
| +}; |
| + |
| +// Extends the base visible state to hide the highlight when the ripple becomes |
| +// hidden. |
| +class InkDropImpl::ShowHighlightOnRippleVisibleState |
| + : public InkDropImpl::NoAutoHighlightVisibleState { |
| + public: |
| + ShowHighlightOnRippleVisibleState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode); |
| + |
| + // InkDropImpl::NoAutoHighlightVisibleState: |
| + void ShowOnHoverChanged() override; |
| + void OnHoverChanged() override; |
| + void ShowOnFocusChanged() override; |
| + void OnFocusChanged() override; |
| + void AnimationStarted(InkDropState ink_drop_state) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ShowHighlightOnRippleVisibleState); |
| +}; |
| + |
| +// ShowHighlightOnRippleHiddenState definition |
| + |
| +InkDropImpl::ShowHighlightOnRippleHiddenState::ShowHighlightOnRippleHiddenState( |
| + HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::NoAutoHighlightHiddenState(state_factory, |
| + animation_duration, |
| + explode) { |
| + LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleHiddenState::AnimationStarted( |
| + InkDropState ink_drop_state) { |
| + if (ink_drop_state != views::InkDropState::HIDDEN) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateVisibleState( |
| + base::TimeDelta::FromMilliseconds( |
| + kHighlightFadeInOnRippleShowingDurationMs), |
| + false)); |
| + } |
| +} |
| + |
| +// ShowHighlightOnRippleVisibleState definition |
| + |
| +InkDropImpl::ShowHighlightOnRippleVisibleState:: |
| + ShowHighlightOnRippleVisibleState(HighlightStateFactory* state_factory, |
| + base::TimeDelta animation_duration, |
| + bool explode) |
| + : InkDropImpl::NoAutoHighlightVisibleState(state_factory, |
| + animation_duration, |
| + explode) { |
| + LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleVisibleState::ShowOnHoverChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightVisibleState::ShowOnHoverChanged(); |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleVisibleState::OnHoverChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightVisibleState::OnHoverChanged(); |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleVisibleState::ShowOnFocusChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightVisibleState::ShowOnFocusChanged(); |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleVisibleState::OnFocusChanged() { |
| + if (GetInkDrop()->GetTargetInkDropState() != InkDropState::HIDDEN) |
| + return; |
| + NoAutoHighlightVisibleState::OnFocusChanged(); |
| +} |
| + |
| +void InkDropImpl::ShowHighlightOnRippleVisibleState::AnimationStarted( |
| + InkDropState ink_drop_state) { |
| + if (ink_drop_state == InkDropState::HIDDEN && |
| + !GetInkDrop()->ShouldHighlight()) { |
| + GetInkDrop()->SetHighlightState(state_factory()->CreateHiddenState( |
| + base::TimeDelta::FromMilliseconds( |
| + kHighlightFadeOutOnRippleHidingDurationMs), |
| + false)); |
| + } |
| +} |
| + |
| +InkDropImpl::HighlightStateFactory::HighlightStateFactory( |
| + InkDropImpl::AutoHighlightMode highlight_mode, |
| + InkDropImpl* ink_drop) |
| + : highlight_mode_(highlight_mode), ink_drop_(ink_drop) {} |
| + |
| +std::unique_ptr<InkDropImpl::HighlightState> |
| +InkDropImpl::HighlightStateFactory::CreateStartState() { |
| + switch (highlight_mode_) { |
| + case InkDropImpl::AutoHighlightMode::NONE: |
| + return base::MakeUnique<NoAutoHighlightHiddenState>( |
| + this, base::TimeDelta(), false); |
| + case InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE: |
| + return base::MakeUnique<HideHighlightOnRippleHiddenState>( |
| + this, base::TimeDelta(), false); |
| + case InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE: |
| + return base::MakeUnique<ShowHighlightOnRippleHiddenState>( |
| + this, base::TimeDelta(), false); |
| + } |
| + // Required for some compilers. |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| +std::unique_ptr<InkDropImpl::HighlightState> |
| +InkDropImpl::HighlightStateFactory::CreateHiddenState( |
| + base::TimeDelta animation_duration, |
| + bool explode) { |
| + switch (highlight_mode_) { |
| + case InkDropImpl::AutoHighlightMode::NONE: |
| + return base::MakeUnique<NoAutoHighlightHiddenState>( |
| + this, animation_duration, explode); |
| + case InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE: |
| + return base::MakeUnique<HideHighlightOnRippleHiddenState>( |
| + this, animation_duration, explode); |
| + case InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE: |
| + return base::MakeUnique<ShowHighlightOnRippleHiddenState>( |
| + this, animation_duration, explode); |
| + } |
| + // Required for some compilers. |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| +std::unique_ptr<InkDropImpl::HighlightState> |
| +InkDropImpl::HighlightStateFactory::CreateVisibleState( |
| + base::TimeDelta animation_duration, |
| + bool explode) { |
| + switch (highlight_mode_) { |
| + case InkDropImpl::AutoHighlightMode::NONE: |
| + return base::MakeUnique<NoAutoHighlightVisibleState>( |
| + this, animation_duration, explode); |
| + case InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE: |
| + return base::MakeUnique<HideHighlightOnRippleVisibleState>( |
| + this, animation_duration, explode); |
| + case InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE: |
| + return base::MakeUnique<ShowHighlightOnRippleVisibleState>( |
| + this, animation_duration, explode); |
| + } |
| + // Required for some compilers. |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host) |
| : ink_drop_host_(ink_drop_host), |
| root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
| root_layer_added_to_host_(false), |
| + show_highlight_on_hover_(true), |
| + show_highlight_on_focus_(false), |
| is_hovered_(false), |
| - is_focused_(false), |
| - highlight_after_ripple_timer_(nullptr) { |
| + is_focused_(false) { |
| + SetAutoHighlightMode(AutoHighlightMode::NONE); |
| root_layer_->set_name("InkDropImpl:RootLayer"); |
| } |
| @@ -67,6 +630,22 @@ InkDropImpl::~InkDropImpl() { |
| DestroyInkDropHighlight(); |
| } |
| +void InkDropImpl::SetShowHighlightOnHover(bool show_highlight_on_hover) { |
| + show_highlight_on_hover_ = show_highlight_on_hover; |
| + highlight_state_->ShowOnHoverChanged(); |
| +} |
| + |
| +void InkDropImpl::SetShowHighlightOnFocus(bool show_highlight_on_focus) { |
| + show_highlight_on_focus_ = show_highlight_on_focus; |
| + highlight_state_->ShowOnFocusChanged(); |
| +} |
| + |
| +void InkDropImpl::SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode) { |
| + highlight_state_factory_ = |
| + base::MakeUnique<HighlightStateFactory>(auto_highlight_mode, this); |
| + SetHighlightState(highlight_state_factory_->CreateStartState()); |
| +} |
| + |
| InkDropState InkDropImpl::GetTargetInkDropState() const { |
| if (!ink_drop_ripple_) |
| return InkDropState::HIDDEN; |
| @@ -83,24 +662,6 @@ void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { |
| DestroyHiddenTargetedAnimations(); |
| if (!ink_drop_ripple_) |
| CreateInkDropRipple(); |
| - |
| - if (ink_drop_ripple_->OverridesHighlight()) { |
| - // When deactivating and the host is focused, snap back to the highlight |
| - // state. (In the case of highlighting due to hover, we'll animate the |
| - // highlight back in after a delay.) |
| - if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) { |
| - ink_drop_ripple_->HideImmediately(); |
| - SetHighlight(true, base::TimeDelta(), false); |
| - return; |
| - } |
| - |
| - if (ink_drop_state != views::InkDropState::HIDDEN) { |
| - SetHighlight(false, base::TimeDelta::FromMilliseconds( |
| - kHighlightFadeOutBeforeRippleDurationMs), |
| - true); |
| - } |
| - } |
| - |
| ink_drop_ripple_->AnimateToState(ink_drop_state); |
| } |
| @@ -108,27 +669,17 @@ void InkDropImpl::SnapToActivated() { |
| DestroyHiddenTargetedAnimations(); |
| if (!ink_drop_ripple_) |
| CreateInkDropRipple(); |
| - |
| - if (ink_drop_ripple_->OverridesHighlight()) |
| - SetHighlight(false, base::TimeDelta(), false); |
| - |
| ink_drop_ripple_->SnapToActivated(); |
| } |
| void InkDropImpl::SetHovered(bool is_hovered) { |
| is_hovered_ = is_hovered; |
| - SetHighlight(ShouldHighlight(), |
| - ShouldHighlight() |
| - ? base::TimeDelta::FromMilliseconds( |
| - kHighlightFadeInFromUserInputDurationMs) |
| - : base::TimeDelta::FromMilliseconds( |
| - kHighlightFadeOutFromUserInputDurationMs), |
| - false); |
| + highlight_state_->OnHoverChanged(); |
| } |
| void InkDropImpl::SetFocused(bool is_focused) { |
| is_focused_ = is_focused; |
| - SetHighlight(ShouldHighlight(), base::TimeDelta(), false); |
| + highlight_state_->OnFocusChanged(); |
| } |
| void InkDropImpl::DestroyHiddenTargetedAnimations() { |
| @@ -198,24 +749,18 @@ bool InkDropImpl::IsHighlightFadingInOrVisible() const { |
| // ----------------------------------------------------------------------------- |
| // views::InkDropRippleObserver: |
| -void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) {} |
| +void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { |
| + highlight_state_->AnimationStarted(ink_drop_state); |
| +} |
| void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, |
| InkDropAnimationEndedReason reason) { |
| + highlight_state_->AnimationEnded(ink_drop_state, reason); |
| if (reason != InkDropAnimationEndedReason::SUCCESS) |
| return; |
| if (ShouldAnimateToHidden(ink_drop_state)) { |
| ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); |
| } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
| - // Re-highlight, as necessary. For hover, there's a delay; for focus, jump |
| - // straight into the animation. |
| - if (!IsHighlightFadingInOrVisible()) { |
| - if (is_focused_) |
| - HighlightAfterRippleTimerFired(); |
| - else if (is_hovered_) |
| - StartHighlightAfterRippleTimer(); |
| - } |
| - |
| // TODO(bruthig): Investigate whether creating and destroying |
| // InkDropRipples is expensive and consider creating an |
| // InkDropRipplePool. See www.crbug.com/522175. |
| @@ -240,41 +785,33 @@ void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, |
| void InkDropImpl::SetHighlight(bool should_highlight, |
| base::TimeDelta animation_duration, |
| bool explode) { |
| - highlight_after_ripple_timer_.reset(); |
| - |
| if (IsHighlightFadingInOrVisible() == should_highlight) |
| return; |
| if (should_highlight) { |
| CreateInkDropHighlight(); |
| - if (highlight_ && |
| - !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible() && |
| - ink_drop_ripple_->OverridesHighlight())) { |
| + if (highlight_) |
|
bruthig
2016/11/01 21:00:10
Add TODO to remove this check since all CreateInkD
bruthig
2016/11/04 18:50:36
Done.
|
| highlight_->FadeIn(animation_duration); |
| - } |
| } else { |
| highlight_->FadeOut(animation_duration, explode); |
| } |
| } |
| bool InkDropImpl::ShouldHighlight() const { |
| - return is_focused_ || is_hovered_; |
| + return ShouldHighlightBasedOnFocus() || |
| + (show_highlight_on_hover_ && is_hovered_); |
| } |
| -void InkDropImpl::StartHighlightAfterRippleTimer() { |
| - highlight_after_ripple_timer_.reset(new base::OneShotTimer); |
| - highlight_after_ripple_timer_->Start( |
| - FROM_HERE, |
| - base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayMs), |
| - base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired, |
| - base::Unretained(this))); |
| +bool InkDropImpl::ShouldHighlightBasedOnFocus() const { |
| + return show_highlight_on_focus_ && is_focused_; |
| } |
| -void InkDropImpl::HighlightAfterRippleTimerFired() { |
| - SetHighlight(true, base::TimeDelta::FromMilliseconds( |
| - kHighlightFadeInAfterRippleDurationMs), |
| - true); |
| - highlight_after_ripple_timer_.reset(); |
| +void InkDropImpl::SetHighlightState( |
| + std::unique_ptr<HighlightState> highlight_state) { |
| + if (highlight_state_) |
|
sky
2016/11/02 02:52:11
I do like the new code. It's easier to understand.
bruthig
2016/11/04 18:50:36
Yaay :)
|
| + highlight_state_->Exit(); |
| + highlight_state_ = std::move(highlight_state); |
| + highlight_state_->Enter(); |
| } |
| } // namespace views |