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

Unified Diff: chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm

Issue 2430403003: [Mac] Refactor the fullscreen toolbar animation (Closed)
Patch Set: Removed unnecessary #include statements Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm
diff --git a/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fcbc8633925f6c34676250dc02d08405aaef35be
--- /dev/null
+++ b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm
@@ -0,0 +1,119 @@
+// 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_controller.h"
+
+#import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.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
+
+//////////////////////////////////////////////////////////////////
+// FullscreenToolbarAnimationController, public:
+
+FullscreenToolbarAnimationController::FullscreenToolbarAnimationController(
+ FullscreenToolbarController* owner)
+ : owner_(owner),
+ animation_(this),
+ hide_toolbar_timer_(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kTabStripChangesDelay),
+ base::Bind(&FullscreenToolbarAnimationController::
+ AnimateToolbarOutIfPossible,
+ 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
+ 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 FullscreenToolbarAnimationController::UpdateToolbarFraction(
+ CGFloat fraction) {
+ toolbar_fraction_ = fraction;
+}
+
+void FullscreenToolbarAnimationController::StopAnimationAndTimer() {
+ animation_.Stop();
+ hide_toolbar_timer_.Stop();
+}
+
+void FullscreenToolbarAnimationController::AnimateToolbarForTabstripChanges() {
+ if ([owner_ mustShowFullscreenToolbar])
+ return;
+
+ AnimateToolbarIn();
+ should_hide_toolbar_after_delay_ = true;
+}
+
+void FullscreenToolbarAnimationController::AnimateToolbarIn() {
+ if (![owner_ isInFullscreen])
+ return;
+
+ if (animation_.IsShowing())
+ return;
+
+ if (disable_animations_during_testing_) {
+ toolbar_fraction_ = 1.0;
+ [owner_ updateToolbar];
+ return;
+ }
+
+ animation_.Reset(toolbar_fraction_);
+ animation_.Show();
+}
+
+void FullscreenToolbarAnimationController::AnimateToolbarOutIfPossible() {
+ if (![owner_ isInFullscreen] || [owner_ mustShowFullscreenToolbar])
+ return;
+
+ if (animation_.IsClosing())
+ return;
+
+ if (disable_animations_during_testing_) {
+ toolbar_fraction_ = 0.0;
+ [owner_ updateToolbar];
+ return;
+ }
+
+ animation_.Reset(toolbar_fraction_);
+ animation_.Hide();
+}
+
+CGFloat FullscreenToolbarAnimationController::GetToolbarFraction() const {
+ return toolbar_fraction_;
+}
+
+BOOL FullscreenToolbarAnimationController::IsAnimationRunning() const {
+ return animation_.is_animating();
+}
+
+//////////////////////////////////////////////////////////////////
+// FullscreenToolbarAnimationController::AnimationDelegate:
+
+void FullscreenToolbarAnimationController::AnimationProgressed(
+ const gfx::Animation* animation) {
+ toolbar_fraction_ = animation->GetCurrentValue();
+ [owner_ updateToolbar];
+}
+
+void FullscreenToolbarAnimationController::AnimationEnded(
+ const gfx::Animation* animation) {
+ if (animation_.IsShowing() && should_hide_toolbar_after_delay_) {
+ hide_toolbar_timer_.Reset();
+ should_hide_toolbar_after_delay_ = false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698