Commit b272a16b authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Fix highlight state getting stuck on after menus close

BUG=919057,916410,934213
R=mohsen

Change-Id: If60bc5958d07fec526b04493f80cb47570b9d00a
Reviewed-on: https://chromium-review.googlesource.com/c/1432880
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636713}
parent f37950a9
...@@ -351,10 +351,14 @@ void InkDropImpl::HideHighlightOnRippleHiddenState::AnimationStarted( ...@@ -351,10 +351,14 @@ void InkDropImpl::HideHighlightOnRippleHiddenState::AnimationStarted(
// |ink_drop_ripple_|. // |ink_drop_ripple_|.
// TODO(bruthig): Investigate if the animation framework can address this // TODO(bruthig): Investigate if the animation framework can address this
// issue instead. See https://crbug.com/663335. // issue instead. See https://crbug.com/663335.
if (GetInkDrop()->ink_drop_ripple_) InkDropImpl* ink_drop = GetInkDrop();
GetInkDrop()->ink_drop_ripple_->SnapToHidden(); HighlightStateFactory* highlight_state_factory = state_factory();
GetInkDrop()->SetHighlightState( if (ink_drop->ink_drop_ripple_)
state_factory()->CreateVisibleState(base::TimeDelta(), false)); ink_drop->ink_drop_ripple_->SnapToHidden();
// |this| may be destroyed after SnapToHidden(), so be sure not to access
// |any members.
ink_drop->SetHighlightState(
highlight_state_factory->CreateVisibleState(base::TimeDelta(), false));
} }
} }
...@@ -629,7 +633,9 @@ void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) { ...@@ -629,7 +633,9 @@ void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) {
root_layer_->SetBounds(gfx::Rect(new_size)); root_layer_->SetBounds(gfx::Rect(new_size));
const bool create_ink_drop_ripple = !!ink_drop_ripple_; const bool create_ink_drop_ripple = !!ink_drop_ripple_;
const InkDropState state = GetTargetInkDropState(); InkDropState state = GetTargetInkDropState();
if (ShouldAnimateToHidden(state))
state = views::InkDropState::HIDDEN;
DestroyInkDropRipple(); DestroyInkDropRipple();
if (highlight_) { if (highlight_) {
......
...@@ -39,16 +39,7 @@ void InkDropRipple::AnimateToState(InkDropState ink_drop_state) { ...@@ -39,16 +39,7 @@ void InkDropRipple::AnimateToState(InkDropState ink_drop_state) {
// and these invalid transitions will be logged as warnings in // and these invalid transitions will be logged as warnings in
// AnimateStateChange(). // AnimateStateChange().
// |animation_observer| will be deleted when AnimationEndedCallback() returns animation_observer_ = CreateAnimationObserver(ink_drop_state);
// true.
// TODO(bruthig): Implement a safer ownership model for the
// |animation_observer|.
ui::CallbackLayerAnimationObserver* animation_observer =
new ui::CallbackLayerAnimationObserver(
base::Bind(&InkDropRipple::AnimationStartedCallback,
base::Unretained(this), ink_drop_state),
base::Bind(&InkDropRipple::AnimationEndedCallback,
base::Unretained(this), ink_drop_state));
InkDropState old_ink_drop_state = target_ink_drop_state_; InkDropState old_ink_drop_state = target_ink_drop_state_;
// Assign to |target_ink_drop_state_| before calling AnimateStateChange() so // Assign to |target_ink_drop_state_| before calling AnimateStateChange() so
...@@ -62,41 +53,27 @@ void InkDropRipple::AnimateToState(InkDropState ink_drop_state) { ...@@ -62,41 +53,27 @@ void InkDropRipple::AnimateToState(InkDropState ink_drop_state) {
} }
AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, AnimateStateChange(old_ink_drop_state, target_ink_drop_state_,
animation_observer); animation_observer_.get());
animation_observer->SetActive(); animation_observer_->SetActive();
// |this| may be deleted! |animation_observer| might synchronously call // |this| may be deleted! |animation_observer_| might synchronously call
// AnimationEndedCallback which can delete |this|. // AnimationEndedCallback which can delete |this|.
} }
void InkDropRipple::SnapToState(InkDropState ink_drop_state) { void InkDropRipple::SnapToState(InkDropState ink_drop_state) {
switch (ink_drop_state) { AbortAllAnimations();
case InkDropState::HIDDEN: if (ink_drop_state == InkDropState::ACTIVATED)
SnapToHidden(); GetRootLayer()->SetVisible(true);
break; else if (ink_drop_state == InkDropState::HIDDEN)
case InkDropState::ACTIVATED: SetStateToHidden();
SnapToActivated(); target_ink_drop_state_ = ink_drop_state;
break; animation_observer_ = CreateAnimationObserver(ink_drop_state);
default: animation_observer_->SetActive();
AbortAllAnimations(); // |this| may be deleted! |animation_observer_| might synchronously call
target_ink_drop_state_ = ink_drop_state; // AnimationEndedCallback which can delete |this|.
}
} }
void InkDropRipple::SnapToActivated() { void InkDropRipple::SnapToActivated() {
AbortAllAnimations(); SnapToState(InkDropState::ACTIVATED);
// |animation_observer| will be deleted when AnimationEndedCallback() returns
// true.
// TODO(bruthig): Implement a safer ownership model for the
// |animation_observer|.
ui::CallbackLayerAnimationObserver* animation_observer =
new ui::CallbackLayerAnimationObserver(
base::Bind(&InkDropRipple::AnimationStartedCallback,
base::Unretained(this), InkDropState::ACTIVATED),
base::Bind(&InkDropRipple::AnimationEndedCallback,
base::Unretained(this), InkDropState::ACTIVATED));
GetRootLayer()->SetVisible(true);
target_ink_drop_state_ = InkDropState::ACTIVATED;
animation_observer->SetActive();
} }
bool InkDropRipple::IsVisible() { bool InkDropRipple::IsVisible() {
...@@ -104,9 +81,7 @@ bool InkDropRipple::IsVisible() { ...@@ -104,9 +81,7 @@ bool InkDropRipple::IsVisible() {
} }
void InkDropRipple::SnapToHidden() { void InkDropRipple::SnapToHidden() {
AbortAllAnimations(); SnapToState(InkDropState::HIDDEN);
SetStateToHidden();
target_ink_drop_state_ = InkDropState::HIDDEN;
} }
test::InkDropRippleTestApi* InkDropRipple::GetTestApi() { test::InkDropRippleTestApi* InkDropRipple::GetTestApi() {
...@@ -131,7 +106,16 @@ bool InkDropRipple::AnimationEndedCallback( ...@@ -131,7 +106,16 @@ bool InkDropRipple::AnimationEndedCallback(
? InkDropAnimationEndedReason::PRE_EMPTED ? InkDropAnimationEndedReason::PRE_EMPTED
: InkDropAnimationEndedReason::SUCCESS); : InkDropAnimationEndedReason::SUCCESS);
// |this| may be deleted! // |this| may be deleted!
return true; return false;
}
std::unique_ptr<ui::CallbackLayerAnimationObserver>
InkDropRipple::CreateAnimationObserver(InkDropState ink_drop_state) {
return std::make_unique<ui::CallbackLayerAnimationObserver>(
base::BindRepeating(&InkDropRipple::AnimationStartedCallback,
base::Unretained(this), ink_drop_state),
base::BindRepeating(&InkDropRipple::AnimationEndedCallback,
base::Unretained(this), ink_drop_state));
} }
} // namespace views } // namespace views
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef UI_VIEWS_ANIMATION_INK_DROP_RIPPLE_H_ #ifndef UI_VIEWS_ANIMATION_INK_DROP_RIPPLE_H_
#define UI_VIEWS_ANIMATION_INK_DROP_RIPPLE_H_ #define UI_VIEWS_ANIMATION_INK_DROP_RIPPLE_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -117,11 +119,18 @@ class VIEWS_EXPORT InkDropRipple { ...@@ -117,11 +119,18 @@ class VIEWS_EXPORT InkDropRipple {
InkDropState ink_drop_state, InkDropState ink_drop_state,
const ui::CallbackLayerAnimationObserver& observer); const ui::CallbackLayerAnimationObserver& observer);
// Creates a new animation observer bound to AnimationStartedCallback() and
// AnimationEndedCallback().
std::unique_ptr<ui::CallbackLayerAnimationObserver> CreateAnimationObserver(
InkDropState ink_drop_state);
// The target InkDropState. // The target InkDropState.
InkDropState target_ink_drop_state_; InkDropState target_ink_drop_state_;
InkDropRippleObserver* observer_; InkDropRippleObserver* observer_;
std::unique_ptr<ui::CallbackLayerAnimationObserver> animation_observer_;
DISALLOW_COPY_AND_ASSIGN(InkDropRipple); DISALLOW_COPY_AND_ASSIGN(InkDropRipple);
}; };
......
...@@ -264,8 +264,8 @@ TEST_P(InkDropRippleTest, SnapToHiddenWithoutActiveAnimations) { ...@@ -264,8 +264,8 @@ TEST_P(InkDropRippleTest, SnapToHiddenWithoutActiveAnimations) {
EXPECT_FALSE(test_api_->HasActiveAnimations()); EXPECT_FALSE(test_api_->HasActiveAnimations());
EXPECT_EQ(views::InkDropState::HIDDEN, EXPECT_EQ(views::InkDropState::HIDDEN,
ink_drop_ripple_->target_ink_drop_state()); ink_drop_ripple_->target_ink_drop_state());
EXPECT_EQ(1, observer_.last_animation_started_ordinal()); EXPECT_EQ(3, observer_.last_animation_started_ordinal());
EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); EXPECT_EQ(4, observer_.last_animation_ended_ordinal());
EXPECT_EQ(InkDropRipple::kHiddenOpacity, test_api_->GetCurrentOpacity()); EXPECT_EQ(InkDropRipple::kHiddenOpacity, test_api_->GetCurrentOpacity());
EXPECT_FALSE(ink_drop_ripple_->IsVisible()); EXPECT_FALSE(ink_drop_ripple_->IsVisible());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment