| 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 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 @implementation FullscreenToolbarController | 188 @implementation FullscreenToolbarController |
| 189 | 189 |
| 190 @synthesize slidingStyle = slidingStyle_; | 190 @synthesize slidingStyle = slidingStyle_; |
| 191 | 191 |
| 192 - (id)initWithBrowserController:(BrowserWindowController*)controller | 192 - (id)initWithBrowserController:(BrowserWindowController*)controller |
| 193 style:(fullscreen_mac::SlidingStyle)style { | 193 style:(fullscreen_mac::SlidingStyle)style { |
| 194 if ((self = [super init])) { | 194 if ((self = [super init])) { |
| 195 browserController_ = controller; | 195 browserController_ = controller; |
| 196 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; | 196 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
| 197 slidingStyle_ = style; | 197 slidingStyle_ = style; |
| 198 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_HIDDEN; | |
| 199 } | 198 } |
| 200 | 199 |
| 201 // Install the Carbon event handler for the menubar show, hide and | 200 // Install the Carbon event handler for the menubar show, hide and |
| 202 // undocumented reveal event. | 201 // undocumented reveal event. |
| 203 EventTypeSpec eventSpecs[3]; | 202 EventTypeSpec eventSpecs[3]; |
| 204 | 203 |
| 205 eventSpecs[0].eventClass = kEventClassMenu; | 204 eventSpecs[0].eventClass = kEventClassMenu; |
| 206 eventSpecs[0].eventKind = kMenuBarRevealEventKind; | 205 eventSpecs[0].eventKind = kMenuBarRevealEventKind; |
| 207 | 206 |
| 208 eventSpecs[1].eventClass = kEventClassMenu; | 207 eventSpecs[1].eventClass = kEventClassMenu; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return; | 290 return; |
| 292 | 291 |
| 293 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) | 292 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) |
| 294 return; | 293 return; |
| 295 | 294 |
| 296 if ([self isToolbarFocused]) | 295 if ([self isToolbarFocused]) |
| 297 return; | 296 return; |
| 298 | 297 |
| 299 [self cancelHideTimer]; | 298 [self cancelHideTimer]; |
| 300 [self animateToolbarVisibility:NO]; | 299 [self animateToolbarVisibility:NO]; |
| 301 shouldShowToolbarWithoutMenu_ = NO; | 300 |
| 301 // The animation will tell us the appropriate progress. |
| 302 // shouldShowToolbarWithoutMenu_ = NO; |
| 302 } | 303 } |
| 303 | 304 |
| 304 - (void)cancelAnimationAndTimer { | 305 - (void)cancelAnimationAndTimer { |
| 305 [self cancelHideTimer]; | 306 [self cancelHideTimer]; |
| 306 [currentAnimation_ stopAnimation]; | 307 [currentAnimation_ stopAnimation]; |
| 307 currentAnimation_.reset(); | 308 currentAnimation_.reset(); |
| 308 } | 309 } |
| 309 | 310 |
| 310 - (void)revealToolbarForTabStripChanges { | 311 - (void)revealToolbarForTabStripChanges { |
| 311 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 312 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 312 switches::kEnableFullscreenToolbarReveal)) { | 313 switches::kEnableFullscreenToolbarReveal)) { |
| 313 return; | 314 return; |
| 314 } | 315 } |
| 315 | 316 |
| 316 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) | 317 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) |
| 317 return; | 318 return; |
| 318 | 319 |
| 319 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. | 320 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. |
| 320 if (hiddenToolbarState_ == fullscreen_mac::TOOLBAR_HIDDEN) { | 321 if ([self toolbarFraction] == 0.0) { |
| 321 isRevealingToolbarForTabStripChanges_ = YES; | 322 isRevealingToolbarForTabStripChanges_ = YES; |
| 322 [self showToolbarIfPossibleWithAnimation:YES]; | 323 [self showToolbarIfPossibleWithAnimation:YES]; |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 | 326 |
| 326 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { | 327 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { |
| 327 if (mode == systemFullscreenMode_) | 328 if (mode == systemFullscreenMode_) |
| 328 return; | 329 return; |
| 329 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) | 330 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) |
| 330 base::mac::RequestFullScreen(mode); | 331 base::mac::RequestFullScreen(mode); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 - (CGFloat)toolbarFraction { | 385 - (CGFloat)toolbarFraction { |
| 385 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 386 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 386 return kHideFraction; | 387 return kHideFraction; |
| 387 | 388 |
| 388 switch (slidingStyle_) { | 389 switch (slidingStyle_) { |
| 389 case fullscreen_mac::OMNIBOX_TABS_PRESENT: | 390 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 390 return kShowFraction; | 391 return kShowFraction; |
| 391 case fullscreen_mac::OMNIBOX_TABS_NONE: | 392 case fullscreen_mac::OMNIBOX_TABS_NONE: |
| 392 return kHideFraction; | 393 return kHideFraction; |
| 393 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: | 394 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: |
| 394 if (hiddenToolbarState_ == fullscreen_mac::TOOLBAR_SHOWN) | 395 // If the menubar is showing, we always want to show the toolbar. |
| 396 if (menubarState_ == fullscreen_mac::MENUBAR_SHOWN) { |
| 395 return kShowFraction; | 397 return kShowFraction; |
| 398 } |
| 396 | 399 |
| 397 if (hiddenToolbarState_ == fullscreen_mac::TOOLBAR_HIDDEN) | 400 // If the menubar is animating in, and the toolbar was not already |
| 398 return kHideFraction; | 401 // showing, then it should animate in at the same rate. |
| 402 if (menubarState_ == fullscreen_mac::MENUBAR_TRANSITIONING && menubarAnima
tingIn_ && |
| 403 !wasToolbarShowingWhenMenubarStartedAnimatingIn_) { |
| 404 return menubarFraction_; |
| 405 } |
| 399 | 406 |
| 407 // If the menubar is animating in, and the toolbar is already showing, |
| 408 // then continue to show it. |
| 409 if (menubarState_ == fullscreen_mac::MENUBAR_TRANSITIONING && |
| 410 menubarAnimatingIn_) { |
| 411 return kShowFraction; |
| 412 } |
| 413 |
| 414 // If the menubar is animating out, we ignore!. |
| 415 if (menubarState_ == fullscreen_mac::MENUBAR_TRANSITIONING && |
| 416 !menubarAnimatingIn_) { |
| 417 } |
| 418 |
| 419 // At this point, menubar is not showing. Is there a custom animation? |
| 400 if (currentAnimation_.get()) | 420 if (currentAnimation_.get()) |
| 401 return [currentAnimation_ toolbarFraction]; | 421 return [currentAnimation_ toolbarFraction]; |
| 402 | 422 |
| 403 return shouldShowToolbarWithoutMenu_ ? kShowFraction : menubarFraction_; | 423 // If mouse is in tracking rect, show toolbar: |
| 424 |
| 425 // If there's a hide timer, show toolbar: |
| 426 |
| 427 // Logic for show & hide tab strip on tab change...haven't thought through |
| 428 // all the edge cases. |
| 429 |
| 430 // Default: hide toolbar. |
| 404 } | 431 } |
| 405 } | 432 } |
| 406 | 433 |
| 407 - (BOOL)isFullscreenTransitionInProgress { | 434 - (BOOL)isFullscreenTransitionInProgress { |
| 408 return [browserController_ isFullscreenTransitionInProgress]; | 435 return [browserController_ isFullscreenTransitionInProgress]; |
| 409 } | 436 } |
| 410 | 437 |
| 411 - (BOOL)isInFullscreen { | 438 - (BOOL)isInFullscreen { |
| 412 return inFullscreenMode_; | 439 return inFullscreenMode_; |
| 413 } | 440 } |
| 414 | 441 |
| 415 - (BOOL)isMouseOnScreen { | 442 - (BOOL)isMouseOnScreen { |
| 416 return NSMouseInRect([NSEvent mouseLocation], | 443 return NSMouseInRect([NSEvent mouseLocation], |
| 417 [[browserController_ window] screen].frame, false); | 444 [[browserController_ window] screen].frame, false); |
| 418 } | 445 } |
| 419 | 446 |
| 420 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame { | 447 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame { |
| 421 NSRect contentBounds = [contentView_ bounds]; | 448 NSRect contentBounds = [contentView_ bounds]; |
| 422 CGFloat yOffset = | 449 CGFloat yOffset = |
| 423 kFloatingBarVerticalOffset - kTrackingAreaAdditionalThreshold; | 450 kFloatingBarVerticalOffset - kTrackingAreaAdditionalThreshold; |
| 424 | 451 |
| 425 trackingAreaFrame_ = frame; | 452 trackingAreaFrame_ = frame; |
| 426 trackingAreaFrame_.origin.y += yOffset; | 453 trackingAreaFrame_.origin.y += yOffset; |
| 427 trackingAreaFrame_.size.height = | 454 trackingAreaFrame_.size.height = |
| 428 NSMaxY(contentBounds) - trackingAreaFrame_.origin.y; | 455 NSMaxY(contentBounds) - trackingAreaFrame_.origin.y; |
| 429 } | 456 } |
| 430 | 457 |
| 431 - (void)animationDidStop:(NSAnimation*)animation { | 458 - (void)animationDidStop:(NSAnimation*)animation { |
| 432 CGFloat toolbarFraction = [self toolbarFraction]; | 459 CGFloat toolbarFraction = [self toolbarFraction]; |
| 433 if (IsCGFloatEqual(toolbarFraction, 1.0)) | |
| 434 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_SHOWN; | |
| 435 else if (IsCGFloatEqual(toolbarFraction, 0.0)) | |
| 436 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_HIDDEN; | |
| 437 else | |
| 438 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_TRANSITIONING; | |
| 439 | 460 |
| 440 if (isRevealingToolbarForTabStripChanges_) { | 461 if (isRevealingToolbarForTabStripChanges_) { |
| 441 if (hiddenToolbarState_ != fullscreen_mac::TOOLBAR_HIDDEN) { | 462 if (IsCGFloatEqual(toolbarFraction, 0.0)) { |
| 442 // Set the timer to hide the toolbar. | 463 // Set the timer to hide the toolbar. |
| 443 [hideTimer_ invalidate]; | 464 [hideTimer_ invalidate]; |
| 444 hideTimer_.reset( | 465 hideTimer_.reset( |
| 445 [[NSTimer scheduledTimerWithTimeInterval:kTabStripChangesDelay | 466 [[NSTimer scheduledTimerWithTimeInterval:kTabStripChangesDelay |
| 446 target:self | 467 target:self |
| 447 selector:@selector(hideTimerFire:) | 468 selector:@selector(hideTimerFire:) |
| 448 userInfo:nil | 469 userInfo:nil |
| 449 repeats:NO] retain]); | 470 repeats:NO] retain]); |
| 450 } else { | 471 } else { |
| 451 isRevealingToolbarForTabStripChanges_ = NO; | 472 isRevealingToolbarForTabStripChanges_ = NO; |
| 452 } | 473 } |
| 453 } | 474 } |
| 454 | 475 |
| 455 // Reset the |currentAnimation_| pointer now that the animation is over. | 476 // Reset the |currentAnimation_| pointer now that the animation is over. |
| 456 currentAnimation_.reset(); | 477 currentAnimation_.reset(); |
| 457 } | 478 } |
| 458 | 479 |
| 459 - (void)animationDidEnd:(NSAnimation*)animation { | 480 - (void)animationDidEnd:(NSAnimation*)animation { |
| 460 [self animationDidStop:animation]; | 481 [self animationDidStop:animation]; |
| 461 [self setupTrackingArea]; | 482 [self setupTrackingArea]; |
| 462 } | 483 } |
| 463 | 484 |
| 464 - (void)setMenuBarRevealProgress:(CGFloat)progress { | 485 - (void)setMenuBarRevealProgress:(CGFloat)progress { |
| 486 // TODO: What happens if a mouse quickly bounces between two screens? What we |
| 487 // really want to know is whether the callback is for the screen that the |
| 488 // browser window is on. I'm not sure what the "progress > menubarFraction_" |
| 489 // check is for but it seems wrong? |
| 465 // If the menubarFraction increases, check if we are in the right screen | 490 // If the menubarFraction increases, check if we are in the right screen |
| 466 // so that the toolbar is not revealed on the wrong screen. | 491 // so that the toolbar is not revealed on the wrong screen. |
| 467 if (![self isMouseOnScreen] && progress > menubarFraction_) | 492 if (![self isMouseOnScreen] && progress > menubarFraction_) |
| 468 return; | 493 return; |
| 469 | 494 |
| 470 BOOL isMenuBarDisappearing = progress < menubarFraction_; | 495 if (IsCGFloatEqual(menubarFraction_, kShowFraction)) { |
| 496 // NSMenubar fully showing. |
| 497 menubarState_ = fullscreen_mac::MENUBAR_SHOWN; |
| 498 } else if (IsCGFloatEqual(menubarFraction_, kShowFraction)) { |
| 499 // NSMenubar fully hidden. |
| 500 menubarState_ = fullscreen_mac::MENUBAR_HIDDEN; |
| 501 } else { |
| 502 menubarState_ = fullscreen_mac::MENUBAR_TRANSITIONING; |
| 503 menubarAnimatingIn_ = progress > menubarFraction_; |
| 504 if (IsCGFloatEqual(menubarFraction_, kHideFraction) && menubarAnimatingIn_)
{ |
| 505 // TODO: What if toolbar was animating when menubar starts animating in? |
| 506 // We need to decide what behavior we want. I think we want to override |
| 507 // the existing animation, so this should be toolbarFraction > 0. |
| 508 wasToolbarShowingWhenMenubarStartedAnimatingIn_ = IsCGFloatEqual([self too
lbarFraction], kShowFraction); |
| 509 } |
| 510 } |
| 471 menubarFraction_ = progress; | 511 menubarFraction_ = progress; |
| 472 | 512 |
| 473 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_HIDDEN) { | 513 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_HIDDEN && |
| 474 shouldShowToolbarWithoutMenu_ = | 514 menubarState_ == fullscreen_mac::MENUBAR_SHOWN) { |
| 475 shouldShowToolbarWithoutMenu_ || | 515 [self setupTrackingArea]; |
| 476 (isMenuBarDisappearing && [self isToolbarFocused]); | |
| 477 | |
| 478 if (IsCGFloatEqual(menubarFraction_, kShowFraction)) { | |
| 479 [self setupTrackingArea]; | |
| 480 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_SHOWN; | |
| 481 } | |
| 482 | |
| 483 // If |shouldShowToolbarWithoutMenu_| is true, then |hiddenToolbarState_| | |
| 484 // should remain fullscreen_mac::TOOLBAR_SHOWN. | |
| 485 if (!shouldShowToolbarWithoutMenu_) { | |
| 486 hiddenToolbarState_ = IsCGFloatEqual(menubarFraction_, kHideFraction) | |
| 487 ? fullscreen_mac::TOOLBAR_HIDDEN | |
| 488 : fullscreen_mac::TOOLBAR_TRANSITIONING; | |
| 489 } | |
| 490 } | 516 } |
| 491 | 517 |
| 492 // If an animation is not running, then -layoutSubviews will not be called | 518 // If an animation is not running, then -layoutSubviews will not be called |
| 493 // for each tick of the menu bar reveal. Do that manually. | 519 // for each tick of the menu bar reveal. Do that manually. |
| 494 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so | 520 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so |
| 495 // that it calls setFrameOffset: instead of setFrame: if the frame's size has | 521 // that it calls setFrameOffset: instead of setFrame: if the frame's size has |
| 496 // not changed. | 522 // not changed. |
| 497 if (!currentAnimation_.get()) | 523 if (!currentAnimation_.get()) |
| 498 [browserController_ layoutSubviews]; | 524 [browserController_ layoutSubviews]; |
| 499 } | 525 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 controller:self]); | 628 controller:self]); |
| 603 DCHECK(currentAnimation_); | 629 DCHECK(currentAnimation_); |
| 604 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 630 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 605 [currentAnimation_ setDelegate:self]; | 631 [currentAnimation_ setDelegate:self]; |
| 606 | 632 |
| 607 // If there is an existing tracking area, remove it. We do not track mouse | 633 // If there is an existing tracking area, remove it. We do not track mouse |
| 608 // movements during animations (see class comment in the header file). | 634 // movements during animations (see class comment in the header file). |
| 609 [self removeTrackingAreaIfNecessary]; | 635 [self removeTrackingAreaIfNecessary]; |
| 610 | 636 |
| 611 [currentAnimation_ startAnimation]; | 637 [currentAnimation_ startAnimation]; |
| 612 hiddenToolbarState_ = fullscreen_mac::TOOLBAR_TRANSITIONING; | |
| 613 } | 638 } |
| 614 | 639 |
| 615 - (void)cancelHideTimer { | 640 - (void)cancelHideTimer { |
| 616 [hideTimer_ invalidate]; | 641 [hideTimer_ invalidate]; |
| 617 hideTimer_.reset(); | 642 hideTimer_.reset(); |
| 618 } | 643 } |
| 619 | 644 |
| 620 - (void)hideTimerFire:(NSTimer*)timer { | 645 - (void)hideTimerFire:(NSTimer*)timer { |
| 621 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. | 646 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. |
| 622 [hideTimer_ invalidate]; // Make sure it doesn't repeat. | 647 [hideTimer_ invalidate]; // Make sure it doesn't repeat. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 637 | 662 |
| 638 // No more calls back up to the BWC. | 663 // No more calls back up to the BWC. |
| 639 browserController_ = nil; | 664 browserController_ = nil; |
| 640 } | 665 } |
| 641 | 666 |
| 642 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 667 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
| 643 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; | 668 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; |
| 644 } | 669 } |
| 645 | 670 |
| 646 @end | 671 @end |
| OLD | NEW |