OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 "chrome/browser/ui/panels/panel_slide_animation.h" | |
6 | |
7 #include "chrome/browser/ui/panels/panel.h" | |
8 | |
9 namespace { | |
10 | |
11 // These values are experimental and subjective. | |
12 const int kSetBoundsAnimationMs = 180; | |
13 const int kSetBoundsAnimationMinimizeMs = 1500; | |
prasadt
2011/12/07 17:59:31
Nit: Change to kSetBoundsAnimationBigMinimizeMs to
| |
14 | |
15 } | |
16 | |
17 PanelSlideAnimation::PanelSlideAnimation(ui::AnimationDelegate* target, | |
18 Panel* panel, | |
19 const gfx::Rect& initial_bounds, | |
20 const gfx::Rect& final_bounds) | |
21 : ui::SlideAnimation(target), | |
22 panel_(panel), | |
23 for_big_minimize_(false), | |
24 animation_stop_to_show_titlebar_(0) { | |
25 // Detect animation that happens when expansion state is set to MINIMIZED | |
26 // and there is relatively big portion of the panel to hide from view. | |
27 // Initialize animation differently in this case, using fast-pause-slow | |
28 // method, see below for more details. | |
29 int duration = kSetBoundsAnimationMs; | |
30 if (panel_->expansion_state() == Panel::MINIMIZED) { | |
31 double hidden_title_height = | |
32 panel_->TitleOnlyHeight() - final_bounds.height(); | |
33 double distance_y = initial_bounds.height() - final_bounds.height(); | |
34 animation_stop_to_show_titlebar_ = 1.0 - hidden_title_height / distance_y; | |
35 if (animation_stop_to_show_titlebar_ > 0.7) { // Relatively big movement. | |
36 for_big_minimize_ = true; | |
37 duration = kSetBoundsAnimationMinimizeMs; | |
38 } | |
39 } | |
40 SetSlideDuration(duration); | |
41 } | |
42 | |
43 PanelSlideAnimation::~PanelSlideAnimation() { | |
44 } | |
45 | |
46 double PanelSlideAnimation::GetCurrentValue() const { | |
47 double progress = ui::SlideAnimation::GetCurrentValue(); | |
48 return ComputeAnimationValue(progress, | |
49 for_big_minimize_, | |
50 animation_stop_to_show_titlebar_); | |
51 } | |
52 | |
53 double PanelSlideAnimation::ComputeAnimationValue(double progress, | |
54 bool for_big_minimize, double animation_stop_to_show_titlebar) { | |
55 if (!for_big_minimize) { | |
56 // Cubic easing out. | |
57 double value = 1.0 - progress; | |
58 return 1.0 - value * value * value; | |
59 } | |
60 | |
61 // Minimize animation is done in 3 steps: | |
62 // 1. Quickly (0 -> 0.15) make only titlebar visible. | |
63 // 2. Freeze for a little bit (0.15->0.6), just showing titlebar. | |
64 // 3. Slowly minimize to thin strip (0.6->1.0) | |
65 const double kProgressAtFreezeStart = 0.15; | |
66 const double kProgressAtFreezeEnd = 0.6; | |
67 double value; | |
68 if (progress <= kProgressAtFreezeStart) { | |
69 value = animation_stop_to_show_titlebar * | |
70 (progress / kProgressAtFreezeStart); | |
71 } else if (progress <= kProgressAtFreezeEnd) { | |
72 value = animation_stop_to_show_titlebar; | |
73 } else { | |
74 value = animation_stop_to_show_titlebar + | |
75 (1.0 - animation_stop_to_show_titlebar) * | |
76 ((progress - kProgressAtFreezeEnd) / (1.0 - kProgressAtFreezeEnd)); | |
77 } | |
78 return value; | |
79 } | |
80 | |
OLD | NEW |