| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_controller.h" | 5 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #import "base/mac/mac_util.h" | 9 #import "base/mac/mac_util.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 11 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 12 | 12 |
| 13 NSString* const kWillEnterFullscreenNotification = | 13 NSString* const kWillEnterFullscreenNotification = |
| 14 @"WillEnterFullscreenNotification"; | 14 @"WillEnterFullscreenNotification"; |
| 15 NSString* const kWillLeaveFullscreenNotification = | 15 NSString* const kWillLeaveFullscreenNotification = |
| 16 @"WillLeaveFullscreenNotification"; | 16 @"WillLeaveFullscreenNotification"; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 // The activation zone for the main menu is 4 pixels high; if we make it any | 19 // The activation zone for the main menu is 4 pixels high; if we make it any |
| 20 // smaller, then the menu can be made to appear without the bar sliding down. | 20 // smaller, then the menu can be made to appear without the bar sliding down. |
| 21 const CGFloat kDropdownActivationZoneHeight = 4; | 21 const CGFloat kDropdownActivationZoneHeight = 4; |
| 22 const NSTimeInterval kDropdownAnimationDuration = 0.12; | 22 const NSTimeInterval kDropdownAnimationDuration = 0.12; |
| 23 const NSTimeInterval kMouseExitCheckDelay = 0.1; | 23 const NSTimeInterval kMouseExitCheckDelay = 0.1; |
| 24 // This show delay attempts to match the delay for the main menu. | 24 // This show delay attempts to match the delay for the main menu. |
| 25 const NSTimeInterval kDropdownShowDelay = 0.3; | 25 const NSTimeInterval kDropdownShowDelay = 0.3; |
| 26 const NSTimeInterval kDropdownHideDelay = 0.2; | 26 const NSTimeInterval kDropdownHideDelay = 0.2; |
| 27 | 27 |
| 28 // The amount by which the floating bar is offset downwards (to avoid the menu) | 28 // The amount by which the floating bar is offset downwards (to avoid the menu) |
| 29 // in fullscreen mode. (We can't use |-[NSMenu menuBarHeight]| since it returns | 29 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it |
| 30 // 0 when the menu bar is hidden.) | 30 // returns 0 when the menu bar is hidden.) |
| 31 const CGFloat kFloatingBarVerticalOffset = 22; | 31 const CGFloat kFloatingBarVerticalOffset = 22; |
| 32 | 32 |
| 33 } // end namespace | 33 } // end namespace |
| 34 | 34 |
| 35 | 35 |
| 36 // Helper class to manage animations for the fullscreen dropdown bar. Calls | 36 // Helper class to manage animations for the dropdown bar. Calls |
| 37 // [FullscreenController changeFloatingBarShownFraction] once per animation | 37 // [PresentationModeController changeFloatingBarShownFraction] once per |
| 38 // step. | 38 // animation step. |
| 39 @interface DropdownAnimation : NSAnimation { | 39 @interface DropdownAnimation : NSAnimation { |
| 40 @private | 40 @private |
| 41 FullscreenController* controller_; | 41 PresentationModeController* controller_; |
| 42 CGFloat startFraction_; | 42 CGFloat startFraction_; |
| 43 CGFloat endFraction_; | 43 CGFloat endFraction_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 @property(readonly, nonatomic) CGFloat startFraction; | 46 @property(readonly, nonatomic) CGFloat startFraction; |
| 47 @property(readonly, nonatomic) CGFloat endFraction; | 47 @property(readonly, nonatomic) CGFloat endFraction; |
| 48 | 48 |
| 49 // Designated initializer. Asks |controller| for the current shown fraction, so | 49 // Designated initializer. Asks |controller| for the current shown fraction, so |
| 50 // if the bar is already partially shown or partially hidden, the animation | 50 // if the bar is already partially shown or partially hidden, the animation |
| 51 // duration may be less than |fullDuration|. | 51 // duration may be less than |fullDuration|. |
| 52 - (id)initWithFraction:(CGFloat)fromFraction | 52 - (id)initWithFraction:(CGFloat)fromFraction |
| 53 fullDuration:(CGFloat)fullDuration | 53 fullDuration:(CGFloat)fullDuration |
| 54 animationCurve:(NSInteger)animationCurve | 54 animationCurve:(NSInteger)animationCurve |
| 55 controller:(FullscreenController*)controller; | 55 controller:(PresentationModeController*)controller; |
| 56 | 56 |
| 57 @end | 57 @end |
| 58 | 58 |
| 59 @implementation DropdownAnimation | 59 @implementation DropdownAnimation |
| 60 | 60 |
| 61 @synthesize startFraction = startFraction_; | 61 @synthesize startFraction = startFraction_; |
| 62 @synthesize endFraction = endFraction_; | 62 @synthesize endFraction = endFraction_; |
| 63 | 63 |
| 64 - (id)initWithFraction:(CGFloat)toFraction | 64 - (id)initWithFraction:(CGFloat)toFraction |
| 65 fullDuration:(CGFloat)fullDuration | 65 fullDuration:(CGFloat)fullDuration |
| 66 animationCurve:(NSInteger)animationCurve | 66 animationCurve:(NSInteger)animationCurve |
| 67 controller:(FullscreenController*)controller { | 67 controller:(PresentationModeController*)controller { |
| 68 // Calculate the effective duration, based on the current shown fraction. | 68 // Calculate the effective duration, based on the current shown fraction. |
| 69 DCHECK(controller); | 69 DCHECK(controller); |
| 70 CGFloat fromFraction = [controller floatingBarShownFraction]; | 70 CGFloat fromFraction = [controller floatingBarShownFraction]; |
| 71 CGFloat effectiveDuration = fabs(fullDuration * (fromFraction - toFraction)); | 71 CGFloat effectiveDuration = fabs(fullDuration * (fromFraction - toFraction)); |
| 72 | 72 |
| 73 if ((self = [super gtm_initWithDuration:effectiveDuration | 73 if ((self = [super gtm_initWithDuration:effectiveDuration |
| 74 eventMask:NSLeftMouseDownMask | 74 eventMask:NSLeftMouseDownMask |
| 75 animationCurve:animationCurve])) { | 75 animationCurve:animationCurve])) { |
| 76 startFraction_ = fromFraction; | 76 startFraction_ = fromFraction; |
| 77 endFraction_ = toFraction; | 77 endFraction_ = toFraction; |
| 78 controller_ = controller; | 78 controller_ = controller; |
| 79 } | 79 } |
| 80 return self; | 80 return self; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Called once per animation step. Overridden to change the floating bar's | 83 // Called once per animation step. Overridden to change the floating bar's |
| 84 // position based on the animation's progress. | 84 // position based on the animation's progress. |
| 85 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 85 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 86 CGFloat fraction = | 86 CGFloat fraction = |
| 87 startFraction_ + (progress * (endFraction_ - startFraction_)); | 87 startFraction_ + (progress * (endFraction_ - startFraction_)); |
| 88 [controller_ changeFloatingBarShownFraction:fraction]; | 88 [controller_ changeFloatingBarShownFraction:fraction]; |
| 89 } | 89 } |
| 90 | 90 |
| 91 @end | 91 @end |
| 92 | 92 |
| 93 | 93 |
| 94 @interface FullscreenController (PrivateMethods) | 94 @interface PresentationModeController (PrivateMethods) |
| 95 | 95 |
| 96 // Returns YES if the fullscreen window is on the primary screen. | 96 // Returns YES if the window is on the primary screen. |
| 97 - (BOOL)isWindowOnPrimaryScreen; | 97 - (BOOL)isWindowOnPrimaryScreen; |
| 98 | 98 |
| 99 // Returns YES if it is ok to show and hide the menu bar in response to the | 99 // Returns YES if it is ok to show and hide the menu bar in response to the |
| 100 // overlay opening and closing. Will return NO if the window is not main or not | 100 // overlay opening and closing. Will return NO if the window is not main or not |
| 101 // on the primary monitor. | 101 // on the primary monitor. |
| 102 - (BOOL)shouldToggleMenuBar; | 102 - (BOOL)shouldToggleMenuBar; |
| 103 | 103 |
| 104 // Returns |kFullScreenModeHideAll| when the overlay is hidden and | 104 // Returns |kFullScreenModeHideAll| when the overlay is hidden and |
| 105 // |kFullScreenModeHideDock| when the overlay is shown. | 105 // |kFullScreenModeHideDock| when the overlay is shown. |
| 106 - (base::mac::FullScreenMode)desiredFullscreenMode; | 106 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; |
| 107 | 107 |
| 108 // Change the overlay to the given fraction, with or without animation. Only | 108 // Change the overlay to the given fraction, with or without animation. Only |
| 109 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This | 109 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This |
| 110 // performs the show/hide (animation) immediately. It does not touch the timers. | 110 // performs the show/hide (animation) immediately. It does not touch the timers. |
| 111 - (void)changeOverlayToFraction:(CGFloat)fraction | 111 - (void)changeOverlayToFraction:(CGFloat)fraction |
| 112 withAnimation:(BOOL)animate; | 112 withAnimation:(BOOL)animate; |
| 113 | 113 |
| 114 // Schedule the floating bar to be shown/hidden because of mouse position. | 114 // Schedule the floating bar to be shown/hidden because of mouse position. |
| 115 - (void)scheduleShowForMouse; | 115 - (void)scheduleShowForMouse; |
| 116 - (void)scheduleHideForMouse; | 116 - (void)scheduleHideForMouse; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 144 - (void)cancelAllTimers; | 144 - (void)cancelAllTimers; |
| 145 | 145 |
| 146 // Methods called when the show/hide timers fire. Do not call directly. | 146 // Methods called when the show/hide timers fire. Do not call directly. |
| 147 - (void)showTimerFire:(NSTimer*)timer; | 147 - (void)showTimerFire:(NSTimer*)timer; |
| 148 - (void)hideTimerFire:(NSTimer*)timer; | 148 - (void)hideTimerFire:(NSTimer*)timer; |
| 149 | 149 |
| 150 // Stops any running animations, removes tracking areas, etc. | 150 // Stops any running animations, removes tracking areas, etc. |
| 151 - (void)cleanup; | 151 - (void)cleanup; |
| 152 | 152 |
| 153 // Shows and hides the UI associated with this window being active (having main | 153 // Shows and hides the UI associated with this window being active (having main |
| 154 // status). This includes hiding the menu bar and displaying the "Exit | 154 // status). This includes hiding the menu bar. These functions are called when |
| 155 // Fullscreen" button. These functions are called when the window gains or | 155 // the window gains or loses main status as well as in |-cleanup|. |
| 156 // loses main status as well as in |-cleanup|. | |
| 157 - (void)showActiveWindowUI; | 156 - (void)showActiveWindowUI; |
| 158 - (void)hideActiveWindowUI; | 157 - (void)hideActiveWindowUI; |
| 159 | 158 |
| 160 @end | 159 @end |
| 161 | 160 |
| 162 | 161 |
| 163 @implementation FullscreenController | 162 @implementation PresentationModeController |
| 164 | 163 |
| 165 @synthesize isFullscreen = isFullscreen_; | 164 @synthesize inPresentationMode = inPresentationMode_; |
| 166 | 165 |
| 167 - (id)initWithBrowserController:(BrowserWindowController*)controller { | 166 - (id)initWithBrowserController:(BrowserWindowController*)controller { |
| 168 if ((self = [super init])) { | 167 if ((self = [super init])) { |
| 169 browserController_ = controller; | 168 browserController_ = controller; |
| 170 currentFullscreenMode_ = base::mac::kFullScreenModeNormal; | 169 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Let the world know what we're up to. | 172 // Let the world know what we're up to. |
| 174 [[NSNotificationCenter defaultCenter] | 173 [[NSNotificationCenter defaultCenter] |
| 175 postNotificationName:kWillEnterFullscreenNotification | 174 postNotificationName:kWillEnterFullscreenNotification |
| 176 object:nil]; | 175 object:nil]; |
| 177 | 176 |
| 178 return self; | 177 return self; |
| 179 } | 178 } |
| 180 | 179 |
| 181 - (void)dealloc { | 180 - (void)dealloc { |
| 182 DCHECK(!isFullscreen_); | 181 DCHECK(!inPresentationMode_); |
| 183 DCHECK(!trackingArea_); | 182 DCHECK(!trackingArea_); |
| 184 [super dealloc]; | 183 [super dealloc]; |
| 185 } | 184 } |
| 186 | 185 |
| 187 - (void)enterFullscreenForContentView:(NSView*)contentView | 186 - (void)enterPresentationModeForContentView:(NSView*)contentView |
| 188 showDropdown:(BOOL)showDropdown { | 187 showDropdown:(BOOL)showDropdown { |
| 189 DCHECK(!isFullscreen_); | 188 DCHECK(!inPresentationMode_); |
| 190 isFullscreen_ = YES; | 189 enteringPresentationMode_ = YES; |
| 190 inPresentationMode_ = YES; |
| 191 contentView_ = contentView; | 191 contentView_ = contentView; |
| 192 [self changeFloatingBarShownFraction:(showDropdown ? 1 : 0)]; | 192 [self changeFloatingBarShownFraction:(showDropdown ? 1 : 0)]; |
| 193 | 193 |
| 194 // Register for notifications. Self is removed as an observer in |-cleanup|. | 194 // Register for notifications. Self is removed as an observer in |-cleanup|. |
| 195 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 195 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 196 NSWindow* window = [browserController_ window]; | 196 NSWindow* window = [browserController_ window]; |
| 197 [nc addObserver:self | |
| 198 selector:@selector(windowDidChangeScreen:) | |
| 199 name:NSWindowDidChangeScreenNotification | |
| 200 object:window]; | |
| 201 | 197 |
| 202 [nc addObserver:self | 198 // Disable these notifications on Lion as they cause crashes. |
| 203 selector:@selector(windowDidMove:) | 199 // TODO(rohitrao): Figure out what happens if a fullscreen window changes |
| 204 name:NSWindowDidMoveNotification | 200 // monitors on Lion. |
| 205 object:window]; | 201 if (base::mac::IsOSSnowLeopardOrEarlier()) { |
| 202 [nc addObserver:self |
| 203 selector:@selector(windowDidChangeScreen:) |
| 204 name:NSWindowDidChangeScreenNotification |
| 205 object:window]; |
| 206 |
| 207 [nc addObserver:self |
| 208 selector:@selector(windowDidMove:) |
| 209 name:NSWindowDidMoveNotification |
| 210 object:window]; |
| 211 } |
| 206 | 212 |
| 207 [nc addObserver:self | 213 [nc addObserver:self |
| 208 selector:@selector(windowDidBecomeMain:) | 214 selector:@selector(windowDidBecomeMain:) |
| 209 name:NSWindowDidBecomeMainNotification | 215 name:NSWindowDidBecomeMainNotification |
| 210 object:window]; | 216 object:window]; |
| 211 | 217 |
| 212 [nc addObserver:self | 218 [nc addObserver:self |
| 213 selector:@selector(windowDidResignMain:) | 219 selector:@selector(windowDidResignMain:) |
| 214 name:NSWindowDidResignMainNotification | 220 name:NSWindowDidResignMainNotification |
| 215 object:window]; | 221 object:window]; |
| 222 |
| 223 enteringPresentationMode_ = NO; |
| 216 } | 224 } |
| 217 | 225 |
| 218 - (void)exitFullscreen { | 226 - (void)exitPresentationMode { |
| 219 [[NSNotificationCenter defaultCenter] | 227 [[NSNotificationCenter defaultCenter] |
| 220 postNotificationName:kWillLeaveFullscreenNotification | 228 postNotificationName:kWillLeaveFullscreenNotification |
| 221 object:nil]; | 229 object:nil]; |
| 222 DCHECK(isFullscreen_); | 230 DCHECK(inPresentationMode_); |
| 231 inPresentationMode_ = NO; |
| 223 [self cleanup]; | 232 [self cleanup]; |
| 224 isFullscreen_ = NO; | |
| 225 } | 233 } |
| 226 | 234 |
| 227 - (void)windowDidChangeScreen:(NSNotification*)notification { | 235 - (void)windowDidChangeScreen:(NSNotification*)notification { |
| 228 [browserController_ resizeFullscreenWindow]; | 236 [browserController_ resizeFullscreenWindow]; |
| 229 } | 237 } |
| 230 | 238 |
| 231 - (void)windowDidMove:(NSNotification*)notification { | 239 - (void)windowDidMove:(NSNotification*)notification { |
| 232 [browserController_ resizeFullscreenWindow]; | 240 [browserController_ resizeFullscreenWindow]; |
| 233 } | 241 } |
| 234 | 242 |
| 235 - (void)windowDidBecomeMain:(NSNotification*)notification { | 243 - (void)windowDidBecomeMain:(NSNotification*)notification { |
| 236 [self showActiveWindowUI]; | 244 [self showActiveWindowUI]; |
| 237 } | 245 } |
| 238 | 246 |
| 239 - (void)windowDidResignMain:(NSNotification*)notification { | 247 - (void)windowDidResignMain:(NSNotification*)notification { |
| 240 [self hideActiveWindowUI]; | 248 [self hideActiveWindowUI]; |
| 241 } | 249 } |
| 242 | 250 |
| 243 - (CGFloat)floatingBarVerticalOffset { | 251 - (CGFloat)floatingBarVerticalOffset { |
| 244 return [self isWindowOnPrimaryScreen] ? kFloatingBarVerticalOffset : 0; | 252 return [self isWindowOnPrimaryScreen] ? kFloatingBarVerticalOffset : 0; |
| 245 } | 253 } |
| 246 | 254 |
| 247 - (void)overlayFrameChanged:(NSRect)frame { | 255 - (void)overlayFrameChanged:(NSRect)frame { |
| 248 if (!isFullscreen_) | 256 if (!inPresentationMode_) |
| 249 return; | 257 return; |
| 250 | 258 |
| 251 // Make sure |trackingAreaBounds_| always reflects either the tracking area or | 259 // Make sure |trackingAreaBounds_| always reflects either the tracking area or |
| 252 // the desired tracking area. | 260 // the desired tracking area. |
| 253 trackingAreaBounds_ = frame; | 261 trackingAreaBounds_ = frame; |
| 254 // The tracking area should always be at least the height of activation zone. | 262 // The tracking area should always be at least the height of activation zone. |
| 255 NSRect contentBounds = [contentView_ bounds]; | 263 NSRect contentBounds = [contentView_ bounds]; |
| 256 trackingAreaBounds_.origin.y = | 264 trackingAreaBounds_.origin.y = |
| 257 std::min(trackingAreaBounds_.origin.y, | 265 std::min(trackingAreaBounds_.origin.y, |
| 258 NSMaxY(contentBounds) - kDropdownActivationZoneHeight); | 266 NSMaxY(contentBounds) - kDropdownActivationZoneHeight); |
| 259 trackingAreaBounds_.size.height = | 267 trackingAreaBounds_.size.height = |
| 260 NSMaxY(contentBounds) - trackingAreaBounds_.origin.y + 1; | 268 NSMaxY(contentBounds) - trackingAreaBounds_.origin.y + 1; |
| 261 | 269 |
| 262 // If an animation is currently running, do not set up a tracking area now. | 270 // If an animation is currently running, do not set up a tracking area now. |
| 263 // Instead, leave it to be created it in |-animationDidEnd:|. | 271 // Instead, leave it to be created it in |-animationDidEnd:|. |
| 264 if (currentAnimation_) | 272 if (currentAnimation_) |
| 265 return; | 273 return; |
| 266 | 274 |
| 275 // If this is part of the initial setup, lock bar visibility if the mouse is |
| 276 // within the tracking area bounds. |
| 277 if (enteringPresentationMode_ && [self mouseInsideTrackingRect]) |
| 278 [browserController_ lockBarVisibilityForOwner:self |
| 279 withAnimation:NO |
| 280 delay:NO]; |
| 267 [self setupTrackingArea]; | 281 [self setupTrackingArea]; |
| 268 } | 282 } |
| 269 | 283 |
| 270 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay { | 284 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay { |
| 271 if (!isFullscreen_) | 285 if (!inPresentationMode_) |
| 272 return; | 286 return; |
| 273 | 287 |
| 274 if (animate) { | 288 if (animate) { |
| 275 if (delay) { | 289 if (delay) { |
| 276 [self startShowTimer]; | 290 [self startShowTimer]; |
| 277 } else { | 291 } else { |
| 278 [self cancelAllTimers]; | 292 [self cancelAllTimers]; |
| 279 [self changeOverlayToFraction:1 withAnimation:YES]; | 293 [self changeOverlayToFraction:1 withAnimation:YES]; |
| 280 } | 294 } |
| 281 } else { | 295 } else { |
| 282 DCHECK(!delay); | 296 DCHECK(!delay); |
| 283 [self cancelAllTimers]; | 297 [self cancelAllTimers]; |
| 284 [self changeOverlayToFraction:1 withAnimation:NO]; | 298 [self changeOverlayToFraction:1 withAnimation:NO]; |
| 285 } | 299 } |
| 286 } | 300 } |
| 287 | 301 |
| 288 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay { | 302 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay { |
| 289 if (!isFullscreen_) | 303 if (!inPresentationMode_) |
| 290 return; | 304 return; |
| 291 | 305 |
| 292 if (animate) { | 306 if (animate) { |
| 293 if (delay) { | 307 if (delay) { |
| 294 [self startHideTimer]; | 308 [self startHideTimer]; |
| 295 } else { | 309 } else { |
| 296 [self cancelAllTimers]; | 310 [self cancelAllTimers]; |
| 297 [self changeOverlayToFraction:0 withAnimation:YES]; | 311 [self changeOverlayToFraction:0 withAnimation:YES]; |
| 298 } | 312 } |
| 299 } else { | 313 } else { |
| 300 DCHECK(!delay); | 314 DCHECK(!delay); |
| 301 [self cancelAllTimers]; | 315 [self cancelAllTimers]; |
| 302 [self changeOverlayToFraction:0 withAnimation:NO]; | 316 [self changeOverlayToFraction:0 withAnimation:NO]; |
| 303 } | 317 } |
| 304 } | 318 } |
| 305 | 319 |
| 306 - (void)cancelAnimationAndTimers { | 320 - (void)cancelAnimationAndTimers { |
| 307 [self cancelAllTimers]; | 321 [self cancelAllTimers]; |
| 308 [currentAnimation_ stopAnimation]; | 322 [currentAnimation_ stopAnimation]; |
| 309 currentAnimation_.reset(); | 323 currentAnimation_.reset(); |
| 310 } | 324 } |
| 311 | 325 |
| 312 - (CGFloat)floatingBarShownFraction { | 326 - (CGFloat)floatingBarShownFraction { |
| 313 return [browserController_ floatingBarShownFraction]; | 327 return [browserController_ floatingBarShownFraction]; |
| 314 } | 328 } |
| 315 | 329 |
| 316 - (void)changeFloatingBarShownFraction:(CGFloat)fraction { | 330 - (void)changeFloatingBarShownFraction:(CGFloat)fraction { |
| 317 [browserController_ setFloatingBarShownFraction:fraction]; | 331 [browserController_ setFloatingBarShownFraction:fraction]; |
| 318 | 332 |
| 319 base::mac::FullScreenMode desiredMode = [self desiredFullscreenMode]; | 333 base::mac::FullScreenMode desiredMode = [self desiredSystemFullscreenMode]; |
| 320 if (desiredMode != currentFullscreenMode_ && [self shouldToggleMenuBar]) { | 334 if (desiredMode != systemFullscreenMode_ && [self shouldToggleMenuBar]) { |
| 321 if (currentFullscreenMode_ == base::mac::kFullScreenModeNormal) | 335 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) |
| 322 base::mac::RequestFullScreen(desiredMode); | 336 base::mac::RequestFullScreen(desiredMode); |
| 323 else | 337 else |
| 324 base::mac::SwitchFullScreenModes(currentFullscreenMode_, desiredMode); | 338 base::mac::SwitchFullScreenModes(systemFullscreenMode_, desiredMode); |
| 325 currentFullscreenMode_ = desiredMode; | 339 systemFullscreenMode_ = desiredMode; |
| 326 } | 340 } |
| 327 } | 341 } |
| 328 | 342 |
| 329 // Used to activate the floating bar in fullscreen mode. | 343 // Used to activate the floating bar in presentation mode. |
| 330 - (void)mouseEntered:(NSEvent*)event { | 344 - (void)mouseEntered:(NSEvent*)event { |
| 331 DCHECK(isFullscreen_); | 345 DCHECK(inPresentationMode_); |
| 332 | 346 |
| 333 // Having gotten a mouse entered, we no longer need to do exit checks. | 347 // Having gotten a mouse entered, we no longer need to do exit checks. |
| 334 [self cancelMouseExitCheck]; | 348 [self cancelMouseExitCheck]; |
| 335 | 349 |
| 336 NSTrackingArea* trackingArea = [event trackingArea]; | 350 NSTrackingArea* trackingArea = [event trackingArea]; |
| 337 if (trackingArea == trackingArea_) { | 351 if (trackingArea == trackingArea_) { |
| 338 // The tracking area shouldn't be active during animation. | 352 // The tracking area shouldn't be active during animation. |
| 339 DCHECK(!currentAnimation_); | 353 DCHECK(!currentAnimation_); |
| 340 [self scheduleShowForMouse]; | 354 [self scheduleShowForMouse]; |
| 341 } | 355 } |
| 342 } | 356 } |
| 343 | 357 |
| 344 // Used to deactivate the floating bar in fullscreen mode. | 358 // Used to deactivate the floating bar in presentation mode. |
| 345 - (void)mouseExited:(NSEvent*)event { | 359 - (void)mouseExited:(NSEvent*)event { |
| 346 DCHECK(isFullscreen_); | 360 DCHECK(inPresentationMode_); |
| 347 | 361 |
| 348 NSTrackingArea* trackingArea = [event trackingArea]; | 362 NSTrackingArea* trackingArea = [event trackingArea]; |
| 349 if (trackingArea == trackingArea_) { | 363 if (trackingArea == trackingArea_) { |
| 350 // The tracking area shouldn't be active during animation. | 364 // The tracking area shouldn't be active during animation. |
| 351 DCHECK(!currentAnimation_); | 365 DCHECK(!currentAnimation_); |
| 352 | 366 |
| 353 // We can get a false mouse exit when the menu slides down, so if the mouse | 367 // We can get a false mouse exit when the menu slides down, so if the mouse |
| 354 // is still actually over the tracking area, we ignore the mouse exit, but | 368 // is still actually over the tracking area, we ignore the mouse exit, but |
| 355 // we set up to check the mouse position again after a delay. | 369 // we set up to check the mouse position again after a delay. |
| 356 if ([self mouseInsideTrackingRect]) { | 370 if ([self mouseInsideTrackingRect]) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 386 | 400 |
| 387 // TODO(viettrungluu): Better would be to check during the animation; doing it | 401 // TODO(viettrungluu): Better would be to check during the animation; doing it |
| 388 // here means that the timing is slightly off. | 402 // here means that the timing is slightly off. |
| 389 if (![self mouseInsideTrackingRect]) | 403 if (![self mouseInsideTrackingRect]) |
| 390 [self scheduleHideForMouse]; | 404 [self scheduleHideForMouse]; |
| 391 } | 405 } |
| 392 | 406 |
| 393 @end | 407 @end |
| 394 | 408 |
| 395 | 409 |
| 396 @implementation FullscreenController (PrivateMethods) | 410 @implementation PresentationModeController (PrivateMethods) |
| 397 | 411 |
| 398 - (BOOL)isWindowOnPrimaryScreen { | 412 - (BOOL)isWindowOnPrimaryScreen { |
| 399 NSScreen* screen = [[browserController_ window] screen]; | 413 NSScreen* screen = [[browserController_ window] screen]; |
| 400 NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0]; | 414 NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0]; |
| 401 return (screen == primaryScreen); | 415 return (screen == primaryScreen); |
| 402 } | 416 } |
| 403 | 417 |
| 404 - (BOOL)shouldToggleMenuBar { | 418 - (BOOL)shouldToggleMenuBar { |
| 405 return [self isWindowOnPrimaryScreen] && | 419 return base::mac::IsOSSnowLeopardOrEarlier() && |
| 420 [self isWindowOnPrimaryScreen] && |
| 406 [[browserController_ window] isMainWindow]; | 421 [[browserController_ window] isMainWindow]; |
| 407 } | 422 } |
| 408 | 423 |
| 409 - (base::mac::FullScreenMode)desiredFullscreenMode { | 424 - (base::mac::FullScreenMode)desiredSystemFullscreenMode { |
| 410 if ([browserController_ floatingBarShownFraction] >= 1.0) | 425 if ([browserController_ floatingBarShownFraction] >= 1.0) |
| 411 return base::mac::kFullScreenModeHideDock; | 426 return base::mac::kFullScreenModeHideDock; |
| 412 return base::mac::kFullScreenModeHideAll; | 427 return base::mac::kFullScreenModeHideAll; |
| 413 } | 428 } |
| 414 | 429 |
| 415 - (void)changeOverlayToFraction:(CGFloat)fraction | 430 - (void)changeOverlayToFraction:(CGFloat)fraction |
| 416 withAnimation:(BOOL)animate { | 431 withAnimation:(BOOL)animate { |
| 417 // The non-animated case is really simple, so do it and return. | 432 // The non-animated case is really simple, so do it and return. |
| 418 if (!animate) { | 433 if (!animate) { |
| 419 [currentAnimation_ stopAnimation]; | 434 [currentAnimation_ stopAnimation]; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 602 } |
| 588 | 603 |
| 589 - (void)cleanup { | 604 - (void)cleanup { |
| 590 [self cancelMouseExitCheck]; | 605 [self cancelMouseExitCheck]; |
| 591 [self cancelAnimationAndTimers]; | 606 [self cancelAnimationAndTimers]; |
| 592 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 607 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 593 | 608 |
| 594 [self removeTrackingAreaIfNecessary]; | 609 [self removeTrackingAreaIfNecessary]; |
| 595 contentView_ = nil; | 610 contentView_ = nil; |
| 596 | 611 |
| 597 // This isn't tracked when not in fullscreen mode. | 612 // This isn't tracked when not in presentation mode. |
| 598 [browserController_ releaseBarVisibilityForOwner:self | 613 [browserController_ releaseBarVisibilityForOwner:self |
| 599 withAnimation:NO | 614 withAnimation:NO |
| 600 delay:NO]; | 615 delay:NO]; |
| 601 | 616 |
| 602 // Call the main status resignation code to perform the associated cleanup, | 617 // Call the main status resignation code to perform the associated cleanup, |
| 603 // since we will no longer be receiving actual status resignation | 618 // since we will no longer be receiving actual status resignation |
| 604 // notifications. | 619 // notifications. |
| 605 [self hideActiveWindowUI]; | 620 [self hideActiveWindowUI]; |
| 606 | 621 |
| 607 // No more calls back up to the BWC. | 622 // No more calls back up to the BWC. |
| 608 browserController_ = nil; | 623 browserController_ = nil; |
| 609 } | 624 } |
| 610 | 625 |
| 611 - (void)showActiveWindowUI { | 626 - (void)showActiveWindowUI { |
| 612 DCHECK_EQ(currentFullscreenMode_, base::mac::kFullScreenModeNormal); | 627 DCHECK_EQ(systemFullscreenMode_, base::mac::kFullScreenModeNormal); |
| 613 if (currentFullscreenMode_ != base::mac::kFullScreenModeNormal) | 628 if (systemFullscreenMode_ != base::mac::kFullScreenModeNormal) |
| 614 return; | 629 return; |
| 615 | 630 |
| 616 if ([self shouldToggleMenuBar]) { | 631 if ([self shouldToggleMenuBar]) { |
| 617 base::mac::FullScreenMode desiredMode = [self desiredFullscreenMode]; | 632 base::mac::FullScreenMode desiredMode = [self desiredSystemFullscreenMode]; |
| 618 base::mac::RequestFullScreen(desiredMode); | 633 base::mac::RequestFullScreen(desiredMode); |
| 619 currentFullscreenMode_ = desiredMode; | 634 systemFullscreenMode_ = desiredMode; |
| 620 } | 635 } |
| 621 | 636 |
| 622 // TODO(rohitrao): Insert the Exit Fullscreen button. http://crbug.com/35956 | 637 // TODO(rohitrao): Insert the Exit Fullscreen button. http://crbug.com/35956 |
| 623 } | 638 } |
| 624 | 639 |
| 625 - (void)hideActiveWindowUI { | 640 - (void)hideActiveWindowUI { |
| 626 if (currentFullscreenMode_ != base::mac::kFullScreenModeNormal) { | 641 if (systemFullscreenMode_ != base::mac::kFullScreenModeNormal) { |
| 627 base::mac::ReleaseFullScreen(currentFullscreenMode_); | 642 base::mac::ReleaseFullScreen(systemFullscreenMode_); |
| 628 currentFullscreenMode_ = base::mac::kFullScreenModeNormal; | 643 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
| 629 } | 644 } |
| 630 | 645 |
| 631 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 | 646 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 |
| 632 } | 647 } |
| 633 | 648 |
| 634 @end | 649 @end |
| OLD | NEW |