| Index: chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.mm
|
| diff --git a/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.mm b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..19ed7a1ca45a6919a56808a5ef08d4204d08cf8e
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.mm
|
| @@ -0,0 +1,123 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.h"
|
| +
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_manager.h"
|
| +#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h"
|
| +
|
| +namespace {
|
| +
|
| +// The duration of the toolbar show/hide animation in ms.
|
| +const NSTimeInterval kToolbarAnimationDuration = 200;
|
| +
|
| +// If the fullscreen toolbar is hidden, it is difficult for the user to see
|
| +// changes in the tabstrip. As a result, if a tab is inserted or the current
|
| +// tab switched to a new one, the toolbar must animate in and out to display
|
| +// the tabstrip changes to the user. The animation drops down the toolbar and
|
| +// then wait for 0.75 seconds before it hides the toolbar.
|
| +const NSTimeInterval kTabStripChangesDelay = 750;
|
| +
|
| +} // end namespace
|
| +
|
| +//////////////////////////////////////////////////////////////////
|
| +// FullscreenToolbarAnimationManager, public:
|
| +
|
| +FullscreenToolbarAnimationManager::FullscreenToolbarAnimationManager(
|
| + FullscreenToolbarLayoutManager* owner)
|
| + : owner_(owner),
|
| + animation_(this),
|
| + hide_toolbar_timer_(
|
| + FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(kTabStripChangesDelay),
|
| + base::Bind(
|
| + &FullscreenToolbarAnimationManager::AnimateToolbarOutIfPossible,
|
| + base::Unretained(this)),
|
| + false),
|
| + toolbar_fraction_(0),
|
| + should_hide_toolbar_after_delay_(false),
|
| + disable_animations_during_testing_(false) {
|
| + animation_.SetSlideDuration(kToolbarAnimationDuration);
|
| + animation_.SetTweenType(gfx::Tween::EASE_OUT);
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::UpdateToolbarFraction(
|
| + CGFloat fraction) {
|
| + toolbar_fraction_ = fraction;
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::StopAnimationAndTimer() {
|
| + animation_.Stop();
|
| + hide_toolbar_timer_.Stop();
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::AnimateToolbarForTabstripChanges() {
|
| + if (owner_->MustShowFullscreenToolbar())
|
| + return;
|
| +
|
| + AnimateToolbarIn();
|
| + should_hide_toolbar_after_delay_ = true;
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::AnimateToolbarIn() {
|
| + if (!owner_->in_fullscreen_mode())
|
| + return;
|
| +
|
| + if (animation_.IsShowing())
|
| + return;
|
| +
|
| + if (disable_animations_during_testing_) {
|
| + toolbar_fraction_ = 1.0;
|
| + owner_->Layout();
|
| + return;
|
| + }
|
| +
|
| + animation_.Reset(toolbar_fraction_);
|
| + animation_.Show();
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::AnimateToolbarOutIfPossible() {
|
| + if (!owner_->in_fullscreen_mode())
|
| + return;
|
| +
|
| + if (animation_.IsClosing())
|
| + return;
|
| +
|
| + if (disable_animations_during_testing_) {
|
| + toolbar_fraction_ = 0;
|
| + owner_->Layout();
|
| + return;
|
| + }
|
| +
|
| + if (owner_->MustShowFullscreenToolbar())
|
| + return;
|
| +
|
| + animation_.Reset(toolbar_fraction_);
|
| + animation_.Hide();
|
| +}
|
| +
|
| +CGFloat FullscreenToolbarAnimationManager::GetToolbarFraction() const {
|
| + return toolbar_fraction_;
|
| +}
|
| +
|
| +BOOL FullscreenToolbarAnimationManager::IsAnimationRunning() const {
|
| + return animation_.is_animating();
|
| +}
|
| +
|
| +//////////////////////////////////////////////////////////////////
|
| +// FullscreenToolbarAnimationManager::AnimationDelegate:
|
| +
|
| +void FullscreenToolbarAnimationManager::AnimationProgressed(
|
| + const gfx::Animation* animation) {
|
| + toolbar_fraction_ = animation->GetCurrentValue();
|
| + owner_->Layout();
|
| +}
|
| +
|
| +void FullscreenToolbarAnimationManager::AnimationEnded(
|
| + const gfx::Animation* animation) {
|
| + if (animation_.IsShowing() && should_hide_toolbar_after_delay_) {
|
| + hide_toolbar_timer_.Reset();
|
| + should_hide_toolbar_after_delay_ = false;
|
| + }
|
| +}
|
|
|