Commit e53da6c7 authored by dimich@chromium.org's avatar dimich@chromium.org

Panels: Adding 3-step animation on minimize on Linux

BUG=104645

Review URL: http://codereview.chromium.org/8826002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113526 0039d316-1c4b-4281-b951-d872f2087c98
parent 021b078a
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/ui/panels/panel_browser_frame_view.h" #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_overflow_strip.h" #include "chrome/browser/ui/panels/panel_overflow_strip.h"
#include "chrome/browser/ui/panels/panel_slide_animation.h"
#include "chrome/browser/ui/panels/panel_strip.h" #include "chrome/browser/ui/panels/panel_strip.h"
#include "chrome/browser/ui/views/frame/browser_frame.h" #include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/webui/task_manager_dialog.h" #include "chrome/browser/ui/webui/task_manager_dialog.h"
...@@ -22,46 +23,12 @@ ...@@ -22,46 +23,12 @@
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace { namespace {
// This value is experimental and subjective.
const int kSetBoundsAnimationMs = 180;
const int kSetBoundsAnimationMinimizeMs = 1500;
// The threshold to differentiate the short click and long click. // The threshold to differentiate the short click and long click.
const int kShortClickThresholdMs = 200; const int kShortClickThresholdMs = 200;
// Delay before click-to-minimize is allowed after the attention has been // Delay before click-to-minimize is allowed after the attention has been
// cleared. // cleared.
const int kSuspendMinimizeOnClickIntervalMs = 500; const int kSuspendMinimizeOnClickIntervalMs = 500;
}
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:
// 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;
} 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;
} }
NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel,
...@@ -169,26 +136,8 @@ void PanelBrowserView::SetBoundsInternal(const gfx::Rect& new_bounds, ...@@ -169,26 +136,8 @@ void PanelBrowserView::SetBoundsInternal(const gfx::Rect& new_bounds,
animation_start_bounds_ = GetBounds(); animation_start_bounds_ = GetBounds();
// 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.
double animation_stop_to_show_titlebar = 0;
bool for_minimize = false;
int duration = kSetBoundsAnimationMs;
if (panel_->expansion_state() == Panel::MINIMIZED) {
animation_stop_to_show_titlebar =
1.0 - static_cast<double>((TitleOnlyHeight() - new_bounds.height())) /
(GetBounds().height() - new_bounds.height());
if (animation_stop_to_show_titlebar > 0.7) { // Relatively big movement.
for_minimize = true;
duration = kSetBoundsAnimationMinimizeMs;
}
}
bounds_animator_.reset(new PanelSlideAnimation( bounds_animator_.reset(new PanelSlideAnimation(
this, for_minimize, animation_stop_to_show_titlebar)); this, panel(), animation_start_bounds_, new_bounds));
bounds_animator_->SetSlideDuration(duration);
bounds_animator_->Show(); bounds_animator_->Show();
} }
......
...@@ -12,28 +12,12 @@ ...@@ -12,28 +12,12 @@
#include "chrome/browser/ui/panels/native_panel.h" #include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/base/animation/animation_delegate.h" #include "ui/base/animation/animation_delegate.h"
#include "ui/base/animation/slide_animation.h"
class Browser; class Browser;
class Panel; class Panel;
class NativePanelTestingWin; class NativePanelTestingWin;
class PanelBrowserFrameView; class PanelBrowserFrameView;
class PanelSlideAnimation;
class PanelSlideAnimation : public ui::SlideAnimation {
public:
PanelSlideAnimation(ui::AnimationDelegate* target,
bool for_minimize,
double animation_stop_to_show_titlebar)
: ui::SlideAnimation(target),
for_minimize_(for_minimize),
animation_stop_to_show_titlebar_(animation_stop_to_show_titlebar) { }
virtual ~PanelSlideAnimation() { }
virtual double GetCurrentValue() const OVERRIDE;
private:
bool for_minimize_;
double animation_stop_to_show_titlebar_;
};
// A browser view that implements Panel specific behavior. // A browser view that implements Panel specific behavior.
class PanelBrowserView : public BrowserView, class PanelBrowserView : public BrowserView,
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
#include "chrome/browser/ui/panels/panel_browser_frame_view.h" #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
#include "chrome/browser/ui/panels/panel_browser_view.h" #include "chrome/browser/ui/panels/panel_browser_view.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_slide_animation.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/menu_button.h"
...@@ -79,7 +79,7 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { ...@@ -79,7 +79,7 @@ class PanelBrowserViewTest : public BasePanelBrowserTest {
return GetBrowserView(panel)->GetNativeHandle(); return GetBrowserView(panel)->GetNativeHandle();
} }
ui::SlideAnimation* GetBoundsAnimator(Panel* panel) const { PanelSlideAnimation* GetBoundsAnimator(Panel* panel) const {
return GetBrowserView(panel)->bounds_animator_.get(); return GetBrowserView(panel)->bounds_animator_.get();
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_settings_menu_model.h" #include "chrome/browser/ui/panels/panel_settings_menu_model.h"
#include "chrome/browser/ui/panels/panel_slide_animation.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "ui/base/animation/slide_animation.h" #include "ui/base/animation/slide_animation.h"
...@@ -17,9 +18,6 @@ ...@@ -17,9 +18,6 @@
namespace { namespace {
// This value is experimental and subjective.
const int kSetBoundsAnimationMs = 180;
// RGB values for titlebar in draw attention state. A shade of orange. // RGB values for titlebar in draw attention state. A shade of orange.
const int kDrawAttentionR = 0xfa; const int kDrawAttentionR = 0xfa;
const int kDrawAttentionG = 0x98; const int kDrawAttentionG = 0x98;
...@@ -149,7 +147,7 @@ void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { ...@@ -149,7 +147,7 @@ void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) {
int left = bounds_.right() - width; int left = bounds_.right() - width;
gtk_window_move(window_, left, top); gtk_window_move(window_, left, top);
StartBoundsAnimation(gfx::Rect(left, top, width, height)); StartBoundsAnimation(bounds_, gfx::Rect(left, top, width, height));
panel_->OnWindowSizeAvailable(); panel_->OnWindowSizeAvailable();
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
...@@ -262,7 +260,7 @@ void PanelBrowserWindowGtk::SetBoundsInternal(const gfx::Rect& bounds, ...@@ -262,7 +260,7 @@ void PanelBrowserWindowGtk::SetBoundsInternal(const gfx::Rect& bounds,
// user drag, we should not animate. // user drag, we should not animate.
gtk_window_move(window(), bounds.x(), bounds.y()); gtk_window_move(window(), bounds.x(), bounds.y());
} else if (window_size_known_) { } else if (window_size_known_) {
StartBoundsAnimation(bounds_); StartBoundsAnimation(bounds_, bounds);
} }
// If window size is not known, wait till the size is known before starting // If window size is not known, wait till the size is known before starting
// the animation. // the animation.
...@@ -412,16 +410,11 @@ int PanelBrowserWindowGtk::TitleOnlyHeight() const { ...@@ -412,16 +410,11 @@ int PanelBrowserWindowGtk::TitleOnlyHeight() const {
} }
void PanelBrowserWindowGtk::StartBoundsAnimation( void PanelBrowserWindowGtk::StartBoundsAnimation(
const gfx::Rect& current_bounds) { const gfx::Rect& from_bounds, const gfx::Rect& to_bounds) {
animation_start_bounds_ = current_bounds; animation_start_bounds_ = from_bounds;
if (!bounds_animator_.get()) {
bounds_animator_.reset(new ui::SlideAnimation(this));
bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs);
}
if (bounds_animator_->IsShowing()) bounds_animator_.reset(new PanelSlideAnimation(
bounds_animator_->Reset(); this, panel_.get(), from_bounds, to_bounds));
bounds_animator_->Show(); bounds_animator_->Show();
} }
......
...@@ -104,7 +104,8 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk, ...@@ -104,7 +104,8 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk,
virtual void EnsurePanelFullyVisible() OVERRIDE; virtual void EnsurePanelFullyVisible() OVERRIDE;
private: private:
void StartBoundsAnimation(const gfx::Rect& current_bounds); void StartBoundsAnimation(const gfx::Rect& from_bounds,
const gfx::Rect& to_bounds);
bool IsAnimatingBounds() const; bool IsAnimatingBounds() const;
// MessageLoop::Observer implementation: // MessageLoop::Observer implementation:
......
// 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 kSetBoundsAnimationBigMinimizeMs = 1500;
}
PanelSlideAnimation::PanelSlideAnimation(ui::AnimationDelegate* target,
Panel* panel,
const gfx::Rect& initial_bounds,
const gfx::Rect& final_bounds)
: ui::SlideAnimation(target),
panel_(panel),
for_big_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_big_minimize_ = true;
duration = kSetBoundsAnimationBigMinimizeMs;
}
}
SetSlideDuration(duration);
}
PanelSlideAnimation::~PanelSlideAnimation() {
}
double PanelSlideAnimation::GetCurrentValue() const {
double progress = ui::SlideAnimation::GetCurrentValue();
return ComputeAnimationValue(progress,
for_big_minimize_,
animation_stop_to_show_titlebar_);
}
double PanelSlideAnimation::ComputeAnimationValue(double progress,
bool for_big_minimize, double animation_stop_to_show_titlebar) {
if (!for_big_minimize) {
// Cubic easing out.
double value = 1.0 - progress;
return 1.0 - value * value * value;
}
// Minimize animation is done in 3 steps:
// 1. Quickly (0 -> 0.15) make only titlebar visible.
// 2. Freeze for a little bit (0.15->0.6), just showing titlebar.
// 3. Slowly minimize to thin strip (0.6->1.0)
const double kProgressAtFreezeStart = 0.15;
const double kProgressAtFreezeEnd = 0.6;
double value;
if (progress <= kProgressAtFreezeStart) {
value = animation_stop_to_show_titlebar *
(progress / kProgressAtFreezeStart);
} else if (progress <= kProgressAtFreezeEnd) {
value = animation_stop_to_show_titlebar;
} else {
value = animation_stop_to_show_titlebar +
(1.0 - animation_stop_to_show_titlebar) *
((progress - kProgressAtFreezeEnd) / (1.0 - kProgressAtFreezeEnd));
}
return value;
}
// 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.
#ifndef CHROME_BROWSER_UI_PANELS_PANEL_SLIDE_ANIMATION_H_
#define CHROME_BROWSER_UI_PANELS_PANEL_SLIDE_ANIMATION_H_
#pragma once
#include "ui/base/animation/slide_animation.h"
namespace ui {
class AnimationDelegate;
}
class Panel;
class PanelSlideAnimation : public ui::SlideAnimation {
public:
PanelSlideAnimation(ui::AnimationDelegate* target,
Panel* panel,
const gfx::Rect& initial_bounds,
const gfx::Rect& final_bounds);
virtual ~PanelSlideAnimation();
virtual double GetCurrentValue() const OVERRIDE;
// Static because it is reused on Mac to override NSAnimation's calculation.
static double ComputeAnimationValue(double progress,
bool for_big_minimize,
double animation_stop_to_show_titlebar);
private:
Panel* panel_; // Weak, owns us.
bool for_big_minimize_;
double animation_stop_to_show_titlebar_;
DISALLOW_COPY_AND_ASSIGN(PanelSlideAnimation);
};
#endif // CHROME_BROWSER_UI_PANELS_PANEL_SLIDE_ANIMATION_H_
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_settings_menu_model.h" #include "chrome/browser/ui/panels/panel_settings_menu_model.h"
#include "chrome/browser/ui/panels/panel_slide_animation.h"
#import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h"
#include "chrome/browser/ui/toolbar/encoding_menu_controller.h" #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
...@@ -475,31 +476,8 @@ enum { ...@@ -475,31 +476,8 @@ enum {
- (float)animation:(NSAnimation*)animation - (float)animation:(NSAnimation*)animation
valueForProgress:(NSAnimationProgress)progress { valueForProgress:(NSAnimationProgress)progress {
if (!playingMinimizeAnimation_) { return PanelSlideAnimation::ComputeAnimationValue(
// Cubic easing out. progress, playingMinimizeAnimation_, animationStopToShowTitlebarOnly_);
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 float kAnimationStopAfterQuickDecrease = 0.15;
const float kAnimationStopAfterShowingTitlebar = 0.6;
float value;
if (progress <= kAnimationStopAfterQuickDecrease) {
value = progress * animationStopToShowTitlebarOnly_ /
kAnimationStopAfterQuickDecrease;
} else if (progress <= kAnimationStopAfterShowingTitlebar) {
value = animationStopToShowTitlebarOnly_;
} else {
value = animationStopToShowTitlebarOnly_ +
(progress - kAnimationStopAfterShowingTitlebar) *
(1.0 - animationStopToShowTitlebarOnly_) /
(1.0 - kAnimationStopAfterShowingTitlebar);
}
return value;
} }
- (void)animationDidEnd:(NSAnimation*)animation { - (void)animationDidEnd:(NSAnimation*)animation {
......
...@@ -3217,6 +3217,8 @@ ...@@ -3217,6 +3217,8 @@
'browser/ui/panels/panel_overflow_strip.h', 'browser/ui/panels/panel_overflow_strip.h',
'browser/ui/panels/panel_settings_menu_model.cc', 'browser/ui/panels/panel_settings_menu_model.cc',
'browser/ui/panels/panel_settings_menu_model.h', 'browser/ui/panels/panel_settings_menu_model.h',
'browser/ui/panels/panel_slide_animation.cc',
'browser/ui/panels/panel_slide_animation.h',
'browser/ui/panels/panel_strip.cc', 'browser/ui/panels/panel_strip.cc',
'browser/ui/panels/panel_strip.h', 'browser/ui/panels/panel_strip.h',
'browser/ui/panels/panel_titlebar_view_cocoa.h', 'browser/ui/panels/panel_titlebar_view_cocoa.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment