1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/login/ui/pin_keyboard_animation.h"
6
7 #include <memory>
8
9 #include "ui/compositor/layer_animation_delegate.h"
10 #include "ui/gfx/animation/tween.h"
11 #include "ui/gfx/interpolated_transform.h"
12
13 namespace ash {
14
PinKeyboardAnimation(bool grow,int height,base::TimeDelta duration,gfx::Tween::Type tween_type)15 PinKeyboardAnimation::PinKeyboardAnimation(bool grow,
16 int height,
17 base::TimeDelta duration,
18 gfx::Tween::Type tween_type)
19 : ui::LayerAnimationElement(
20 LayerAnimationElement::TRANSFORM | LayerAnimationElement::OPACITY,
21 duration),
22 tween_type_(tween_type) {
23 if (!grow)
24 std::swap(start_opacity_, end_opacity_);
25
26 transform_ = std::make_unique<ui::InterpolatedScale>(
27 gfx::Point3F(1, start_opacity_, 1), gfx::Point3F(1, end_opacity_, 1));
28 }
29
30 PinKeyboardAnimation::~PinKeyboardAnimation() = default;
31
OnStart(ui::LayerAnimationDelegate * delegate)32 void PinKeyboardAnimation::OnStart(ui::LayerAnimationDelegate* delegate) {}
33
OnProgress(double current,ui::LayerAnimationDelegate * delegate)34 bool PinKeyboardAnimation::OnProgress(double current,
35 ui::LayerAnimationDelegate* delegate) {
36 const double tweened = gfx::Tween::CalculateValue(tween_type_, current);
37 delegate->SetOpacityFromAnimation(
38 gfx::Tween::FloatValueBetween(tweened, start_opacity_, end_opacity_),
39 ui::PropertyChangeReason::FROM_ANIMATION);
40 delegate->SetTransformFromAnimation(transform_->Interpolate(tweened),
41 ui::PropertyChangeReason::FROM_ANIMATION);
42 return true;
43 }
44
OnGetTarget(TargetValue * target) const45 void PinKeyboardAnimation::OnGetTarget(TargetValue* target) const {}
46
OnAbort(ui::LayerAnimationDelegate * delegate)47 void PinKeyboardAnimation::OnAbort(ui::LayerAnimationDelegate* delegate) {}
48
49 } // namespace ash
50