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

Side by Side Diff: chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm

Issue 2430403003: [Mac] Refactor the fullscreen toolbar animation (Closed)
Patch Set: Fix for erikchen 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #import "base/auto_reset.h"
10 #include "base/command_line.h" 9 #include "base/command_line.h"
11 #import "base/mac/mac_util.h" 10 #import "base/mac/mac_util.h"
12 #include "base/mac/sdk_forward_declarations.h" 11 #include "base/mac/sdk_forward_declarations.h"
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" 13 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h"
14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control ler.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h "
17 #include "ui/base/cocoa/appkit_utils.h" 16 #include "ui/base/cocoa/appkit_utils.h"
18 #import "ui/base/cocoa/nsview_additions.h" 17 #import "ui/base/cocoa/nsview_additions.h"
19 #import "ui/base/cocoa/tracking_area.h" 18 #import "ui/base/cocoa/tracking_area.h"
20 19
21 namespace { 20 namespace {
22 21
23 // The duration of the toolbar show/hide animation.
24 const NSTimeInterval kDropdownAnimationDuration = 0.20;
25
26 // If the fullscreen toolbar is hidden, it is difficult for the user to see
27 // changes in the tabstrip. As a result, if a tab is inserted or the current
28 // tab switched to a new one, the toolbar must animate in and out to display
29 // the tabstrip changes to the user. The animation drops down the toolbar and
30 // then wait for 0.75 seconds before it hides the toolbar.
31 const NSTimeInterval kTabStripChangesDelay = 0.75;
32
33 // Additional height threshold added at the toolbar's bottom. This is to mimic 22 // Additional height threshold added at the toolbar's bottom. This is to mimic
34 // threshold the mouse position needs to be at before the menubar automatically 23 // threshold the mouse position needs to be at before the menubar automatically
35 // hides. 24 // hides.
36 const CGFloat kTrackingAreaAdditionalThreshold = 20; 25 const CGFloat kTrackingAreaAdditionalThreshold = 20;
37 26
38 // Visibility fractions for the menubar and toolbar. 27 // Visibility fractions for the menubar and toolbar.
39 const CGFloat kHideFraction = 0.0; 28 const CGFloat kHideFraction = 0.0;
40 const CGFloat kShowFraction = 1.0; 29 const CGFloat kShowFraction = 1.0;
41 30
42 // The amount by which the toolbar is offset downwards (to avoid the menu) 31 // The amount by which the toolbar is offset downwards (to avoid the menu)
43 // when the toolbar style is OMNIBOX_TABS_HIDDEN. (We can't use 32 // when the toolbar style is OMNIBOX_TABS_HIDDEN. (We can't use
44 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) 33 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.)
45 const CGFloat kToolbarVerticalOffset = 22; 34 const CGFloat kToolbarVerticalOffset = 22;
46 35
47 } // end namespace 36 } // end namespace
48 37
49 // Helper class to manage animations for the dropdown bar. Calls
50 // [FullscreenToolbarController changeToolbarFraction] once per
51 // animation step.
52 @interface DropdownAnimation : NSAnimation {
53 @private
54 FullscreenToolbarController* controller_;
55 CGFloat startFraction_;
56 CGFloat endFraction_;
57 CGFloat toolbarFraction_;
58 }
59
60 @property(readonly, nonatomic) CGFloat endFraction;
61 @property(readonly, nonatomic) CGFloat toolbarFraction;
62
63 // Designated initializer. Asks |controller| for the current shown fraction, so
64 // if the bar is already partially shown or partially hidden, the animation
65 // duration may be less than |fullDuration|.
66 - (id)initWithFraction:(CGFloat)fromFraction
67 fullDuration:(CGFloat)fullDuration
68 animationCurve:(NSAnimationCurve)animationCurve
69 controller:(FullscreenToolbarController*)controller;
70
71 @end
72
73 @implementation DropdownAnimation
74
75 @synthesize endFraction = endFraction_;
76 @synthesize toolbarFraction = toolbarFraction_;
77
78 - (id)initWithFraction:(CGFloat)toFraction
79 fullDuration:(CGFloat)fullDuration
80 animationCurve:(NSAnimationCurve)animationCurve
81 controller:(FullscreenToolbarController*)controller {
82 // Calculate the effective duration, based on the current shown fraction.
83 DCHECK(controller);
84 CGFloat fromFraction = [controller toolbarFraction];
85 CGFloat effectiveDuration = fabs(fullDuration * (fromFraction - toFraction));
86
87 if ((self = [super gtm_initWithDuration:effectiveDuration
88 eventMask:NSLeftMouseDownMask
89 animationCurve:animationCurve])) {
90 startFraction_ = fromFraction;
91 endFraction_ = toFraction;
92 controller_ = controller;
93 }
94 return self;
95 }
96
97 // Called once per animation step. Overridden to change the floating bar's
98 // position based on the animation's progress.
99 - (void)setCurrentProgress:(NSAnimationProgress)progress {
100 toolbarFraction_ =
101 startFraction_ + (progress * (endFraction_ - startFraction_));
102 [controller_ updateToolbar];
103 }
104
105 @end
106
107 @interface FullscreenToolbarController (PrivateMethods) 38 @interface FullscreenToolbarController (PrivateMethods)
108 39
109 // Updates the visibility of the menu bar and the dock. 40 // Updates the visibility of the menu bar and the dock.
110 - (void)updateMenuBarAndDockVisibility; 41 - (void)updateMenuBarAndDockVisibility;
111 42
112 // Methods to set up or remove the tracking area. 43 // Methods to set up or remove the tracking area.
113 - (void)updateTrackingArea; 44 - (void)updateTrackingArea;
114 - (void)removeTrackingAreaIfNecessary; 45 - (void)removeTrackingAreaIfNecessary;
115 46
116 // Returns YES if the mouse is inside the tracking area. 47 // Returns YES if the mouse is inside the tracking area.
117 - (BOOL)mouseInsideTrackingArea; 48 - (BOOL)mouseInsideTrackingArea;
118 49
119 // Whether the current screen is expected to have a menu bar, regardless of 50 // Whether the current screen is expected to have a menu bar, regardless of
120 // current visibility of the menu bar. 51 // current visibility of the menu bar.
121 - (BOOL)doesScreenHaveMenuBar; 52 - (BOOL)doesScreenHaveMenuBar;
122 53
123 // Returns YES if the window is on the primary screen. 54 // Returns YES if the window is on the primary screen.
124 - (BOOL)isWindowOnPrimaryScreen; 55 - (BOOL)isWindowOnPrimaryScreen;
125 56
126 // Returns |kFullScreenModeHideAll| when the overlay is hidden and 57 // Returns |kFullScreenModeHideAll| when the overlay is hidden and
127 // |kFullScreenModeHideDock| when the overlay is shown. 58 // |kFullScreenModeHideDock| when the overlay is shown.
128 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; 59 - (base::mac::FullScreenMode)desiredSystemFullscreenMode;
129 60
130 // Animate the overlay to the given visibility with animation. If |visible|
131 // is true, animate the toolbar to a fraction of 1.0. Otherwise it's 0.0.
132 - (void)animateToolbarVisibility:(BOOL)visible;
133
134 // Cancels the timer for hiding the floating bar.
135 - (void)cancelHideTimer;
136
137 // Methods called when the hide timers fire. Do not call directly.
138 - (void)hideTimerFire:(NSTimer*)timer;
139
140 // Stops any running animations, etc. 61 // Stops any running animations, etc.
141 - (void)cleanup; 62 - (void)cleanup;
142 63
143 // Whether the menu bar should be shown in immersive fullscreen for the screen 64 // Whether the menu bar should be shown in immersive fullscreen for the screen
144 // that contains the window. 65 // that contains the window.
145 - (BOOL)shouldShowMenubarInImmersiveFullscreen; 66 - (BOOL)shouldShowMenubarInImmersiveFullscreen;
146 67
147 @end 68 @end
148 69
149 @implementation FullscreenToolbarController 70 @implementation FullscreenToolbarController
150 71
151 @synthesize slidingStyle = slidingStyle_; 72 @synthesize slidingStyle = slidingStyle_;
152 73
153 - (id)initWithBrowserController:(BrowserWindowController*)controller 74 - (id)initWithBrowserController:(BrowserWindowController*)controller
154 style:(FullscreenSlidingStyle)style { 75 style:(FullscreenSlidingStyle)style {
155 if ((self = [super init])) { 76 if ((self = [super init])) {
156 browserController_ = controller; 77 browserController_ = controller;
157 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 78 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
158 slidingStyle_ = style; 79 slidingStyle_ = style;
80 animationController_.reset(new FullscreenToolbarAnimationController(self));
159 } 81 }
160 82
161 return self; 83 return self;
162 } 84 }
163 85
164 - (void)dealloc { 86 - (void)dealloc {
165 DCHECK(!inFullscreenMode_); 87 DCHECK(!inFullscreenMode_);
166 [super dealloc]; 88 [super dealloc];
167 } 89 }
168 90
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 129 }
208 130
209 - (void)windowDidBecomeMain:(NSNotification*)notification { 131 - (void)windowDidBecomeMain:(NSNotification*)notification {
210 [self updateMenuBarAndDockVisibility]; 132 [self updateMenuBarAndDockVisibility];
211 } 133 }
212 134
213 - (void)windowDidResignMain:(NSNotification*)notification { 135 - (void)windowDidResignMain:(NSNotification*)notification {
214 [self updateMenuBarAndDockVisibility]; 136 [self updateMenuBarAndDockVisibility];
215 } 137 }
216 138
217 - (void)lockBarVisibilityWithAnimation:(BOOL)animate {
218 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES);
219 [self ensureOverlayShownWithAnimation:animate];
220 }
221
222 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate {
223 base::AutoReset<BOOL> autoReset(&isReleasingBarVisibility_, YES);
224 [self ensureOverlayHiddenWithAnimation:animate];
225 }
226
227 - (void)ensureOverlayShownWithAnimation:(BOOL)animate { 139 - (void)ensureOverlayShownWithAnimation:(BOOL)animate {
228 if (!inFullscreenMode_) 140 animationController_->AnimateToolbarIn();
229 return;
230
231 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
232 return;
233
234 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN)
235 return;
236
237 [self cancelHideTimer];
238 [self animateToolbarVisibility:YES];
239 } 141 }
240 142
241 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate { 143 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate {
242 if (!inFullscreenMode_) 144 animationController_->AnimateToolbarOutIfPossible();
243 return;
244
245 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN)
246 return;
247
248 if ([browserController_ isBarVisibilityLockedForOwner:nil])
249 return;
250
251 if ([self mouseInsideTrackingArea] ||
252 [menubarTracker_ state] == FullscreenMenubarState::SHOWN) {
253 return;
254 }
255
256 [self cancelHideTimer];
257 [self animateToolbarVisibility:NO];
258 } 145 }
259 146
147 // Cancels any running animation and timers.
260 - (void)cancelAnimationAndTimer { 148 - (void)cancelAnimationAndTimer {
261 [self cancelHideTimer]; 149 animationController_->StopAnimationAndTimer();
262 [currentAnimation_ stopAnimation];
263 currentAnimation_.reset();
264 } 150 }
265 151
266 - (void)revealToolbarForTabStripChanges { 152 - (void)revealToolbarForTabStripChanges {
267 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 153 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
268 switches::kEnableFullscreenToolbarReveal)) { 154 switches::kEnableFullscreenToolbarReveal)) {
269 return; 155 return;
270 } 156 }
271 157
272 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. 158 animationController_->AnimateToolbarForTabstripChanges();
273 if (ui::IsCGFloatEqual([self toolbarFraction], kHideFraction)) {
274 isRevealingToolbarForTabStripChanges_ = YES;
275 [self ensureOverlayShownWithAnimation:YES];
276 }
277 } 159 }
278 160
279 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { 161 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode {
280 if (mode == systemFullscreenMode_) 162 if (mode == systemFullscreenMode_)
281 return; 163 return;
282 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) 164 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal)
283 base::mac::RequestFullScreen(mode); 165 base::mac::RequestFullScreen(mode);
284 else if (mode == base::mac::kFullScreenModeNormal) 166 else if (mode == base::mac::kFullScreenModeNormal)
285 base::mac::ReleaseFullScreen(systemFullscreenMode_); 167 base::mac::ReleaseFullScreen(systemFullscreenMode_);
286 else 168 else
287 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); 169 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode);
288 systemFullscreenMode_ = mode; 170 systemFullscreenMode_ = mode;
289 } 171 }
290 172
291 - (void)mouseEntered:(NSEvent*)event { 173 - (void)mouseEntered:(NSEvent*)event {
292 // Empty implementation. Required for CrTrackingArea. 174 // Empty implementation. Required for CrTrackingArea.
293 } 175 }
294 176
295 - (void)mouseExited:(NSEvent*)event { 177 - (void)mouseExited:(NSEvent*)event {
296 DCHECK(inFullscreenMode_); 178 DCHECK(inFullscreenMode_);
297 DCHECK_EQ([event trackingArea], trackingArea_.get()); 179 DCHECK_EQ([event trackingArea], trackingArea_.get());
298 180
299 if ([browserController_ isBarVisibilityLockedForOwner:nil]) 181 if ([browserController_ isBarVisibilityLockedForOwner:nil])
300 return; 182 return;
301 183
302 // If the menubar is gone, animate the toolbar out. 184 // If the menubar is gone, animate the toolbar out.
303 if ([menubarTracker_ state] == FullscreenMenubarState::HIDDEN) { 185 if ([menubarTracker_ state] == FullscreenMenubarState::HIDDEN)
304 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES);
305 [self ensureOverlayHiddenWithAnimation:YES]; 186 [self ensureOverlayHiddenWithAnimation:YES];
306 }
307 187
308 [self removeTrackingAreaIfNecessary]; 188 [self removeTrackingAreaIfNecessary];
309 } 189 }
310 190
311 - (void)updateToolbar { 191 - (void)updateToolbar {
312 [browserController_ layoutSubviews]; 192 [browserController_ layoutSubviews];
313 [self updateTrackingArea]; 193 [self updateTrackingArea];
194 animationController_->ToolbarDidUpdate();
314 195
315 // In AppKit fullscreen, moving the mouse to the top of the screen toggles 196 // In AppKit fullscreen, moving the mouse to the top of the screen toggles
316 // menu visibility. Replicate the same effect for immersive fullscreen. 197 // menu visibility. Replicate the same effect for immersive fullscreen.
317 if ([browserController_ isInImmersiveFullscreen]) 198 if ([browserController_ isInImmersiveFullscreen])
318 [self updateMenuBarAndDockVisibility]; 199 [self updateMenuBarAndDockVisibility];
319 } 200 }
320 201
321 - (BrowserWindowController*)browserWindowController { 202 - (BrowserWindowController*)browserWindowController {
322 return browserController_; 203 return browserController_;
323 } 204 }
(...skipping 22 matching lines...) Expand all
346 - (CGFloat)toolbarFraction { 227 - (CGFloat)toolbarFraction {
347 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 228 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
348 return kHideFraction; 229 return kHideFraction;
349 230
350 switch (slidingStyle_) { 231 switch (slidingStyle_) {
351 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: 232 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT:
352 return kShowFraction; 233 return kShowFraction;
353 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: 234 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE:
354 return kHideFraction; 235 return kHideFraction;
355 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: 236 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN:
356 FullscreenMenubarState menubarState = [menubarTracker_ state]; 237 if ([self mustShowFullscreenToolbar])
357 if (menubarState == FullscreenMenubarState::SHOWN)
358 return kShowFraction; 238 return kShowFraction;
359 239
360 if ([self mouseInsideTrackingArea]) 240 if (animationController_->IsAnimationRunning())
361 return kShowFraction; 241 return animationController_->GetToolbarFractionFromProgress();
362
363 if (currentAnimation_.get())
364 return [currentAnimation_ toolbarFraction];
365
366 if (isLockingBarVisibility_)
367 return kHideFraction;
368 else if (isReleasingBarVisibility_)
369 return kShowFraction;
370 else if ([browserController_ isBarVisibilityLockedForOwner:nil])
371 return kShowFraction;
372
373 if (hideTimer_.get() || shouldAnimateToolbarOut_)
374 return kShowFraction;
375 242
376 return [menubarTracker_ menubarFraction]; 243 return [menubarTracker_ menubarFraction];
377 } 244 }
378 } 245 }
379 246
247 - (BOOL)mustShowFullscreenToolbar {
248 if (!inFullscreenMode_)
249 return NO;
250
251 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT)
252 return YES;
253
254 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_NONE)
255 return NO;
256
257 FullscreenMenubarState menubarState = [menubarTracker_ state];
258 return menubarState == FullscreenMenubarState::SHOWN ||
259 [self mouseInsideTrackingArea] ||
260 [browserController_ isBarVisibilityLockedForOwner:nil];
261 }
262
380 - (BOOL)isFullscreenTransitionInProgress { 263 - (BOOL)isFullscreenTransitionInProgress {
381 return [browserController_ isFullscreenTransitionInProgress]; 264 return [browserController_ isFullscreenTransitionInProgress];
382 } 265 }
383 266
384 - (BOOL)isInFullscreen { 267 - (BOOL)isInFullscreen {
385 return inFullscreenMode_; 268 return inFullscreenMode_;
386 } 269 }
387 270
388 - (BOOL)isMouseOnScreen { 271 - (BOOL)isMouseOnScreen {
389 return NSMouseInRect([NSEvent mouseLocation], 272 return NSMouseInRect([NSEvent mouseLocation],
390 [[browserController_ window] screen].frame, false); 273 [[browserController_ window] screen].frame, false);
391 } 274 }
392 275
393 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame { 276 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame {
394 NSRect contentBounds = [contentView_ bounds]; 277 NSRect contentBounds = [contentView_ bounds];
395 trackingAreaFrame_ = frame; 278 trackingAreaFrame_ = frame;
396 trackingAreaFrame_.origin.y -= kTrackingAreaAdditionalThreshold; 279 trackingAreaFrame_.origin.y -= kTrackingAreaAdditionalThreshold;
397 trackingAreaFrame_.size.height = 280 trackingAreaFrame_.size.height =
398 NSMaxY(contentBounds) - trackingAreaFrame_.origin.y; 281 NSMaxY(contentBounds) - trackingAreaFrame_.origin.y;
399 } 282 }
400 283
401 - (void)animationDidStop:(NSAnimation*)animation {
402 if (isRevealingToolbarForTabStripChanges_) {
403 if ([self toolbarFraction] > 0.0) {
404 // Set the timer to hide the toolbar.
405 [hideTimer_ invalidate];
406 hideTimer_.reset(
407 [[NSTimer scheduledTimerWithTimeInterval:kTabStripChangesDelay
408 target:self
409 selector:@selector(hideTimerFire:)
410 userInfo:nil
411 repeats:NO] retain]);
412 } else {
413 isRevealingToolbarForTabStripChanges_ = NO;
414 }
415 }
416
417 // Reset the |currentAnimation_| pointer now that the animation is over.
418 currentAnimation_.reset();
419 }
420
421 - (void)animationDidEnd:(NSAnimation*)animation {
422 [self animationDidStop:animation];
423 [self updateTrackingArea];
424 }
425
426 @end 284 @end
427 285
428 @implementation FullscreenToolbarController (PrivateMethods) 286 @implementation FullscreenToolbarController (PrivateMethods)
429 287
430 - (void)updateMenuBarAndDockVisibility { 288 - (void)updateMenuBarAndDockVisibility {
431 if (![self isMouseOnScreen] || 289 if (![self isMouseOnScreen] ||
432 ![browserController_ isInImmersiveFullscreen]) { 290 ![browserController_ isInImmersiveFullscreen]) {
433 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; 291 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal];
434 return; 292 return;
435 } 293 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 NSScreen* primaryScreen = [[NSScreen screens] firstObject]; 360 NSScreen* primaryScreen = [[NSScreen screens] firstObject];
503 return (screen == primaryScreen); 361 return (screen == primaryScreen);
504 } 362 }
505 363
506 - (base::mac::FullScreenMode)desiredSystemFullscreenMode { 364 - (base::mac::FullScreenMode)desiredSystemFullscreenMode {
507 if ([self shouldShowMenubarInImmersiveFullscreen]) 365 if ([self shouldShowMenubarInImmersiveFullscreen])
508 return base::mac::kFullScreenModeHideDock; 366 return base::mac::kFullScreenModeHideDock;
509 return base::mac::kFullScreenModeHideAll; 367 return base::mac::kFullScreenModeHideAll;
510 } 368 }
511 369
512 - (void)animateToolbarVisibility:(BOOL)visible {
513 CGFloat fraction = visible ? kShowFraction : kHideFraction;
514
515 // If we're already animating to the given fraction, then there's nothing
516 // more to do.
517 if (currentAnimation_ && [currentAnimation_ endFraction] == fraction)
518 return;
519
520 // In all other cases, we want to cancel any running animation (which may be
521 // to show or to hide).
522 [currentAnimation_ stopAnimation];
523
524 // Create the animation and set it up.
525 currentAnimation_.reset([[DropdownAnimation alloc]
526 initWithFraction:fraction
527 fullDuration:kDropdownAnimationDuration
528 animationCurve:NSAnimationEaseOut
529 controller:self]);
530 DCHECK(currentAnimation_);
531 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking];
532 [currentAnimation_ setDelegate:self];
533
534 // If there is an existing tracking area, remove it. We do not track mouse
535 // movements during animations (see class comment in the header file).
536 [self removeTrackingAreaIfNecessary];
537
538 [currentAnimation_ startAnimation];
539 }
540
541 - (void)cancelHideTimer {
542 [hideTimer_ invalidate];
543 hideTimer_.reset();
544 }
545
546 - (void)hideTimerFire:(NSTimer*)timer {
547 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer.
548 [hideTimer_ invalidate]; // Make sure it doesn't repeat.
549 hideTimer_.reset(); // And get rid of it.
550 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES);
551 [self animateToolbarVisibility:NO];
552 }
553
554 - (void)cleanup { 370 - (void)cleanup {
555 [self cancelAnimationAndTimer]; 371 animationController_->StopAnimationAndTimer();
556 [[NSNotificationCenter defaultCenter] removeObserver:self]; 372 [[NSNotificationCenter defaultCenter] removeObserver:self];
557 373
558 [self removeTrackingAreaIfNecessary]; 374 [self removeTrackingAreaIfNecessary];
559 375
560 // Call the main status resignation code to perform the associated cleanup, 376 // Call the main status resignation code to perform the associated cleanup,
561 // since we will no longer be receiving actual status resignation 377 // since we will no longer be receiving actual status resignation
562 // notifications. 378 // notifications.
563 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; 379 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal];
564 380
565 menubarTracker_.reset(); 381 menubarTracker_.reset();
566 382
567 // No more calls back up to the BWC. 383 // No more calls back up to the BWC.
568 browserController_ = nil; 384 browserController_ = nil;
569 } 385 }
570 386
571 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 387 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
572 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; 388 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99;
573 } 389 }
574 390
575 @end 391 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698