Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/ui/panels/panel_browser_view.cc

Issue 8787009: Add 3-stage animation for minimization of Panels on Win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_browser_view.h" 5 #include "chrome/browser/ui/panels/panel_browser_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/ui/panels/panel.h" 9 #include "chrome/browser/ui/panels/panel.h"
10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" 10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
11 #include "chrome/browser/ui/panels/panel_manager.h" 11 #include "chrome/browser/ui/panels/panel_manager.h"
12 #include "chrome/browser/ui/views/frame/browser_frame.h" 12 #include "chrome/browser/ui/views/frame/browser_frame.h"
13 #include "chrome/browser/ui/webui/task_manager_dialog.h" 13 #include "chrome/browser/ui/webui/task_manager_dialog.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
18 #include "ui/base/animation/slide_animation.h" 18 #include "ui/base/animation/slide_animation.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
21 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 22
23 namespace { 23 namespace {
24 // This value is experimental and subjective. 24 // This value is experimental and subjective.
25 const int kSetBoundsAnimationMs = 180; 25 const int kSetBoundsAnimationMs = 180;
26 const int kSetBoundsAnimationMinimizeMs = 1500;
26 27
27 // The threshold to differentiate the short click and long click. 28 // The threshold to differentiate the short click and long click.
28 const int kShortClickThresholdMs = 200; 29 const int kShortClickThresholdMs = 200;
29 30
30 // Delay before click-to-minimize is allowed after the attention has been 31 // Delay before click-to-minimize is allowed after the attention has been
31 // cleared. 32 // cleared.
32 const int kSuspendMinimizeOnClickIntervalMs = 500; 33 const int kSuspendMinimizeOnClickIntervalMs = 500;
33 34
34 } 35 }
35 36
37 class CustomSlideAnimation : public ui::SlideAnimation {
38 public:
39 CustomSlideAnimation(ui::AnimationDelegate* target,
40 bool do_minimize,
41 double animation_stop_to_show_titlebar)
42 : ui::SlideAnimation(target),
43 do_minimize_(do_minimize),
44 animation_stop_to_show_titlebar_(animation_stop_to_show_titlebar) { }
45
46 virtual ~CustomSlideAnimation() {}
47 virtual double GetCurrentValue() const OVERRIDE;
48 private:
jianli 2011/12/03 01:08:06 nit: empty line
Dmitry Titov 2011/12/03 01:27:52 Done.
49 bool do_minimize_;
jianli 2011/12/03 01:08:06 nit: probably for_minimize_ sounds better?
Dmitry Titov 2011/12/03 01:27:52 Done.
50 double animation_stop_to_show_titlebar_;
51 };
52
53 double CustomSlideAnimation::GetCurrentValue() const {
54 double progress = ui::SlideAnimation::GetCurrentValue();
55 if (!do_minimize_) {
56 // Cubic easing out.
57 float value = 1.0 - progress;
58 return 1.0 - value * value * value;
59 }
60
61 // Minimize animation:
62 // 1. Quickly (0 -> 0.15) make only titlebar visible.
63 // 2. Stay a little bit (0.15->0.6) in place, just showing titlebar.
64 // 3. Slowly minimize to thin strip (0.6->1.0)
65 const double kAnimationStopAfterQuickDecrease = 0.15;
66 const double kAnimationStopAfterShowingTitlebar = 0.6;
67 double value;
68 if (progress <= kAnimationStopAfterQuickDecrease) {
69 value = progress * animation_stop_to_show_titlebar_ /
jianli 2011/12/03 01:08:06 nit: indenting
Dmitry Titov 2011/12/03 01:27:52 Done.
70 kAnimationStopAfterQuickDecrease;
71 } else if (progress <= kAnimationStopAfterShowingTitlebar) {
72 value = animation_stop_to_show_titlebar_;
73 } else {
74 value = animation_stop_to_show_titlebar_ +
75 (progress - kAnimationStopAfterShowingTitlebar) *
76 (1.0 - animation_stop_to_show_titlebar_) /
77 (1.0 - kAnimationStopAfterShowingTitlebar);
78 }
79 return value;
80 }
81
36 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, 82 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel,
37 const gfx::Rect& bounds) { 83 const gfx::Rect& bounds) {
38 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); 84 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds);
39 (new BrowserFrame(view))->InitBrowserFrame(); 85 (new BrowserFrame(view))->InitBrowserFrame();
40 return view; 86 return view;
41 } 87 }
42 88
43 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, 89 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel,
44 const gfx::Rect& bounds) 90 const gfx::Rect& bounds)
45 : BrowserView(browser), 91 : BrowserView(browser),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 bounds_ = bounds; 167 bounds_ = bounds;
122 168
123 // No animation if the panel is being dragged. 169 // No animation if the panel is being dragged.
124 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { 170 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) {
125 ::BrowserView::SetBounds(bounds); 171 ::BrowserView::SetBounds(bounds);
126 return; 172 return;
127 } 173 }
128 174
129 animation_start_bounds_ = GetBounds(); 175 animation_start_bounds_ = GetBounds();
130 176
131 if (!bounds_animator_.get()) { 177 // Detect animation that happens when expansion state is set to MINIMIZED
132 bounds_animator_.reset(new ui::SlideAnimation(this)); 178 // and there is relatively big portion of the panel to hide from view.
133 bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs); 179 // Initialize animation differently in this case, using fast-pause-slow
180 // method, see below for more details.
181 double animation_stop_to_show_titlebar = 0;
182 bool do_minimize = false;
183 int duration = kSetBoundsAnimationMs;
184 if (panel_->expansion_state() == Panel::MINIMIZED) {
185 animation_stop_to_show_titlebar =
186 1.0 - static_cast<double>((TitleOnlyHeight() - bounds.height())) /
187 (GetBounds().height() - bounds.height());
188 if (animation_stop_to_show_titlebar > 0.7) { // Relatively big movement.
189 do_minimize = true;
190 duration = kSetBoundsAnimationMinimizeMs;
191 }
134 } 192 }
135 193
136 if (bounds_animator_->IsShowing()) 194 bounds_animator_.reset(new CustomSlideAnimation(
137 bounds_animator_->Reset(); 195 this, do_minimize, animation_stop_to_show_titlebar));
196 bounds_animator_->SetSlideDuration(duration);
138 bounds_animator_->Show(); 197 bounds_animator_->Show();
139 } 198 }
140 199
141 void PanelBrowserView::UpdateTitleBar() { 200 void PanelBrowserView::UpdateTitleBar() {
142 ::BrowserView::UpdateTitleBar(); 201 ::BrowserView::UpdateTitleBar();
143 GetFrameView()->UpdateTitleBar(); 202 GetFrameView()->UpdateTitleBar();
144 } 203 }
145 204
146 bool PanelBrowserView::GetSavedWindowPlacement( 205 bool PanelBrowserView::GetSavedWindowPlacement(
147 gfx::Rect* bounds, 206 gfx::Rect* bounds,
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 645 }
587 646
588 bool NativePanelTestingWin::IsWindowSizeKnown() const { 647 bool NativePanelTestingWin::IsWindowSizeKnown() const {
589 return true; 648 return true;
590 } 649 }
591 650
592 bool NativePanelTestingWin::IsAnimatingBounds() const { 651 bool NativePanelTestingWin::IsAnimatingBounds() const {
593 return panel_browser_view_->bounds_animator_.get() && 652 return panel_browser_view_->bounds_animator_.get() &&
594 panel_browser_view_->bounds_animator_->is_animating(); 653 panel_browser_view_->bounds_animator_->is_animating();
595 } 654 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698