| 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..cc5f07966b689f01597a86b4f3f6fc30db6ba54e 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,509 @@ bool ShouldAnimateToHidden(InkDropState ink_drop_state) {
|
|
|
| } // namespace
|
|
|
| +// 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;
|
| + void AnimationStarted(InkDropState ink_drop_state) override;
|
| + void AnimationEnded(InkDropState ink_drop_state,
|
| + InkDropAnimationEndedReason reason) override;
|
| +
|
| + private:
|
| + // Handles all changes to the hover/focus status and transitions to a visible
|
| + // state if necessary.
|
| + 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 Exit() override {}
|
| + 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:
|
| + // Handles all changes to the hover/focus status and transitions to a hidden
|
| + // state if necessary.
|
| + 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));
|
| + }
|
| +}
|
| +
|
| +void InkDropImpl::NoAutoHighlightHiddenState::AnimationStarted(
|
| + InkDropState ink_drop_state) {}
|
| +
|
| +void InkDropImpl::NoAutoHighlightHiddenState::AnimationEnded(
|
| + InkDropState ink_drop_state,
|
| + InkDropAnimationEndedReason reason) {}
|
| +
|
| +// 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));
|
| + }
|
| +}
|
| +
|
| +void InkDropImpl::NoAutoHighlightVisibleState::AnimationStarted(
|
| + InkDropState ink_drop_state) {}
|
| +
|
| +void InkDropImpl::NoAutoHighlightVisibleState::AnimationEnded(
|
| + InkDropState ink_drop_state,
|
| + InkDropAnimationEndedReason reason) {}
|
| +
|
| +//
|
| +// 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. Transitions to
|
| + // a visible state if the ink drop should be highlighted.
|
| + 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) {}
|
| +
|
| +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) {}
|
| +
|
| +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) {}
|
| +
|
| +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) {}
|
| +
|
| +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) {
|
| + exiting_highlight_state_(false) {
|
| + SetAutoHighlightMode(AutoHighlightMode::NONE);
|
| root_layer_->set_name("InkDropImpl:RootLayer");
|
| }
|
|
|
| @@ -67,6 +569,25 @@ 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) {
|
| + // Exit the current state completely first in case state tear down accesses
|
| + // the current |highlight_state_factory_| instance.
|
| + ExitHighlightState();
|
| + 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 +604,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 +611,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() {
|
| @@ -159,6 +652,8 @@ void InkDropImpl::CreateInkDropHighlight() {
|
| DestroyInkDropHighlight();
|
|
|
| highlight_ = ink_drop_host_->CreateInkDropHighlight();
|
| + // TODO(bruthig): Remove check for null since all CreateInkDropHighlight()
|
| + // methods should return a valid instance.
|
| if (!highlight_)
|
| return;
|
| highlight_->set_observer(this);
|
| @@ -198,24 +693,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 +729,45 @@ 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())) {
|
| + // TODO(bruthig): Remove check for null since all CreateInkDropHighlight()
|
| + // methods should return a valid instance.
|
| + if (highlight_)
|
| 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) {
|
| + ExitHighlightState();
|
| + highlight_state_ = std::move(highlight_state);
|
| + highlight_state_->Enter();
|
| +}
|
| +
|
| +void InkDropImpl::ExitHighlightState() {
|
| + DCHECK(!exiting_highlight_state_) << "HighlightStates should not be changed "
|
| + "within a call to "
|
| + "HighlightState::Exit().";
|
| + if (highlight_state_) {
|
| + base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true);
|
| + highlight_state_->Exit();
|
| + }
|
| + highlight_state_ = nullptr;
|
| }
|
|
|
| } // namespace views
|
|
|