OLD | NEW |
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/panels/panel_overflow_strip.h" | 12 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
13 #include "chrome/browser/ui/panels/panel_strip.h" | 13 #include "chrome/browser/ui/panels/panel_strip.h" |
14 #include "chrome/browser/ui/views/frame/browser_frame.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame.h" |
15 #include "chrome/browser/ui/webui/task_manager_dialog.h" | 15 #include "chrome/browser/ui/webui/task_manager_dialog.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
20 #include "ui/base/animation/slide_animation.h" | |
21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
23 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
24 | 23 |
25 namespace { | 24 namespace { |
26 // This value is experimental and subjective. | 25 // This value is experimental and subjective. |
27 const int kSetBoundsAnimationMs = 180; | 26 const int kSetBoundsAnimationMs = 180; |
| 27 const int kSetBoundsAnimationMinimizeMs = 1500; |
28 | 28 |
29 // The threshold to differentiate the short click and long click. | 29 // The threshold to differentiate the short click and long click. |
30 const int kShortClickThresholdMs = 200; | 30 const int kShortClickThresholdMs = 200; |
31 | 31 |
32 // Delay before click-to-minimize is allowed after the attention has been | 32 // Delay before click-to-minimize is allowed after the attention has been |
33 // cleared. | 33 // cleared. |
34 const int kSuspendMinimizeOnClickIntervalMs = 500; | 34 const int kSuspendMinimizeOnClickIntervalMs = 500; |
35 | 35 |
36 } | 36 } |
37 | 37 |
| 38 double PanelSlideAnimation::GetCurrentValue() const { |
| 39 double progress = ui::SlideAnimation::GetCurrentValue(); |
| 40 if (!for_minimize_) { |
| 41 // Cubic easing out. |
| 42 float value = 1.0 - progress; |
| 43 return 1.0 - value * value * value; |
| 44 } |
| 45 |
| 46 // Minimize animation: |
| 47 // 1. Quickly (0 -> 0.15) make only titlebar visible. |
| 48 // 2. Stay a little bit (0.15->0.6) in place, just showing titlebar. |
| 49 // 3. Slowly minimize to thin strip (0.6->1.0) |
| 50 const double kAnimationStopAfterQuickDecrease = 0.15; |
| 51 const double kAnimationStopAfterShowingTitlebar = 0.6; |
| 52 double value; |
| 53 if (progress <= kAnimationStopAfterQuickDecrease) { |
| 54 value = progress * animation_stop_to_show_titlebar_ / |
| 55 kAnimationStopAfterQuickDecrease; |
| 56 } else if (progress <= kAnimationStopAfterShowingTitlebar) { |
| 57 value = animation_stop_to_show_titlebar_; |
| 58 } else { |
| 59 value = animation_stop_to_show_titlebar_ + |
| 60 (progress - kAnimationStopAfterShowingTitlebar) * |
| 61 (1.0 - animation_stop_to_show_titlebar_) / |
| 62 (1.0 - kAnimationStopAfterShowingTitlebar); |
| 63 } |
| 64 return value; |
| 65 } |
| 66 |
38 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 67 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
39 const gfx::Rect& bounds) { | 68 const gfx::Rect& bounds) { |
40 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 69 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
41 (new BrowserFrame(view))->InitBrowserFrame(); | 70 (new BrowserFrame(view))->InitBrowserFrame(); |
42 return view; | 71 return view; |
43 } | 72 } |
44 | 73 |
45 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 74 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
46 const gfx::Rect& bounds) | 75 const gfx::Rect& bounds) |
47 : BrowserView(browser), | 76 : BrowserView(browser), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 bounds_ = new_bounds; | 162 bounds_ = new_bounds; |
134 | 163 |
135 // No animation if the panel is being dragged. | 164 // No animation if the panel is being dragged. |
136 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { | 165 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { |
137 ::BrowserView::SetBounds(new_bounds); | 166 ::BrowserView::SetBounds(new_bounds); |
138 return; | 167 return; |
139 } | 168 } |
140 | 169 |
141 animation_start_bounds_ = GetBounds(); | 170 animation_start_bounds_ = GetBounds(); |
142 | 171 |
143 if (!bounds_animator_.get()) { | 172 // Detect animation that happens when expansion state is set to MINIMIZED |
144 bounds_animator_.reset(new ui::SlideAnimation(this)); | 173 // and there is relatively big portion of the panel to hide from view. |
145 bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs); | 174 // Initialize animation differently in this case, using fast-pause-slow |
| 175 // method, see below for more details. |
| 176 double animation_stop_to_show_titlebar = 0; |
| 177 bool for_minimize = false; |
| 178 int duration = kSetBoundsAnimationMs; |
| 179 if (panel_->expansion_state() == Panel::MINIMIZED) { |
| 180 animation_stop_to_show_titlebar = |
| 181 1.0 - static_cast<double>((TitleOnlyHeight() - new_bounds.height())) / |
| 182 (GetBounds().height() - new_bounds.height()); |
| 183 if (animation_stop_to_show_titlebar > 0.7) { // Relatively big movement. |
| 184 for_minimize = true; |
| 185 duration = kSetBoundsAnimationMinimizeMs; |
| 186 } |
146 } | 187 } |
147 | 188 |
148 if (bounds_animator_->IsShowing()) | 189 bounds_animator_.reset(new PanelSlideAnimation( |
149 bounds_animator_->Reset(); | 190 this, for_minimize, animation_stop_to_show_titlebar)); |
| 191 bounds_animator_->SetSlideDuration(duration); |
150 bounds_animator_->Show(); | 192 bounds_animator_->Show(); |
151 } | 193 } |
152 | 194 |
153 void PanelBrowserView::UpdateTitleBar() { | 195 void PanelBrowserView::UpdateTitleBar() { |
154 ::BrowserView::UpdateTitleBar(); | 196 ::BrowserView::UpdateTitleBar(); |
155 GetFrameView()->UpdateTitleBar(); | 197 GetFrameView()->UpdateTitleBar(); |
156 } | 198 } |
157 | 199 |
158 bool PanelBrowserView::GetSavedWindowPlacement( | 200 bool PanelBrowserView::GetSavedWindowPlacement( |
159 gfx::Rect* bounds, | 201 gfx::Rect* bounds, |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 } | 670 } |
629 | 671 |
630 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 672 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
631 return true; | 673 return true; |
632 } | 674 } |
633 | 675 |
634 bool NativePanelTestingWin::IsAnimatingBounds() const { | 676 bool NativePanelTestingWin::IsAnimatingBounds() const { |
635 return panel_browser_view_->bounds_animator_.get() && | 677 return panel_browser_view_->bounds_animator_.get() && |
636 panel_browser_view_->bounds_animator_->is_animating(); | 678 panel_browser_view_->bounds_animator_->is_animating(); |
637 } | 679 } |
OLD | NEW |