Commit e776f9c0 authored by spqchan's avatar spqchan Committed by Commit bot

[Mac] Fix for fullscreen toolbar

Added back mouse tracking to fix an edge case where the menu
bar disappears when but the mouse is still hovering the toolbar.

The tracking area is only used to keep the toolbar active when this
happens. The toolbar will hide when the mouse leaves the tracking
area.

BUG=639562

Review-Url: https://codereview.chromium.org/2272783002
Cr-Commit-Position: refs/heads/master@{#414888}
parent f8c26a79
...@@ -565,12 +565,14 @@ class Command; ...@@ -565,12 +565,14 @@ class Command;
// Query/lock/release the requirement that the tab strip/toolbar/attached // Query/lock/release the requirement that the tab strip/toolbar/attached
// bookmark bar bar cluster is visible (e.g., when one of its elements has // bookmark bar bar cluster is visible (e.g., when one of its elements has
// focus). This is required for the floating bar in presentation mode, but // focus). This is required for the floating bar if it's hidden in fullscreen,
// should also be called when not in presentation mode; see the comments for // but should also be called when not in fullscreen mode; see the comments for
// |barVisibilityLocks_| for more details. Double locks/releases by the same // |barVisibilityLocks_| for more details. Double locks/releases by the same
// owner are ignored. If |animate:| is YES, then an animation may be // owner are ignored. If |animate:| is YES, then an animation may be
// performed. In the case of multiple calls, later calls have precedence with // performed. In the case of multiple calls, later calls have precedence with
// the rule that |animate:NO| has precedence over |animate:YES|. // the rule that |animate:NO| has precedence over |animate:YES|. If |owner| is
// nil in isBarVisibilityLockedForOwner, the method returns YES if there are
// any locks.
- (BOOL)isBarVisibilityLockedForOwner:(id)owner; - (BOOL)isBarVisibilityLockedForOwner:(id)owner;
- (void)lockBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate; - (void)lockBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate;
- (void)releaseBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate; - (void)releaseBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate;
......
...@@ -1979,9 +1979,9 @@ willAnimateFromState:(BookmarkBar::State)oldState ...@@ -1979,9 +1979,9 @@ willAnimateFromState:(BookmarkBar::State)oldState
} }
- (BOOL)isBarVisibilityLockedForOwner:(id)owner { - (BOOL)isBarVisibilityLockedForOwner:(id)owner {
DCHECK(owner);
DCHECK(barVisibilityLocks_); DCHECK(barVisibilityLocks_);
return [barVisibilityLocks_ containsObject:owner]; return owner ? [barVisibilityLocks_ containsObject:owner]
: [barVisibilityLocks_ count];
} }
- (void)lockBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate { - (void)lockBarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate {
......
...@@ -761,7 +761,6 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ...@@ -761,7 +761,6 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
// Toggle the visibility of the fullscreen toolbar. Verify that the toolbar // Toggle the visibility of the fullscreen toolbar. Verify that the toolbar
// is hidden and the preference is correctly updated. // is hidden and the preference is correctly updated.
[[controller() fullscreenToolbarController] setToolbarFraction:0.0];
[[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0]; [[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0];
chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR);
EXPECT_FALSE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); EXPECT_FALSE(prefs->GetBoolean(prefs::kShowFullscreenToolbar));
......
...@@ -454,14 +454,9 @@ willPositionSheet:(NSWindow*)sheet ...@@ -454,14 +454,9 @@ willPositionSheet:(NSWindow*)sheet
} }
- (void)configureFullscreenToolbarController { - (void)configureFullscreenToolbarController {
BOOL fullscreenForTab = [self isFullscreenForTabContentOrExtension]; NSView* contentView = [[self window] contentView];
BOOL kioskMode =
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode);
BOOL showDropdown =
!fullscreenForTab && !kioskMode && ([self floatingBarHasFocus]);
[fullscreenToolbarController_ [fullscreenToolbarController_
setupFullscreenToolbarWithDropdown:showDropdown]; setupFullscreenToolbarForContentView:contentView];
} }
- (void)adjustUIForExitingFullscreenAndStopOmniboxSliding { - (void)adjustUIForExitingFullscreenAndStopOmniboxSliding {
...@@ -474,6 +469,10 @@ willPositionSheet:(NSWindow*)sheet ...@@ -474,6 +469,10 @@ willPositionSheet:(NSWindow*)sheet
} }
- (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style { - (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style {
// The UI should only be adjusted in fullscreen mode.
if (![self isInAnyFullscreenMode])
return;
if (!fullscreenToolbarController_) { if (!fullscreenToolbarController_) {
fullscreenToolbarController_.reset( fullscreenToolbarController_.reset(
[self newFullscreenToolbarControllerWithStyle:style]); [self newFullscreenToolbarControllerWithStyle:style]);
...@@ -1009,8 +1008,11 @@ willPositionSheet:(NSWindow*)sheet ...@@ -1009,8 +1008,11 @@ willPositionSheet:(NSWindow*)sheet
[self layoutTabContentArea:output.contentAreaFrame]; [self layoutTabContentArea:output.contentAreaFrame];
if (!NSIsEmptyRect(output.fullscreenBackingBarFrame)) if (!NSIsEmptyRect(output.fullscreenBackingBarFrame)) {
[floatingBarBackingView_ setFrame:output.fullscreenBackingBarFrame]; [floatingBarBackingView_ setFrame:output.fullscreenBackingBarFrame];
[fullscreenToolbarController_
setTrackingAreaFromOverlayFrame:output.fullscreenBackingBarFrame];
}
[findBarCocoaController_ [findBarCocoaController_
positionFindBarViewAtMaxY:output.findBarMaxY positionFindBarViewAtMaxY:output.findBarMaxY
......
...@@ -168,17 +168,8 @@ const CGFloat kLocationBarRightOffset = 35; ...@@ -168,17 +168,8 @@ const CGFloat kLocationBarRightOffset = 35;
CGFloat yOffset = 0; CGFloat yOffset = 0;
if (parameters_.inAnyFullscreen) { if (parameters_.inAnyFullscreen) {
yOffset += parameters_.menubarOffset; yOffset += parameters_.menubarOffset;
switch (parameters_.slidingStyle) { yOffset += std::floor((1 - parameters_.toolbarFraction) *
case fullscreen_mac::OMNIBOX_TABS_PRESENT: [self fullscreenBackingBarHeight]);
break;
case fullscreen_mac::OMNIBOX_TABS_NONE:
case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
// In presentation mode, |yOffset| accounts for the sliding position of
// the floating bar and the extra offset needed to dodge the menu bar.
yOffset += std::floor((1 - parameters_.toolbarFraction) *
[self fullscreenBackingBarHeight]);
break;
}
} }
fullscreenYOffset_ = yOffset; fullscreenYOffset_ = yOffset;
} }
......
...@@ -47,7 +47,7 @@ class BrowserWindowLayoutTest : public testing::Test { ...@@ -47,7 +47,7 @@ class BrowserWindowLayoutTest : public testing::Test {
[layout setInAnyFullscreen:YES]; [layout setInAnyFullscreen:YES];
[layout setFullscreenSlidingStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT]; [layout setFullscreenSlidingStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT];
[layout setFullscreenMenubarOffset:0]; [layout setFullscreenMenubarOffset:0];
[layout setFullscreenToolbarFraction:0]; [layout setFullscreenToolbarFraction:1];
[layout setFullscreenButtonFrame:NSZeroRect]; [layout setFullscreenButtonFrame:NSZeroRect];
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
@class BrowserWindowController; @class BrowserWindowController;
@class CrTrackingArea;
@class DropdownAnimation; @class DropdownAnimation;
namespace fullscreen_mac { namespace fullscreen_mac {
...@@ -25,16 +26,12 @@ enum SlidingStyle { ...@@ -25,16 +26,12 @@ enum SlidingStyle {
// Provides a controller to fullscreen toolbar for a single browser // Provides a controller to fullscreen toolbar for a single browser
// window. This class handles running animations, showing and hiding the // window. This class handles running animations, showing and hiding the
// floating dropdown bar, and managing the tracking area associated with the // fullscreen toolbar, and managing the tracking area associated with the
// dropdown. This class does not directly manage any views -- the // toolbar. This class does not directly manage any views -- the
// BrowserWindowController is responsible for positioning and z-ordering views. // BrowserWindowController is responsible for positioning and z-ordering views.
// //
// Tracking areas are disabled while animations are running. If
// |overlayFrameChanged:| is called while an animation is running, the // TODO (spqchan): Write tests for this class. See crbug.com/640064.
// controller saves the new frame and installs the appropriate tracking area
// when the animation finishes. This is largely done for ease of
// implementation; it is easier to check the mouse location at each animation
// step than it is to manage a constantly-changing tracking area.
@interface FullscreenToolbarController : NSObject<NSAnimationDelegate> { @interface FullscreenToolbarController : NSObject<NSAnimationDelegate> {
@private @private
// Our parent controller. // Our parent controller.
...@@ -43,6 +40,18 @@ enum SlidingStyle { ...@@ -43,6 +40,18 @@ enum SlidingStyle {
// Whether or not we are in fullscreen mode. // Whether or not we are in fullscreen mode.
BOOL inFullscreenMode_; BOOL inFullscreenMode_;
// The content view for the window. This is nil when not in fullscreen mode.
NSView* contentView_; // weak
// The frame for the tracking area. The value is the toolbar overlay's frame
// with additional height added at the bottom.
NSRect trackingAreaFrame_;
// The tracking area associated with the toolbar overlay bar. This tracking
// area is used to keep the toolbar active if the menubar had animated out
// but the mouse is still on the toolbar.
base::scoped_nsobject<CrTrackingArea> trackingArea_;
// Pointer to the currently running animation. Is nil if no animation is // Pointer to the currently running animation. Is nil if no animation is
// running. // running.
base::scoped_nsobject<DropdownAnimation> currentAnimation_; base::scoped_nsobject<DropdownAnimation> currentAnimation_;
...@@ -69,32 +78,36 @@ enum SlidingStyle { ...@@ -69,32 +78,36 @@ enum SlidingStyle {
// Only used in AppKit Fullscreen. // Only used in AppKit Fullscreen.
CGFloat menubarFraction_; CGFloat menubarFraction_;
// The fraction of the omnibox/tabstrip that is showing. Ranges from 0 to 1. // The toolbar fraction set by the menu progress.
// Used in both AppKit and Immersive Fullscreen. CGFloat toolbarFractionFromMenuProgress_;
CGFloat toolbarFraction_;
// A Carbon event handler that tracks the revealed fraction of the menu bar. // A Carbon event handler that tracks the revealed fraction of the menu bar.
EventHandlerRef menuBarTrackingHandler_; EventHandlerRef menuBarTrackingHandler_;
// True when the toolbar is dropped to show tabstrip changes. // True when the toolbar is dropped to show tabstrip changes.
BOOL revealToolbarForTabStripChanges_; BOOL isRevealingToolbarForTabStripChanges_;
// True when the toolbar should be animated back out via a DropdownAnimation.
// This is set and unset in hideTimer:. It's set to YES before it calls
// animateToolbarVisibility: and then set to NO after the animation has
// started.
BOOL shouldAnimateToolbarOut_;
} }
@property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle;
@property(nonatomic, assign) CGFloat toolbarFraction;
// Designated initializer. // Designated initializer.
- (id)initWithBrowserController:(BrowserWindowController*)controller - (id)initWithBrowserController:(BrowserWindowController*)controller
style:(fullscreen_mac::SlidingStyle)style; style:(fullscreen_mac::SlidingStyle)style;
// Informs the controller that the browser has entered or exited presentation // Informs the controller that the browser has entered or exited fullscreen
// mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called // mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called
// after the window is setup, just before it is shown. |-exitFullscreenMode| // after the window is setup, just before it is shown. |-exitFullscreenMode|
// should be called before any views are moved back to the non-fullscreen // should be called before any views are moved back to the non-fullscreen
// window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called, // window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called,
// it must be balanced with a call to |-exitFullscreenMode| before the // it must be balanced with a call to |-exitFullscreenMode| before the
// controller is released. // controller is released.
- (void)setupFullscreenToolbarWithDropdown:(BOOL)showDropdown; - (void)setupFullscreenToolbarForContentView:(NSView*)contentView;
- (void)exitFullscreenMode; - (void)exitFullscreenMode;
// Returns the amount by which the floating bar should be offset downwards (to // Returns the amount by which the floating bar should be offset downwards (to
...@@ -119,15 +132,30 @@ enum SlidingStyle { ...@@ -119,15 +132,30 @@ enum SlidingStyle {
// Ranges from 0 to -22. // Ranges from 0 to -22.
- (CGFloat)menubarOffset; - (CGFloat)menubarOffset;
// Returns the fraction of the toolbar exposed at the top.
// It returns 1.0 if the toolbar is fully shown and 0.0 if the toolbar is
// hidden. Otherwise, if the toolbar is in progress of animating, it will
// return a float that ranges from (0, 1).
- (CGFloat)toolbarFraction;
// Returns YES if the mouse is on the window's screen. This is used to check // Returns YES if the mouse is on the window's screen. This is used to check
// if the menubar events belong to window's screen since the menubar would // if the menubar events belong to window's screen since the menubar would
// only be revealed if the mouse is there. // only be revealed if the mouse is there.
- (BOOL)isMouseOnScreen; - (BOOL)isMouseOnScreen;
// Returns true if the browser is in the process of entering/exiting // Sets |trackingAreaFrame_| from the given overlay frame.
- (void)setTrackingAreaFromOverlayFrame:(NSRect)frame;
// Returns YES if the browser is in the process of entering/exiting
// fullscreen. // fullscreen.
- (BOOL)isFullscreenTransitionInProgress; - (BOOL)isFullscreenTransitionInProgress;
// Returns YES if the browser in in fullscreen.
- (BOOL)isInFullscreen;
// Updates the toolbar by updating the layout, menubar and dock.
- (void)updateToolbar;
@end @end
// Private methods exposed for testing. // Private methods exposed for testing.
...@@ -138,11 +166,6 @@ enum SlidingStyle { ...@@ -138,11 +166,6 @@ enum SlidingStyle {
// Callback for menu bar animations. // Callback for menu bar animations.
- (void)setMenuBarRevealProgress:(CGFloat)progress; - (void)setMenuBarRevealProgress:(CGFloat)progress;
// Updates the local state that reflects the fraction of the toolbar area that
// is showing. This function has the side effect of changing the AppKit
// Fullscreen option for whether the menu bar is shown.
- (void)changeToolbarFraction:(CGFloat)fraction;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ #endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment