Commit 34cc6778 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

Multipaste: Add clipboard nudge fade in and fade out animations

This CL adds fade in/out animation for showing/hiding the clipboard
nudge. The nudge scales down when fading in and scales up in size when
fading out.

Bug: 1143809
Change-Id: I4c299c9c6264efcefdc6b9d35fd7a1563f8cb0ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2511350
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824551}
parent 133c49ba
......@@ -26,6 +26,8 @@ class ASH_EXPORT ClipboardNudge : public ShelfObserver {
HotseatState new_state) override;
void Close();
views::Widget* widget() { return widget_.get(); }
private:
class ClipboardNudgeView;
......
......@@ -6,15 +6,22 @@
#define ASH_CLIPBOARD_CLIPBOARD_NUDGE_CONSTANTS_H_
#include "base/time/time.h"
#include "ui/gfx/animation/tween.h"
namespace ash {
constexpr static int kNotificationLimit = 3;
constexpr static base::TimeDelta kMinInterval = base::TimeDelta::FromDays(1);
constexpr static base::TimeDelta kMaxTimeBetweenPaste =
constexpr int kNotificationLimit = 3;
constexpr base::TimeDelta kMinInterval = base::TimeDelta::FromDays(1);
constexpr base::TimeDelta kMaxTimeBetweenPaste =
base::TimeDelta::FromMinutes(10);
constexpr static base::TimeDelta kNudgeShowTime =
base::TimeDelta::FromSeconds(6);
constexpr base::TimeDelta kNudgeShowTime = base::TimeDelta::FromSeconds(6);
constexpr float kNudgeFadeAnimationScale = 1.2f;
constexpr base::TimeDelta kNudgeFadeAnimationTime =
base::TimeDelta::FromMilliseconds(250);
constexpr gfx::Tween::Type kNudgeFadeOpacityAnimationTweenType =
gfx::Tween::LINEAR;
constexpr gfx::Tween::Type kNudgeFadeScalingAnimationTweenType =
gfx::Tween::LINEAR_OUT_SLOW_IN;
} // namespace ash
......
......@@ -20,6 +20,8 @@
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "ui/base/clipboard/clipboard_monitor.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
namespace {
......@@ -31,6 +33,30 @@ constexpr char kLastTimeShown[] = "last_time_shown";
// showing the nudge and recording the feature being opened/used.
constexpr int kBucketCount = 61;
// A class for observing the clipboard nudge fade out animation. Once the fade
// out animation is complete the clipboard nudge will be destroyed.
class ImplicitNudgeHideAnimationObserver
: public ui::ImplicitAnimationObserver {
public:
explicit ImplicitNudgeHideAnimationObserver(
std::unique_ptr<ash::ClipboardNudge> nudge)
: nudge_(std::move(nudge)) {}
ImplicitNudgeHideAnimationObserver(
const ImplicitNudgeHideAnimationObserver&) = delete;
ImplicitNudgeHideAnimationObserver& operator=(
const ImplicitNudgeHideAnimationObserver&) = delete;
~ImplicitNudgeHideAnimationObserver() override {
StopObservingImplicitAnimations();
nudge_->Close();
}
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override { delete this; }
private:
std::unique_ptr<ash::ClipboardNudge> nudge_;
};
} // namespace
namespace ash {
......@@ -124,6 +150,7 @@ void ClipboardNudgeController::OnActiveUserPrefServiceChanged(
void ClipboardNudgeController::ShowNudge() {
// Create and show the nudge.
nudge_ = std::make_unique<ClipboardNudge>();
StartFadeAnimation(/*show=*/true);
// Start a timer to close the nudge after a set amount of time.
hide_nudge_timer_.Start(FROM_HERE, kNudgeShowTime,
......@@ -139,8 +166,43 @@ void ClipboardNudgeController::ShowNudge() {
}
void ClipboardNudgeController::HideNudge() {
nudge_->Close();
nudge_.reset();
StartFadeAnimation(/*show=*/false);
}
void ClipboardNudgeController::StartFadeAnimation(bool show) {
ui::Layer* layer = nudge_->widget()->GetLayer();
gfx::Rect widget_bounds = layer->bounds();
gfx::Transform scaled_nudge_transform;
float x_offset =
widget_bounds.width() * (1.0f - kNudgeFadeAnimationScale) / 2.0f;
float y_offset =
widget_bounds.height() * (1.0f - kNudgeFadeAnimationScale) / 2.0f;
scaled_nudge_transform.Translate(x_offset, y_offset);
scaled_nudge_transform.Scale(kNudgeFadeAnimationScale,
kNudgeFadeAnimationScale);
layer->SetOpacity(show ? 0.0f : 1.0f);
layer->SetTransform(show ? scaled_nudge_transform : gfx::Transform());
{
// Perform the scaling animation on the clipboard nudge.
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.SetTransitionDuration(kNudgeFadeAnimationTime);
settings.SetTweenType(kNudgeFadeScalingAnimationTweenType);
layer->SetTransform(show ? gfx::Transform() : scaled_nudge_transform);
}
{
// Perform the opacity animation on the clipboard nudge.
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.SetTransitionDuration(kNudgeFadeAnimationTime);
settings.SetTweenType(kNudgeFadeOpacityAnimationTweenType);
layer->SetOpacity(show ? 1.0f : 0.0f);
if (!show) {
settings.AddObserver(
new ImplicitNudgeHideAnimationObserver(std::move(nudge_)));
}
}
}
void ClipboardNudgeController::HandleNudgeShown() {
......
......@@ -87,6 +87,9 @@ class ASH_EXPORT ClipboardNudgeController
// Hides the nudge widget.
void HideNudge();
// Begins the animation for fading in or fading out the clipboard nudge.
void StartFadeAnimation(bool show);
// Time the nudge was last shown.
base::Time last_shown_time_;
......
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