| 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 7322a777d4e3e1c1bf4954fbc4868a66f048c0dc..f5864108b04b34c3ac27f4d18ae405b4bf0d01e9 100644
|
| --- a/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
|
| +++ b/chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm
|
| @@ -12,6 +12,7 @@
|
| #import "chrome/browser/ui/cocoa/browser_window_controller.h"
|
| #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h"
|
| #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "ui/base/cocoa/appkit_utils.h"
|
| #import "ui/base/cocoa/nsview_additions.h"
|
| @@ -19,11 +20,6 @@
|
|
|
| namespace {
|
|
|
| -// Additional height threshold added at the toolbar's bottom. This is to mimic
|
| -// threshold the mouse position needs to be at before the menubar automatically
|
| -// hides.
|
| -const CGFloat kTrackingAreaAdditionalThreshold = 20;
|
| -
|
| // Visibility fractions for the menubar and toolbar.
|
| const CGFloat kHideFraction = 0.0;
|
| const CGFloat kShowFraction = 1.0;
|
| @@ -40,13 +36,6 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| // Updates the visibility of the menu bar and the dock.
|
| - (void)updateMenuBarAndDockVisibility;
|
|
|
| -// Methods to set up or remove the tracking area.
|
| -- (void)updateTrackingArea;
|
| -- (void)removeTrackingAreaIfNecessary;
|
| -
|
| -// Returns YES if the mouse is inside the tracking area.
|
| -- (BOOL)mouseInsideTrackingArea;
|
| -
|
| // Whether the current screen is expected to have a menu bar, regardless of
|
| // current visibility of the menu bar.
|
| - (BOOL)doesScreenHaveMenuBar;
|
| @@ -88,13 +77,15 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| [super dealloc];
|
| }
|
|
|
| -- (void)setupFullscreenToolbarForContentView:(NSView*)contentView {
|
| +- (void)enterFullscreenMode {
|
| DCHECK(!inFullscreenMode_);
|
| - contentView_ = contentView;
|
| inFullscreenMode_ = YES;
|
|
|
| menubarTracker_.reset([[FullscreenMenubarTracker alloc]
|
| initWithFullscreenToolbarController:self]);
|
| + mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc]
|
| + initWithFullscreenToolbarController:self
|
| + animationController:animationController_.get()]);
|
|
|
| [self updateMenuBarAndDockVisibility];
|
|
|
| @@ -170,28 +161,10 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| systemFullscreenMode_ = mode;
|
| }
|
|
|
| -- (void)mouseEntered:(NSEvent*)event {
|
| - // Empty implementation. Required for CrTrackingArea.
|
| -}
|
| -
|
| -- (void)mouseExited:(NSEvent*)event {
|
| - DCHECK(inFullscreenMode_);
|
| - DCHECK_EQ([event trackingArea], trackingArea_.get());
|
| -
|
| - if ([browserController_ isBarVisibilityLockedForOwner:nil])
|
| - return;
|
| -
|
| - // If the menubar is gone, animate the toolbar out.
|
| - if ([menubarTracker_ state] == FullscreenMenubarState::HIDDEN)
|
| - [self ensureOverlayHiddenWithAnimation:YES];
|
| -
|
| - [self removeTrackingAreaIfNecessary];
|
| -}
|
| -
|
| - (void)updateToolbar {
|
| [browserController_ layoutSubviews];
|
| - [self updateTrackingArea];
|
| animationController_->ToolbarDidUpdate();
|
| + [mouseTracker_ updateTrackingArea];
|
|
|
| // In AppKit fullscreen, moving the mouse to the top of the screen toggles
|
| // menu visibility. Replicate the same effect for immersive fullscreen.
|
| @@ -256,7 +229,7 @@ const CGFloat kToolbarVerticalOffset = 22;
|
|
|
| FullscreenMenubarState menubarState = [menubarTracker_ state];
|
| return menubarState == FullscreenMenubarState::SHOWN ||
|
| - [self mouseInsideTrackingArea] ||
|
| + [mouseTracker_ mouseInsideTrackingArea] ||
|
| [browserController_ isBarVisibilityLockedForOwner:nil];
|
| }
|
|
|
| @@ -273,12 +246,9 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| [[browserController_ window] screen].frame, false);
|
| }
|
|
|
| -- (void)setTrackingAreaFromOverlayFrame:(NSRect)frame {
|
| - NSRect contentBounds = [contentView_ bounds];
|
| - trackingAreaFrame_ = frame;
|
| - trackingAreaFrame_.origin.y -= kTrackingAreaAdditionalThreshold;
|
| - trackingAreaFrame_.size.height =
|
| - NSMaxY(contentBounds) - trackingAreaFrame_.origin.y;
|
| +- (void)updateToolbarFrame:(NSRect)frame {
|
| + if (mouseTracker_.get())
|
| + [mouseTracker_ updateToolbarFrame:frame];
|
| }
|
|
|
| @end
|
| @@ -301,51 +271,6 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| [self setSystemFullscreenModeTo:[self desiredSystemFullscreenMode]];
|
| }
|
|
|
| -- (void)updateTrackingArea {
|
| - // Remove the tracking area if the toolbar isn't fully shown.
|
| - if (!ui::IsCGFloatEqual([self toolbarFraction], kShowFraction)) {
|
| - [self removeTrackingAreaIfNecessary];
|
| - return;
|
| - }
|
| -
|
| - if (trackingArea_) {
|
| - // If the tracking rectangle is already |trackingAreaBounds_|, quit early.
|
| - NSRect oldRect = [trackingArea_ rect];
|
| - if (NSEqualRects(trackingAreaFrame_, oldRect))
|
| - return;
|
| -
|
| - // Otherwise, remove it.
|
| - [self removeTrackingAreaIfNecessary];
|
| - }
|
| -
|
| - // Create and add a new tracking area for |frame|.
|
| - trackingArea_.reset([[CrTrackingArea alloc]
|
| - initWithRect:trackingAreaFrame_
|
| - options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow
|
| - owner:self
|
| - userInfo:nil]);
|
| - DCHECK(contentView_);
|
| - [contentView_ addTrackingArea:trackingArea_];
|
| -}
|
| -
|
| -- (void)removeTrackingAreaIfNecessary {
|
| - if (trackingArea_) {
|
| - DCHECK(contentView_); // |contentView_| better be valid.
|
| - [contentView_ removeTrackingArea:trackingArea_];
|
| - trackingArea_.reset();
|
| - }
|
| -}
|
| -
|
| -- (BOOL)mouseInsideTrackingArea {
|
| - if (!trackingArea_)
|
| - return NO;
|
| -
|
| - NSWindow* window = [browserController_ window];
|
| - NSPoint mouseLoc = [window mouseLocationOutsideOfEventStream];
|
| - NSPoint mousePos = [contentView_ convertPoint:mouseLoc fromView:nil];
|
| - return NSMouseInRect(mousePos, trackingAreaFrame_, [contentView_ isFlipped]);
|
| -}
|
| -
|
| - (BOOL)doesScreenHaveMenuBar {
|
| if (![[NSScreen class]
|
| respondsToSelector:@selector(screensHaveSeparateSpaces)])
|
| @@ -371,14 +296,13 @@ const CGFloat kToolbarVerticalOffset = 22;
|
| animationController_->StopAnimationAndTimer();
|
| [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
| - [self removeTrackingAreaIfNecessary];
|
| -
|
| // Call the main status resignation code to perform the associated cleanup,
|
| // since we will no longer be receiving actual status resignation
|
| // notifications.
|
| [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal];
|
|
|
| menubarTracker_.reset();
|
| + mouseTracker_.reset();
|
|
|
| // No more calls back up to the BWC.
|
| browserController_ = nil;
|
|
|