Skip to content

Commit

Permalink
Adjust lock screen note action background animation
Browse files Browse the repository at this point in the history
The CL updates the drop ripple animation duration and final opacity
for the lock screen action background (flood fill) ink drop.

BUG=746596

Change-Id: I31aa7c9f1c24dfbcbb3a6119524f00e195ccbfdf
Reviewed-on: https://chromium-review.googlesource.com/721624
Commit-Queue: Toni Barzic <tbarzic@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Mohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513919}
  • Loading branch information
Toni Barzic authored and Commit Bot committed Nov 3, 2017
1 parent 49c4b2a commit 0024a5b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
5 changes: 4 additions & 1 deletion ash/lock_screen_action/lock_screen_action_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ class LockScreenActionBackgroundView::NoteBackground
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override {
gfx::Point center = base::i18n::IsRTL() ? GetLocalBounds().origin()
: GetLocalBounds().top_right();
return std::make_unique<views::FloodFillInkDropRipple>(
auto ink_drop_ripple = std::make_unique<views::FloodFillInkDropRipple>(
size(), gfx::Insets(), center, SK_ColorBLACK, 1);
ink_drop_ripple->set_use_hide_transform_duration_for_hide_fade_out(true);
ink_drop_ripple->set_duration_factor(1.5);
return ink_drop_ripple;
}

SkColor GetInkDropBaseColor() const override { return SK_ColorBLACK; }
Expand Down
44 changes: 27 additions & 17 deletions ui/views/animation/flood_fill_ink_drop_ripple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ int kAnimationDurationInMs[] = {
300, // DEACTIVATED_FADE_OUT
};

// Returns the InkDropState sub animation duration for the given |state|.
base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
if (!gfx::Animation::ShouldRenderRichAnimation())
return base::TimeDelta();

return base::TimeDelta::FromMilliseconds(
(views::InkDropRipple::UseFastAnimations()
? 1
: views::InkDropRipple::kSlowAnimationDurationFactor) *
kAnimationDurationInMs[state]);
}

gfx::Rect CalculateClipBounds(const gfx::Size& host_size,
const gfx::Insets& clip_insets) {
gfx::Rect clip_bounds(host_size);
Expand All @@ -130,6 +118,8 @@ FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size,
: clip_insets_(clip_insets),
center_point_(center_point),
visible_opacity_(visible_opacity),
use_hide_transform_duration_for_hide_fade_out_(false),
duration_factor_(1.f),
root_layer_(ui::LAYER_NOT_DRAWN),
circle_layer_delegate_(color,
CalculateCircleLayerRadius(
Expand Down Expand Up @@ -274,10 +264,11 @@ void FloodFillInkDropRipple::AnimateStateChange(
<< ToString(old_ink_drop_state)
<< " new_ink_drop_state=" << ToString(new_ink_drop_state);

AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(
ALTERNATE_ACTION_TRIGGERED_FADE_OUT),
ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
gfx::Tween::EASE_IN_OUT, animation_observer);
AnimateToOpacity(
kHiddenOpacity,
GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_FADE_OUT),
ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, gfx::Tween::EASE_IN_OUT,
animation_observer);
break;
case InkDropState::ACTIVATED: {
if (old_ink_drop_state == InkDropState::ACTION_PENDING) {
Expand Down Expand Up @@ -315,7 +306,7 @@ void FloodFillInkDropRipple::AnimateStateChange(

void FloodFillInkDropRipple::SetStateToHidden() {
painted_layer_.SetTransform(CalculateTransform(kMinRadius));
root_layer_.SetOpacity(InkDropRipple::kHiddenOpacity);
root_layer_.SetOpacity(kHiddenOpacity);
root_layer_.SetVisible(false);
}

Expand Down Expand Up @@ -454,4 +445,23 @@ float FloodFillInkDropRipple::MaxDistanceToCorners(
return largest_distance;
}

// Returns the InkDropState sub animation duration for the given |state|.
base::TimeDelta FloodFillInkDropRipple::GetAnimationDuration(int state) {
if (!gfx::Animation::ShouldRenderRichAnimation())
return base::TimeDelta();

int state_override = state;
// Override the requested state if needed.
if (use_hide_transform_duration_for_hide_fade_out_ &&
state == HIDDEN_FADE_OUT) {
state_override = HIDDEN_TRANSFORM;
}

return base::TimeDelta::FromMilliseconds(
(views::InkDropRipple::UseFastAnimations()
? 1
: views::InkDropRipple::kSlowAnimationDurationFactor) *
kAnimationDurationInMs[state_override] * duration_factor_);
}

} // namespace views
18 changes: 18 additions & 0 deletions ui/views/animation/flood_fill_ink_drop_ripple.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ class VIEWS_EXPORT FloodFillInkDropRipple : public InkDropRipple {
void SnapToActivated() override;
ui::Layer* GetRootLayer() override;

void set_use_hide_transform_duration_for_hide_fade_out(bool value) {
use_hide_transform_duration_for_hide_fade_out_ = value;
}

void set_duration_factor(float duration_factor) {
duration_factor_ = duration_factor;
}

private:
friend class test::FloodFillInkDropRippleTestApi;

Expand Down Expand Up @@ -129,6 +137,9 @@ class VIEWS_EXPORT FloodFillInkDropRipple : public InkDropRipple {
// |root_layer_| bounds.
float MaxDistanceToCorners(const gfx::Point& point) const;

// Returns the InkDropState sub animation duration for the given |state|.
base::TimeDelta GetAnimationDuration(int state);

// Insets of the clip area relative to the host bounds.
gfx::Insets clip_insets_;

Expand All @@ -138,6 +149,13 @@ class VIEWS_EXPORT FloodFillInkDropRipple : public InkDropRipple {
// Ink drop opacity when it is visible.
float visible_opacity_;

// Whether the fade out animation to hidden state should have the same
// duration as the associated scale transform animation.
bool use_hide_transform_duration_for_hide_fade_out_;

// The factor used to scale down/up animation duration.
float duration_factor_;

// The root layer that parents the animating layer. The root layer is used to
// manipulate opacity and clipping bounds, and it child is used to manipulate
// the different shape of the ink drop.
Expand Down

0 comments on commit 0024a5b

Please sign in to comment.