Commit 4189ddf3 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Properly animate the collapse when the last notification slides out.

Currently, the message center closes apbruptly after the last notification
slides out. It should instead gracefully animate being hidden.

Video:
https://screencast.googleplex.com/cast/NTQzNTM4NTg3MjEyMTg1Nnw2NmNlZThiNi1lZA

TEST=manually verified, updated unit test
BUG=958603

Change-Id: If1c9e6ced1670bc208af281d42f687af3084a488
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610651Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Tim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659576}
parent b102e647
...@@ -43,6 +43,8 @@ namespace { ...@@ -43,6 +43,8 @@ namespace {
constexpr base::TimeDelta kHideStackingBarAnimationDuration = constexpr base::TimeDelta kHideStackingBarAnimationDuration =
base::TimeDelta::FromMilliseconds(330); base::TimeDelta::FromMilliseconds(330);
constexpr base::TimeDelta kCollapseAnimationDuration =
base::TimeDelta::FromMilliseconds(640);
enum ClearAllButtonTag { enum ClearAllButtonTag {
kStackingBarClearAllButtonTag, kStackingBarClearAllButtonTag,
...@@ -338,6 +340,8 @@ void UnifiedMessageCenterView::OnNotificationSlidOut() { ...@@ -338,6 +340,8 @@ void UnifiedMessageCenterView::OnNotificationSlidOut() {
if (stacking_counter_->visible() && if (stacking_counter_->visible() &&
message_list_view_->GetTotalNotificationCount() <= 1) { message_list_view_->GetTotalNotificationCount() <= 1) {
StartHideStackingBarAnimation(); StartHideStackingBarAnimation();
} else if (!message_list_view_->GetTotalNotificationCount()) {
StartCollapseAnimation();
} }
} }
...@@ -409,6 +413,12 @@ gfx::Size UnifiedMessageCenterView::CalculatePreferredSize() const { ...@@ -409,6 +413,12 @@ gfx::Size UnifiedMessageCenterView::CalculatePreferredSize() const {
// Hide Clear All button at the buttom from initial viewport. // Hide Clear All button at the buttom from initial viewport.
preferred_size.set_height(preferred_size.height() - kClearAllButtonRowHeight); preferred_size.set_height(preferred_size.height() - kClearAllButtonRowHeight);
if (animation_state_ == UnifiedMessageCenterAnimationState::COLLAPSE) {
int height = preferred_size.height() * (1.0 - GetAnimationValue());
preferred_size.set_height(height);
}
return preferred_size; return preferred_size;
} }
...@@ -474,12 +484,12 @@ void UnifiedMessageCenterView::AnimationEnded(const gfx::Animation* animation) { ...@@ -474,12 +484,12 @@ void UnifiedMessageCenterView::AnimationEnded(const gfx::Animation* animation) {
case UnifiedMessageCenterAnimationState::HIDE_STACKING_BAR: case UnifiedMessageCenterAnimationState::HIDE_STACKING_BAR:
break; break;
case UnifiedMessageCenterAnimationState::COLLAPSE: case UnifiedMessageCenterAnimationState::COLLAPSE:
NOTIMPLEMENTED();
break; break;
} }
animation_state_ = UnifiedMessageCenterAnimationState::IDLE; animation_state_ = UnifiedMessageCenterAnimationState::IDLE;
stacking_counter_->SetAnimationState(animation_state_); stacking_counter_->SetAnimationState(animation_state_);
UpdateVisibility();
} }
void UnifiedMessageCenterView::AnimationProgressed( void UnifiedMessageCenterView::AnimationProgressed(
...@@ -505,6 +515,14 @@ void UnifiedMessageCenterView::StartHideStackingBarAnimation() { ...@@ -505,6 +515,14 @@ void UnifiedMessageCenterView::StartHideStackingBarAnimation() {
animation_->Start(); animation_->Start();
} }
void UnifiedMessageCenterView::StartCollapseAnimation() {
animation_->End();
animation_state_ = UnifiedMessageCenterAnimationState::COLLAPSE;
stacking_counter_->SetAnimationState(animation_state_);
animation_->SetDuration(kCollapseAnimationDuration);
animation_->Start();
}
double UnifiedMessageCenterView::GetAnimationValue() const { double UnifiedMessageCenterView::GetAnimationValue() const {
return gfx::Tween::CalculateValue(gfx::Tween::FAST_OUT_SLOW_IN, return gfx::Tween::CalculateValue(gfx::Tween::FAST_OUT_SLOW_IN,
animation_->GetCurrentValue()); animation_->GetCurrentValue());
...@@ -513,11 +531,13 @@ double UnifiedMessageCenterView::GetAnimationValue() const { ...@@ -513,11 +531,13 @@ double UnifiedMessageCenterView::GetAnimationValue() const {
void UnifiedMessageCenterView::UpdateVisibility() { void UnifiedMessageCenterView::UpdateVisibility() {
SessionControllerImpl* session_controller = SessionControllerImpl* session_controller =
Shell::Get()->session_controller(); Shell::Get()->session_controller();
SetVisible(available_height_ >= kUnifiedNotificationMinimumHeight && SetVisible(
message_list_view_->GetPreferredSize().height() > 0 && available_height_ >= kUnifiedNotificationMinimumHeight &&
session_controller->ShouldShowNotificationTray() && (animation_state_ == UnifiedMessageCenterAnimationState::COLLAPSE ||
(!session_controller->IsScreenLocked() || message_list_view_->GetPreferredSize().height() > 0) &&
AshMessageCenterLockScreenController::IsEnabled())); session_controller->ShouldShowNotificationTray() &&
(!session_controller->IsScreenLocked() ||
AshMessageCenterLockScreenController::IsEnabled()));
// When notification list went invisible, the last notification should be // When notification list went invisible, the last notification should be
// targeted next time. // targeted next time.
......
...@@ -152,6 +152,9 @@ class ASH_EXPORT UnifiedMessageCenterView ...@@ -152,6 +152,9 @@ class ASH_EXPORT UnifiedMessageCenterView
// Starts the animation to hide the notification stacking bar. // Starts the animation to hide the notification stacking bar.
void StartHideStackingBarAnimation(); void StartHideStackingBarAnimation();
// Starts the animation to collapse the message center.
void StartCollapseAnimation();
// Returns the current animation value after tweening. // Returns the current animation value after tweening.
double GetAnimationValue() const; double GetAnimationValue() const;
......
...@@ -227,10 +227,20 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) { ...@@ -227,10 +227,20 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) {
GetScrollerContents()->height() - GetScrollerContents()->height() -
GetScroller()->GetVisibleRect().bottom()); GetScroller()->GetVisibleRect().bottom());
// The notification first slides out of the list.
MessageCenter::Get()->RemoveNotification(id0, true /* by_user */); MessageCenter::Get()->RemoveNotification(id0, true /* by_user */);
AnimateMessageListToEnd(); AnimateMessageListToEnd();
// After all the last notifiation slides out, the message center and list
// should collapse.
auto* collapse_animation = GetMessageCenterAnimation();
collapse_animation->SetCurrentValue(0.5);
message_center_view()->AnimationProgressed(collapse_animation);
AnimateMessageListToMiddle(); AnimateMessageListToMiddle();
EXPECT_TRUE(message_center_view()->visible()); EXPECT_TRUE(message_center_view()->visible());
// The message center is now hidden after all animations complete.
collapse_animation->End();
AnimateMessageListToEnd(); AnimateMessageListToEnd();
EXPECT_FALSE(message_center_view()->visible()); EXPECT_FALSE(message_center_view()->visible());
} }
......
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