Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm

Issue 2296903002: [Mac] Fullscreen Toolbar Edge Cases (Closed)
Patch Set: edge case Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/mac/mac_util.h" 10 #import "base/mac/mac_util.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 @end 140 @end
141 141
142 @interface FullscreenToolbarController (PrivateMethods) 142 @interface FullscreenToolbarController (PrivateMethods)
143 143
144 // Updates the visibility of the menu bar and the dock. 144 // Updates the visibility of the menu bar and the dock.
145 - (void)updateMenuBarAndDockVisibility; 145 - (void)updateMenuBarAndDockVisibility;
146 146
147 // Methods to set up or remove the tracking area. 147 // Methods to set up or remove the tracking area.
148 - (void)setupTrackingArea; 148 - (void)updateTrackingArea;
149 - (void)removeTrackingAreaIfNecessary; 149 - (void)removeTrackingAreaIfNecessary;
150 150
151 // Returns YES if the mouse is inside the tracking area. 151 // Returns YES if the mouse is inside the tracking area.
152 - (BOOL)mouseInsideTrackingArea; 152 - (BOOL)mouseInsideTrackingArea;
153 153
154 // Whether the current screen is expected to have a menu bar, regardless of 154 // Whether the current screen is expected to have a menu bar, regardless of
155 // current visibility of the menu bar. 155 // current visibility of the menu bar.
156 - (BOOL)doesScreenHaveMenuBar; 156 - (BOOL)doesScreenHaveMenuBar;
157 157
158 // Returns YES if the window is on the primary screen. 158 // Returns YES if the window is on the primary screen.
(...skipping 25 matching lines...) Expand all
184 @implementation FullscreenToolbarController 184 @implementation FullscreenToolbarController
185 185
186 @synthesize slidingStyle = slidingStyle_; 186 @synthesize slidingStyle = slidingStyle_;
187 187
188 - (id)initWithBrowserController:(BrowserWindowController*)controller 188 - (id)initWithBrowserController:(BrowserWindowController*)controller
189 style:(fullscreen_mac::SlidingStyle)style { 189 style:(fullscreen_mac::SlidingStyle)style {
190 if ((self = [super init])) { 190 if ((self = [super init])) {
191 browserController_ = controller; 191 browserController_ = controller;
192 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 192 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
193 slidingStyle_ = style; 193 slidingStyle_ = style;
194 menubarState_ = fullscreen_mac::MENUBAR_HIDDEN;
194 } 195 }
195 196
196 // Install the Carbon event handler for the menubar show, hide and 197 // Install the Carbon event handler for the menubar show, hide and
197 // undocumented reveal event. 198 // undocumented reveal event.
198 EventTypeSpec eventSpecs[3]; 199 EventTypeSpec eventSpecs[3];
199 200
200 eventSpecs[0].eventClass = kEventClassMenu; 201 eventSpecs[0].eventClass = kEventClassMenu;
201 eventSpecs[0].eventKind = kMenuBarRevealEventKind; 202 eventSpecs[0].eventKind = kMenuBarRevealEventKind;
202 203
203 eventSpecs[1].eventClass = kEventClassMenu; 204 eventSpecs[1].eventClass = kEventClassMenu;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 261 }
261 262
262 - (void)windowDidResignMain:(NSNotification*)notification { 263 - (void)windowDidResignMain:(NSNotification*)notification {
263 [self updateMenuBarAndDockVisibility]; 264 [self updateMenuBarAndDockVisibility];
264 } 265 }
265 266
266 - (CGFloat)floatingBarVerticalOffset { 267 - (CGFloat)floatingBarVerticalOffset {
267 return kFloatingBarVerticalOffset; 268 return kFloatingBarVerticalOffset;
268 } 269 }
269 270
271 - (void)lockBarVisibilityWithAnimation:(BOOL)animate {
272 isLockingBarVisibility_ = YES;
Robert Sesek 2016/09/08 18:37:42 I think this is a good candidate for base::AutoRes
spqchan 2016/09/08 21:35:57 Done.
spqchan 2016/09/08 21:35:57 Done.
273 [self ensureOverlayShownWithAnimation:animate];
274 isLockingBarVisibility_ = NO;
275 }
276
277 - (void)releaseBarVisibilityWithAnimation:(BOOL)animate {
278 isReleasingBarVisibility_ = YES;
279 [self ensureOverlayHiddenWithAnimation:animate];
280 isReleasingBarVisibility_ = NO;
281 }
282
270 - (void)ensureOverlayShownWithAnimation:(BOOL)animate { 283 - (void)ensureOverlayShownWithAnimation:(BOOL)animate {
271 if (!inFullscreenMode_) 284 if (!inFullscreenMode_)
272 return; 285 return;
273 286
274 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 287 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
275 return; 288 return;
276 289
277 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) 290 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN)
278 return; 291 return;
279 292
280 [self cancelHideTimer]; 293 [self cancelHideTimer];
281 [self animateToolbarVisibility:YES]; 294 [self animateToolbarVisibility:YES];
282 } 295 }
283 296
284 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate { 297 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate {
285 if (!inFullscreenMode_) 298 if (!inFullscreenMode_)
286 return; 299 return;
287 300
288 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN) 301 if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN)
289 return; 302 return;
290 303
304 if ([browserController_ isBarVisibilityLockedForOwner:nil])
305 return;
306
307 if ([self mouseInsideTrackingArea] ||
308 menubarState_ == fullscreen_mac::MENUBAR_SHOWN) {
309 return;
310 }
311
291 [self cancelHideTimer]; 312 [self cancelHideTimer];
292 [self animateToolbarVisibility:NO]; 313 [self animateToolbarVisibility:NO];
293 } 314 }
294 315
295 - (void)cancelAnimationAndTimer { 316 - (void)cancelAnimationAndTimer {
296 [self cancelHideTimer]; 317 [self cancelHideTimer];
297 [currentAnimation_ stopAnimation]; 318 [currentAnimation_ stopAnimation];
298 currentAnimation_.reset(); 319 currentAnimation_.reset();
299 } 320 }
300 321
(...skipping 23 matching lines...) Expand all
324 } 345 }
325 346
326 - (void)mouseEntered:(NSEvent*)event { 347 - (void)mouseEntered:(NSEvent*)event {
327 // Empty implementation. Required for CrTrackingArea. 348 // Empty implementation. Required for CrTrackingArea.
328 } 349 }
329 350
330 - (void)mouseExited:(NSEvent*)event { 351 - (void)mouseExited:(NSEvent*)event {
331 DCHECK(inFullscreenMode_); 352 DCHECK(inFullscreenMode_);
332 DCHECK_EQ([event trackingArea], trackingArea_.get()); 353 DCHECK_EQ([event trackingArea], trackingArea_.get());
333 354
355 if ([browserController_ isBarVisibilityLockedForOwner:nil])
356 return;
357
334 // If the menubar is gone, animate the toolbar out. 358 // If the menubar is gone, animate the toolbar out.
335 if (IsCGFloatEqual(menubarFraction_, kHideFraction)) 359 if (menubarState_ == fullscreen_mac::MENUBAR_HIDDEN) {
360 shouldAnimateToolbarOut_ = YES;
336 [self ensureOverlayHiddenWithAnimation:YES]; 361 [self ensureOverlayHiddenWithAnimation:YES];
362 shouldAnimateToolbarOut_ = NO;
363 }
337 364
338 [self removeTrackingAreaIfNecessary]; 365 [self removeTrackingAreaIfNecessary];
339 } 366 }
340 367
341 - (void)updateToolbar { 368 - (void)updateToolbar {
342 [browserController_ layoutSubviews]; 369 [browserController_ layoutSubviews];
343 370
344 // In AppKit fullscreen, moving the mouse to the top of the screen toggles 371 // In AppKit fullscreen, moving the mouse to the top of the screen toggles
345 // menu visibility. Replicate the same effect for immersive fullscreen. 372 // menu visibility. Replicate the same effect for immersive fullscreen.
346 if ([browserController_ isInImmersiveFullscreen]) 373 if ([browserController_ isInImmersiveFullscreen])
(...skipping 14 matching lines...) Expand all
361 - (CGFloat)menubarOffset { 388 - (CGFloat)menubarOffset {
362 if ([browserController_ isInAppKitFullscreen]) 389 if ([browserController_ isInAppKitFullscreen])
363 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]); 390 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]);
364 391
365 return [self shouldShowMenubarInImmersiveFullscreen] 392 return [self shouldShowMenubarInImmersiveFullscreen]
366 ? -[self floatingBarVerticalOffset] 393 ? -[self floatingBarVerticalOffset]
367 : 0; 394 : 0;
368 } 395 }
369 396
370 - (CGFloat)toolbarFraction { 397 - (CGFloat)toolbarFraction {
371 if ([browserController_ isBarVisibilityLockedForOwner:nil])
372 return kShowFraction;
373
374 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 398 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
375 return kHideFraction; 399 return kHideFraction;
376 400
377 switch (slidingStyle_) { 401 switch (slidingStyle_) {
378 case fullscreen_mac::OMNIBOX_TABS_PRESENT: 402 case fullscreen_mac::OMNIBOX_TABS_PRESENT:
379 return kShowFraction; 403 return kShowFraction;
380 case fullscreen_mac::OMNIBOX_TABS_NONE: 404 case fullscreen_mac::OMNIBOX_TABS_NONE:
381 return kHideFraction; 405 return kHideFraction;
382 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: 406 case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
407 if (menubarState_ == fullscreen_mac::MENUBAR_SHOWN)
408 return kShowFraction;
409
410 if ([self mouseInsideTrackingArea])
411 return kShowFraction;
412
413 if (isLockingBarVisibility_)
414 return kHideFraction;
415 else if (isReleasingBarVisibility_)
416 return kShowFraction;
417 else if ([browserController_ isBarVisibilityLockedForOwner:nil])
418 return kShowFraction;
419
383 if (currentAnimation_.get()) 420 if (currentAnimation_.get())
384 return [currentAnimation_ toolbarFraction]; 421 return [currentAnimation_ toolbarFraction];
385 422
386 if (hideTimer_.get() || shouldAnimateToolbarOut_) 423 if (hideTimer_.get() || shouldAnimateToolbarOut_)
387 return kShowFraction; 424 return kShowFraction;
388 425
389 return toolbarFractionFromMenuProgress_; 426 return menubarFraction_;
390 } 427 }
391 } 428 }
392 429
393 - (BOOL)isFullscreenTransitionInProgress { 430 - (BOOL)isFullscreenTransitionInProgress {
394 return [browserController_ isFullscreenTransitionInProgress]; 431 return [browserController_ isFullscreenTransitionInProgress];
395 } 432 }
396 433
397 - (BOOL)isInFullscreen { 434 - (BOOL)isInFullscreen {
398 return inFullscreenMode_; 435 return inFullscreenMode_;
399 } 436 }
(...skipping 26 matching lines...) Expand all
426 isRevealingToolbarForTabStripChanges_ = NO; 463 isRevealingToolbarForTabStripChanges_ = NO;
427 } 464 }
428 } 465 }
429 466
430 // Reset the |currentAnimation_| pointer now that the animation is over. 467 // Reset the |currentAnimation_| pointer now that the animation is over.
431 currentAnimation_.reset(); 468 currentAnimation_.reset();
432 } 469 }
433 470
434 - (void)animationDidEnd:(NSAnimation*)animation { 471 - (void)animationDidEnd:(NSAnimation*)animation {
435 [self animationDidStop:animation]; 472 [self animationDidStop:animation];
436 [self setupTrackingArea]; 473 [self updateTrackingArea];
437 } 474 }
438 475
439 - (void)setMenuBarRevealProgress:(CGFloat)progress { 476 - (void)setMenuBarRevealProgress:(CGFloat)progress {
440 // If the menubarFraction increases, check if we are in the right screen 477 // If the menubarFraction increases, check if we are in the right screen
441 // so that the toolbar is not revealed on the wrong screen. 478 // so that the toolbar is not revealed on the wrong screen.
442 if (![self isMouseOnScreen] && progress > menubarFraction_) 479 if (![self isMouseOnScreen] && progress > menubarFraction_)
443 return; 480 return;
444 481
482 if (IsCGFloatEqual(progress, kShowFraction))
483 menubarState_ = fullscreen_mac::MENUBAR_SHOWN;
484 else if (IsCGFloatEqual(progress, kHideFraction))
485 menubarState_ = fullscreen_mac::MENUBAR_HIDDEN;
486 else if (progress < menubarFraction_)
487 menubarState_ = fullscreen_mac::MENUBAR_HIDING;
488 else if (progress > menubarFraction_)
489 menubarState_ = fullscreen_mac::MENUBAR_SHOWING;
490
445 menubarFraction_ = progress; 491 menubarFraction_ = progress;
446 492
447 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_HIDDEN) { 493 if (slidingStyle_ == fullscreen_mac::OMNIBOX_TABS_HIDDEN) {
448 if (IsCGFloatEqual(menubarFraction_, kShowFraction)) 494 if (menubarState_ == fullscreen_mac::MENUBAR_HIDDEN ||
449 [self setupTrackingArea]; 495 menubarState_ == fullscreen_mac::MENUBAR_SHOWN) {
450 496 [self updateTrackingArea];
451 // If the menubar is disappearing from the screen, check if the mouse 497 }
452 // is still interacting with the toolbar. If it is, don't set
453 // |toolbarFractionFromMenuProgress_| so that the the toolbar will remain
454 // on the screen.
455 BOOL isMenuBarDisappearing =
456 menubarFraction_ < toolbarFractionFromMenuProgress_;
457 if (!(isMenuBarDisappearing && [self mouseInsideTrackingArea]))
458 toolbarFractionFromMenuProgress_ = progress;
459 } 498 }
460 499
461 // If an animation is not running, then -layoutSubviews will not be called 500 // If an animation is not running, then -layoutSubviews will not be called
462 // for each tick of the menu bar reveal. Do that manually. 501 // for each tick of the menu bar reveal. Do that manually.
463 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so 502 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so
464 // that it calls setFrameOffset: instead of setFrame: if the frame's size has 503 // that it calls setFrameOffset: instead of setFrame: if the frame's size has
465 // not changed. 504 // not changed.
466 if (!currentAnimation_.get()) 505 if (!currentAnimation_.get())
467 [browserController_ layoutSubviews]; 506 [browserController_ layoutSubviews];
468 } 507 }
(...skipping 11 matching lines...) Expand all
480 519
481 // The screen does not have a menu bar, so there's no need to hide it. 520 // The screen does not have a menu bar, so there's no need to hide it.
482 if (![self doesScreenHaveMenuBar]) { 521 if (![self doesScreenHaveMenuBar]) {
483 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock]; 522 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeHideDock];
484 return; 523 return;
485 } 524 }
486 525
487 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]]; 526 [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]];
488 } 527 }
489 528
490 - (void)setupTrackingArea { 529 - (void)updateTrackingArea {
530 // Remove the tracking area if the toolbar isn't fully shown.
531 if (!IsCGFloatEqual([self toolbarFraction], kShowFraction)) {
532 [self removeTrackingAreaIfNecessary];
533 return;
534 }
535
491 if (trackingArea_) { 536 if (trackingArea_) {
492 // If the tracking rectangle is already |trackingAreaBounds_|, quit early. 537 // If the tracking rectangle is already |trackingAreaBounds_|, quit early.
493 NSRect oldRect = [trackingArea_ rect]; 538 NSRect oldRect = [trackingArea_ rect];
494 if (NSEqualRects(trackingAreaFrame_, oldRect)) 539 if (NSEqualRects(trackingAreaFrame_, oldRect))
495 return; 540 return;
496 541
497 // Otherwise, remove it. 542 // Otherwise, remove it.
498 [self removeTrackingAreaIfNecessary]; 543 [self removeTrackingAreaIfNecessary];
499 } 544 }
500 545
501 // Create and add a new tracking area for |frame|. 546 // Create and add a new tracking area for |frame|.
502 trackingArea_.reset([[CrTrackingArea alloc] 547 trackingArea_.reset([[CrTrackingArea alloc]
503 initWithRect:trackingAreaFrame_ 548 initWithRect:trackingAreaFrame_
504 options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow 549 options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow
505 owner:self 550 owner:self
506 userInfo:nil]); 551 userInfo:nil]);
507 DCHECK(contentView_); 552 DCHECK(contentView_);
508 [contentView_ addTrackingArea:trackingArea_]; 553 [contentView_ addTrackingArea:trackingArea_];
509 } 554 }
510 555
511 - (void)removeTrackingAreaIfNecessary { 556 - (void)removeTrackingAreaIfNecessary {
512 if (trackingArea_) { 557 if (trackingArea_) {
513 DCHECK(contentView_); // |contentView_| better be valid. 558 DCHECK(contentView_); // |contentView_| better be valid.
514 [contentView_ removeTrackingArea:trackingArea_]; 559 [contentView_ removeTrackingArea:trackingArea_];
515 trackingArea_.reset(); 560 trackingArea_.reset();
516 } 561 }
517 } 562 }
518 563
519 - (BOOL)mouseInsideTrackingArea { 564 - (BOOL)mouseInsideTrackingArea {
565 if (!trackingArea_)
566 return NO;
567
520 NSWindow* window = [browserController_ window]; 568 NSWindow* window = [browserController_ window];
521 NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream]; 569 NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream];
522 NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil]; 570 NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil];
523 return NSMouseInRect(mousePos, trackingAreaFrame_, [contentView_ isFlipped]); 571 return NSMouseInRect(mousePos, trackingAreaFrame_, [contentView_ isFlipped]);
524 } 572 }
525 573
526 - (BOOL)doesScreenHaveMenuBar { 574 - (BOOL)doesScreenHaveMenuBar {
527 if (![[NSScreen class] 575 if (![[NSScreen class]
528 respondsToSelector:@selector(screensHaveSeparateSpaces)]) 576 respondsToSelector:@selector(screensHaveSeparateSpaces)])
529 return [self isWindowOnPrimaryScreen]; 577 return [self isWindowOnPrimaryScreen];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 648
601 // No more calls back up to the BWC. 649 // No more calls back up to the BWC.
602 browserController_ = nil; 650 browserController_ = nil;
603 } 651 }
604 652
605 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 653 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
606 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; 654 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99;
607 } 655 }
608 656
609 @end 657 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698