| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 5 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/panels/panel.h" | 7 #include "chrome/browser/ui/panels/panel.h" |
| 8 #include "chrome/browser/ui/panels/panel_manager.h" | 8 #include "chrome/browser/ui/panels/panel_manager.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 // These values are experimental and subjective. | 12 // These values are experimental and subjective. |
| 13 const int kDefaultFramerateHz = 50; | 13 const int kDefaultFramerateHz = 50; |
| 14 const int kSetBoundsAnimationMs = 180; | 14 const int kSetBoundsAnimationMs = 180; |
| 15 const int kSetBoundsAnimationBigMinimizeMs = 1500; | 15 const int kSetBoundsAnimationBigMinimizeMs = 1500; |
| 16 | 16 |
| 17 } | 17 } |
| 18 | 18 |
| 19 PanelBoundsAnimation::PanelBoundsAnimation(ui::AnimationDelegate* target, | 19 PanelBoundsAnimation::PanelBoundsAnimation(gfx::AnimationDelegate* target, |
| 20 Panel* panel, | 20 Panel* panel, |
| 21 const gfx::Rect& initial_bounds, | 21 const gfx::Rect& initial_bounds, |
| 22 const gfx::Rect& final_bounds) | 22 const gfx::Rect& final_bounds) |
| 23 : ui::LinearAnimation(kDefaultFramerateHz, target), | 23 : gfx::LinearAnimation(kDefaultFramerateHz, target), |
| 24 panel_(panel), | 24 panel_(panel), |
| 25 for_big_minimize_(false), | 25 for_big_minimize_(false), |
| 26 animation_stop_to_show_titlebar_(0) { | 26 animation_stop_to_show_titlebar_(0) { |
| 27 // Detect animation that happens when expansion state is set to MINIMIZED | 27 // Detect animation that happens when expansion state is set to MINIMIZED |
| 28 // and there is relatively big portion of the panel to hide from view. | 28 // and there is relatively big portion of the panel to hide from view. |
| 29 // Initialize animation differently in this case, using fast-pause-slow | 29 // Initialize animation differently in this case, using fast-pause-slow |
| 30 // method, see below for more details. | 30 // method, see below for more details. |
| 31 int duration = kSetBoundsAnimationMs; | 31 int duration = kSetBoundsAnimationMs; |
| 32 if (initial_bounds.height() > final_bounds.height() && | 32 if (initial_bounds.height() > final_bounds.height() && |
| 33 panel_->expansion_state() == Panel::MINIMIZED) { | 33 panel_->expansion_state() == Panel::MINIMIZED) { |
| 34 double hidden_title_height = | 34 double hidden_title_height = |
| 35 panel_->TitleOnlyHeight() - final_bounds.height(); | 35 panel_->TitleOnlyHeight() - final_bounds.height(); |
| 36 double distance_y = initial_bounds.height() - final_bounds.height(); | 36 double distance_y = initial_bounds.height() - final_bounds.height(); |
| 37 animation_stop_to_show_titlebar_ = 1.0 - hidden_title_height / distance_y; | 37 animation_stop_to_show_titlebar_ = 1.0 - hidden_title_height / distance_y; |
| 38 if (animation_stop_to_show_titlebar_ > 0.7) { // Relatively big movement. | 38 if (animation_stop_to_show_titlebar_ > 0.7) { // Relatively big movement. |
| 39 for_big_minimize_ = true; | 39 for_big_minimize_ = true; |
| 40 duration = kSetBoundsAnimationBigMinimizeMs; | 40 duration = kSetBoundsAnimationBigMinimizeMs; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 SetDuration(PanelManager::AdjustTimeInterval(duration)); | 43 SetDuration(PanelManager::AdjustTimeInterval(duration)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 PanelBoundsAnimation::~PanelBoundsAnimation() { | 46 PanelBoundsAnimation::~PanelBoundsAnimation() { |
| 47 } | 47 } |
| 48 | 48 |
| 49 double PanelBoundsAnimation::GetCurrentValue() const { | 49 double PanelBoundsAnimation::GetCurrentValue() const { |
| 50 return ComputeAnimationValue(ui::LinearAnimation::GetCurrentValue(), | 50 return ComputeAnimationValue(gfx::LinearAnimation::GetCurrentValue(), |
| 51 for_big_minimize_, | 51 for_big_minimize_, |
| 52 animation_stop_to_show_titlebar_); | 52 animation_stop_to_show_titlebar_); |
| 53 } | 53 } |
| 54 | 54 |
| 55 double PanelBoundsAnimation::ComputeAnimationValue(double progress, | 55 double PanelBoundsAnimation::ComputeAnimationValue(double progress, |
| 56 bool for_big_minimize, double animation_stop_to_show_titlebar) { | 56 bool for_big_minimize, double animation_stop_to_show_titlebar) { |
| 57 if (!for_big_minimize) { | 57 if (!for_big_minimize) { |
| 58 // Cubic easing out. | 58 // Cubic easing out. |
| 59 double value = 1.0 - progress; | 59 double value = 1.0 - progress; |
| 60 return 1.0 - value * value * value; | 60 return 1.0 - value * value * value; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 (progress / kProgressAtFreezeStart); | 72 (progress / kProgressAtFreezeStart); |
| 73 } else if (progress <= kProgressAtFreezeEnd) { | 73 } else if (progress <= kProgressAtFreezeEnd) { |
| 74 value = animation_stop_to_show_titlebar; | 74 value = animation_stop_to_show_titlebar; |
| 75 } else { | 75 } else { |
| 76 value = animation_stop_to_show_titlebar + | 76 value = animation_stop_to_show_titlebar + |
| 77 (1.0 - animation_stop_to_show_titlebar) * | 77 (1.0 - animation_stop_to_show_titlebar) * |
| 78 ((progress - kProgressAtFreezeEnd) / (1.0 - kProgressAtFreezeEnd)); | 78 ((progress - kProgressAtFreezeEnd) / (1.0 - kProgressAtFreezeEnd)); |
| 79 } | 79 } |
| 80 return value; | 80 return value; |
| 81 } | 81 } |
| OLD | NEW |