| 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" |
| 11 #import "base/mac/mac_util.h" | 11 #import "base/mac/mac_util.h" |
| 12 #include "base/mac/sdk_forward_declarations.h" | 12 #include "base/mac/sdk_forward_declarations.h" |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 16 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 17 #include "ui/base/cocoa/appkit_utils.h" |
| 16 #import "ui/base/cocoa/nsview_additions.h" | 18 #import "ui/base/cocoa/nsview_additions.h" |
| 17 #import "ui/base/cocoa/tracking_area.h" | 19 #import "ui/base/cocoa/tracking_area.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 // The duration of the toolbar show/hide animation. | 23 // The duration of the toolbar show/hide animation. |
| 22 const NSTimeInterval kDropdownAnimationDuration = 0.20; | 24 const NSTimeInterval kDropdownAnimationDuration = 0.20; |
| 23 | 25 |
| 24 // If the fullscreen toolbar is hidden, it is difficult for the user to see | 26 // If the fullscreen toolbar is hidden, it is difficult for the user to see |
| 25 // changes in the tabstrip. As a result, if a tab is inserted or the current | 27 // changes in the tabstrip. As a result, if a tab is inserted or the current |
| 26 // tab switched to a new one, the toolbar must animate in and out to display | 28 // tab switched to a new one, the toolbar must animate in and out to display |
| 27 // the tabstrip changes to the user. The animation drops down the toolbar and | 29 // the tabstrip changes to the user. The animation drops down the toolbar and |
| 28 // then wait for 0.75 seconds before it hides the toolbar. | 30 // then wait for 0.75 seconds before it hides the toolbar. |
| 29 const NSTimeInterval kTabStripChangesDelay = 0.75; | 31 const NSTimeInterval kTabStripChangesDelay = 0.75; |
| 30 | 32 |
| 31 // Additional height threshold added at the toolbar's bottom. This is to mimic | 33 // Additional height threshold added at the toolbar's bottom. This is to mimic |
| 32 // threshold the mouse position needs to be at before the menubar automatically | 34 // threshold the mouse position needs to be at before the menubar automatically |
| 33 // hides. | 35 // hides. |
| 34 const CGFloat kTrackingAreaAdditionalThreshold = 20; | 36 const CGFloat kTrackingAreaAdditionalThreshold = 20; |
| 35 | 37 |
| 36 // The event kind value for a undocumented menubar show/hide Carbon event. | |
| 37 const CGFloat kMenuBarRevealEventKind = 2004; | |
| 38 | |
| 39 // The amount by which the floating bar is offset downwards (to avoid the menu) | |
| 40 // when the toolbar is hidden. (We can't use |-[NSMenu menuBarHeight]| since it | |
| 41 // returns 0 when the menu bar is hidden.) | |
| 42 const CGFloat kFloatingBarVerticalOffset = 22; | |
| 43 | |
| 44 // Visibility fractions for the menubar and toolbar. | 38 // Visibility fractions for the menubar and toolbar. |
| 45 const CGFloat kHideFraction = 0.0; | 39 const CGFloat kHideFraction = 0.0; |
| 46 const CGFloat kShowFraction = 1.0; | 40 const CGFloat kShowFraction = 1.0; |
| 47 | 41 |
| 48 // Helper function for comparing CGFloat values. | 42 // The amount by which the toolbar is offset downwards (to avoid the menu) |
| 49 BOOL IsCGFloatEqual(CGFloat a, CGFloat b) { | 43 // when the toolbar style is OMNIBOX_TABS_HIDDEN. (We can't use |
| 50 return fabs(a - b) <= std::numeric_limits<CGFloat>::epsilon(); | 44 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) |
| 51 } | 45 const CGFloat kToolbarVerticalOffset = 22; |
| 52 | |
| 53 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, | |
| 54 EventRef event, | |
| 55 void* context) { | |
| 56 FullscreenToolbarController* self = | |
| 57 static_cast<FullscreenToolbarController*>(context); | |
| 58 | |
| 59 // If Chrome has multiple fullscreen windows in their own space, the Handler | |
| 60 // becomes flaky and might start receiving kMenuBarRevealEventKind events | |
| 61 // from another space. Since the menubar in the another space is in either a | |
| 62 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0. | |
| 63 // As such, we should ignore the kMenuBarRevealEventKind event if it gives | |
| 64 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and | |
| 65 // kEventMenuBarHidden to set these values. | |
| 66 if (![self isFullscreenTransitionInProgress] && [self isInFullscreen]) { | |
| 67 if (GetEventKind(event) == kMenuBarRevealEventKind) { | |
| 68 CGFloat revealFraction = 0; | |
| 69 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL, | |
| 70 sizeof(CGFloat), NULL, &revealFraction); | |
| 71 if (revealFraction > kHideFraction && revealFraction < kShowFraction) | |
| 72 [self setMenuBarRevealProgress:revealFraction]; | |
| 73 } else if (GetEventKind(event) == kEventMenuBarShown) { | |
| 74 [self setMenuBarRevealProgress:kShowFraction]; | |
| 75 } else { | |
| 76 [self setMenuBarRevealProgress:kHideFraction]; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 return CallNextEventHandler(handler, event); | |
| 81 } | |
| 82 | 46 |
| 83 } // end namespace | 47 } // end namespace |
| 84 | 48 |
| 85 // Helper class to manage animations for the dropdown bar. Calls | 49 // Helper class to manage animations for the dropdown bar. Calls |
| 86 // [FullscreenToolbarController changeToolbarFraction] once per | 50 // [FullscreenToolbarController changeToolbarFraction] once per |
| 87 // animation step. | 51 // animation step. |
| 88 @interface DropdownAnimation : NSAnimation { | 52 @interface DropdownAnimation : NSAnimation { |
| 89 @private | 53 @private |
| 90 FullscreenToolbarController* controller_; | 54 FullscreenToolbarController* controller_; |
| 91 CGFloat startFraction_; | 55 CGFloat startFraction_; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 @implementation FullscreenToolbarController | 149 @implementation FullscreenToolbarController |
| 186 | 150 |
| 187 @synthesize slidingStyle = slidingStyle_; | 151 @synthesize slidingStyle = slidingStyle_; |
| 188 | 152 |
| 189 - (id)initWithBrowserController:(BrowserWindowController*)controller | 153 - (id)initWithBrowserController:(BrowserWindowController*)controller |
| 190 style:(FullscreenSlidingStyle)style { | 154 style:(FullscreenSlidingStyle)style { |
| 191 if ((self = [super init])) { | 155 if ((self = [super init])) { |
| 192 browserController_ = controller; | 156 browserController_ = controller; |
| 193 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; | 157 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
| 194 slidingStyle_ = style; | 158 slidingStyle_ = style; |
| 195 menubarState_ = FullscreenMenubarState::HIDDEN; | |
| 196 } | 159 } |
| 197 | 160 |
| 198 // Install the Carbon event handler for the menubar show, hide and | |
| 199 // undocumented reveal event. | |
| 200 EventTypeSpec eventSpecs[3]; | |
| 201 | |
| 202 eventSpecs[0].eventClass = kEventClassMenu; | |
| 203 eventSpecs[0].eventKind = kMenuBarRevealEventKind; | |
| 204 | |
| 205 eventSpecs[1].eventClass = kEventClassMenu; | |
| 206 eventSpecs[1].eventKind = kEventMenuBarShown; | |
| 207 | |
| 208 eventSpecs[2].eventClass = kEventClassMenu; | |
| 209 eventSpecs[2].eventKind = kEventMenuBarHidden; | |
| 210 | |
| 211 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler), 3, | |
| 212 eventSpecs, self, &menuBarTrackingHandler_); | |
| 213 | |
| 214 return self; | 161 return self; |
| 215 } | 162 } |
| 216 | 163 |
| 217 - (void)dealloc { | 164 - (void)dealloc { |
| 218 RemoveEventHandler(menuBarTrackingHandler_); | |
| 219 DCHECK(!inFullscreenMode_); | 165 DCHECK(!inFullscreenMode_); |
| 220 [super dealloc]; | 166 [super dealloc]; |
| 221 } | 167 } |
| 222 | 168 |
| 223 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView { | 169 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView { |
| 224 DCHECK(!inFullscreenMode_); | 170 DCHECK(!inFullscreenMode_); |
| 225 contentView_ = contentView; | 171 contentView_ = contentView; |
| 226 inFullscreenMode_ = YES; | 172 inFullscreenMode_ = YES; |
| 227 | 173 |
| 174 menubarTracker_.reset([[FullscreenMenubarTracker alloc] |
| 175 initWithFullscreenToolbarController:self]); |
| 176 |
| 228 [self updateMenuBarAndDockVisibility]; | 177 [self updateMenuBarAndDockVisibility]; |
| 229 | 178 |
| 230 // Register for notifications. Self is removed as an observer in |-cleanup|. | 179 // Register for notifications. Self is removed as an observer in |-cleanup|. |
| 231 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 180 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 232 NSWindow* window = [browserController_ window]; | 181 NSWindow* window = [browserController_ window]; |
| 233 | 182 |
| 234 [nc addObserver:self | 183 [nc addObserver:self |
| 235 selector:@selector(windowDidBecomeMain:) | 184 selector:@selector(windowDidBecomeMain:) |
| 236 name:NSWindowDidBecomeMainNotification | 185 name:NSWindowDidBecomeMainNotification |
| 237 object:window]; | 186 object:window]; |
| 238 | 187 |
| 239 [nc addObserver:self | 188 [nc addObserver:self |
| 240 selector:@selector(windowDidResignMain:) | 189 selector:@selector(windowDidResignMain:) |
| 241 name:NSWindowDidResignMainNotification | 190 name:NSWindowDidResignMainNotification |
| 242 object:window]; | 191 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]; | |
| 250 } | 192 } |
| 251 | 193 |
| 252 - (void)exitFullscreenMode { | 194 - (void)exitFullscreenMode { |
| 253 DCHECK(inFullscreenMode_); | 195 DCHECK(inFullscreenMode_); |
| 254 inFullscreenMode_ = NO; | 196 inFullscreenMode_ = NO; |
| 255 | 197 |
| 256 [self cleanup]; | 198 [self cleanup]; |
| 257 } | 199 } |
| 258 | 200 |
| 259 - (void)windowDidChangeScreen:(NSNotification*)notification { | 201 - (void)windowDidChangeScreen:(NSNotification*)notification { |
| 260 [browserController_ resizeFullscreenWindow]; | 202 [browserController_ resizeFullscreenWindow]; |
| 261 } | 203 } |
| 262 | 204 |
| 263 - (void)windowDidMove:(NSNotification*)notification { | 205 - (void)windowDidMove:(NSNotification*)notification { |
| 264 [browserController_ resizeFullscreenWindow]; | 206 [browserController_ resizeFullscreenWindow]; |
| 265 } | 207 } |
| 266 | 208 |
| 267 - (void)windowDidBecomeMain:(NSNotification*)notification { | 209 - (void)windowDidBecomeMain:(NSNotification*)notification { |
| 268 [self updateMenuBarAndDockVisibility]; | 210 [self updateMenuBarAndDockVisibility]; |
| 269 } | 211 } |
| 270 | 212 |
| 271 - (void)windowDidResignMain:(NSNotification*)notification { | 213 - (void)windowDidResignMain:(NSNotification*)notification { |
| 272 [self updateMenuBarAndDockVisibility]; | 214 [self updateMenuBarAndDockVisibility]; |
| 273 } | 215 } |
| 274 | 216 |
| 275 - (void)activeSpaceDidChange:(NSNotification*)notification { | |
| 276 menubarFraction_ = kHideFraction; | |
| 277 menubarState_ = FullscreenMenubarState::HIDDEN; | |
| 278 [browserController_ layoutSubviews]; | |
| 279 } | |
| 280 | |
| 281 - (CGFloat)floatingBarVerticalOffset { | |
| 282 return kFloatingBarVerticalOffset; | |
| 283 } | |
| 284 | |
| 285 - (void)lockBarVisibilityWithAnimation:(BOOL)animate { | 217 - (void)lockBarVisibilityWithAnimation:(BOOL)animate { |
| 286 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); | 218 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); |
| 287 [self ensureOverlayShownWithAnimation:animate]; | 219 [self ensureOverlayShownWithAnimation:animate]; |
| 288 } | 220 } |
| 289 | 221 |
| 290 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { | 222 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { |
| 291 base::AutoReset<BOOL> autoReset(&isReleasingBarVisibility_, YES); | 223 base::AutoReset<BOOL> autoReset(&isReleasingBarVisibility_, YES); |
| 292 [self ensureOverlayHiddenWithAnimation:animate]; | 224 [self ensureOverlayHiddenWithAnimation:animate]; |
| 293 } | 225 } |
| 294 | 226 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 310 if (!inFullscreenMode_) | 242 if (!inFullscreenMode_) |
| 311 return; | 243 return; |
| 312 | 244 |
| 313 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN) | 245 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN) |
| 314 return; | 246 return; |
| 315 | 247 |
| 316 if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 248 if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
| 317 return; | 249 return; |
| 318 | 250 |
| 319 if ([self mouseInsideTrackingArea] || | 251 if ([self mouseInsideTrackingArea] || |
| 320 menubarState_ == FullscreenMenubarState::SHOWN) { | 252 [menubarTracker_ state] == FullscreenMenubarState::SHOWN) { |
| 321 return; | 253 return; |
| 322 } | 254 } |
| 323 | 255 |
| 324 [self cancelHideTimer]; | 256 [self cancelHideTimer]; |
| 325 [self animateToolbarVisibility:NO]; | 257 [self animateToolbarVisibility:NO]; |
| 326 } | 258 } |
| 327 | 259 |
| 328 - (void)cancelAnimationAndTimer { | 260 - (void)cancelAnimationAndTimer { |
| 329 [self cancelHideTimer]; | 261 [self cancelHideTimer]; |
| 330 [currentAnimation_ stopAnimation]; | 262 [currentAnimation_ stopAnimation]; |
| 331 currentAnimation_.reset(); | 263 currentAnimation_.reset(); |
| 332 } | 264 } |
| 333 | 265 |
| 334 - (void)revealToolbarForTabStripChanges { | 266 - (void)revealToolbarForTabStripChanges { |
| 335 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 267 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 336 switches::kEnableFullscreenToolbarReveal)) { | 268 switches::kEnableFullscreenToolbarReveal)) { |
| 337 return; | 269 return; |
| 338 } | 270 } |
| 339 | 271 |
| 340 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. | 272 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. |
| 341 if (IsCGFloatEqual([self toolbarFraction], kHideFraction)) { | 273 if (ui::IsCGFloatEqual([self toolbarFraction], kHideFraction)) { |
| 342 isRevealingToolbarForTabStripChanges_ = YES; | 274 isRevealingToolbarForTabStripChanges_ = YES; |
| 343 [self ensureOverlayShownWithAnimation:YES]; | 275 [self ensureOverlayShownWithAnimation:YES]; |
| 344 } | 276 } |
| 345 } | 277 } |
| 346 | 278 |
| 347 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { | 279 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { |
| 348 if (mode == systemFullscreenMode_) | 280 if (mode == systemFullscreenMode_) |
| 349 return; | 281 return; |
| 350 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) | 282 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) |
| 351 base::mac::RequestFullScreen(mode); | 283 base::mac::RequestFullScreen(mode); |
| 352 else if (mode == base::mac::kFullScreenModeNormal) | 284 else if (mode == base::mac::kFullScreenModeNormal) |
| 353 base::mac::ReleaseFullScreen(systemFullscreenMode_); | 285 base::mac::ReleaseFullScreen(systemFullscreenMode_); |
| 354 else | 286 else |
| 355 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); | 287 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); |
| 356 systemFullscreenMode_ = mode; | 288 systemFullscreenMode_ = mode; |
| 357 } | 289 } |
| 358 | 290 |
| 359 - (void)mouseEntered:(NSEvent*)event { | 291 - (void)mouseEntered:(NSEvent*)event { |
| 360 // Empty implementation. Required for CrTrackingArea. | 292 // Empty implementation. Required for CrTrackingArea. |
| 361 } | 293 } |
| 362 | 294 |
| 363 - (void)mouseExited:(NSEvent*)event { | 295 - (void)mouseExited:(NSEvent*)event { |
| 364 DCHECK(inFullscreenMode_); | 296 DCHECK(inFullscreenMode_); |
| 365 DCHECK_EQ([event trackingArea], trackingArea_.get()); | 297 DCHECK_EQ([event trackingArea], trackingArea_.get()); |
| 366 | 298 |
| 367 if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 299 if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
| 368 return; | 300 return; |
| 369 | 301 |
| 370 // If the menubar is gone, animate the toolbar out. | 302 // If the menubar is gone, animate the toolbar out. |
| 371 if (menubarState_ == FullscreenMenubarState::HIDDEN) { | 303 if ([menubarTracker_ state] == FullscreenMenubarState::HIDDEN) { |
| 372 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); | 304 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); |
| 373 [self ensureOverlayHiddenWithAnimation:YES]; | 305 [self ensureOverlayHiddenWithAnimation:YES]; |
| 374 } | 306 } |
| 375 | 307 |
| 376 [self removeTrackingAreaIfNecessary]; | 308 [self removeTrackingAreaIfNecessary]; |
| 377 } | 309 } |
| 378 | 310 |
| 379 - (void)updateToolbar { | 311 - (void)updateToolbar { |
| 380 [browserController_ layoutSubviews]; | 312 [browserController_ layoutSubviews]; |
| 313 [self updateTrackingArea]; |
| 381 | 314 |
| 382 // In AppKit fullscreen, moving the mouse to the top of the screen toggles | 315 // In AppKit fullscreen, moving the mouse to the top of the screen toggles |
| 383 // menu visibility. Replicate the same effect for immersive fullscreen. | 316 // menu visibility. Replicate the same effect for immersive fullscreen. |
| 384 if ([browserController_ isInImmersiveFullscreen]) | 317 if ([browserController_ isInImmersiveFullscreen]) |
| 385 [self updateMenuBarAndDockVisibility]; | 318 [self updateMenuBarAndDockVisibility]; |
| 386 } | 319 } |
| 387 | 320 |
| 321 - (BrowserWindowController*)browserWindowController { |
| 322 return browserController_; |
| 323 } |
| 324 |
| 388 // This method works, but is fragile. | 325 // This method works, but is fragile. |
| 389 // | 326 // |
| 390 // It gets used during view layout, which sometimes needs to be done at the | 327 // It gets used during view layout, which sometimes needs to be done at the |
| 391 // beginning of an animation. As such, this method needs to reflect the | 328 // beginning of an animation. As such, this method needs to reflect the |
| 392 // menubarOffset expected at the end of the animation. This information is not | 329 // menubarOffset expected at the end of the animation. This information is not |
| 393 // readily available. (The layout logic needs a refactor). | 330 // readily available. (The layout logic needs a refactor). |
| 394 // | 331 // |
| 395 // For AppKit Fullscreen, the menubar always starts hidden, and | 332 // For AppKit Fullscreen, the menubar always starts hidden, and |
| 396 // menubarFraction_ always starts at 0, so the logic happens to work. For | 333 // menubarFraction_ always starts at 0, so the logic happens to work. For |
| 397 // Immersive Fullscreen, this class controls the visibility of the menu bar, so | 334 // Immersive Fullscreen, this class controls the visibility of the menu bar, so |
| 398 // the logic is correct and not fragile. | 335 // the logic is correct and not fragile. |
| 399 - (CGFloat)menubarOffset { | 336 - (CGFloat)menubarOffset { |
| 400 if ([browserController_ isInAppKitFullscreen]) | 337 if ([browserController_ isInAppKitFullscreen]) { |
| 401 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]); | 338 return -std::floor([menubarTracker_ menubarFraction] * |
| 339 kToolbarVerticalOffset); |
| 340 } |
| 402 | 341 |
| 403 return [self shouldShowMenubarInImmersiveFullscreen] | 342 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset |
| 404 ? -[self floatingBarVerticalOffset] | 343 : 0; |
| 405 : 0; | |
| 406 } | 344 } |
| 407 | 345 |
| 408 - (CGFloat)toolbarFraction { | 346 - (CGFloat)toolbarFraction { |
| 409 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 347 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 410 return kHideFraction; | 348 return kHideFraction; |
| 411 | 349 |
| 412 switch (slidingStyle_) { | 350 switch (slidingStyle_) { |
| 413 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: | 351 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: |
| 414 return kShowFraction; | 352 return kShowFraction; |
| 415 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: | 353 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: |
| 416 return kHideFraction; | 354 return kHideFraction; |
| 417 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: | 355 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: |
| 418 if (menubarState_ == FullscreenMenubarState::SHOWN) | 356 FullscreenMenubarState menubarState = [menubarTracker_ state]; |
| 357 if (menubarState == FullscreenMenubarState::SHOWN) |
| 419 return kShowFraction; | 358 return kShowFraction; |
| 420 | 359 |
| 421 if ([self mouseInsideTrackingArea]) | 360 if ([self mouseInsideTrackingArea]) |
| 422 return kShowFraction; | 361 return kShowFraction; |
| 423 | 362 |
| 424 if (currentAnimation_.get()) | 363 if (currentAnimation_.get()) |
| 425 return [currentAnimation_ toolbarFraction]; | 364 return [currentAnimation_ toolbarFraction]; |
| 426 | 365 |
| 427 if (isLockingBarVisibility_) | 366 if (isLockingBarVisibility_) |
| 428 return kHideFraction; | 367 return kHideFraction; |
| 429 else if (isReleasingBarVisibility_) | 368 else if (isReleasingBarVisibility_) |
| 430 return kShowFraction; | 369 return kShowFraction; |
| 431 else if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 370 else if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
| 432 return kShowFraction; | 371 return kShowFraction; |
| 433 | 372 |
| 434 if (hideTimer_.get() || shouldAnimateToolbarOut_) | 373 if (hideTimer_.get() || shouldAnimateToolbarOut_) |
| 435 return kShowFraction; | 374 return kShowFraction; |
| 436 | 375 |
| 437 return menubarFraction_; | 376 return [menubarTracker_ menubarFraction]; |
| 438 } | 377 } |
| 439 } | 378 } |
| 440 | 379 |
| 441 - (BOOL)isFullscreenTransitionInProgress { | 380 - (BOOL)isFullscreenTransitionInProgress { |
| 442 return [browserController_ isFullscreenTransitionInProgress]; | 381 return [browserController_ isFullscreenTransitionInProgress]; |
| 443 } | 382 } |
| 444 | 383 |
| 445 - (BOOL)isInFullscreen { | 384 - (BOOL)isInFullscreen { |
| 446 return inFullscreenMode_; | 385 return inFullscreenMode_; |
| 447 } | 386 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 477 | 416 |
| 478 // Reset the |currentAnimation_| pointer now that the animation is over. | 417 // Reset the |currentAnimation_| pointer now that the animation is over. |
| 479 currentAnimation_.reset(); | 418 currentAnimation_.reset(); |
| 480 } | 419 } |
| 481 | 420 |
| 482 - (void)animationDidEnd:(NSAnimation*)animation { | 421 - (void)animationDidEnd:(NSAnimation*)animation { |
| 483 [self animationDidStop:animation]; | 422 [self animationDidStop:animation]; |
| 484 [self updateTrackingArea]; | 423 [self updateTrackingArea]; |
| 485 } | 424 } |
| 486 | 425 |
| 487 - (void)setMenuBarRevealProgress:(CGFloat)progress { | |
| 488 // If the menubarFraction increases, check if we are in the right screen | |
| 489 // so that the toolbar is not revealed on the wrong screen. | |
| 490 if (![self isMouseOnScreen] && progress > menubarFraction_) | |
| 491 return; | |
| 492 | |
| 493 // Ignore the menubarFraction changes if the Space is inactive. | |
| 494 if (![[browserController_ window] isOnActiveSpace]) | |
| 495 return; | |
| 496 | |
| 497 if (IsCGFloatEqual(progress, kShowFraction)) | |
| 498 menubarState_ = FullscreenMenubarState::SHOWN; | |
| 499 else if (IsCGFloatEqual(progress, kHideFraction)) | |
| 500 menubarState_ = FullscreenMenubarState::HIDDEN; | |
| 501 else if (progress < menubarFraction_) | |
| 502 menubarState_ = FullscreenMenubarState::HIDING; | |
| 503 else if (progress > menubarFraction_) | |
| 504 menubarState_ = FullscreenMenubarState::SHOWING; | |
| 505 | |
| 506 menubarFraction_ = progress; | |
| 507 | |
| 508 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN) { | |
| 509 if (menubarState_ == FullscreenMenubarState::HIDDEN || | |
| 510 menubarState_ == FullscreenMenubarState::SHOWN) { | |
| 511 [self updateTrackingArea]; | |
| 512 } | |
| 513 } | |
| 514 | |
| 515 // If an animation is not running, then -layoutSubviews will not be called | |
| 516 // for each tick of the menu bar reveal. Do that manually. | |
| 517 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so | |
| 518 // that it calls setFrameOffset: instead of setFrame: if the frame's size has | |
| 519 // not changed. | |
| 520 if (!currentAnimation_.get()) | |
| 521 [browserController_ layoutSubviews]; | |
| 522 } | |
| 523 | |
| 524 @end | 426 @end |
| 525 | 427 |
| 526 @implementation FullscreenToolbarController (PrivateMethods) | 428 @implementation FullscreenToolbarController (PrivateMethods) |
| 527 | 429 |
| 528 - (void)updateMenuBarAndDockVisibility { | 430 - (void)updateMenuBarAndDockVisibility { |
| 529 if (![self isMouseOnScreen] || | 431 if (![self isMouseOnScreen] || |
| 530 ![browserController_ isInImmersiveFullscreen]) { | 432 ![browserController_ isInImmersiveFullscreen]) { |
| 531 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 433 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 532 return; | 434 return; |
| 533 } | 435 } |
| 534 | 436 |
| 535 // The screen does not have a menu bar, so there's no need to hide it. | 437 // The screen does not have a menu bar, so there's no need to hide it. |
| 536 if (![self doesScreenHaveMenuBar]) { | 438 if (![self doesScreenHaveMenuBar]) { |
| 537 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; | 439 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; |
| 538 return; | 440 return; |
| 539 } | 441 } |
| 540 | 442 |
| 541 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; | 443 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; |
| 542 } | 444 } |
| 543 | 445 |
| 544 - (void)updateTrackingArea { | 446 - (void)updateTrackingArea { |
| 545 // Remove the tracking area if the toolbar isn't fully shown. | 447 // Remove the tracking area if the toolbar isn't fully shown. |
| 546 if (!IsCGFloatEqual([self toolbarFraction], kShowFraction)) { | 448 if (!ui::IsCGFloatEqual([self toolbarFraction], kShowFraction)) { |
| 547 [self removeTrackingAreaIfNecessary]; | 449 [self removeTrackingAreaIfNecessary]; |
| 548 return; | 450 return; |
| 549 } | 451 } |
| 550 | 452 |
| 551 if (trackingArea_) { | 453 if (trackingArea_) { |
| 552 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. | 454 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. |
| 553 NSRect oldRect = [trackingArea_ rect]; | 455 NSRect oldRect = [trackingArea_ rect]; |
| 554 if (NSEqualRects(trackingAreaFrame_, oldRect)) | 456 if (NSEqualRects(trackingAreaFrame_, oldRect)) |
| 555 return; | 457 return; |
| 556 | 458 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. | 547 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. |
| 646 [hideTimer_ invalidate]; // Make sure it doesn't repeat. | 548 [hideTimer_ invalidate]; // Make sure it doesn't repeat. |
| 647 hideTimer_.reset(); // And get rid of it. | 549 hideTimer_.reset(); // And get rid of it. |
| 648 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); | 550 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); |
| 649 [self animateToolbarVisibility:NO]; | 551 [self animateToolbarVisibility:NO]; |
| 650 } | 552 } |
| 651 | 553 |
| 652 - (void)cleanup { | 554 - (void)cleanup { |
| 653 [self cancelAnimationAndTimer]; | 555 [self cancelAnimationAndTimer]; |
| 654 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 556 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 655 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | |
| 656 | 557 |
| 657 [self removeTrackingAreaIfNecessary]; | 558 [self removeTrackingAreaIfNecessary]; |
| 658 | 559 |
| 659 // Call the main status resignation code to perform the associated cleanup, | 560 // Call the main status resignation code to perform the associated cleanup, |
| 660 // since we will no longer be receiving actual status resignation | 561 // since we will no longer be receiving actual status resignation |
| 661 // notifications. | 562 // notifications. |
| 662 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 563 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 663 | 564 |
| 565 menubarTracker_.reset(); |
| 566 |
| 664 // No more calls back up to the BWC. | 567 // No more calls back up to the BWC. |
| 665 browserController_ = nil; | 568 browserController_ = nil; |
| 666 } | 569 } |
| 667 | 570 |
| 668 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 571 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
| 669 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; | 572 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; |
| 670 } | 573 } |
| 671 | 574 |
| 672 @end | 575 @end |
| OLD | NEW |