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_slide_animation.h" |
13 #include "chrome/browser/ui/panels/panel_strip.h" | 14 #include "chrome/browser/ui/panels/panel_strip.h" |
14 #include "chrome/browser/ui/views/frame/browser_frame.h" | 15 #include "chrome/browser/ui/views/frame/browser_frame.h" |
15 #include "chrome/browser/ui/webui/task_manager_dialog.h" | 16 #include "chrome/browser/ui/webui/task_manager_dialog.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 // This value is experimental and subjective. | |
26 const int kSetBoundsAnimationMs = 180; | |
27 const int kSetBoundsAnimationMinimizeMs = 1500; | |
28 | |
29 // The threshold to differentiate the short click and long click. | 26 // The threshold to differentiate the short click and long click. |
30 const int kShortClickThresholdMs = 200; | 27 const int kShortClickThresholdMs = 200; |
31 | 28 |
32 // Delay before click-to-minimize is allowed after the attention has been | 29 // Delay before click-to-minimize is allowed after the attention has been |
33 // cleared. | 30 // cleared. |
34 const int kSuspendMinimizeOnClickIntervalMs = 500; | 31 const int kSuspendMinimizeOnClickIntervalMs = 500; |
35 | |
36 } | |
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 } | 32 } |
66 | 33 |
67 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 34 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
68 const gfx::Rect& bounds) { | 35 const gfx::Rect& bounds) { |
69 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 36 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
70 (new BrowserFrame(view))->InitBrowserFrame(); | 37 (new BrowserFrame(view))->InitBrowserFrame(); |
71 return view; | 38 return view; |
72 } | 39 } |
73 | 40 |
74 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 41 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 bounds_ = new_bounds; | 129 bounds_ = new_bounds; |
163 | 130 |
164 // No animation if the panel is being dragged. | 131 // No animation if the panel is being dragged. |
165 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { | 132 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { |
166 ::BrowserView::SetBounds(new_bounds); | 133 ::BrowserView::SetBounds(new_bounds); |
167 return; | 134 return; |
168 } | 135 } |
169 | 136 |
170 animation_start_bounds_ = GetBounds(); | 137 animation_start_bounds_ = GetBounds(); |
171 | 138 |
172 // Detect animation that happens when expansion state is set to MINIMIZED | |
173 // and there is relatively big portion of the panel to hide from view. | |
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 } | |
187 } | |
188 | |
189 bounds_animator_.reset(new PanelSlideAnimation( | 139 bounds_animator_.reset(new PanelSlideAnimation( |
190 this, for_minimize, animation_stop_to_show_titlebar)); | 140 this, panel(), animation_start_bounds_, new_bounds)); |
191 bounds_animator_->SetSlideDuration(duration); | |
192 bounds_animator_->Show(); | 141 bounds_animator_->Show(); |
193 } | 142 } |
194 | 143 |
195 void PanelBrowserView::UpdateTitleBar() { | 144 void PanelBrowserView::UpdateTitleBar() { |
196 ::BrowserView::UpdateTitleBar(); | 145 ::BrowserView::UpdateTitleBar(); |
197 GetFrameView()->UpdateTitleBar(); | 146 GetFrameView()->UpdateTitleBar(); |
198 } | 147 } |
199 | 148 |
200 bool PanelBrowserView::GetSavedWindowPlacement( | 149 bool PanelBrowserView::GetSavedWindowPlacement( |
201 gfx::Rect* bounds, | 150 gfx::Rect* bounds, |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 } | 619 } |
671 | 620 |
672 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 621 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
673 return true; | 622 return true; |
674 } | 623 } |
675 | 624 |
676 bool NativePanelTestingWin::IsAnimatingBounds() const { | 625 bool NativePanelTestingWin::IsAnimatingBounds() const { |
677 return panel_browser_view_->bounds_animator_.get() && | 626 return panel_browser_view_->bounds_animator_.get() && |
678 panel_browser_view_->bounds_animator_->is_animating(); | 627 panel_browser_view_->bounds_animator_->is_animating(); |
679 } | 628 } |
OLD | NEW |