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 " |
16 #import "ui/base/cocoa/nsview_additions.h" | 17 #import "ui/base/cocoa/nsview_additions.h" |
17 #import "ui/base/cocoa/tracking_area.h" | 18 #import "ui/base/cocoa/tracking_area.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // The duration of the toolbar show/hide animation. | 22 // The duration of the toolbar show/hide animation. |
22 const NSTimeInterval kDropdownAnimationDuration = 0.20; | 23 const NSTimeInterval kDropdownAnimationDuration = 0.20; |
23 | 24 |
24 // If the fullscreen toolbar is hidden, it is difficult for the user to see | 25 // 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 | 26 // 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 | 27 // 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 | 28 // 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. | 29 // then wait for 0.75 seconds before it hides the toolbar. |
29 const NSTimeInterval kTabStripChangesDelay = 0.75; | 30 const NSTimeInterval kTabStripChangesDelay = 0.75; |
30 | 31 |
31 // Additional height threshold added at the toolbar's bottom. This is to mimic | 32 // 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 | 33 // threshold the mouse position needs to be at before the menubar automatically |
33 // hides. | 34 // hides. |
34 const CGFloat kTrackingAreaAdditionalThreshold = 20; | 35 const CGFloat kTrackingAreaAdditionalThreshold = 20; |
35 | 36 |
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. | 37 // Visibility fractions for the menubar and toolbar. |
45 const CGFloat kHideFraction = 0.0; | 38 const CGFloat kHideFraction = 0.0; |
46 const CGFloat kShowFraction = 1.0; | 39 const CGFloat kShowFraction = 1.0; |
47 | 40 |
48 // Helper function for comparing CGFloat values. | 41 // The amount by which the toolbar is offset downwards (to avoid the menu) |
49 BOOL IsCGFloatEqual(CGFloat a, CGFloat b) { | 42 // when the toolbar style is OMNIBOX_TABS_HIDDEN. (We can't use |
50 return fabs(a - b) <= std::numeric_limits<CGFloat>::epsilon(); | 43 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) |
51 } | 44 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 | 45 |
83 } // end namespace | 46 } // end namespace |
84 | 47 |
85 // Helper class to manage animations for the dropdown bar. Calls | 48 // Helper class to manage animations for the dropdown bar. Calls |
86 // [FullscreenToolbarController changeToolbarFraction] once per | 49 // [FullscreenToolbarController changeToolbarFraction] once per |
87 // animation step. | 50 // animation step. |
88 @interface DropdownAnimation : NSAnimation { | 51 @interface DropdownAnimation : NSAnimation { |
89 @private | 52 @private |
90 FullscreenToolbarController* controller_; | 53 FullscreenToolbarController* controller_; |
91 CGFloat startFraction_; | 54 CGFloat startFraction_; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 @implementation FullscreenToolbarController | 148 @implementation FullscreenToolbarController |
186 | 149 |
187 @synthesize slidingStyle = slidingStyle_; | 150 @synthesize slidingStyle = slidingStyle_; |
188 | 151 |
189 - (id)initWithBrowserController:(BrowserWindowController*)controller | 152 - (id)initWithBrowserController:(BrowserWindowController*)controller |
190 style:(FullscreenSlidingStyle)style { | 153 style:(FullscreenSlidingStyle)style { |
191 if ((self = [super init])) { | 154 if ((self = [super init])) { |
192 browserController_ = controller; | 155 browserController_ = controller; |
193 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; | 156 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; |
194 slidingStyle_ = style; | 157 slidingStyle_ = style; |
195 menubarState_ = FullscreenMenubarState::HIDDEN; | |
196 } | 158 } |
197 | 159 |
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; | 160 return self; |
215 } | 161 } |
216 | 162 |
217 - (void)dealloc { | 163 - (void)dealloc { |
218 RemoveEventHandler(menuBarTrackingHandler_); | |
219 DCHECK(!inFullscreenMode_); | 164 DCHECK(!inFullscreenMode_); |
220 [super dealloc]; | 165 [super dealloc]; |
221 } | 166 } |
222 | 167 |
223 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView { | 168 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView { |
224 DCHECK(!inFullscreenMode_); | 169 DCHECK(!inFullscreenMode_); |
225 contentView_ = contentView; | 170 contentView_ = contentView; |
226 inFullscreenMode_ = YES; | 171 inFullscreenMode_ = YES; |
227 | 172 |
173 menubarTracker_.reset([[FullscreenMenubarTracker alloc] | |
174 initWithFullscreenToolbarController:self]); | |
175 | |
228 [self updateMenuBarAndDockVisibility]; | 176 [self updateMenuBarAndDockVisibility]; |
229 | 177 |
230 // Register for notifications. Self is removed as an observer in |-cleanup|. | 178 // Register for notifications. Self is removed as an observer in |-cleanup|. |
231 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 179 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
232 NSWindow* window = [browserController_ window]; | 180 NSWindow* window = [browserController_ window]; |
233 | 181 |
234 [nc addObserver:self | 182 [nc addObserver:self |
235 selector:@selector(windowDidBecomeMain:) | 183 selector:@selector(windowDidBecomeMain:) |
236 name:NSWindowDidBecomeMainNotification | 184 name:NSWindowDidBecomeMainNotification |
237 object:window]; | 185 object:window]; |
238 | 186 |
239 [nc addObserver:self | 187 [nc addObserver:self |
240 selector:@selector(windowDidResignMain:) | 188 selector:@selector(windowDidResignMain:) |
241 name:NSWindowDidResignMainNotification | 189 name:NSWindowDidResignMainNotification |
242 object:window]; | 190 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 } | 191 } |
251 | 192 |
252 - (void)exitFullscreenMode { | 193 - (void)exitFullscreenMode { |
253 DCHECK(inFullscreenMode_); | 194 DCHECK(inFullscreenMode_); |
254 inFullscreenMode_ = NO; | 195 inFullscreenMode_ = NO; |
255 | 196 |
256 [self cleanup]; | 197 [self cleanup]; |
257 } | 198 } |
258 | 199 |
259 - (void)windowDidChangeScreen:(NSNotification*)notification { | 200 - (void)windowDidChangeScreen:(NSNotification*)notification { |
260 [browserController_ resizeFullscreenWindow]; | 201 [browserController_ resizeFullscreenWindow]; |
261 } | 202 } |
262 | 203 |
263 - (void)windowDidMove:(NSNotification*)notification { | 204 - (void)windowDidMove:(NSNotification*)notification { |
264 [browserController_ resizeFullscreenWindow]; | 205 [browserController_ resizeFullscreenWindow]; |
265 } | 206 } |
266 | 207 |
267 - (void)windowDidBecomeMain:(NSNotification*)notification { | 208 - (void)windowDidBecomeMain:(NSNotification*)notification { |
268 [self updateMenuBarAndDockVisibility]; | 209 [self updateMenuBarAndDockVisibility]; |
269 } | 210 } |
270 | 211 |
271 - (void)windowDidResignMain:(NSNotification*)notification { | 212 - (void)windowDidResignMain:(NSNotification*)notification { |
272 [self updateMenuBarAndDockVisibility]; | 213 [self updateMenuBarAndDockVisibility]; |
273 } | 214 } |
274 | 215 |
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 { | 216 - (void)lockBarVisibilityWithAnimation:(BOOL)animate { |
286 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); | 217 base::AutoReset<BOOL> autoReset(&isLockingBarVisibility_, YES); |
287 [self ensureOverlayShownWithAnimation:animate]; | 218 [self ensureOverlayShownWithAnimation:animate]; |
288 } | 219 } |
289 | 220 |
290 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { | 221 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate { |
291 base::AutoReset<BOOL> autoReset(&isReleasingBarVisibility_, YES); | 222 base::AutoReset<BOOL> autoReset(&isReleasingBarVisibility_, YES); |
292 [self ensureOverlayHiddenWithAnimation:animate]; | 223 [self ensureOverlayHiddenWithAnimation:animate]; |
293 } | 224 } |
294 | 225 |
(...skipping 15 matching lines...) Expand all Loading... | |
310 if (!inFullscreenMode_) | 241 if (!inFullscreenMode_) |
311 return; | 242 return; |
312 | 243 |
313 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN) | 244 if (self.slidingStyle != FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN) |
314 return; | 245 return; |
315 | 246 |
316 if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 247 if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
317 return; | 248 return; |
318 | 249 |
319 if ([self mouseInsideTrackingArea] || | 250 if ([self mouseInsideTrackingArea] || |
320 menubarState_ == FullscreenMenubarState::SHOWN) { | 251 [menubarTracker_ state] == FullscreenMenubarState::SHOWN) { |
321 return; | 252 return; |
322 } | 253 } |
323 | 254 |
324 [self cancelHideTimer]; | 255 [self cancelHideTimer]; |
325 [self animateToolbarVisibility:NO]; | 256 [self animateToolbarVisibility:NO]; |
326 } | 257 } |
327 | 258 |
328 - (void)cancelAnimationAndTimer { | 259 - (void)cancelAnimationAndTimer { |
329 [self cancelHideTimer]; | 260 [self cancelHideTimer]; |
330 [currentAnimation_ stopAnimation]; | 261 [currentAnimation_ stopAnimation]; |
331 currentAnimation_.reset(); | 262 currentAnimation_.reset(); |
332 } | 263 } |
333 | 264 |
334 - (void)revealToolbarForTabStripChanges { | 265 - (void)revealToolbarForTabStripChanges { |
335 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 266 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
336 switches::kEnableFullscreenToolbarReveal)) { | 267 switches::kEnableFullscreenToolbarReveal)) { |
337 return; | 268 return; |
338 } | 269 } |
339 | 270 |
340 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. | 271 // Reveal the toolbar for tabstrip changes if the toolbar is hidden. |
341 if (IsCGFloatEqual([self toolbarFraction], kHideFraction)) { | 272 if (base::mac::IsCGFloatEqual([self toolbarFraction], kHideFraction)) { |
342 isRevealingToolbarForTabStripChanges_ = YES; | 273 isRevealingToolbarForTabStripChanges_ = YES; |
343 [self ensureOverlayShownWithAnimation:YES]; | 274 [self ensureOverlayShownWithAnimation:YES]; |
344 } | 275 } |
345 } | 276 } |
346 | 277 |
347 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { | 278 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { |
348 if (mode == systemFullscreenMode_) | 279 if (mode == systemFullscreenMode_) |
349 return; | 280 return; |
350 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) | 281 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) |
351 base::mac::RequestFullScreen(mode); | 282 base::mac::RequestFullScreen(mode); |
352 else if (mode == base::mac::kFullScreenModeNormal) | 283 else if (mode == base::mac::kFullScreenModeNormal) |
353 base::mac::ReleaseFullScreen(systemFullscreenMode_); | 284 base::mac::ReleaseFullScreen(systemFullscreenMode_); |
354 else | 285 else |
355 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); | 286 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); |
356 systemFullscreenMode_ = mode; | 287 systemFullscreenMode_ = mode; |
357 } | 288 } |
358 | 289 |
359 - (void)mouseEntered:(NSEvent*)event { | 290 - (void)mouseEntered:(NSEvent*)event { |
360 // Empty implementation. Required for CrTrackingArea. | 291 // Empty implementation. Required for CrTrackingArea. |
361 } | 292 } |
362 | 293 |
363 - (void)mouseExited:(NSEvent*)event { | 294 - (void)mouseExited:(NSEvent*)event { |
364 DCHECK(inFullscreenMode_); | 295 DCHECK(inFullscreenMode_); |
365 DCHECK_EQ([event trackingArea], trackingArea_.get()); | 296 DCHECK_EQ([event trackingArea], trackingArea_.get()); |
366 | 297 |
367 if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 298 if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
368 return; | 299 return; |
369 | 300 |
370 // If the menubar is gone, animate the toolbar out. | 301 // If the menubar is gone, animate the toolbar out. |
371 if (menubarState_ == FullscreenMenubarState::HIDDEN) { | 302 if ([menubarTracker_ state] == FullscreenMenubarState::HIDDEN) { |
372 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); | 303 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); |
373 [self ensureOverlayHiddenWithAnimation:YES]; | 304 [self ensureOverlayHiddenWithAnimation:YES]; |
374 } | 305 } |
375 | 306 |
376 [self removeTrackingAreaIfNecessary]; | 307 [self removeTrackingAreaIfNecessary]; |
377 } | 308 } |
378 | 309 |
379 - (void)updateToolbar { | 310 - (void)updateToolbar { |
380 [browserController_ layoutSubviews]; | 311 [browserController_ layoutSubviews]; |
312 [self updateTrackingArea]; | |
erikchen
2016/10/19 01:43:23
in the code path that you're replacing, lines 311
spqchan
2016/10/19 01:51:23
Good point. Right now the order doesn't matter but
| |
381 | 313 |
382 // In AppKit fullscreen, moving the mouse to the top of the screen toggles | 314 // In AppKit fullscreen, moving the mouse to the top of the screen toggles |
383 // menu visibility. Replicate the same effect for immersive fullscreen. | 315 // menu visibility. Replicate the same effect for immersive fullscreen. |
384 if ([browserController_ isInImmersiveFullscreen]) | 316 if ([browserController_ isInImmersiveFullscreen]) |
385 [self updateMenuBarAndDockVisibility]; | 317 [self updateMenuBarAndDockVisibility]; |
386 } | 318 } |
387 | 319 |
320 - (BrowserWindowController*)browserWindowController { | |
321 return browserController_; | |
322 } | |
323 | |
388 // This method works, but is fragile. | 324 // This method works, but is fragile. |
389 // | 325 // |
390 // It gets used during view layout, which sometimes needs to be done at the | 326 // 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 | 327 // 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 | 328 // menubarOffset expected at the end of the animation. This information is not |
393 // readily available. (The layout logic needs a refactor). | 329 // readily available. (The layout logic needs a refactor). |
394 // | 330 // |
395 // For AppKit Fullscreen, the menubar always starts hidden, and | 331 // For AppKit Fullscreen, the menubar always starts hidden, and |
396 // menubarFraction_ always starts at 0, so the logic happens to work. For | 332 // 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 | 333 // Immersive Fullscreen, this class controls the visibility of the menu bar, so |
398 // the logic is correct and not fragile. | 334 // the logic is correct and not fragile. |
399 - (CGFloat)menubarOffset { | 335 - (CGFloat)menubarOffset { |
400 if ([browserController_ isInAppKitFullscreen]) | 336 if ([browserController_ isInAppKitFullscreen]) { |
401 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]); | 337 return -std::floor([menubarTracker_ menubarFraction] * |
338 kToolbarVerticalOffset); | |
339 } | |
402 | 340 |
403 return [self shouldShowMenubarInImmersiveFullscreen] | 341 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset |
404 ? -[self floatingBarVerticalOffset] | 342 : 0; |
405 : 0; | |
406 } | 343 } |
407 | 344 |
408 - (CGFloat)toolbarFraction { | 345 - (CGFloat)toolbarFraction { |
409 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 346 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
410 return kHideFraction; | 347 return kHideFraction; |
411 | 348 |
412 switch (slidingStyle_) { | 349 switch (slidingStyle_) { |
413 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: | 350 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: |
414 return kShowFraction; | 351 return kShowFraction; |
415 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: | 352 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: |
416 return kHideFraction; | 353 return kHideFraction; |
417 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: | 354 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: |
418 if (menubarState_ == FullscreenMenubarState::SHOWN) | 355 FullscreenMenubarState menubarState = [menubarTracker_ state]; |
356 if (menubarState == FullscreenMenubarState::SHOWN) | |
419 return kShowFraction; | 357 return kShowFraction; |
420 | 358 |
421 if ([self mouseInsideTrackingArea]) | 359 if ([self mouseInsideTrackingArea]) |
422 return kShowFraction; | 360 return kShowFraction; |
423 | 361 |
424 if (currentAnimation_.get()) | 362 if (currentAnimation_.get()) |
425 return [currentAnimation_ toolbarFraction]; | 363 return [currentAnimation_ toolbarFraction]; |
426 | 364 |
427 if (isLockingBarVisibility_) | 365 if (isLockingBarVisibility_) |
428 return kHideFraction; | 366 return kHideFraction; |
429 else if (isReleasingBarVisibility_) | 367 else if (isReleasingBarVisibility_) |
430 return kShowFraction; | 368 return kShowFraction; |
431 else if ([browserController_ isBarVisibilityLockedForOwner:nil]) | 369 else if ([browserController_ isBarVisibilityLockedForOwner:nil]) |
432 return kShowFraction; | 370 return kShowFraction; |
433 | 371 |
434 if (hideTimer_.get() || shouldAnimateToolbarOut_) | 372 if (hideTimer_.get() || shouldAnimateToolbarOut_) |
435 return kShowFraction; | 373 return kShowFraction; |
436 | 374 |
437 return menubarFraction_; | 375 return [menubarTracker_ menubarFraction]; |
438 } | 376 } |
439 } | 377 } |
440 | 378 |
441 - (BOOL)isFullscreenTransitionInProgress { | 379 - (BOOL)isFullscreenTransitionInProgress { |
442 return [browserController_ isFullscreenTransitionInProgress]; | 380 return [browserController_ isFullscreenTransitionInProgress]; |
443 } | 381 } |
444 | 382 |
445 - (BOOL)isInFullscreen { | 383 - (BOOL)isInFullscreen { |
446 return inFullscreenMode_; | 384 return inFullscreenMode_; |
447 } | 385 } |
(...skipping 29 matching lines...) Expand all Loading... | |
477 | 415 |
478 // Reset the |currentAnimation_| pointer now that the animation is over. | 416 // Reset the |currentAnimation_| pointer now that the animation is over. |
479 currentAnimation_.reset(); | 417 currentAnimation_.reset(); |
480 } | 418 } |
481 | 419 |
482 - (void)animationDidEnd:(NSAnimation*)animation { | 420 - (void)animationDidEnd:(NSAnimation*)animation { |
483 [self animationDidStop:animation]; | 421 [self animationDidStop:animation]; |
484 [self updateTrackingArea]; | 422 [self updateTrackingArea]; |
485 } | 423 } |
486 | 424 |
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 | 425 @end |
525 | 426 |
526 @implementation FullscreenToolbarController (PrivateMethods) | 427 @implementation FullscreenToolbarController (PrivateMethods) |
527 | 428 |
528 - (void)updateMenuBarAndDockVisibility { | 429 - (void)updateMenuBarAndDockVisibility { |
529 if (![self isMouseOnScreen] || | 430 if (![self isMouseOnScreen] || |
530 ![browserController_ isInImmersiveFullscreen]) { | 431 ![browserController_ isInImmersiveFullscreen]) { |
531 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 432 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
532 return; | 433 return; |
533 } | 434 } |
534 | 435 |
535 // The screen does not have a menu bar, so there's no need to hide it. | 436 // The screen does not have a menu bar, so there's no need to hide it. |
536 if (![self doesScreenHaveMenuBar]) { | 437 if (![self doesScreenHaveMenuBar]) { |
537 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; | 438 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; |
538 return; | 439 return; |
539 } | 440 } |
540 | 441 |
541 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; | 442 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; |
542 } | 443 } |
543 | 444 |
544 - (void)updateTrackingArea { | 445 - (void)updateTrackingArea { |
545 // Remove the tracking area if the toolbar isn't fully shown. | 446 // Remove the tracking area if the toolbar isn't fully shown. |
546 if (!IsCGFloatEqual([self toolbarFraction], kShowFraction)) { | 447 if (!base::mac::IsCGFloatEqual([self toolbarFraction], kShowFraction)) { |
547 [self removeTrackingAreaIfNecessary]; | 448 [self removeTrackingAreaIfNecessary]; |
548 return; | 449 return; |
549 } | 450 } |
550 | 451 |
551 if (trackingArea_) { | 452 if (trackingArea_) { |
552 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. | 453 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. |
553 NSRect oldRect = [trackingArea_ rect]; | 454 NSRect oldRect = [trackingArea_ rect]; |
554 if (NSEqualRects(trackingAreaFrame_, oldRect)) | 455 if (NSEqualRects(trackingAreaFrame_, oldRect)) |
555 return; | 456 return; |
556 | 457 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. | 546 DCHECK_EQ(hideTimer_, timer); // This better be our hide timer. |
646 [hideTimer_ invalidate]; // Make sure it doesn't repeat. | 547 [hideTimer_ invalidate]; // Make sure it doesn't repeat. |
647 hideTimer_.reset(); // And get rid of it. | 548 hideTimer_.reset(); // And get rid of it. |
648 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); | 549 base::AutoReset<BOOL> autoReset(&shouldAnimateToolbarOut_, YES); |
649 [self animateToolbarVisibility:NO]; | 550 [self animateToolbarVisibility:NO]; |
650 } | 551 } |
651 | 552 |
652 - (void)cleanup { | 553 - (void)cleanup { |
653 [self cancelAnimationAndTimer]; | 554 [self cancelAnimationAndTimer]; |
654 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 555 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
655 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | |
656 | 556 |
657 [self removeTrackingAreaIfNecessary]; | 557 [self removeTrackingAreaIfNecessary]; |
658 | 558 |
659 // Call the main status resignation code to perform the associated cleanup, | 559 // Call the main status resignation code to perform the associated cleanup, |
660 // since we will no longer be receiving actual status resignation | 560 // since we will no longer be receiving actual status resignation |
661 // notifications. | 561 // notifications. |
662 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; | 562 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; |
663 | 563 |
564 menubarTracker_.reset(); | |
565 | |
664 // No more calls back up to the BWC. | 566 // No more calls back up to the BWC. |
665 browserController_ = nil; | 567 browserController_ = nil; |
666 } | 568 } |
667 | 569 |
668 - (BOOL)shouldShowMenubarInImmersiveFullscreen { | 570 - (BOOL)shouldShowMenubarInImmersiveFullscreen { |
669 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; | 571 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; |
670 } | 572 } |
671 | 573 |
672 @end | 574 @end |
OLD | NEW |