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

Side by Side Diff: chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm

Issue 2430403003: [Mac] Refactor the fullscreen toolbar animation (Closed)
Patch Set: Fix for rsesek Created 4 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control ler.h"
6
7 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h"
8
9 namespace {
10
11 // The duration of the toolbar show/hide animation in ms.
12 const NSTimeInterval kToolbarAnimationDuration = 200;
13
14 // If the fullscreen toolbar is hidden, it is difficult for the user to see
15 // changes in the tabstrip. As a result, if a tab is inserted or the current
16 // tab switched to a new one, the toolbar must animate in and out to display
17 // the tabstrip changes to the user. The animation drops down the toolbar and
18 // then wait for 0.75 seconds before it hides the toolbar.
19 const NSTimeInterval kTabStripChangesDelay = 750;
20
21 } // end namespace
22
23 //////////////////////////////////////////////////////////////////
24 // FullscreenToolbarAnimationController, public:
25
26 FullscreenToolbarAnimationController::FullscreenToolbarAnimationController(
27 FullscreenToolbarController* owner)
28 : owner_(owner),
29 animation_(this),
30 hide_toolbar_timer_(
31 FROM_HERE,
32 base::TimeDelta::FromMilliseconds(kTabStripChangesDelay),
33 base::Bind(&FullscreenToolbarAnimationController::
34 AnimateToolbarOutIfPossible,
35 base::Unretained(this)),
36 false),
37 animation_start_value_(0),
38 should_hide_toolbar_after_delay_(false) {
39 animation_.SetSlideDuration(kToolbarAnimationDuration);
40 animation_.SetTweenType(gfx::Tween::EASE_OUT);
41 }
42
43 void FullscreenToolbarAnimationController::ToolbarDidUpdate() {
44 animation_start_value_ = [owner_ toolbarFraction];
45 }
46
47 void FullscreenToolbarAnimationController::StopAnimationAndTimer() {
48 animation_.Stop();
49 hide_toolbar_timer_.Stop();
50 }
51
52 void FullscreenToolbarAnimationController::AnimateToolbarForTabstripChanges() {
53 // Don't kickstart the animation if the toolbar is already displayed.
54 if ([owner_ mustShowFullscreenToolbar])
55 return;
56
57 AnimateToolbarIn();
58 should_hide_toolbar_after_delay_ = true;
59 }
60
61 void FullscreenToolbarAnimationController::AnimateToolbarIn() {
62 if (![owner_ isInFullscreen])
63 return;
64
65 if (animation_.IsShowing())
66 return;
67
68 animation_.Reset(animation_start_value_);
69 animation_.Show();
70 }
71
72 void FullscreenToolbarAnimationController::AnimateToolbarOutIfPossible() {
73 if (![owner_ isInFullscreen] || [owner_ mustShowFullscreenToolbar])
74 return;
75
76 if (animation_.IsClosing())
77 return;
78
79 animation_.Reset(animation_start_value_);
80 animation_.Hide();
81 }
82
83 CGFloat FullscreenToolbarAnimationController::GetToolbarFractionFromProgress()
84 const {
85 return animation_.GetCurrentValue();
86 }
87
88 bool FullscreenToolbarAnimationController::IsAnimationRunning() const {
89 return animation_.is_animating();
90 }
91
92 //////////////////////////////////////////////////////////////////
93 // FullscreenToolbarAnimationController::AnimationDelegate:
94
95 void FullscreenToolbarAnimationController::AnimationProgressed(
96 const gfx::Animation* animation) {
97 [owner_ updateToolbar];
98 }
99
100 void FullscreenToolbarAnimationController::AnimationEnded(
101 const gfx::Animation* animation) {
102 if (animation_.IsShowing() && should_hide_toolbar_after_delay_) {
103 hide_toolbar_timer_.Reset();
104 should_hide_toolbar_after_delay_ = false;
105 }
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698