Chromium Code Reviews| 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 // These values are experimental and subjective. | |
| 11 const int kSetBoundsAnimationMs = 180; | |
| 12 const int kSetBoundsAnimationMinimizeMs = 1500; | |
| 13 } | |
| 14 | |
| 15 PanelSlideAnimation::PanelSlideAnimation(ui::AnimationDelegate* target, | |
| 16 Panel* panel, | |
| 17 gfx::Rect initial_bounds, | |
| 18 gfx::Rect final_bounds) | |
| 19 : ui::SlideAnimation(target), | |
|
jianli
2011/12/06 19:55:10
nit: 4 spaces for indenting.
Dmitry Titov
2011/12/07 03:46:04
Done.
| |
| 20 panel_(panel), | |
| 21 for_minimize_(false), | |
| 22 animation_stop_to_show_titlebar_(0) { | |
| 23 // Detect animation that happens when expansion state is set to MINIMIZED | |
| 24 // and there is relatively big portion of the panel to hide from view. | |
| 25 // Initialize animation differently in this case, using fast-pause-slow | |
| 26 // method, see below for more details. | |
| 27 int duration = kSetBoundsAnimationMs; | |
| 28 if (panel_->expansion_state() == Panel::MINIMIZED) { | |
| 29 double hidden_title_height = | |
| 30 panel_->TitleOnlyHeight() - final_bounds.height(); | |
| 31 double distance_y = initial_bounds.height() - final_bounds.height(); | |
| 32 animation_stop_to_show_titlebar_ = 1.0 - hidden_title_height / distance_y; | |
| 33 if (animation_stop_to_show_titlebar_ > 0.7) { // Relatively big movement. | |
| 34 for_minimize_ = true; | |
| 35 duration = kSetBoundsAnimationMinimizeMs; | |
| 36 } | |
| 37 } | |
| 38 SetSlideDuration(duration); | |
| 39 } | |
| 40 | |
| 41 PanelSlideAnimation::~PanelSlideAnimation() { } | |
|
jianli
2011/12/06 19:55:10
nit: better to put into 2 lines.
Dmitry Titov
2011/12/07 03:46:04
Done.
| |
| 42 | |
| 43 double PanelSlideAnimation::GetCurrentValue() const { | |
|
jianli
2011/12/06 19:55:10
It might be better to change this to a helper func
Dmitry Titov
2011/12/07 03:46:04
Done.
| |
| 44 double progress = ui::SlideAnimation::GetCurrentValue(); | |
| 45 if (!for_minimize_) { | |
| 46 // Cubic easing out. | |
| 47 float value = 1.0 - progress; | |
| 48 return 1.0 - value * value * value; | |
| 49 } | |
| 50 | |
| 51 // Minimize animation: | |
| 52 // 1. Quickly (0 -> 0.15) make only titlebar visible. | |
| 53 // 2. Stay a little bit (0.15->0.6) in place, just showing titlebar. | |
| 54 // 3. Slowly minimize to thin strip (0.6->1.0) | |
| 55 const double kAnimationStopAfterQuickDecrease = 0.15; | |
| 56 const double kAnimationStopAfterShowingTitlebar = 0.6; | |
| 57 double value; | |
| 58 if (progress <= kAnimationStopAfterQuickDecrease) { | |
| 59 value = progress * animation_stop_to_show_titlebar_ / | |
|
jianli
2011/12/06 19:55:10
nit: indenting
Dmitry Titov
2011/12/07 03:46:04
Done.
| |
| 60 kAnimationStopAfterQuickDecrease; | |
| 61 } else if (progress <= kAnimationStopAfterShowingTitlebar) { | |
| 62 value = animation_stop_to_show_titlebar_; | |
| 63 } else { | |
| 64 value = animation_stop_to_show_titlebar_ + | |
| 65 (progress - kAnimationStopAfterShowingTitlebar) * | |
| 66 (1.0 - animation_stop_to_show_titlebar_) / | |
| 67 (1.0 - kAnimationStopAfterShowingTitlebar); | |
| 68 } | |
| 69 return value; | |
| 70 } | |
| 71 | |
| OLD | NEW |