Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_slide_animation.cc |
| diff --git a/chrome/browser/ui/panels/panel_slide_animation.cc b/chrome/browser/ui/panels/panel_slide_animation.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d1f22a7c1688e4494e2ab108e900267c7af938a2 |
| --- /dev/null |
| +++ b/chrome/browser/ui/panels/panel_slide_animation.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/panels/panel_slide_animation.h" |
| + |
| +#include "chrome/browser/ui/panels/panel.h" |
| + |
| +namespace { |
| +// These values are experimental and subjective. |
| +const int kSetBoundsAnimationMs = 180; |
| +const int kSetBoundsAnimationMinimizeMs = 1500; |
| +} |
| + |
| +PanelSlideAnimation::PanelSlideAnimation(ui::AnimationDelegate* target, |
| + Panel* panel, |
| + gfx::Rect initial_bounds, |
| + gfx::Rect final_bounds) |
| + : ui::SlideAnimation(target), |
|
jianli
2011/12/06 19:55:10
nit: 4 spaces for indenting.
Dmitry Titov
2011/12/07 03:46:04
Done.
|
| + panel_(panel), |
| + for_minimize_(false), |
| + animation_stop_to_show_titlebar_(0) { |
| + // Detect animation that happens when expansion state is set to MINIMIZED |
| + // and there is relatively big portion of the panel to hide from view. |
| + // Initialize animation differently in this case, using fast-pause-slow |
| + // method, see below for more details. |
| + int duration = kSetBoundsAnimationMs; |
| + if (panel_->expansion_state() == Panel::MINIMIZED) { |
| + double hidden_title_height = |
| + panel_->TitleOnlyHeight() - final_bounds.height(); |
| + double distance_y = initial_bounds.height() - final_bounds.height(); |
| + animation_stop_to_show_titlebar_ = 1.0 - hidden_title_height / distance_y; |
| + if (animation_stop_to_show_titlebar_ > 0.7) { // Relatively big movement. |
| + for_minimize_ = true; |
| + duration = kSetBoundsAnimationMinimizeMs; |
| + } |
| + } |
| + SetSlideDuration(duration); |
| +} |
| + |
| +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.
|
| + |
| +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.
|
| + double progress = ui::SlideAnimation::GetCurrentValue(); |
| + if (!for_minimize_) { |
| + // Cubic easing out. |
| + float value = 1.0 - progress; |
| + return 1.0 - value * value * value; |
| + } |
| + |
| + // Minimize animation: |
| + // 1. Quickly (0 -> 0.15) make only titlebar visible. |
| + // 2. Stay a little bit (0.15->0.6) in place, just showing titlebar. |
| + // 3. Slowly minimize to thin strip (0.6->1.0) |
| + const double kAnimationStopAfterQuickDecrease = 0.15; |
| + const double kAnimationStopAfterShowingTitlebar = 0.6; |
| + double value; |
| + if (progress <= kAnimationStopAfterQuickDecrease) { |
| + 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.
|
| + kAnimationStopAfterQuickDecrease; |
| + } else if (progress <= kAnimationStopAfterShowingTitlebar) { |
| + value = animation_stop_to_show_titlebar_; |
| + } else { |
| + value = animation_stop_to_show_titlebar_ + |
| + (progress - kAnimationStopAfterShowingTitlebar) * |
| + (1.0 - animation_stop_to_show_titlebar_) / |
| + (1.0 - kAnimationStopAfterShowingTitlebar); |
| + } |
| + return value; |
| +} |
| + |