Chromium Code Reviews| 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" |
| 11 #include "base/mac/sdk_forward_declarations.h" | 11 #include "base/mac/sdk_forward_declarations.h" |
| 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " | 14 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " |
| 15 #import "ui/base/cocoa/nsview_additions.h" | 15 #import "ui/base/cocoa/nsview_additions.h" |
| 16 #import "ui/base/cocoa/tracking_area.h" | |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // The activation zone for the main menu is 4 pixels high; if we make it any | 20 // The duration of the toolbar show/hide animation. |
| 20 // smaller, then the menu can be made to appear without the bar sliding down. | 21 const NSTimeInterval kDropdownAnimationDuration = 0.20; |
| 21 const NSTimeInterval kDropdownAnimationDuration = 0.12; | |
| 22 | 22 |
| 23 // The duration the toolbar is revealed for tab strip changes. | 23 // If the fullscreen toolbar is hidden, it is difficult for the user to see |
| 24 const NSTimeInterval kDropdownForTabStripChangesDuration = 0.75; | 24 // changes in the tabstrip. As a result, if a tab is inserted or the current |
| 25 // tab switched to a new one, the toolbar must animate in and out to display | |
| 26 // the tabstrip changes to the user. The animation drops down the toolbar and | |
| 27 // then wait for 0.75 seconds before it hides the toolbar. | |
| 28 const NSTimeInterval kTabStripChangesDelay = 0.75; | |
| 29 | |
| 30 // Additional height threshold added at the toolbar's bottom. This is to mimic | |
| 31 // threshold the mouse position needs to be at before the menubar automatically | |
| 32 // hides. | |
| 33 const CGFloat kTrackingAreaAdditionalThreshold = 24; | |
| 25 | 34 |
| 26 // The event kind value for a undocumented menubar show/hide Carbon event. | 35 // The event kind value for a undocumented menubar show/hide Carbon event. |
| 27 const CGFloat kMenuBarRevealEventKind = 2004; | 36 const CGFloat kMenuBarRevealEventKind = 2004; |
| 28 | 37 |
| 29 // The amount by which the floating bar is offset downwards (to avoid the menu) | 38 // The amount by which the floating bar is offset downwards (to avoid the menu) |
| 30 // when the toolbar is hidden. (We can't use |-[NSMenu menuBarHeight]| since it | 39 // when the toolbar is hidden. (We can't use |-[NSMenu menuBarHeight]| since it |
| 31 // returns 0 when the menu bar is hidden.) | 40 // returns 0 when the menu bar is hidden.) |
| 32 const CGFloat kFloatingBarVerticalOffset = 22; | 41 const CGFloat kFloatingBarVerticalOffset = 22; |
| 33 | 42 |
| 34 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, | 43 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, |
| 35 EventRef event, | 44 EventRef event, |
| 36 void* context) { | 45 void* context) { |
| 37 FullscreenToolbarController* self = | 46 FullscreenToolbarController* self = |
| 38 static_cast<FullscreenToolbarController*>(context); | 47 static_cast<FullscreenToolbarController*>(context); |
| 39 | 48 |
| 40 // If Chrome has multiple fullscreen windows in their own space, the Handler | 49 // If Chrome has multiple fullscreen windows in their own space, the Handler |
| 41 // becomes flaky and might start receiving kMenuBarRevealEventKind events | 50 // becomes flaky and might start receiving kMenuBarRevealEventKind events |
| 42 // from another space. Since the menubar in the another space is in either a | 51 // from another space. Since the menubar in the another space is in either a |
| 43 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0. | 52 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0. |
| 44 // As such, we should ignore the kMenuBarRevealEventKind event if it gives | 53 // As such, we should ignore the kMenuBarRevealEventKind event if it gives |
| 45 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and | 54 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and |
| 46 // kEventMenuBarHidden to set these values. | 55 // kEventMenuBarHidden to set these values. |
| 47 if (![self isFullscreenTransitionInProgress]) { | 56 if (![self isFullscreenTransitionInProgress] && [self isInFullscreen]) { |
| 48 if (GetEventKind(event) == kMenuBarRevealEventKind) { | 57 if (GetEventKind(event) == kMenuBarRevealEventKind) { |
| 49 CGFloat revealFraction = 0; | 58 CGFloat revealFraction = 0; |
| 50 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL, | 59 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL, |
| 51 sizeof(CGFloat), NULL, &revealFraction); | 60 sizeof(CGFloat), NULL, &revealFraction); |
| 52 if (revealFraction > 0.0 && revealFraction < 1.0) | 61 if (revealFraction > 0.0 && revealFraction < 1.0) |
| 53 [self setMenuBarRevealProgress:revealFraction]; | 62 [self setMenuBarRevealProgress:revealFraction]; |
| 54 } else if (GetEventKind(event) == kEventMenuBarShown) { | 63 } else if (GetEventKind(event) == kEventMenuBarShown) { |
| 55 [self setMenuBarRevealProgress:1.0]; | 64 [self setMenuBarRevealProgress:1.0]; |
| 56 } else { | 65 } else { |
| 57 [self setMenuBarRevealProgress:0.0]; | 66 [self setMenuBarRevealProgress:0.0]; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 [controller_ changeToolbarFraction:fraction]; | 127 [controller_ changeToolbarFraction:fraction]; |
| 119 } | 128 } |
| 120 | 129 |
| 121 @end | 130 @end |
| 122 | 131 |
| 123 @interface FullscreenToolbarController (PrivateMethods) | 132 @interface FullscreenToolbarController (PrivateMethods) |
| 124 | 133 |
| 125 // Updates the visibility of the menu bar and the dock. | 134 // Updates the visibility of the menu bar and the dock. |
| 126 - (void)updateMenuBarAndDockVisibility; | 135 - (void)updateMenuBarAndDockVisibility; |
| 127 | 136 |
| 137 // Methods to set up or remove the tracking area. | |
| 138 - (void)setupTrackingArea; | |
| 139 - (void)removeTrackingAreaIfNecessary; | |
| 140 | |
| 141 // Returns YES if the mouse is inside the tracking area. | |
| 142 - (BOOL)mouseInsideTrackingArea; | |
| 143 | |
| 128 // Whether the current screen is expected to have a menu bar, regardless of | 144 // Whether the current screen is expected to have a menu bar, regardless of |
| 129 // current visibility of the menu bar. | 145 // current visibility of the menu bar. |
| 130 - (BOOL)doesScreenHaveMenuBar; | 146 - (BOOL)doesScreenHaveMenuBar; |
| 131 | 147 |
| 132 // Returns YES if the window is on the primary screen. | 148 // Returns YES if the window is on the primary screen. |
| 133 - (BOOL)isWindowOnPrimaryScreen; | 149 - (BOOL)isWindowOnPrimaryScreen; |
| 134 | 150 |
| 135 // Returns |kFullScreenModeHideAll| when the overlay is hidden and | 151 // Returns |kFullScreenModeHideAll| when the overlay is hidden and |
| 136 // |kFullScreenModeHideDock| when the overlay is shown. | 152 // |kFullScreenModeHideDock| when the overlay is shown. |
| 137 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; | 153 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; |
| 138 | 154 |
| 139 // Change the overlay to the given fraction, with or without animation. Only | 155 // Change the overlay to the given fraction, with or without animation. Only |
| 140 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This | 156 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This |
| 141 // performs the show/hide (animation) immediately. It does not touch the timers. | 157 // performs the show/hide (animation) immediately. It does not touch the timers. |
| 142 - (void)changeOverlayToFraction:(CGFloat)fraction withAnimation:(BOOL)animate; | 158 - (void)changeOverlayToFraction:(CGFloat)fraction withAnimation:(BOOL)animate; |
| 143 | 159 |
| 160 // Releases the bar visibility and hides the toolbar. | |
| 161 - (void)releaseAndHideBarVisibility; | |
| 162 | |
| 144 // Cancels the timer for hiding the floating bar. | 163 // Cancels the timer for hiding the floating bar. |
| 145 - (void)cancelHideTimer; | 164 - (void)cancelHideTimer; |
| 146 | 165 |
| 147 // Methods called when the hide timers fire. Do not call directly. | 166 // Methods called when the hide timers fire. Do not call directly. |
| 148 - (void)hideTimerFire:(NSTimer*)timer; | 167 - (void)hideTimerFire:(NSTimer*)timer; |
| 149 | 168 |
| 150 // Stops any running animations, etc. | 169 // Stops any running animations, etc. |
| 151 - (void)cleanup; | 170 - (void)cleanup; |
| 152 | 171 |
| 153 // Shows and hides the UI associated with this window being active (having main | 172 // Shows and hides the UI associated with this window being active (having main |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 212 |
| 194 return self; | 213 return self; |
| 195 } | 214 } |
| 196 | 215 |
| 197 - (void)dealloc { | 216 - (void)dealloc { |
| 198 RemoveEventHandler(menuBarTrackingHandler_); | 217 RemoveEventHandler(menuBarTrackingHandler_); |
| 199 DCHECK(!inFullscreenMode_); | 218 DCHECK(!inFullscreenMode_); |
| 200 [super dealloc]; | 219 [super dealloc]; |
| 201 } | 220 } |
| 202 | 221 |
| 203 - (void)setupFullscreenToolbarWithDropdown:(BOOL)showDropdown { | 222 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView |
| 223 showDropdown:(BOOL)showDropdown { | |
| 204 DCHECK(!inFullscreenMode_); | 224 DCHECK(!inFullscreenMode_); |
| 225 contentView_ = contentView; | |
| 226 | |
| 205 inFullscreenMode_ = YES; | 227 inFullscreenMode_ = YES; |
| 228 | |
| 206 [self changeToolbarFraction:(showDropdown ? 1 : 0)]; | 229 [self changeToolbarFraction:(showDropdown ? 1 : 0)]; |
| 207 [self updateMenuBarAndDockVisibility]; | 230 [self updateMenuBarAndDockVisibility]; |
| 208 | 231 |
| 209 // Register for notifications. Self is removed as an observer in |-cleanup|. | 232 // Register for notifications. Self is removed as an observer in |-cleanup|. |
| 210 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 233 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 211 NSWindow* window = [browserController_ window]; | 234 NSWindow* window = [browserController_ window]; |
| 212 | 235 |
| 213 [nc addObserver:self | 236 [nc addObserver:self |
| 214 selector:@selector(windowDidBecomeMain:) | 237 selector:@selector(windowDidBecomeMain:) |
| 215 name:NSWindowDidBecomeMainNotification | 238 name:NSWindowDidBecomeMainNotification |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 return; | 317 return; |
| 295 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) | 318 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) |
| 296 base::mac::RequestFullScreen(mode); | 319 base::mac::RequestFullScreen(mode); |
| 297 else if (mode == base::mac::kFullScreenModeNormal) | 320 else if (mode == base::mac::kFullScreenModeNormal) |
| 298 base::mac::ReleaseFullScreen(systemFullscreenMode_); | 321 base::mac::ReleaseFullScreen(systemFullscreenMode_); |
| 299 else | 322 else |
| 300 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); | 323 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); |
| 301 systemFullscreenMode_ = mode; | 324 systemFullscreenMode_ = mode; |
| 302 } | 325 } |
| 303 | 326 |
| 327 - (void)mouseEntered:(NSEvent*)event { | |
| 328 // Empty implementation. Required for CrTrackingArea. | |
| 329 } | |
| 330 | |
| 331 - (void)mouseExited:(NSEvent*)event { | |
| 332 DCHECK(inFullscreenMode_); | |
| 333 | |
| 334 // Release the toolbar if the mouse exits the tracking area, | |
| 335 if ([event trackingArea] == trackingArea_.get()) | |
| 336 [self releaseAndHideBarVisibility]; | |
| 337 } | |
| 338 | |
| 304 - (void)changeToolbarFraction:(CGFloat)fraction { | 339 - (void)changeToolbarFraction:(CGFloat)fraction { |
| 305 toolbarFraction_ = fraction; | 340 toolbarFraction_ = |
| 341 [browserController_ isBarVisibilityLockedForOwner:nil] ? 1.0 : fraction; | |
|
erikchen
2016/08/23 21:19:58
This line concerns me a lot. The previous method s
| |
| 342 | |
| 306 [browserController_ layoutSubviews]; | 343 [browserController_ layoutSubviews]; |
| 307 | 344 |
| 308 // In AppKit fullscreen, moving the mouse to the top of the screen toggles | 345 // In AppKit fullscreen, moving the mouse to the top of the screen toggles |
| 309 // menu visibility. Replicate the same effect for immersive fullscreen. | 346 // menu visibility. Replicate the same effect for immersive fullscreen. |
| 310 if ([browserController_ isInImmersiveFullscreen]) | 347 if ([browserController_ isInImmersiveFullscreen]) |
| 311 [self updateMenuBarAndDockVisibility]; | 348 [self updateMenuBarAndDockVisibility]; |
| 312 } | 349 } |
| 313 | 350 |
| 314 // This method works, but is fragile. | 351 // This method works, but is fragile. |
| 315 // | 352 // |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 328 | 365 |
| 329 return [self shouldShowMenubarInImmersiveFullscreen] | 366 return [self shouldShowMenubarInImmersiveFullscreen] |
| 330 ? -[self floatingBarVerticalOffset] | 367 ? -[self floatingBarVerticalOffset] |
| 331 : 0; | 368 : 0; |
| 332 } | 369 } |
| 333 | 370 |
| 334 - (BOOL)isFullscreenTransitionInProgress { | 371 - (BOOL)isFullscreenTransitionInProgress { |
| 335 return [browserController_ isFullscreenTransitionInProgress]; | 372 return [browserController_ isFullscreenTransitionInProgress]; |
| 336 } | 373 } |
| 337 | 374 |
| 375 - (BOOL)isInFullscreen { | |
| 376 return inFullscreenMode_; | |
| 377 } | |
| 378 | |
| 338 - (BOOL)isMouseOnScreen { | 379 - (BOOL)isMouseOnScreen { |
| 339 return NSMouseInRect([NSEvent mouseLocation], | 380 return NSMouseInRect([NSEvent mouseLocation], |
| 340 [[browserController_ window] screen].frame, false); | 381 [[browserController_ window] screen].frame, false); |
| 341 } | 382 } |
| 342 | 383 |
| 384 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame { | |
| 385 trackingAreaFrame_ = frame; | |
| 386 trackingAreaFrame_.origin.y -= kTrackingAreaAdditionalThreshold; | |
| 387 trackingAreaFrame_.size.height += kTrackingAreaAdditionalThreshold; | |
| 388 } | |
| 389 | |
| 343 - (void)animationDidStop:(NSAnimation*)animation { | 390 - (void)animationDidStop:(NSAnimation*)animation { |
| 344 // Reset the |currentAnimation_| pointer now that the animation is over. | 391 // Reset the |currentAnimation_| pointer now that the animation is over. |
| 345 currentAnimation_.reset(); | 392 currentAnimation_.reset(); |
| 346 | 393 |
| 347 if (revealToolbarForTabStripChanges_) { | 394 if (revealToolbarForTabStripChanges_) { |
| 348 if (toolbarFraction_ > 0.0) { | 395 if (toolbarFraction_ > 0.0) { |
| 349 // Set the timer to hide the toolbar. | 396 // Set the timer to hide the toolbar. |
| 350 [hideTimer_ invalidate]; | 397 [hideTimer_ invalidate]; |
| 351 hideTimer_.reset([[NSTimer | 398 hideTimer_.reset( |
| 352 scheduledTimerWithTimeInterval:kDropdownForTabStripChangesDuration | 399 [[NSTimer scheduledTimerWithTimeInterval:kTabStripChangesDelay |
| 353 target:self | 400 target:self |
| 354 selector:@selector(hideTimerFire:) | 401 selector:@selector(hideTimerFire:) |
| 355 userInfo:nil | 402 userInfo:nil |
| 356 repeats:NO] retain]); | 403 repeats:NO] retain]); |
| 357 } else { | 404 } else { |
| 358 revealToolbarForTabStripChanges_ = NO; | 405 revealToolbarForTabStripChanges_ = NO; |
| 359 } | 406 } |
| 360 } | 407 } |
| 361 } | 408 } |
| 362 | 409 |
| 363 - (void)animationDidEnd:(NSAnimation*)animation { | 410 - (void)animationDidEnd:(NSAnimation*)animation { |
| 364 [self animationDidStop:animation]; | 411 [self animationDidStop:animation]; |
| 412 [self setupTrackingArea]; | |
| 365 } | 413 } |
| 366 | 414 |
| 367 - (void)setMenuBarRevealProgress:(CGFloat)progress { | 415 - (void)setMenuBarRevealProgress:(CGFloat)progress { |
| 368 // If the menubarFraction increases, check if we are in the right screen | 416 // If the menubarFraction increases, check if we are in the right screen |
| 369 // so that the toolbar is not revealed on the wrong screen. | 417 // so that the toolbar is not revealed on the wrong screen. |
| 370 if (![self isMouseOnScreen] && progress > menubarFraction_) | 418 if (![self isMouseOnScreen] && progress > menubarFraction_) |
|
erikchen
2016/08/23 21:19:58
If the active screen changes, but the menubar frac
| |
| 371 return; | 419 return; |
| 372 | 420 |
| 373 menubarFraction_ = progress; | 421 menubarFraction_ = progress; |
| 374 | 422 |
| 375 // If an animation is not running, then -layoutSubviews will not be called | 423 // If an animation is not running, then -layoutSubviews will not be called |
| 376 // for each tick of the menu bar reveal. Do that manually. | 424 // for each tick of the menu bar reveal. Do that manually. |
| 377 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so | 425 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so |
| 378 // that it calls setFrameOffset: instead of setFrame: if the frame's size has | 426 // that it calls setFrameOffset: instead of setFrame: if the frame's size has |
| 379 // not changed. | 427 // not changed. |
| 380 if (!currentAnimation_.get()) { | 428 if (!currentAnimation_.get()) { |
| 381 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_NONE) | 429 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_NONE) |
| 382 toolbarFraction_ = progress; | 430 [self changeToolbarFraction:progress]; |
| 383 [browserController_ layoutSubviews]; | 431 else |
| 432 [browserController_ layoutSubviews]; | |
| 433 } | |
| 434 | |
| 435 if (toolbarFraction_ == 1.0) { | |
| 436 // Lock the toolbar's visibility and set up the tracking area. | |
| 437 [browserController_ lockBarVisibilityForOwner:self withAnimation:NO]; | |
| 438 [self setupTrackingArea]; | |
| 439 | |
| 440 // If the menubar is gone, check if the mouse is inside the new tracking | |
| 441 // area. There's a chance that the tracking area had slipped away from the | |
| 442 // cursor when toolbar shifted up from the menubar changes. As a result, | |
| 443 // this would've prevent us from getting a |mouseExited:| call. | |
| 444 if (menubarFraction_ == 0 && ![self mouseInsideTrackingArea]) | |
| 445 [self releaseAndHideBarVisibility]; | |
| 384 } | 446 } |
| 385 } | 447 } |
| 386 | 448 |
| 387 @end | 449 @end |
| 388 | 450 |
| 389 @implementation FullscreenToolbarController (PrivateMethods) | 451 @implementation FullscreenToolbarController (PrivateMethods) |
| 390 | 452 |
| 391 - (void)updateMenuBarAndDockVisibility { | 453 - (void)updateMenuBarAndDockVisibility { |
| 392 if (![self isMouseOnScreen] || | 454 if (![self isMouseOnScreen] || |
| 393 ![browserController_ isInImmersiveFullscreen]) { | 455 ![browserController_ isInImmersiveFullscreen]) { |
| 394 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 456 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 395 return; | 457 return; |
| 396 } | 458 } |
| 397 | 459 |
| 398 // The screen does not have a menu bar, so there's no need to hide it. | 460 // The screen does not have a menu bar, so there's no need to hide it. |
| 399 if (![self doesScreenHaveMenuBar]) { | 461 if (![self doesScreenHaveMenuBar]) { |
| 400 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; | 462 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; |
| 401 return; | 463 return; |
| 402 } | 464 } |
| 403 | 465 |
| 404 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; | 466 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; |
| 405 } | 467 } |
| 406 | 468 |
| 469 - (void)setupTrackingArea { | |
| 470 if (trackingArea_) { | |
| 471 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. | |
| 472 NSRect oldRect = [trackingArea_ rect]; | |
| 473 if (NSEqualRects(trackingAreaFrame_, oldRect)) | |
| 474 return; | |
| 475 | |
| 476 // Otherwise, remove it. | |
| 477 [self removeTrackingAreaIfNecessary]; | |
| 478 } | |
| 479 | |
| 480 // Create and add a new tracking area for |frame|. | |
| 481 trackingArea_.reset([[CrTrackingArea alloc] | |
| 482 initWithRect:trackingAreaFrame_ | |
| 483 options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | |
| 484 owner:self | |
| 485 userInfo:nil]); | |
| 486 DCHECK(contentView_); | |
| 487 [contentView_ addTrackingArea:trackingArea_]; | |
| 488 } | |
| 489 | |
| 490 - (void)removeTrackingAreaIfNecessary { | |
| 491 if (trackingArea_) { | |
| 492 DCHECK(contentView_); // |contentView_| better be valid. | |
| 493 [contentView_ removeTrackingArea:trackingArea_]; | |
| 494 trackingArea_.reset(); | |
| 495 } | |
| 496 } | |
| 497 | |
| 498 - (BOOL)mouseInsideTrackingArea { | |
| 499 NSWindow* window = [browserController_ window]; | |
| 500 NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream]; | |
| 501 NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil]; | |
| 502 return NSMouseInRect(mousePos, trackingAreaFrame_, [contentView_ isFlipped]); | |
| 503 } | |
| 504 | |
| 407 - (BOOL)doesScreenHaveMenuBar { | 505 - (BOOL)doesScreenHaveMenuBar { |
| 408 if (![[NSScreen class] | 506 if (![[NSScreen class] |
| 409 respondsToSelector:@selector(screensHaveSeparateSpaces)]) | 507 respondsToSelector:@selector(screensHaveSeparateSpaces)]) |
| 410 return [self isWindowOnPrimaryScreen]; | 508 return [self isWindowOnPrimaryScreen]; |
| 411 | 509 |
| 412 BOOL eachScreenShouldHaveMenuBar = [NSScreen screensHaveSeparateSpaces]; | 510 BOOL eachScreenShouldHaveMenuBar = [NSScreen screensHaveSeparateSpaces]; |
| 413 return eachScreenShouldHaveMenuBar ?: [self isWindowOnPrimaryScreen]; | 511 return eachScreenShouldHaveMenuBar ?: [self isWindowOnPrimaryScreen]; |
| 414 } | 512 } |
| 415 | 513 |
| 416 - (BOOL)isWindowOnPrimaryScreen { | 514 - (BOOL)isWindowOnPrimaryScreen { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 445 // Create the animation and set it up. | 543 // Create the animation and set it up. |
| 446 currentAnimation_.reset([[DropdownAnimation alloc] | 544 currentAnimation_.reset([[DropdownAnimation alloc] |
| 447 initWithFraction:fraction | 545 initWithFraction:fraction |
| 448 fullDuration:kDropdownAnimationDuration | 546 fullDuration:kDropdownAnimationDuration |
| 449 animationCurve:NSAnimationEaseOut | 547 animationCurve:NSAnimationEaseOut |
| 450 controller:self]); | 548 controller:self]); |
| 451 DCHECK(currentAnimation_); | 549 DCHECK(currentAnimation_); |
| 452 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 550 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 453 [currentAnimation_ setDelegate:self]; | 551 [currentAnimation_ setDelegate:self]; |
| 454 | 552 |
| 553 // If there is an existing tracking area, remove it. We do not track mouse | |
| 554 // movements during animations (see class comment in the header file). | |
| 555 [self removeTrackingAreaIfNecessary]; | |
| 556 | |
| 455 [currentAnimation_ startAnimation]; | 557 [currentAnimation_ startAnimation]; |
| 456 } | 558 } |
| 457 | 559 |
| 560 - (void)releaseAndHideBarVisibility { | |
| 561 // There are two ways for the toolbar to hide: | |
| 562 // 1. Via the menubar, if the menubar is fully visible. | |
| 563 // With its visibility released, the Carbon menubar events will hide the | |
| 564 // toobar in sync with the menubar. For this case, we need to call | |
| 565 // ensureOverlayShownWithAnimation: so that the toolbar won't hide before | |
| 566 // the menubar does. | |
| 567 // 2. Via DropdownAnimation, if the menubar is already gone. The animation is | |
| 568 // created when we call releaseBarVisibilityForOwner:, and it will hide | |
| 569 // the toolbar. | |
| 570 [browserController_ releaseBarVisibilityForOwner:self withAnimation:YES]; | |
| 571 if (menubarFraction_ == 1.0) | |
| 572 [self ensureOverlayShownWithAnimation:NO]; | |
| 573 | |
| 574 [self removeTrackingAreaIfNecessary]; | |
| 575 } | |
| 576 | |
| 458 - (void)cancelHideTimer { | 577 - (void)cancelHideTimer { |
| 459 [hideTimer_ invalidate]; | 578 [hideTimer_ invalidate]; |
| 460 hideTimer_.reset(); | 579 hideTimer_.reset(); |
| 461 } | 580 } |
| 462 | 581 |
| 463 - (void)hideTimerFire:(NSTimer*)timer { | 582 - (void)hideTimerFire:(NSTimer*)timer { |
| 464 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. | 583 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. |
| 465 [hideTimer_ invalidate]; // Make sure it doesn't repeat. | 584 [hideTimer_ invalidate]; // Make sure it doesn't repeat. |
| 466 hideTimer_.reset(); // And get rid of it. | 585 hideTimer_.reset(); // And get rid of it. |
| 467 [self changeOverlayToFraction:0 withAnimation:YES]; | 586 [self changeOverlayToFraction:0 withAnimation:YES]; |
| 468 } | 587 } |
| 469 | 588 |
| 470 - (void)cleanup { | 589 - (void)cleanup { |
| 471 [self cancelAnimationAndTimer]; | 590 [self cancelAnimationAndTimer]; |
| 472 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 591 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 473 | 592 |
| 593 [self removeTrackingAreaIfNecessary]; | |
| 594 | |
| 474 // This isn't tracked when not in fullscreen mode. | 595 // This isn't tracked when not in fullscreen mode. |
| 475 [browserController_ releaseBarVisibilityForOwner:self withAnimation:NO]; | 596 [browserController_ releaseBarVisibilityForOwner:self withAnimation:NO]; |
| 476 | 597 |
| 477 // Call the main status resignation code to perform the associated cleanup, | 598 // Call the main status resignation code to perform the associated cleanup, |
| 478 // since we will no longer be receiving actual status resignation | 599 // since we will no longer be receiving actual status resignation |
| 479 // notifications. | 600 // notifications. |
| 480 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 601 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 481 | 602 |
| 482 // No more calls back up to the BWC. | 603 // No more calls back up to the BWC. |
| 483 browserController_ = nil; | 604 browserController_ = nil; |
| 484 } | 605 } |
| 485 | 606 |
| 486 - (void)showActiveWindowUI { | 607 - (void)showActiveWindowUI { |
| 487 [self updateMenuBarAndDockVisibility]; | 608 [self updateMenuBarAndDockVisibility]; |
| 488 } | 609 } |
| 489 | 610 |
| 490 - (void)hideActiveWindowUI { | 611 - (void)hideActiveWindowUI { |
| 491 [self updateMenuBarAndDockVisibility]; | 612 [self updateMenuBarAndDockVisibility]; |
| 492 } | 613 } |
| 493 | 614 |
| 494 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 615 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
| 495 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99; | 616 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99; |
| 496 } | 617 } |
| 497 | 618 |
| 498 @end | 619 @end |
| OLD | NEW |