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 { |
|
prasadt
2011/12/06 23:21:30
Empty line needed as per coding-style.
Dmitry Titov
2011/12/07 03:46:04
Done.
|
| +// These values are experimental and subjective. |
| +const int kSetBoundsAnimationMs = 180; |
| +const int kSetBoundsAnimationMinimizeMs = 1500; |
|
prasadt
2011/12/06 23:21:30
Empty line needed as per coding-style.
Dmitry Titov
2011/12/07 03:46:04
Done.
|
| +} |
| + |
| +PanelSlideAnimation::PanelSlideAnimation(ui::AnimationDelegate* target, |
| + Panel* panel, |
| + gfx::Rect initial_bounds, |
| + gfx::Rect final_bounds) |
| + : ui::SlideAnimation(target), |
| + 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. |
|
prasadt
2011/12/06 23:21:30
I find it easier to read the other way:
distance_
Dmitry Titov
2011/12/07 03:46:04
Hmm. it would add another long-name variable. Why
prasadt
2011/12/07 17:59:31
distance_to_title_height_ratio tells me its a rati
|
| + for_minimize_ = true; |
|
prasadt
2011/12/06 23:21:30
for_minimize_ is not quite what it is. How about c
Dmitry Titov
2011/12/07 03:46:04
I wanted to capture "we are doing minimize animati
|
| + duration = kSetBoundsAnimationMinimizeMs; |
|
prasadt
2011/12/06 23:21:30
Same comment - I suggest calling it kSetBoundsAnim
Dmitry Titov
2011/12/07 03:46:04
Ditto. 3 steps is just current impl of it.
|
| + } |
| + } |
| + SetSlideDuration(duration); |
| +} |
| + |
| +PanelSlideAnimation::~PanelSlideAnimation() { } |
| + |
| +double PanelSlideAnimation::GetCurrentValue() const { |
| + double progress = ui::SlideAnimation::GetCurrentValue(); |
| + if (!for_minimize_) { |
| + // Cubic easing out. |
| + float value = 1.0 - progress; |
| + return 1.0 - value * value * value; |
| + } |
| + |
| + // Minimize animation: |
|
prasadt
2011/12/06 23:21:30
Minimize animation: -> Three step animation:
dcheng
2011/12/06 23:49:01
Doesn't the 3-step animation only apply to minimiz
prasadt
2011/12/06 23:58:11
3-step implies minimizing but minimizing does not
dcheng
2011/12/07 00:02:45
I see. I don't think three step is particularly sp
Dmitry Titov
2011/12/07 03:46:04
I changed comment to mention that minimize animati
|
| + // 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_ / |
| + kAnimationStopAfterQuickDecrease; |
|
prasadt
2011/12/06 23:21:30
I think the intent comes through more clearly if y
Dmitry Titov
2011/12/07 03:46:04
Done.
|
| + } else if (progress <= kAnimationStopAfterShowingTitlebar) { |
|
prasadt
2011/12/06 23:21:30
Shouldn't the if condition be:
if (progress <= (kA
Dmitry Titov
2011/12/07 03:46:04
Discussed offline, changed constants names to be m
|
| + 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); |
|
prasadt
2011/12/06 23:21:30
The above equation doesn't seem to add up for some
Dmitry Titov
2011/12/07 03:46:04
Changed from 'physical' (time past * speed) to 'ma
|
| + } |
| + return value; |
| +} |
| + |