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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
diff --git a/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm b/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
index e34cb4cb1cd6855e6bfc1b57bef253d304ea6508..e8e5aa498d32738cd71887e4a77012c3ca438e0b 100644
--- a/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
+++ b/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
@@ -145,7 +145,7 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
- (void)updateMenuBarAndDockVisibility;
// Methods to set up or remove the tracking area.
-- (void)setupTrackingArea;
+- (void)updateTrackingArea;
- (void)removeTrackingAreaIfNecessary;
// Returns YES if the mouse is inside the tracking area.
@@ -191,6 +191,7 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
browserController_ = controller;
systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
slidingStyle_ = style;
+ menubarState_ = fullscreen_mac::MENUBAR_HIDDEN;
}
// Install the Carbon event handler for the menubar show, hide and
@@ -267,6 +268,18 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
return kFloatingBarVerticalOffset;
}
+- (void)lockBarVisibilityWithAnimation:(BOOL)animate {
+ 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.
+ [self ensureOverlayShownWithAnimation:animate];
+ isLockingBarVisibility_ = NO;
+}
+
+- (void)releaseBarVisibilityWithAnimation:(BOOL)animate {
+ isReleasingBarVisibility_ = YES;
+ [self ensureOverlayHiddenWithAnimation:animate];
+ isReleasingBarVisibility_ = NO;
+}
+
- (void)ensureOverlayShownWithAnimation:(BOOL)animate {
if (!inFullscreenMode_)
return;
@@ -288,6 +301,14 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
if (self.slidingStyle != fullscreen_mac::OMNIBOX_TABS_HIDDEN)
return;
+ if ([browserController_ isBarVisibilityLockedForOwner:nil])
+ return;
+
+ if ([self mouseInsideTrackingArea] ||
+ menubarState_ == fullscreen_mac::MENUBAR_SHOWN) {
+ return;
+ }
+
[self cancelHideTimer];
[self animateToolbarVisibility:NO];
}
@@ -331,9 +352,15 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
DCHECK(inFullscreenMode_);
DCHECK_EQ([event trackingArea], trackingArea_.get());
+ if ([browserController_ isBarVisibilityLockedForOwner:nil])
+ return;
+
// If the menubar is gone, animate the toolbar out.
- if (IsCGFloatEqual(menubarFraction_, kHideFraction))
+ if (menubarState_ == fullscreen_mac::MENUBAR_HIDDEN) {
+ shouldAnimateToolbarOut_ = YES;
[self ensureOverlayHiddenWithAnimation:YES];
+ shouldAnimateToolbarOut_ = NO;
+ }
[self removeTrackingAreaIfNecessary];
}
@@ -368,9 +395,6 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
}
- (CGFloat)toolbarFraction {
- if ([browserController_ isBarVisibilityLockedForOwner:nil])
- return kShowFraction;
-
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
return kHideFraction;
@@ -380,13 +404,26 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
case fullscreen_mac::OMNIBOX_TABS_NONE:
return kHideFraction;
case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
+ if (menubarState_ == fullscreen_mac::MENUBAR_SHOWN)
+ return kShowFraction;
+
+ if ([self mouseInsideTrackingArea])
+ return kShowFraction;
+
+ if (isLockingBarVisibility_)
+ return kHideFraction;
+ else if (isReleasingBarVisibility_)
+ return kShowFraction;
+ else if ([browserController_ isBarVisibilityLockedForOwner:nil])
+ return kShowFraction;
+
if (currentAnimation_.get())
return [currentAnimation_ toolbarFraction];
if (hideTimer_.get() || shouldAnimateToolbarOut_)
return kShowFraction;
- return toolbarFractionFromMenuProgress_;
+ return menubarFraction_;
}
}
@@ -433,7 +470,7 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
- (void)animationDidEnd:(NSAnimation*)animation {
[self animationDidStop:animation];
- [self setupTrackingArea];
+ [self updateTrackingArea];
}
- (void)setMenuBarRevealProgress:(CGFloat)progress {
@@ -442,20 +479,22 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
if (![self isMouseOnScreen] && progress > menubarFraction_)
return;
+ if (IsCGFloatEqual(progress, kShowFraction))
+ menubarState_ = fullscreen_mac::MENUBAR_SHOWN;
+ else if (IsCGFloatEqual(progress, kHideFraction))
+ menubarState_ = fullscreen_mac::MENUBAR_HIDDEN;
+ else if (progress < menubarFraction_)
+ menubarState_ = fullscreen_mac::MENUBAR_HIDING;
+ else if (progress > menubarFraction_)
+ menubarState_ = fullscreen_mac::MENUBAR_SHOWING;
+
menubarFraction_ = progress;
- if (self.slidingStyle == fullscreen_mac::OMNIBOX_TABS_HIDDEN) {
- if (IsCGFloatEqual(menubarFraction_, kShowFraction))
- [self setupTrackingArea];
-
- // If the menubar is disappearing from the screen, check if the mouse
- // is still interacting with the toolbar. If it is, don't set
- // |toolbarFractionFromMenuProgress_| so that the the toolbar will remain
- // on the screen.
- BOOL isMenuBarDisappearing =
- menubarFraction_ < toolbarFractionFromMenuProgress_;
- if (!(isMenuBarDisappearing && [self mouseInsideTrackingArea]))
- toolbarFractionFromMenuProgress_ = progress;
+ if (slidingStyle_ == fullscreen_mac::OMNIBOX_TABS_HIDDEN) {
+ if (menubarState_ == fullscreen_mac::MENUBAR_HIDDEN ||
+ menubarState_ == fullscreen_mac::MENUBAR_SHOWN) {
+ [self updateTrackingArea];
+ }
}
// If an animation is not running, then -layoutSubviews will not be called
@@ -487,7 +526,13 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
[self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]];
}
-- (void)setupTrackingArea {
+- (void)updateTrackingArea {
+ // Remove the tracking area if the toolbar isn't fully shown.
+ if (!IsCGFloatEqual([self toolbarFraction], kShowFraction)) {
+ [self removeTrackingAreaIfNecessary];
+ return;
+ }
+
if (trackingArea_) {
// If the tracking rectangle is already |trackingAreaBounds_|, quit early.
NSRect oldRect = [trackingArea_ rect];
@@ -517,6 +562,9 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
}
- (BOOL)mouseInsideTrackingArea {
+ if (!trackingArea_)
+ return NO;
+
NSWindow* window = [browserController_ window];
NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream];
NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil];

Powered by Google App Engine
This is Rietveld 408576698