Chromium Code Reviews| OLD | NEW |
|---|---|
| (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)), | |
|
erikchen
2016/10/21 17:22:03
is it possible for there to be a task queued on th
spqchan
2016/10/21 18:26:55
No, the Timer's deconstructor will stop and abando
| |
| 36 false), | |
| 37 toolbar_fraction_(0), | |
| 38 should_hide_toolbar_after_delay_(false), | |
| 39 disable_animations_during_testing_(false) { | |
| 40 animation_.SetSlideDuration(kToolbarAnimationDuration); | |
| 41 animation_.SetTweenType(gfx::Tween::EASE_OUT); | |
| 42 } | |
| 43 | |
| 44 void FullscreenToolbarAnimationController::UpdateToolbarFraction( | |
| 45 CGFloat fraction) { | |
| 46 toolbar_fraction_ = fraction; | |
| 47 } | |
| 48 | |
| 49 void FullscreenToolbarAnimationController::StopAnimationAndTimer() { | |
| 50 animation_.Stop(); | |
| 51 hide_toolbar_timer_.Stop(); | |
| 52 } | |
| 53 | |
| 54 void FullscreenToolbarAnimationController::AnimateToolbarForTabstripChanges() { | |
| 55 if ([owner_ mustShowFullscreenToolbar]) | |
| 56 return; | |
| 57 | |
| 58 AnimateToolbarIn(); | |
| 59 should_hide_toolbar_after_delay_ = true; | |
| 60 } | |
| 61 | |
| 62 void FullscreenToolbarAnimationController::AnimateToolbarIn() { | |
| 63 if (![owner_ isInFullscreen]) | |
| 64 return; | |
| 65 | |
| 66 if (animation_.IsShowing()) | |
| 67 return; | |
| 68 | |
| 69 if (disable_animations_during_testing_) { | |
| 70 toolbar_fraction_ = 1.0; | |
| 71 [owner_ updateToolbar]; | |
| 72 return; | |
| 73 } | |
| 74 | |
| 75 animation_.Reset(toolbar_fraction_); | |
| 76 animation_.Show(); | |
| 77 } | |
| 78 | |
| 79 void FullscreenToolbarAnimationController::AnimateToolbarOutIfPossible() { | |
| 80 if (![owner_ isInFullscreen] || [owner_ mustShowFullscreenToolbar]) | |
| 81 return; | |
| 82 | |
| 83 if (animation_.IsClosing()) | |
| 84 return; | |
| 85 | |
| 86 if (disable_animations_during_testing_) { | |
| 87 toolbar_fraction_ = 0.0; | |
| 88 [owner_ updateToolbar]; | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 animation_.Reset(toolbar_fraction_); | |
| 93 animation_.Hide(); | |
| 94 } | |
| 95 | |
| 96 CGFloat FullscreenToolbarAnimationController::GetToolbarFraction() const { | |
| 97 return toolbar_fraction_; | |
| 98 } | |
| 99 | |
| 100 BOOL FullscreenToolbarAnimationController::IsAnimationRunning() const { | |
| 101 return animation_.is_animating(); | |
| 102 } | |
| 103 | |
| 104 ////////////////////////////////////////////////////////////////// | |
| 105 // FullscreenToolbarAnimationController::AnimationDelegate: | |
| 106 | |
| 107 void FullscreenToolbarAnimationController::AnimationProgressed( | |
| 108 const gfx::Animation* animation) { | |
| 109 toolbar_fraction_ = animation->GetCurrentValue(); | |
| 110 [owner_ updateToolbar]; | |
| 111 } | |
| 112 | |
| 113 void FullscreenToolbarAnimationController::AnimationEnded( | |
| 114 const gfx::Animation* animation) { | |
| 115 if (animation_.IsShowing() && should_hide_toolbar_after_delay_) { | |
| 116 hide_toolbar_timer_.Reset(); | |
| 117 should_hide_toolbar_after_delay_ = false; | |
| 118 } | |
| 119 } | |
| OLD | NEW |