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_manager
.h" |
| 6 |
| 7 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_manager.h" |
| 8 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 9 |
| 10 namespace { |
| 11 |
| 12 // The duration of the toolbar show/hide animation in ms. |
| 13 const NSTimeInterval kToolbarAnimationDuration = 200; |
| 14 |
| 15 // If the fullscreen toolbar is hidden, it is difficult for the user to see |
| 16 // changes in the tabstrip. As a result, if a tab is inserted or the current |
| 17 // tab switched to a new one, the toolbar must animate in and out to display |
| 18 // the tabstrip changes to the user. The animation drops down the toolbar and |
| 19 // then wait for 0.75 seconds before it hides the toolbar. |
| 20 const NSTimeInterval kTabStripChangesDelay = 750; |
| 21 |
| 22 } // end namespace |
| 23 |
| 24 ////////////////////////////////////////////////////////////////// |
| 25 // FullscreenToolbarAnimationManager, public: |
| 26 |
| 27 FullscreenToolbarAnimationManager::FullscreenToolbarAnimationManager( |
| 28 FullscreenToolbarLayoutManager* owner) |
| 29 : owner_(owner), |
| 30 animation_(this), |
| 31 hide_toolbar_timer_( |
| 32 FROM_HERE, |
| 33 base::TimeDelta::FromMilliseconds(kTabStripChangesDelay), |
| 34 base::Bind( |
| 35 &FullscreenToolbarAnimationManager::AnimateToolbarOutIfPossible, |
| 36 base::Unretained(this)), |
| 37 false), |
| 38 toolbar_fraction_(0), |
| 39 should_hide_toolbar_after_delay_(false), |
| 40 disable_animations_during_testing_(false) { |
| 41 animation_.SetSlideDuration(kToolbarAnimationDuration); |
| 42 animation_.SetTweenType(gfx::Tween::EASE_OUT); |
| 43 } |
| 44 |
| 45 void FullscreenToolbarAnimationManager::UpdateToolbarFraction( |
| 46 CGFloat fraction) { |
| 47 toolbar_fraction_ = fraction; |
| 48 } |
| 49 |
| 50 void FullscreenToolbarAnimationManager::StopAnimationAndTimer() { |
| 51 animation_.Stop(); |
| 52 hide_toolbar_timer_.Stop(); |
| 53 } |
| 54 |
| 55 void FullscreenToolbarAnimationManager::AnimateToolbarForTabstripChanges() { |
| 56 if (owner_->MustShowFullscreenToolbar()) |
| 57 return; |
| 58 |
| 59 AnimateToolbarIn(); |
| 60 should_hide_toolbar_after_delay_ = true; |
| 61 } |
| 62 |
| 63 void FullscreenToolbarAnimationManager::AnimateToolbarIn() { |
| 64 if (!owner_->in_fullscreen_mode()) |
| 65 return; |
| 66 |
| 67 if (animation_.IsShowing()) |
| 68 return; |
| 69 |
| 70 if (disable_animations_during_testing_) { |
| 71 toolbar_fraction_ = 1.0; |
| 72 owner_->Layout(); |
| 73 return; |
| 74 } |
| 75 |
| 76 animation_.Reset(toolbar_fraction_); |
| 77 animation_.Show(); |
| 78 } |
| 79 |
| 80 void FullscreenToolbarAnimationManager::AnimateToolbarOutIfPossible() { |
| 81 if (!owner_->in_fullscreen_mode()) |
| 82 return; |
| 83 |
| 84 if (animation_.IsClosing()) |
| 85 return; |
| 86 |
| 87 if (disable_animations_during_testing_) { |
| 88 toolbar_fraction_ = 0; |
| 89 owner_->Layout(); |
| 90 return; |
| 91 } |
| 92 |
| 93 if (owner_->MustShowFullscreenToolbar()) |
| 94 return; |
| 95 |
| 96 animation_.Reset(toolbar_fraction_); |
| 97 animation_.Hide(); |
| 98 } |
| 99 |
| 100 CGFloat FullscreenToolbarAnimationManager::GetToolbarFraction() const { |
| 101 return toolbar_fraction_; |
| 102 } |
| 103 |
| 104 BOOL FullscreenToolbarAnimationManager::IsAnimationRunning() const { |
| 105 return animation_.is_animating(); |
| 106 } |
| 107 |
| 108 ////////////////////////////////////////////////////////////////// |
| 109 // FullscreenToolbarAnimationManager::AnimationDelegate: |
| 110 |
| 111 void FullscreenToolbarAnimationManager::AnimationProgressed( |
| 112 const gfx::Animation* animation) { |
| 113 toolbar_fraction_ = animation->GetCurrentValue(); |
| 114 owner_->Layout(); |
| 115 } |
| 116 |
| 117 void FullscreenToolbarAnimationManager::AnimationEnded( |
| 118 const gfx::Animation* animation) { |
| 119 if (animation_.IsShowing() && should_hide_toolbar_after_delay_) { |
| 120 hide_toolbar_timer_.Reset(); |
| 121 should_hide_toolbar_after_delay_ = false; |
| 122 } |
| 123 } |
OLD | NEW |