| 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/presentation_mode_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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 30 const NSTimeInterval kDropdownShowDelay = 0.3; | 30 const NSTimeInterval kDropdownShowDelay = 0.3; |
| 31 const NSTimeInterval kDropdownHideDelay = 0.2; | 31 const NSTimeInterval kDropdownHideDelay = 0.2; |
| 32 | 32 |
| 33 // The duration the toolbar is revealed for tab strip changes. | 33 // The duration the toolbar is revealed for tab strip changes. |
| 34 const NSTimeInterval kDropdownForTabStripChangesDuration = 0.75; | 34 const NSTimeInterval kDropdownForTabStripChangesDuration = 0.75; |
| 35 | 35 |
| 36 // The event kind value for a undocumented menubar show/hide Carbon event. | 36 // The event kind value for a undocumented menubar show/hide Carbon event. |
| 37 const CGFloat kMenuBarRevealEventKind = 2004; | 37 const CGFloat kMenuBarRevealEventKind = 2004; |
| 38 | 38 |
| 39 // The amount by which the floating bar is offset downwards (to avoid the menu) | 39 // The amount by which the floating bar is offset downwards (to avoid the menu) |
| 40 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it | 40 // when the toolbar is hidden. (We can't use |-[NSMenu menuBarHeight]| since it |
| 41 // returns 0 when the menu bar is hidden.) | 41 // returns 0 when the menu bar is hidden.) |
| 42 const CGFloat kFloatingBarVerticalOffset = 22; | 42 const CGFloat kFloatingBarVerticalOffset = 22; |
| 43 | 43 |
| 44 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, | 44 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, |
| 45 EventRef event, | 45 EventRef event, |
| 46 void* context) { | 46 void* context) { |
| 47 PresentationModeController* self = | 47 FullscreenToolbarController* self = |
| 48 static_cast<PresentationModeController*>(context); | 48 static_cast<FullscreenToolbarController*>(context); |
| 49 | 49 |
| 50 // If Chrome has multiple fullscreen windows in their own space, the Handler | 50 // If Chrome has multiple fullscreen windows in their own space, the Handler |
| 51 // becomes flaky and might start receiving kMenuBarRevealEventKind events | 51 // becomes flaky and might start receiving kMenuBarRevealEventKind events |
| 52 // from another space. Since the menubar in the another space is in either a | 52 // from another space. Since the menubar in the another space is in either a |
| 53 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0. | 53 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0. |
| 54 // As such, we should ignore the kMenuBarRevealEventKind event if it gives | 54 // As such, we should ignore the kMenuBarRevealEventKind event if it gives |
| 55 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and | 55 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and |
| 56 // kEventMenuBarHidden to set these values. | 56 // kEventMenuBarHidden to set these values. |
| 57 if ([self isMainWindow] && ![self isFullscreenTransitionInProgress]) { | 57 if ([self isMainWindow] && ![self isFullscreenTransitionInProgress]) { |
| 58 if (GetEventKind(event) == kMenuBarRevealEventKind) { | 58 if (GetEventKind(event) == kMenuBarRevealEventKind) { |
| 59 CGFloat revealFraction = 0; | 59 CGFloat revealFraction = 0; |
| 60 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL, | 60 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL, |
| 61 sizeof(CGFloat), NULL, &revealFraction); | 61 sizeof(CGFloat), NULL, &revealFraction); |
| 62 if (revealFraction > 0.0 && revealFraction < 1.0) | 62 if (revealFraction > 0.0 && revealFraction < 1.0) |
| 63 [self setMenuBarRevealProgress:revealFraction]; | 63 [self setMenuBarRevealProgress:revealFraction]; |
| 64 } else if (GetEventKind(event) == kEventMenuBarShown) { | 64 } else if (GetEventKind(event) == kEventMenuBarShown) { |
| 65 [self setMenuBarRevealProgress:1.0]; | 65 [self setMenuBarRevealProgress:1.0]; |
| 66 } else { | 66 } else { |
| 67 [self setMenuBarRevealProgress:0.0]; | 67 [self setMenuBarRevealProgress:0.0]; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 return CallNextEventHandler(handler, event); | 71 return CallNextEventHandler(handler, event); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // end namespace | 74 } // end namespace |
| 75 | 75 |
| 76 // Helper class to manage animations for the dropdown bar. Calls | 76 // Helper class to manage animations for the dropdown bar. Calls |
| 77 // [PresentationModeController changeToolbarFraction] once per | 77 // [FullscreenToolbarController changeToolbarFraction] once per |
| 78 // animation step. | 78 // animation step. |
| 79 @interface DropdownAnimation : NSAnimation { | 79 @interface DropdownAnimation : NSAnimation { |
| 80 @private | 80 @private |
| 81 PresentationModeController* controller_; | 81 FullscreenToolbarController* controller_; |
| 82 CGFloat startFraction_; | 82 CGFloat startFraction_; |
| 83 CGFloat endFraction_; | 83 CGFloat endFraction_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 @property(readonly, nonatomic) CGFloat startFraction; | 86 @property(readonly, nonatomic) CGFloat startFraction; |
| 87 @property(readonly, nonatomic) CGFloat endFraction; | 87 @property(readonly, nonatomic) CGFloat endFraction; |
| 88 | 88 |
| 89 // Designated initializer. Asks |controller| for the current shown fraction, so | 89 // Designated initializer. Asks |controller| for the current shown fraction, so |
| 90 // if the bar is already partially shown or partially hidden, the animation | 90 // if the bar is already partially shown or partially hidden, the animation |
| 91 // duration may be less than |fullDuration|. | 91 // duration may be less than |fullDuration|. |
| 92 - (id)initWithFraction:(CGFloat)fromFraction | 92 - (id)initWithFraction:(CGFloat)fromFraction |
| 93 fullDuration:(CGFloat)fullDuration | 93 fullDuration:(CGFloat)fullDuration |
| 94 animationCurve:(NSAnimationCurve)animationCurve | 94 animationCurve:(NSAnimationCurve)animationCurve |
| 95 controller:(PresentationModeController*)controller; | 95 controller:(FullscreenToolbarController*)controller; |
| 96 | 96 |
| 97 @end | 97 @end |
| 98 | 98 |
| 99 @implementation DropdownAnimation | 99 @implementation DropdownAnimation |
| 100 | 100 |
| 101 @synthesize startFraction = startFraction_; | 101 @synthesize startFraction = startFraction_; |
| 102 @synthesize endFraction = endFraction_; | 102 @synthesize endFraction = endFraction_; |
| 103 | 103 |
| 104 - (id)initWithFraction:(CGFloat)toFraction | 104 - (id)initWithFraction:(CGFloat)toFraction |
| 105 fullDuration:(CGFloat)fullDuration | 105 fullDuration:(CGFloat)fullDuration |
| 106 animationCurve:(NSAnimationCurve)animationCurve | 106 animationCurve:(NSAnimationCurve)animationCurve |
| 107 controller:(PresentationModeController*)controller { | 107 controller:(FullscreenToolbarController*)controller { |
| 108 // Calculate the effective duration, based on the current shown fraction. | 108 // Calculate the effective duration, based on the current shown fraction. |
| 109 DCHECK(controller); | 109 DCHECK(controller); |
| 110 CGFloat fromFraction = controller.toolbarFraction; | 110 CGFloat fromFraction = controller.toolbarFraction; |
| 111 CGFloat effectiveDuration = fabs(fullDuration * (fromFraction - toFraction)); | 111 CGFloat effectiveDuration = fabs(fullDuration * (fromFraction - toFraction)); |
| 112 | 112 |
| 113 if ((self = [super gtm_initWithDuration:effectiveDuration | 113 if ((self = [super gtm_initWithDuration:effectiveDuration |
| 114 eventMask:NSLeftMouseDownMask | 114 eventMask:NSLeftMouseDownMask |
| 115 animationCurve:animationCurve])) { | 115 animationCurve:animationCurve])) { |
| 116 startFraction_ = fromFraction; | 116 startFraction_ = fromFraction; |
| 117 endFraction_ = toFraction; | 117 endFraction_ = toFraction; |
| 118 controller_ = controller; | 118 controller_ = controller; |
| 119 } | 119 } |
| 120 return self; | 120 return self; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Called once per animation step. Overridden to change the floating bar's | 123 // Called once per animation step. Overridden to change the floating bar's |
| 124 // position based on the animation's progress. | 124 // position based on the animation's progress. |
| 125 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 125 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 126 CGFloat fraction = | 126 CGFloat fraction = |
| 127 startFraction_ + (progress * (endFraction_ - startFraction_)); | 127 startFraction_ + (progress * (endFraction_ - startFraction_)); |
| 128 [controller_ changeToolbarFraction:fraction]; | 128 [controller_ changeToolbarFraction:fraction]; |
| 129 } | 129 } |
| 130 | 130 |
| 131 @end | 131 @end |
| 132 | 132 |
| 133 | 133 @interface FullscreenToolbarController (PrivateMethods) |
| 134 @interface PresentationModeController (PrivateMethods) | |
| 135 | 134 |
| 136 // Updates the visibility of the menu bar and the dock. | 135 // Updates the visibility of the menu bar and the dock. |
| 137 - (void)updateMenuBarAndDockVisibility; | 136 - (void)updateMenuBarAndDockVisibility; |
| 138 | 137 |
| 139 // Whether the current screen is expected to have a menu bar, regardless of | 138 // Whether the current screen is expected to have a menu bar, regardless of |
| 140 // current visibility of the menu bar. | 139 // current visibility of the menu bar. |
| 141 - (BOOL)doesScreenHaveMenuBar; | 140 - (BOOL)doesScreenHaveMenuBar; |
| 142 | 141 |
| 143 // Returns YES if the window is on the primary screen. | 142 // Returns YES if the window is on the primary screen. |
| 144 - (BOOL)isWindowOnPrimaryScreen; | 143 - (BOOL)isWindowOnPrimaryScreen; |
| 145 | 144 |
| 146 // Returns |kFullScreenModeHideAll| when the overlay is hidden and | 145 // Returns |kFullScreenModeHideAll| when the overlay is hidden and |
| 147 // |kFullScreenModeHideDock| when the overlay is shown. | 146 // |kFullScreenModeHideDock| when the overlay is shown. |
| 148 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; | 147 - (base::mac::FullScreenMode)desiredSystemFullscreenMode; |
| 149 | 148 |
| 150 // Change the overlay to the given fraction, with or without animation. Only | 149 // Change the overlay to the given fraction, with or without animation. Only |
| 151 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This | 150 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This |
| 152 // performs the show/hide (animation) immediately. It does not touch the timers. | 151 // performs the show/hide (animation) immediately. It does not touch the timers. |
| 153 - (void)changeOverlayToFraction:(CGFloat)fraction | 152 - (void)changeOverlayToFraction:(CGFloat)fraction withAnimation:(BOOL)animate; |
| 154 withAnimation:(BOOL)animate; | |
| 155 | 153 |
| 156 // Schedule the floating bar to be shown/hidden because of mouse position. | 154 // Schedule the floating bar to be shown/hidden because of mouse position. |
| 157 - (void)scheduleShowForMouse; | 155 - (void)scheduleShowForMouse; |
| 158 - (void)scheduleHideForMouse; | 156 - (void)scheduleHideForMouse; |
| 159 | 157 |
| 160 // Set up the tracking area used to activate the sliding bar or keep it active | 158 // Set up the tracking area used to activate the sliding bar or keep it active |
| 161 // using with the rectangle in |trackingAreaBounds_|, or remove the tracking | 159 // using with the rectangle in |trackingAreaBounds_|, or remove the tracking |
| 162 // area if one was previously set up. | 160 // area if one was previously set up. |
| 163 - (void)setupTrackingArea; | 161 - (void)setupTrackingArea; |
| 164 - (void)removeTrackingAreaIfNecessary; | 162 - (void)removeTrackingAreaIfNecessary; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // the window gains or loses main status as well as in |-cleanup|. | 195 // the window gains or loses main status as well as in |-cleanup|. |
| 198 - (void)showActiveWindowUI; | 196 - (void)showActiveWindowUI; |
| 199 - (void)hideActiveWindowUI; | 197 - (void)hideActiveWindowUI; |
| 200 | 198 |
| 201 // Whether the menu bar should be shown in immersive fullscreen for the screen | 199 // Whether the menu bar should be shown in immersive fullscreen for the screen |
| 202 // that contains the window. | 200 // that contains the window. |
| 203 - (BOOL)shouldShowMenubarInImmersiveFullscreen; | 201 - (BOOL)shouldShowMenubarInImmersiveFullscreen; |
| 204 | 202 |
| 205 @end | 203 @end |
| 206 | 204 |
| 207 @implementation PresentationModeController | 205 @implementation FullscreenToolbarController |
| 208 | 206 |
| 209 @synthesize inPresentationMode = inPresentationMode_; | |
| 210 @synthesize slidingStyle = slidingStyle_; | 207 @synthesize slidingStyle = slidingStyle_; |
| 211 @synthesize toolbarFraction = toolbarFraction_; | 208 @synthesize toolbarFraction = toolbarFraction_; |
| 212 | 209 |
| 213 - (id)initWithBrowserController:(BrowserWindowController*)controller | 210 - (id)initWithBrowserController:(BrowserWindowController*)controller |
| 214 style:(fullscreen_mac::SlidingStyle)style { | 211 style:(fullscreen_mac::SlidingStyle)style { |
| 215 if ((self = [super init])) { | 212 if ((self = [super init])) { |
| 216 browserController_ = controller; | 213 browserController_ = controller; |
| 217 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; | 214 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
| 218 slidingStyle_ = style; | 215 slidingStyle_ = style; |
| 219 } | 216 } |
| 220 | 217 |
| 221 // Let the world know what we're up to. | 218 // Let the world know what we're up to. |
| 222 [[NSNotificationCenter defaultCenter] | 219 [[NSNotificationCenter defaultCenter] |
| 223 postNotificationName:kWillEnterFullscreenNotification | 220 postNotificationName:kWillEnterFullscreenNotification |
| 224 object:nil]; | 221 object:nil]; |
| 225 | 222 |
| 226 // Install the Carbon event handler for the menubar show, hide and | 223 // Install the Carbon event handler for the menubar show, hide and |
| 227 // undocumented reveal event. | 224 // undocumented reveal event. |
| 228 EventTypeSpec eventSpecs[3]; | 225 EventTypeSpec eventSpecs[3]; |
| 229 | 226 |
| 230 eventSpecs[0].eventClass = kEventClassMenu; | 227 eventSpecs[0].eventClass = kEventClassMenu; |
| 231 eventSpecs[0].eventKind = kMenuBarRevealEventKind; | 228 eventSpecs[0].eventKind = kMenuBarRevealEventKind; |
| 232 | 229 |
| 233 eventSpecs[1].eventClass = kEventClassMenu; | 230 eventSpecs[1].eventClass = kEventClassMenu; |
| 234 eventSpecs[1].eventKind = kEventMenuBarShown; | 231 eventSpecs[1].eventKind = kEventMenuBarShown; |
| 235 | 232 |
| 236 eventSpecs[2].eventClass = kEventClassMenu; | 233 eventSpecs[2].eventClass = kEventClassMenu; |
| 237 eventSpecs[2].eventKind = kEventMenuBarHidden; | 234 eventSpecs[2].eventKind = kEventMenuBarHidden; |
| 238 | 235 |
| 239 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler), 3, | 236 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler), 3, |
| 240 eventSpecs, self, &menuBarTrackingHandler_); | 237 eventSpecs, self, &menuBarTrackingHandler_); |
| 241 | 238 |
| 242 return self; | 239 return self; |
| 243 } | 240 } |
| 244 | 241 |
| 245 - (void)dealloc { | 242 - (void)dealloc { |
| 246 RemoveEventHandler(menuBarTrackingHandler_); | 243 RemoveEventHandler(menuBarTrackingHandler_); |
| 247 DCHECK(!inPresentationMode_); | 244 DCHECK(!inFullscreenMode_); |
| 248 DCHECK(!trackingArea_); | 245 DCHECK(!trackingArea_); |
| 249 [super dealloc]; | 246 [super dealloc]; |
| 250 } | 247 } |
| 251 | 248 |
| 252 - (void)enterPresentationModeForContentView:(NSView*)contentView | 249 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView |
| 253 showDropdown:(BOOL)showDropdown { | 250 showDropdown:(BOOL)showDropdown { |
| 254 DCHECK(!inPresentationMode_); | 251 DCHECK(!inFullscreenMode_); |
| 255 enteringPresentationMode_ = YES; | 252 settingUp_ = YES; |
| 256 inPresentationMode_ = YES; | 253 inFullscreenMode_ = YES; |
| 257 contentView_ = contentView; | 254 contentView_ = contentView; |
| 258 [self changeToolbarFraction:(showDropdown ? 1 : 0)]; | 255 [self changeToolbarFraction:(showDropdown ? 1 : 0)]; |
| 259 [self updateMenuBarAndDockVisibility]; | 256 [self updateMenuBarAndDockVisibility]; |
| 260 | 257 |
| 261 // Register for notifications. Self is removed as an observer in |-cleanup|. | 258 // Register for notifications. Self is removed as an observer in |-cleanup|. |
| 262 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 259 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 263 NSWindow* window = [browserController_ window]; | 260 NSWindow* window = [browserController_ window]; |
| 264 | 261 |
| 265 [nc addObserver:self | 262 [nc addObserver:self |
| 266 selector:@selector(windowDidBecomeMain:) | 263 selector:@selector(windowDidBecomeMain:) |
| 267 name:NSWindowDidBecomeMainNotification | 264 name:NSWindowDidBecomeMainNotification |
| 268 object:window]; | 265 object:window]; |
| 269 | 266 |
| 270 [nc addObserver:self | 267 [nc addObserver:self |
| 271 selector:@selector(windowDidResignMain:) | 268 selector:@selector(windowDidResignMain:) |
| 272 name:NSWindowDidResignMainNotification | 269 name:NSWindowDidResignMainNotification |
| 273 object:window]; | 270 object:window]; |
| 274 | 271 |
| 275 enteringPresentationMode_ = NO; | 272 settingUp_ = NO; |
| 276 } | 273 } |
| 277 | 274 |
| 278 - (void)exitPresentationMode { | 275 - (void)exitFullscreenMode { |
| 279 [[NSNotificationCenter defaultCenter] | 276 [[NSNotificationCenter defaultCenter] |
| 280 postNotificationName:kWillLeaveFullscreenNotification | 277 postNotificationName:kWillLeaveFullscreenNotification |
| 281 object:nil]; | 278 object:nil]; |
| 282 DCHECK(inPresentationMode_); | 279 DCHECK(inFullscreenMode_); |
| 283 inPresentationMode_ = NO; | 280 inFullscreenMode_ = NO; |
| 284 | 281 |
| 285 [self cleanup]; | 282 [self cleanup]; |
| 286 } | 283 } |
| 287 | 284 |
| 288 - (void)windowDidChangeScreen:(NSNotification*)notification { | 285 - (void)windowDidChangeScreen:(NSNotification*)notification { |
| 289 [browserController_ resizeFullscreenWindow]; | 286 [browserController_ resizeFullscreenWindow]; |
| 290 } | 287 } |
| 291 | 288 |
| 292 - (void)windowDidMove:(NSNotification*)notification { | 289 - (void)windowDidMove:(NSNotification*)notification { |
| 293 [browserController_ resizeFullscreenWindow]; | 290 [browserController_ resizeFullscreenWindow]; |
| 294 } | 291 } |
| 295 | 292 |
| 296 - (void)windowDidBecomeMain:(NSNotification*)notification { | 293 - (void)windowDidBecomeMain:(NSNotification*)notification { |
| 297 [self showActiveWindowUI]; | 294 [self showActiveWindowUI]; |
| 298 } | 295 } |
| 299 | 296 |
| 300 - (void)windowDidResignMain:(NSNotification*)notification { | 297 - (void)windowDidResignMain:(NSNotification*)notification { |
| 301 [self hideActiveWindowUI]; | 298 [self hideActiveWindowUI]; |
| 302 } | 299 } |
| 303 | 300 |
| 304 // On OSX 10.8+, the menu bar shows on the secondary screen in fullscreen. | 301 // On OSX 10.8+, the menu bar shows on the secondary screen in fullscreen. |
| 305 - (CGFloat)floatingBarVerticalOffset { | 302 - (CGFloat)floatingBarVerticalOffset { |
| 306 return kFloatingBarVerticalOffset; | 303 return kFloatingBarVerticalOffset; |
| 307 } | 304 } |
| 308 | 305 |
| 309 - (void)overlayFrameChanged:(NSRect)frame { | 306 - (void)overlayFrameChanged:(NSRect)frame { |
| 310 if (!inPresentationMode_) | 307 if (!inFullscreenMode_) |
| 311 return; | 308 return; |
| 312 | 309 |
| 313 // Make sure |trackingAreaBounds_| always reflects either the tracking area or | 310 // Make sure |trackingAreaBounds_| always reflects either the tracking area or |
| 314 // the desired tracking area. | 311 // the desired tracking area. |
| 315 trackingAreaBounds_ = frame; | 312 trackingAreaBounds_ = frame; |
| 316 // The tracking area should always be at least the height of activation zone. | 313 // The tracking area should always be at least the height of activation zone. |
| 317 NSRect contentBounds = [contentView_ bounds]; | 314 NSRect contentBounds = [contentView_ bounds]; |
| 318 trackingAreaBounds_.origin.y = | 315 trackingAreaBounds_.origin.y = |
| 319 std::min(trackingAreaBounds_.origin.y, | 316 std::min(trackingAreaBounds_.origin.y, |
| 320 NSMaxY(contentBounds) - kDropdownActivationZoneHeight); | 317 NSMaxY(contentBounds) - kDropdownActivationZoneHeight); |
| 321 trackingAreaBounds_.size.height = | 318 trackingAreaBounds_.size.height = |
| 322 NSMaxY(contentBounds) - trackingAreaBounds_.origin.y + 1; | 319 NSMaxY(contentBounds) - trackingAreaBounds_.origin.y + 1; |
| 323 | 320 |
| 324 // If an animation is currently running, do not set up a tracking area now. | 321 // If an animation is currently running, do not set up a tracking area now. |
| 325 // Instead, leave it to be created it in |-animationDidEnd:|. | 322 // Instead, leave it to be created it in |-animationDidEnd:|. |
| 326 if (currentAnimation_) | 323 if (currentAnimation_) |
| 327 return; | 324 return; |
| 328 | 325 |
| 329 // If this is part of the initial setup, lock bar visibility if the mouse is | 326 // If this is part of the initial setup, lock bar visibility if the mouse is |
| 330 // within the tracking area bounds. | 327 // within the tracking area bounds. |
| 331 if (enteringPresentationMode_ && [self mouseInsideTrackingRect]) | 328 if (settingUp_ && [self mouseInsideTrackingRect]) |
| 332 [browserController_ lockBarVisibilityForOwner:self | 329 [browserController_ lockBarVisibilityForOwner:self |
| 333 withAnimation:NO | 330 withAnimation:NO |
| 334 delay:NO]; | 331 delay:NO]; |
| 335 [self setupTrackingArea]; | 332 [self setupTrackingArea]; |
| 336 } | 333 } |
| 337 | 334 |
| 338 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay { | 335 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay { |
| 339 if (!inPresentationMode_) | 336 if (!inFullscreenMode_) |
| 340 return; | 337 return; |
| 341 | 338 |
| 342 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 339 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 343 return; | 340 return; |
| 344 | 341 |
| 345 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) | 342 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) |
| 346 return; | 343 return; |
| 347 | 344 |
| 348 if (animate) { | 345 if (animate) { |
| 349 if (delay) { | 346 if (delay) { |
| 350 [self startShowTimer]; | 347 [self startShowTimer]; |
| 351 } else { | 348 } else { |
| 352 [self cancelAllTimers]; | 349 [self cancelAllTimers]; |
| 353 [self changeOverlayToFraction:1 withAnimation:YES]; | 350 [self changeOverlayToFraction:1 withAnimation:YES]; |
| 354 } | 351 } |
| 355 } else { | 352 } else { |
| 356 DCHECK(!delay); | 353 DCHECK(!delay); |
| 357 [self cancelAllTimers]; | 354 [self cancelAllTimers]; |
| 358 [self changeOverlayToFraction:1 withAnimation:NO]; | 355 [self changeOverlayToFraction:1 withAnimation:NO]; |
| 359 } | 356 } |
| 360 } | 357 } |
| 361 | 358 |
| 362 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay { | 359 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay { |
| 363 if (!inPresentationMode_) | 360 if (!inFullscreenMode_) |
| 364 return; | 361 return; |
| 365 | 362 |
| 366 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) | 363 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) |
| 367 return; | 364 return; |
| 368 | 365 |
| 369 if (animate) { | 366 if (animate) { |
| 370 if (delay) { | 367 if (delay) { |
| 371 [self startHideTimer]; | 368 [self startHideTimer]; |
| 372 } else { | 369 } else { |
| 373 [self cancelAllTimers]; | 370 [self cancelAllTimers]; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 436 } |
| 440 | 437 |
| 441 - (BOOL)isFullscreenTransitionInProgress { | 438 - (BOOL)isFullscreenTransitionInProgress { |
| 442 return [browserController_ isFullscreenTransitionInProgress]; | 439 return [browserController_ isFullscreenTransitionInProgress]; |
| 443 } | 440 } |
| 444 | 441 |
| 445 - (BOOL)isMainWindow { | 442 - (BOOL)isMainWindow { |
| 446 return [browserController_ window].isMainWindow; | 443 return [browserController_ window].isMainWindow; |
| 447 } | 444 } |
| 448 | 445 |
| 449 // Used to activate the floating bar in presentation mode. | 446 // Used to activate the floating bar if the toolbar is hidden. |
| 450 - (void)mouseEntered:(NSEvent*)event { | 447 - (void)mouseEntered:(NSEvent*)event { |
| 451 DCHECK(inPresentationMode_); | 448 DCHECK(inFullscreenMode_); |
| 452 | 449 |
| 453 // Having gotten a mouse entered, we no longer need to do exit checks. | 450 // Having gotten a mouse entered, we no longer need to do exit checks. |
| 454 [self cancelMouseExitCheck]; | 451 [self cancelMouseExitCheck]; |
| 455 | 452 |
| 456 NSTrackingArea* trackingArea = [event trackingArea]; | 453 NSTrackingArea* trackingArea = [event trackingArea]; |
| 457 if (trackingArea == trackingArea_) { | 454 if (trackingArea == trackingArea_) { |
| 458 // The tracking area shouldn't be active during animation. | 455 // The tracking area shouldn't be active during animation. |
| 459 DCHECK(!currentAnimation_); | 456 DCHECK(!currentAnimation_); |
| 460 | 457 |
| 461 // Don't show anything if the style is set to OMNIBOX_TABS_NONE. | 458 // Don't show anything if the style is set to OMNIBOX_TABS_NONE. |
| 462 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_NONE) | 459 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_NONE) |
| 463 [self scheduleShowForMouse]; | 460 [self scheduleShowForMouse]; |
| 464 } | 461 } |
| 465 } | 462 } |
| 466 | 463 |
| 467 // Used to deactivate the floating bar in presentation mode. | 464 // Used to deactivate the floating bar if the toolbar is hidden. |
| 468 - (void)mouseExited:(NSEvent*)event { | 465 - (void)mouseExited:(NSEvent*)event { |
| 469 DCHECK(inPresentationMode_); | 466 DCHECK(inFullscreenMode_); |
| 470 | 467 |
| 471 NSTrackingArea* trackingArea = [event trackingArea]; | 468 NSTrackingArea* trackingArea = [event trackingArea]; |
| 472 if (trackingArea == trackingArea_) { | 469 if (trackingArea == trackingArea_) { |
| 473 // The tracking area shouldn't be active during animation. | 470 // The tracking area shouldn't be active during animation. |
| 474 DCHECK(!currentAnimation_); | 471 DCHECK(!currentAnimation_); |
| 475 | 472 |
| 476 // We can get a false mouse exit when the menu slides down, so if the mouse | 473 // We can get a false mouse exit when the menu slides down, so if the mouse |
| 477 // is still actually over the tracking area, we ignore the mouse exit, but | 474 // is still actually over the tracking area, we ignore the mouse exit, but |
| 478 // we set up to check the mouse position again after a delay. | 475 // we set up to check the mouse position again after a delay. |
| 479 if ([self mouseInsideTrackingRect]) { | 476 if ([self mouseInsideTrackingRect]) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // for each tick of the menu bar reveal. Do that manually. | 532 // for each tick of the menu bar reveal. Do that manually. |
| 536 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so | 533 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so |
| 537 // that it calls setFrameOffset: instead of setFrame: if the frame's size has | 534 // that it calls setFrameOffset: instead of setFrame: if the frame's size has |
| 538 // not changed. | 535 // not changed. |
| 539 if (!currentAnimation_.get()) | 536 if (!currentAnimation_.get()) |
| 540 [browserController_ layoutSubviews]; | 537 [browserController_ layoutSubviews]; |
| 541 } | 538 } |
| 542 | 539 |
| 543 @end | 540 @end |
| 544 | 541 |
| 545 | 542 @implementation FullscreenToolbarController (PrivateMethods) |
| 546 @implementation PresentationModeController (PrivateMethods) | |
| 547 | 543 |
| 548 - (void)updateMenuBarAndDockVisibility { | 544 - (void)updateMenuBarAndDockVisibility { |
| 549 if (![self isMainWindow] || ![browserController_ isInImmersiveFullscreen]) { | 545 if (![self isMainWindow] || ![browserController_ isInImmersiveFullscreen]) { |
| 550 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 546 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 551 return; | 547 return; |
| 552 } | 548 } |
| 553 | 549 |
| 554 // The screen does not have a menu bar, so there's no need to hide it. | 550 // The screen does not have a menu bar, so there's no need to hide it. |
| 555 if (![self doesScreenHaveMenuBar]) { | 551 if (![self doesScreenHaveMenuBar]) { |
| 556 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; | 552 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 574 NSScreen* primaryScreen = [[NSScreen screens] firstObject]; | 570 NSScreen* primaryScreen = [[NSScreen screens] firstObject]; |
| 575 return (screen == primaryScreen); | 571 return (screen == primaryScreen); |
| 576 } | 572 } |
| 577 | 573 |
| 578 - (base::mac::FullScreenMode)desiredSystemFullscreenMode { | 574 - (base::mac::FullScreenMode)desiredSystemFullscreenMode { |
| 579 if ([self shouldShowMenubarInImmersiveFullscreen]) | 575 if ([self shouldShowMenubarInImmersiveFullscreen]) |
| 580 return base::mac::kFullScreenModeHideDock; | 576 return base::mac::kFullScreenModeHideDock; |
| 581 return base::mac::kFullScreenModeHideAll; | 577 return base::mac::kFullScreenModeHideAll; |
| 582 } | 578 } |
| 583 | 579 |
| 584 - (void)changeOverlayToFraction:(CGFloat)fraction | 580 - (void)changeOverlayToFraction:(CGFloat)fraction withAnimation:(BOOL)animate { |
| 585 withAnimation:(BOOL)animate { | |
| 586 // The non-animated case is really simple, so do it and return. | 581 // The non-animated case is really simple, so do it and return. |
| 587 if (!animate) { | 582 if (!animate) { |
| 588 [currentAnimation_ stopAnimation]; | 583 [currentAnimation_ stopAnimation]; |
| 589 [self changeToolbarFraction:fraction]; | 584 [self changeToolbarFraction:fraction]; |
| 590 return; | 585 return; |
| 591 } | 586 } |
| 592 | 587 |
| 593 // If we're already animating to the given fraction, then there's nothing more | 588 // If we're already animating to the given fraction, then there's nothing more |
| 594 // to do. | 589 // to do. |
| 595 if (currentAnimation_ && [currentAnimation_ endFraction] == fraction) | 590 if (currentAnimation_ && [currentAnimation_ endFraction] == fraction) |
| 596 return; | 591 return; |
| 597 | 592 |
| 598 // In all other cases, we want to cancel any running animation (which may be | 593 // In all other cases, we want to cancel any running animation (which may be |
| 599 // to show or to hide). | 594 // to show or to hide). |
| 600 [currentAnimation_ stopAnimation]; | 595 [currentAnimation_ stopAnimation]; |
| 601 | 596 |
| 602 // Create the animation and set it up. | 597 // Create the animation and set it up. |
| 603 currentAnimation_.reset( | 598 currentAnimation_.reset([[DropdownAnimation alloc] |
| 604 [[DropdownAnimation alloc] initWithFraction:fraction | 599 initWithFraction:fraction |
| 605 fullDuration:kDropdownAnimationDuration | 600 fullDuration:kDropdownAnimationDuration |
| 606 animationCurve:NSAnimationEaseOut | 601 animationCurve:NSAnimationEaseOut |
| 607 controller:self]); | 602 controller:self]); |
| 608 DCHECK(currentAnimation_); | 603 DCHECK(currentAnimation_); |
| 609 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 604 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 610 [currentAnimation_ setDelegate:self]; | 605 [currentAnimation_ setDelegate:self]; |
| 611 | 606 |
| 612 // If there is an existing tracking area, remove it. We do not track mouse | 607 // If there is an existing tracking area, remove it. We do not track mouse |
| 613 // movements during animations (see class comment in the header file). | 608 // movements during animations (see class comment in the header file). |
| 614 [self removeTrackingAreaIfNecessary]; | 609 [self removeTrackingAreaIfNecessary]; |
| 615 | 610 |
| 616 [currentAnimation_ startAnimation]; | 611 [currentAnimation_ startAnimation]; |
| 617 } | 612 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 633 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. | 628 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. |
| 634 NSRect oldRect = [trackingArea_ rect]; | 629 NSRect oldRect = [trackingArea_ rect]; |
| 635 if (NSEqualRects(trackingAreaBounds_, oldRect)) | 630 if (NSEqualRects(trackingAreaBounds_, oldRect)) |
| 636 return; | 631 return; |
| 637 | 632 |
| 638 // Otherwise, remove it. | 633 // Otherwise, remove it. |
| 639 [self removeTrackingAreaIfNecessary]; | 634 [self removeTrackingAreaIfNecessary]; |
| 640 } | 635 } |
| 641 | 636 |
| 642 // Create and add a new tracking area for |frame|. | 637 // Create and add a new tracking area for |frame|. |
| 643 trackingArea_.reset( | 638 trackingArea_.reset([[NSTrackingArea alloc] |
| 644 [[NSTrackingArea alloc] initWithRect:trackingAreaBounds_ | 639 initWithRect:trackingAreaBounds_ |
| 645 options:NSTrackingMouseEnteredAndExited | | 640 options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow |
| 646 NSTrackingActiveInKeyWindow | 641 owner:self |
| 647 owner:self | 642 userInfo:nil]); |
| 648 userInfo:nil]); | |
| 649 DCHECK(contentView_); | 643 DCHECK(contentView_); |
| 650 [contentView_ addTrackingArea:trackingArea_]; | 644 [contentView_ addTrackingArea:trackingArea_]; |
| 651 } | 645 } |
| 652 | 646 |
| 653 - (void)removeTrackingAreaIfNecessary { | 647 - (void)removeTrackingAreaIfNecessary { |
| 654 if (trackingArea_) { | 648 if (trackingArea_) { |
| 655 DCHECK(contentView_); // |contentView_| better be valid. | 649 DCHECK(contentView_); // |contentView_| better be valid. |
| 656 [contentView_ removeTrackingArea:trackingArea_]; | 650 [contentView_ removeTrackingArea:trackingArea_]; |
| 657 trackingArea_.reset(); | 651 trackingArea_.reset(); |
| 658 } | 652 } |
| 659 } | 653 } |
| 660 | 654 |
| 661 - (BOOL)mouseInsideTrackingRect { | 655 - (BOOL)mouseInsideTrackingRect { |
| 662 NSWindow* window = [browserController_ window]; | 656 NSWindow* window = [browserController_ window]; |
| 663 NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream]; | 657 NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream]; |
| 664 NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil]; | 658 NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil]; |
| 665 return NSMouseInRect(mousePos, trackingAreaBounds_, [contentView_ isFlipped]); | 659 return NSMouseInRect(mousePos, trackingAreaBounds_, [contentView_ isFlipped]); |
| 666 } | 660 } |
| 667 | 661 |
| 668 - (void)setupMouseExitCheck { | 662 - (void)setupMouseExitCheck { |
| 669 [self performSelector:@selector(checkForMouseExit) | 663 [self performSelector:@selector(checkForMouseExit) |
| 670 withObject:nil | 664 withObject:nil |
| 671 afterDelay:kMouseExitCheckDelay]; | 665 afterDelay:kMouseExitCheckDelay]; |
| 672 } | 666 } |
| 673 | 667 |
| 674 - (void)cancelMouseExitCheck { | 668 - (void)cancelMouseExitCheck { |
| 675 [NSObject cancelPreviousPerformRequestsWithTarget:self | 669 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 676 selector:@selector(checkForMouseExit) object:nil]; | 670 selector:@selector(checkForMouseExit) |
| 671 object:nil]; |
| 677 } | 672 } |
| 678 | 673 |
| 679 - (void)checkForMouseExit { | 674 - (void)checkForMouseExit { |
| 680 if ([self mouseInsideTrackingRect]) | 675 if ([self mouseInsideTrackingRect]) |
| 681 [self setupMouseExitCheck]; | 676 [self setupMouseExitCheck]; |
| 682 else | 677 else |
| 683 [self scheduleHideForMouse]; | 678 [self scheduleHideForMouse]; |
| 684 } | 679 } |
| 685 | 680 |
| 686 - (void)startShowTimer { | 681 - (void)startShowTimer { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 } | 746 } |
| 752 | 747 |
| 753 - (void)cleanup { | 748 - (void)cleanup { |
| 754 [self cancelMouseExitCheck]; | 749 [self cancelMouseExitCheck]; |
| 755 [self cancelAnimationAndTimers]; | 750 [self cancelAnimationAndTimers]; |
| 756 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 751 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 757 | 752 |
| 758 [self removeTrackingAreaIfNecessary]; | 753 [self removeTrackingAreaIfNecessary]; |
| 759 contentView_ = nil; | 754 contentView_ = nil; |
| 760 | 755 |
| 761 // This isn't tracked when not in presentation mode. | 756 // This isn't tracked when not in fullscreen mode. |
| 762 [browserController_ releaseBarVisibilityForOwner:self | 757 [browserController_ releaseBarVisibilityForOwner:self |
| 763 withAnimation:NO | 758 withAnimation:NO |
| 764 delay:NO]; | 759 delay:NO]; |
| 765 | 760 |
| 766 // Call the main status resignation code to perform the associated cleanup, | 761 // Call the main status resignation code to perform the associated cleanup, |
| 767 // since we will no longer be receiving actual status resignation | 762 // since we will no longer be receiving actual status resignation |
| 768 // notifications. | 763 // notifications. |
| 769 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 764 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
| 770 | 765 |
| 771 // No more calls back up to the BWC. | 766 // No more calls back up to the BWC. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 782 [self updateMenuBarAndDockVisibility]; | 777 [self updateMenuBarAndDockVisibility]; |
| 783 | 778 |
| 784 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 | 779 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 |
| 785 } | 780 } |
| 786 | 781 |
| 787 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 782 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
| 788 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99; | 783 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99; |
| 789 } | 784 } |
| 790 | 785 |
| 791 @end | 786 @end |
| OLD | NEW |