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

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

Issue 2296903002: [Mac] Fullscreen Toolbar Edge Cases (Closed)
Patch Set: Fixed an 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
« no previous file with comments | « chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
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)
336 [self ensureOverlayHiddenWithAnimation:YES]; 360 [self ensureOverlayHiddenWithAnimation:YES];
337 361
338 [self removeTrackingAreaIfNecessary]; 362 [self removeTrackingAreaIfNecessary];
339 } 363 }
340 364
341 - (void)updateToolbar { 365 - (void)updateToolbar {
342 [browserController_ layoutSubviews]; 366 [browserController_ layoutSubviews];
343 367
344 // In AppKit fullscreen, moving the mouse to the top of the screen toggles 368 // In AppKit fullscreen, moving the mouse to the top of the screen toggles
345 // menu visibility. Replicate the same effect for immersive fullscreen. 369 // menu visibility. Replicate the same effect for immersive fullscreen.
(...skipping 15 matching lines...) Expand all
361 - (CGFloat)menubarOffset { 385 - (CGFloat)menubarOffset {
362 if ([browserController_ isInAppKitFullscreen]) 386 if ([browserController_ isInAppKitFullscreen])
363 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]); 387 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]);
364 388
365 return [self shouldShowMenubarInImmersiveFullscreen] 389 return [self shouldShowMenubarInImmersiveFullscreen]
366 ? -[self floatingBarVerticalOffset] 390 ? -[self floatingBarVerticalOffset]
367 : 0; 391 : 0;
368 } 392 }
369 393
370 - (CGFloat)toolbarFraction { 394 - (CGFloat)toolbarFraction {
371 if ([browserController_ isBarVisibilityLockedForOwner:nil])
372 return kShowFraction;
373
374 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 395 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
375 return kHideFraction; 396 return kHideFraction;
376 397
377 switch (slidingStyle_) { 398 switch (slidingStyle_) {
378 case fullscreen_mac::OMNIBOX_TABS_PRESENT: 399 case fullscreen_mac::OMNIBOX_TABS_PRESENT:
379 return kShowFraction; 400 return kShowFraction;
380 case fullscreen_mac::OMNIBOX_TABS_NONE: 401 case fullscreen_mac::OMNIBOX_TABS_NONE:
381 return kHideFraction; 402 return kHideFraction;
382 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: 403 case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
404 if (menubarState_ == fullscreen_mac::MENUBAR_SHOWN ||
405 menubarState_ == fullscreen_mac::MENUBAR_SHOWING) {
406 return toolbarFractionFromMenuProgress_;
407 }
408
409 if (isLockingBarVisibility_)
410 return kHideFraction;
411 else if (isReleasingBarVisibility_)
412 return kShowFraction;
413 else if ([browserController_ isBarVisibilityLockedForOwner:nil])
414 return kShowFraction;
415
383 if (currentAnimation_.get()) 416 if (currentAnimation_.get())
384 return [currentAnimation_ toolbarFraction]; 417 return [currentAnimation_ toolbarFraction];
385 418
386 if (hideTimer_.get() || shouldAnimateToolbarOut_) 419 if (hideTimer_.get() || shouldAnimateToolbarOut_)
387 return kShowFraction; 420 return kShowFraction;
388 421
389 return toolbarFractionFromMenuProgress_; 422 return toolbarFractionFromMenuProgress_;
erikchen 2016/09/07 21:58:49 I think that there is a logic error here. If the u
spqchan 2016/09/08 01:49:41 Done.
390 } 423 }
391 } 424 }
392 425
393 - (BOOL)isFullscreenTransitionInProgress { 426 - (BOOL)isFullscreenTransitionInProgress {
394 return [browserController_ isFullscreenTransitionInProgress]; 427 return [browserController_ isFullscreenTransitionInProgress];
395 } 428 }
396 429
397 - (BOOL)isInFullscreen { 430 - (BOOL)isInFullscreen {
398 return inFullscreenMode_; 431 return inFullscreenMode_;
399 } 432 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 [self animationDidStop:animation]; 468 [self animationDidStop:animation];
436 [self setupTrackingArea]; 469 [self setupTrackingArea];
437 } 470 }
438 471
439 - (void)setMenuBarRevealProgress:(CGFloat)progress { 472 - (void)setMenuBarRevealProgress:(CGFloat)progress {
440 // If the menubarFraction increases, check if we are in the right screen 473 // If the menubarFraction increases, check if we are in the right screen
441 // so that the toolbar is not revealed on the wrong screen. 474 // so that the toolbar is not revealed on the wrong screen.
442 if (![self isMouseOnScreen] && progress > menubarFraction_) 475 if (![self isMouseOnScreen] && progress > menubarFraction_)
443 return; 476 return;
444 477
478 if (IsCGFloatEqual(progress, kShowFraction))
479 menubarState_ = fullscreen_mac::MENUBAR_SHOWN;
480 else if (IsCGFloatEqual(progress, kHideFraction))
481 menubarState_ = fullscreen_mac::MENUBAR_HIDDEN;
482 else if (progress < menubarFraction_)
483 menubarState_ = fullscreen_mac::MENUBAR_HIDING;
484 else if (progress > menubarFraction_)
485 menubarState_ = fullscreen_mac::MENUBAR_SHOWING;
486
445 menubarFraction_ = progress; 487 menubarFraction_ = progress;
446 488
447 if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_HIDDEN) { 489 if (slidingStyle_ == fullscreen_mac::OMNIBOX_TABS_HIDDEN) {
448 if (IsCGFloatEqual(menubarFraction_, kShowFraction)) 490 if (menubarState_ == fullscreen_mac::MENUBAR_SHOWN)
449 [self setupTrackingArea]; 491 [self setupTrackingArea];
450 492
451 // If the menubar is disappearing from the screen, check if the mouse 493 // If the menubar is in the process of hiding from the screen, check if
452 // is still interacting with the toolbar. If it is, don't set 494 // the user is still interacting with the toolbar. If not, don't set
453 // |toolbarFractionFromMenuProgress_| so that the the toolbar will remain 495 // |toolbarFractionFromMenuProgress_| so that the the toolbar will remain
454 // on the screen. 496 // on the screen.
455 BOOL isMenuBarDisappearing = 497 BOOL isMenubarGoneOrDisappear =
456 menubarFraction_ < toolbarFractionFromMenuProgress_; 498 menubarState_ == fullscreen_mac::MENUBAR_HIDING ||
457 if (!(isMenuBarDisappearing && [self mouseInsideTrackingArea])) 499 menubarState_ == fullscreen_mac::MENUBAR_HIDDEN;
500 BOOL isToolbarFocused =
501 [self mouseInsideTrackingArea] ||
502 [browserController_ isBarVisibilityLockedForOwner:nil];
503 if (!(isMenubarGoneOrDisappear && isToolbarFocused))
458 toolbarFractionFromMenuProgress_ = progress; 504 toolbarFractionFromMenuProgress_ = progress;
459 } 505 }
460 506
461 // If an animation is not running, then -layoutSubviews will not be called 507 // If an animation is not running, then -layoutSubviews will not be called
462 // for each tick of the menu bar reveal. Do that manually. 508 // for each tick of the menu bar reveal. Do that manually.
463 // TODO(erikchen): The animation is janky. layoutSubviews need a refactor so 509 // 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 510 // that it calls setFrameOffset: instead of setFrame: if the frame's size has
465 // not changed. 511 // not changed.
466 if (!currentAnimation_.get()) 512 if (!currentAnimation_.get())
467 [browserController_ layoutSubviews]; 513 [browserController_ layoutSubviews];
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 646
601 // No more calls back up to the BWC. 647 // No more calls back up to the BWC.
602 browserController_ = nil; 648 browserController_ = nil;
603 } 649 }
604 650
605 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 651 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
606 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; 652 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99;
607 } 653 }
608 654
609 @end 655 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698