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

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 erikchen 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::UpdateToolbar() {
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 if ([owner_ mustShowFullscreenToolbar])
54 return;
55
56 AnimateToolbarIn();
57 should_hide_toolbar_after_delay_ = true;
58 }
59
60 void FullscreenToolbarAnimationController::AnimateToolbarIn() {
61 if (![owner_ isInFullscreen])
62 return;
63
64 if (animation_.IsShowing())
65 return;
66
67 animation_.Reset(animation_start_value_);
68 animation_.Show();
69 }
70
71 void FullscreenToolbarAnimationController::AnimateToolbarOutIfPossible() {
72 if (![owner_ isInFullscreen] || [owner_ mustShowFullscreenToolbar])
73 return;
74
75 if (animation_.IsClosing())
76 return;
77
78 animation_.Reset(animation_start_value_);
79 animation_.Hide();
80 }
81
82 CGFloat FullscreenToolbarAnimationController::GetToolbarFractionFromProgress()
83 const {
84 return animation_.GetCurrentValue();
85 }
86
87 BOOL FullscreenToolbarAnimationController::IsAnimationRunning() const {
88 return animation_.is_animating();
89 }
90
91 //////////////////////////////////////////////////////////////////
92 // FullscreenToolbarAnimationController::AnimationDelegate:
93
94 void FullscreenToolbarAnimationController::AnimationProgressed(
95 const gfx::Animation* animation) {
96 [owner_ updateToolbar];
97 }
98
99 void FullscreenToolbarAnimationController::AnimationEnded(
100 const gfx::Animation* animation) {
101 if (animation_.IsShowing() && should_hide_toolbar_after_delay_) {
102 hide_toolbar_timer_.Reset();
103 should_hide_toolbar_after_delay_ = false;
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698