OLD | NEW |
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" | 9 #import "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 [nc addObserver:self | 234 [nc addObserver:self |
235 selector:@selector(windowDidBecomeMain:) | 235 selector:@selector(windowDidBecomeMain:) |
236 name:NSWindowDidBecomeMainNotification | 236 name:NSWindowDidBecomeMainNotification |
237 object:window]; | 237 object:window]; |
238 | 238 |
239 [nc addObserver:self | 239 [nc addObserver:self |
240 selector:@selector(windowDidResignMain:) | 240 selector:@selector(windowDidResignMain:) |
241 name:NSWindowDidResignMainNotification | 241 name:NSWindowDidResignMainNotification |
242 object:window]; | 242 object:window]; |
| 243 |
| 244 // Register for Active Space change notifications. |
| 245 [[[NSWorkspace sharedWorkspace] notificationCenter] |
| 246 addObserver:self |
| 247 selector:@selector(activeSpaceDidChange:) |
| 248 name:NSWorkspaceActiveSpaceDidChangeNotification |
| 249 object:nil]; |
243 } | 250 } |
244 | 251 |
245 - (void)exitFullscreenMode { | 252 - (void)exitFullscreenMode { |
246 DCHECK(inFullscreenMode_); | 253 DCHECK(inFullscreenMode_); |
247 inFullscreenMode_ = NO; | 254 inFullscreenMode_ = NO; |
248 | 255 |
249 [self cleanup]; | 256 [self cleanup]; |
250 } | 257 } |
251 | 258 |
252 - (void)windowDidChangeScreen:(NSNotification*)notification { | 259 - (void)windowDidChangeScreen:(NSNotification*)notification { |
253 [browserController_ resizeFullscreenWindow]; | 260 [browserController_ resizeFullscreenWindow]; |
254 } | 261 } |
255 | 262 |
256 - (void)windowDidMove:(NSNotification*)notification { | 263 - (void)windowDidMove:(NSNotification*)notification { |
257 [browserController_ resizeFullscreenWindow]; | 264 [browserController_ resizeFullscreenWindow]; |
258 } | 265 } |
259 | 266 |
260 - (void)windowDidBecomeMain:(NSNotification*)notification { | 267 - (void)windowDidBecomeMain:(NSNotification*)notification { |
261 [self updateMenuBarAndDockVisibility]; | 268 [self updateMenuBarAndDockVisibility]; |
262 } | 269 } |
263 | 270 |
264 - (void)windowDidResignMain:(NSNotification*)notification { | 271 - (void)windowDidResignMain:(NSNotification*)notification { |
265 [self updateMenuBarAndDockVisibility]; | 272 [self updateMenuBarAndDockVisibility]; |
266 } | 273 } |
267 | 274 |
| 275 - (void)activeSpaceDidChange:(NSNotification*)notification { |
| 276 menubarFraction_ = kHideFraction; |
| 277 menubarState_ = FullscreenMenubarState::HIDDEN; |
| 278 [browserController_ layoutSubviews]; |
| 279 } |
| 280 |
268 - (CGFloat)floatingBarVerticalOffset { | 281 - (CGFloat)floatingBarVerticalOffset { |
269 return kFloatingBarVerticalOffset; | 282 return kFloatingBarVerticalOffset; |
270 } | 283 } |
271 | 284 |
272 - (void)lockBarVisibilityWithAnimation:(BOOL)animate { | 285 - (void)lockBarVisibilityWithAnimation:(BOOL)animate { |
273 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); | 286 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); |
274 [self ensureOverlayShownWithAnimation:animate]; | 287 [self ensureOverlayShownWithAnimation:animate]; |
275 } | 288 } |
276 | 289 |
277 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { | 290 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 [self animationDidStop:animation]; | 483 [self animationDidStop:animation]; |
471 [self updateTrackingArea]; | 484 [self updateTrackingArea]; |
472 } | 485 } |
473 | 486 |
474 - (void)setMenuBarRevealProgress:(CGFloat)progress { | 487 - (void)setMenuBarRevealProgress:(CGFloat)progress { |
475 // If the menubarFraction increases, check if we are in the right screen | 488 // If the menubarFraction increases, check if we are in the right screen |
476 // so that the toolbar is not revealed on the wrong screen. | 489 // so that the toolbar is not revealed on the wrong screen. |
477 if (![self isMouseOnScreen] && progress > menubarFraction_) | 490 if (![self isMouseOnScreen] && progress > menubarFraction_) |
478 return; | 491 return; |
479 | 492 |
| 493 // Ignore the menubarFraction changes if the Space is inactive. |
| 494 if (![[browserController_ window] isOnActiveSpace]) |
| 495 return; |
| 496 |
480 if (IsCGFloatEqual(progress, kShowFraction)) | 497 if (IsCGFloatEqual(progress, kShowFraction)) |
481 menubarState_ = FullscreenMenubarState::SHOWN; | 498 menubarState_ = FullscreenMenubarState::SHOWN; |
482 else if (IsCGFloatEqual(progress, kHideFraction)) | 499 else if (IsCGFloatEqual(progress, kHideFraction)) |
483 menubarState_ = FullscreenMenubarState::HIDDEN; | 500 menubarState_ = FullscreenMenubarState::HIDDEN; |
484 else if (progress < menubarFraction_) | 501 else if (progress < menubarFraction_) |
485 menubarState_ = FullscreenMenubarState::HIDING; | 502 menubarState_ = FullscreenMenubarState::HIDING; |
486 else if (progress > menubarFraction_) | 503 else if (progress > menubarFraction_) |
487 menubarState_ = FullscreenMenubarState::SHOWING; | 504 menubarState_ = FullscreenMenubarState::SHOWING; |
488 | 505 |
489 menubarFraction_ = progress; | 506 menubarFraction_ = progress; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. | 645 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. |
629 [hideTimer_ invalidate]; // Make sure it doesn't repeat. | 646 [hideTimer_ invalidate]; // Make sure it doesn't repeat. |
630 hideTimer_.reset(); // And get rid of it. | 647 hideTimer_.reset(); // And get rid of it. |
631 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); | 648 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); |
632 [self animateToolbarVisibility:NO]; | 649 [self animateToolbarVisibility:NO]; |
633 } | 650 } |
634 | 651 |
635 - (void)cleanup { | 652 - (void)cleanup { |
636 [self cancelAnimationAndTimer]; | 653 [self cancelAnimationAndTimer]; |
637 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 654 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 655 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; |
638 | 656 |
639 [self removeTrackingAreaIfNecessary]; | 657 [self removeTrackingAreaIfNecessary]; |
640 | 658 |
641 // Call the main status resignation code to perform the associated cleanup, | 659 // Call the main status resignation code to perform the associated cleanup, |
642 // since we will no longer be receiving actual status resignation | 660 // since we will no longer be receiving actual status resignation |
643 // notifications. | 661 // notifications. |
644 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 662 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
645 | 663 |
646 // No more calls back up to the BWC. | 664 // No more calls back up to the BWC. |
647 browserController_ = nil; | 665 browserController_ = nil; |
648 } | 666 } |
649 | 667 |
650 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 668 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
651 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; | 669 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; |
652 } | 670 } |
653 | 671 |
654 @end | 672 @end |
OLD | NEW |