Commit 5407de10 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Mac: clean up FullscreenToolbarController

- Remove some structure that was previously necessary for Cocoa browser
- the visibility lock controller is vestigial: we release the lock,
but never acquire it

Bug: 1063417
Change-Id: I55ccc6b14b0ffed7d81beb640a54ec8b1110e831
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2117321Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753211}
parent 39649d64
......@@ -2401,12 +2401,8 @@ jumbo_static_library("ui") {
"cocoa/fullscreen/fullscreen_toolbar_animation_controller.mm",
"cocoa/fullscreen/fullscreen_toolbar_controller.h",
"cocoa/fullscreen/fullscreen_toolbar_controller.mm",
"cocoa/fullscreen/fullscreen_toolbar_controller_views.h",
"cocoa/fullscreen/fullscreen_toolbar_controller_views.mm",
"cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h",
"cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.mm",
"cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.h",
"cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.mm",
"cocoa/handoff_active_url_observer.cc",
"cocoa/handoff_active_url_observer.h",
"cocoa/handoff_active_url_observer_bridge.h",
......
......@@ -10,7 +10,6 @@
#include "base/mac/mac_util.h"
#include "base/stl_util.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.h"
#include "ui/base/cocoa/appkit_utils.h"
namespace {
......@@ -18,6 +17,8 @@ namespace {
// The event kind value for a undocumented menubar show/hide Carbon event.
const CGFloat kMenuBarRevealEventKind = 2004;
// TODO(https://crbug.com/1063417): Replace this with something that works
// on modern macOS versions.
OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
EventRef event,
void* context) {
......@@ -50,7 +51,6 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
@interface FullscreenMenubarTracker () {
FullscreenToolbarController* _controller; // weak
id<FullscreenToolbarContextDelegate> _delegate; // weak
// A Carbon event handler that tracks the revealed fraction of the menubar.
EventHandlerRef _menubarTrackingHandler;
......@@ -70,7 +70,6 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
(FullscreenToolbarController*)controller {
if ((self = [super init])) {
_controller = controller;
_delegate = [controller delegate];
_state = FullscreenMenubarState::HIDDEN;
// Install the Carbon event handler for the menubar show, hide and
......@@ -112,8 +111,8 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
}
- (void)setMenubarProgress:(CGFloat)progress {
if (![_delegate isInAnyFullscreenMode] ||
[_delegate isFullscreenTransitionInProgress]) {
if (![_controller isInAnyFullscreenMode] ||
[_controller isFullscreenTransitionInProgress]) {
return;
}
......@@ -123,7 +122,7 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
return;
// Ignore the menubarFraction changes if the Space is inactive.
if (![[_delegate window] isOnActiveSpace])
if (![[_controller window] isOnActiveSpace])
return;
if (ui::IsCGFloatEqual(progress, 1.0))
......@@ -137,7 +136,6 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
_menubarFraction = progress;
[_controller layoutToolbar];
// AppKit drives the menu bar animation from a nested run loop. Flush
// explicitly so that Chrome's UI updates during the animation.
[CATransaction flush];
......@@ -145,14 +143,12 @@ OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
- (BOOL)isMouseOnScreen {
return NSMouseInRect([NSEvent mouseLocation],
[[_delegate window] screen].frame, false);
[[_controller window] screen].frame, false);
}
- (void)activeSpaceDidChange:(NSNotification*)notification {
_menubarFraction = 0.0;
_state = FullscreenMenubarState::HIDDEN;
[[_controller visibilityLockController] releaseToolbarVisibilityForOwner:self
withAnimation:NO];
[_controller layoutToolbar];
}
......
......@@ -8,13 +8,9 @@
#import <Cocoa/Cocoa.h>
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
@class BrowserWindowController;
class BrowserView;
@class FullscreenMenubarTracker;
class FullscreenToolbarAnimationController;
@class FullscreenToolbarMouseTracker;
@class FullscreenToolbarVisibilityLockController;
namespace content {
class WebContents;
......@@ -53,36 +49,11 @@ enum class FullscreenToolbarStyle {
// window. This class sets up the animation manager, visibility locks, menubar
// tracking, and mouse tracking associated with the toolbar. It receives input
// from these objects to update and recompute the fullscreen toolbar laytout.
@interface FullscreenToolbarController : NSObject {
@private
// Whether or not we are in fullscreen mode.
BOOL _inFullscreenMode;
// Updates the fullscreen toolbar layout for changes in the menubar. This
// object is only set when the browser is in fullscreen mode.
base::scoped_nsobject<FullscreenMenubarTracker> _menubarTracker;
// Maintains the toolbar's visibility locks for the TOOLBAR_HIDDEN style.
base::scoped_nsobject<FullscreenToolbarVisibilityLockController>
_visibilityLockController;
// Manages the toolbar animations for the TOOLBAR_HIDDEN style.
std::unique_ptr<FullscreenToolbarAnimationController> _animationController;
// When the menu bar and toolbar are visible, creates a tracking area which
// is used to keep them visible until the mouse moves far enough away from
// them. Only set when the browser is in fullscreen mode.
base::scoped_nsobject<FullscreenToolbarMouseTracker> _mouseTracker;
// The style of the fullscreen toolbar.
FullscreenToolbarStyle _toolbarStyle;
// Delegate for query fullscreen status and context. Weak.
id<FullscreenToolbarContextDelegate> _delegate;
}
@interface FullscreenToolbarController
: NSObject <FullscreenToolbarContextDelegate>
// Designated initializer.
- (id)initWithDelegate:(id<FullscreenToolbarContextDelegate>)delegate;
- (id)initWithBrowserView:(BrowserView*)browserView;
// Informs the controller that the browser has entered or exited fullscreen
// mode. |-enterFullscreenMode| should be called when the window is about to
......@@ -119,31 +90,9 @@ enum class FullscreenToolbarStyle {
// Returns the object in |menubarTracker_|;
- (FullscreenMenubarTracker*)menubarTracker;
// Returns the object in |visibilityLockController_|;
- (FullscreenToolbarVisibilityLockController*)visibilityLockController;
// Sets the value of |toolbarStyle_|.
- (void)setToolbarStyle:(FullscreenToolbarStyle)style;
- (id<FullscreenToolbarContextDelegate>)delegate;
@end
// Private methods exposed for testing.
@interface FullscreenToolbarController (ExposedForTesting)
// Returns |animationController_|.
- (FullscreenToolbarAnimationController*)animationController;
// Allows tests to set a mock FullscreenMenubarTracker object.
- (void)setMenubarTracker:(FullscreenMenubarTracker*)tracker;
// Allows tests to set a mock FullscreenToolbarMouseTracker object.
- (void)setMouseTracker:(FullscreenToolbarMouseTracker*)tracker;
// Sets the value of |inFullscreenMode_|.
- (void)setTestFullscreenMode:(BOOL)isInFullscreen;
@end
#endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_CONTROLLER_H_
......@@ -6,28 +6,46 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/mac/scoped_nsobject.h"
#include "chrome/browser/profiles/profile.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"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.h"
#import "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
#include "ui/views/cocoa/native_widget_mac_ns_window_host.h"
@implementation FullscreenToolbarController
@implementation FullscreenToolbarController {
// Whether or not we are in fullscreen mode.
BOOL _inFullscreenMode;
- (id)initWithDelegate:(id<FullscreenToolbarContextDelegate>)delegate {
// Updates the fullscreen toolbar layout for changes in the menubar. This
// object is only set when the browser is in fullscreen mode.
base::scoped_nsobject<FullscreenMenubarTracker> _menubarTracker;
// Manages the toolbar animations for the TOOLBAR_HIDDEN style.
std::unique_ptr<FullscreenToolbarAnimationController> _animationController;
// When the menu bar and toolbar are visible, creates a tracking area which
// is used to keep them visible until the mouse moves far enough away from
// them. Only set when the browser is in fullscreen mode.
base::scoped_nsobject<FullscreenToolbarMouseTracker> _mouseTracker;
// The style of the fullscreen toolbar.
FullscreenToolbarStyle _toolbarStyle;
BrowserView* _browserView; // weak
}
- (id)initWithBrowserView:(BrowserView*)browserView {
if ((self = [super init])) {
_browserView = browserView;
_animationController =
std::make_unique<FullscreenToolbarAnimationController>(self);
_visibilityLockController.reset(
[[FullscreenToolbarVisibilityLockController alloc]
initWithFullscreenToolbarController:self
animationController:_animationController.get()]);
}
_delegate = delegate;
return self;
}
......@@ -101,9 +119,7 @@
if (_toolbarStyle == FullscreenToolbarStyle::TOOLBAR_NONE)
return NO;
FullscreenMenubarState menubarState = [_menubarTracker state];
return menubarState == FullscreenMenubarState::SHOWN ||
[_visibilityLockController isToolbarVisibilityLocked];
return [_menubarTracker state] == FullscreenMenubarState::SHOWN;
}
- (void)updateToolbarFrame:(NSRect)frame {
......@@ -112,6 +128,7 @@
}
- (void)layoutToolbar {
_browserView->Layout();
_animationController->ToolbarDidUpdate();
[_mouseTracker updateTrackingArea];
}
......@@ -124,36 +141,26 @@
return _menubarTracker.get();
}
- (FullscreenToolbarVisibilityLockController*)visibilityLockController {
return _visibilityLockController.get();
}
- (void)setToolbarStyle:(FullscreenToolbarStyle)style {
_toolbarStyle = style;
}
- (id<FullscreenToolbarContextDelegate>)delegate {
return _delegate;
}
@end
@implementation FullscreenToolbarController (ExposedForTesting)
- (FullscreenToolbarAnimationController*)animationController {
return _animationController.get();
}
- (void)setMenubarTracker:(FullscreenMenubarTracker*)tracker {
_menubarTracker.reset([tracker retain]);
- (BOOL)isInAnyFullscreenMode {
return _browserView->IsFullscreen();
}
- (void)setMouseTracker:(FullscreenToolbarMouseTracker*)tracker {
_mouseTracker.reset([tracker retain]);
- (BOOL)isFullscreenTransitionInProgress {
auto* host =
views::NativeWidgetMacNSWindowHost::GetFromNativeWindow([self window]);
if (auto* bridge = host->GetInProcessNSWindowBridge())
return bridge->in_fullscreen_transition();
DLOG(ERROR) << "TODO(https://crbug.com/915110): Support fullscreen "
"transitions for RemoteMacViews PWA windows.";
return false;
}
- (void)setTestFullscreenMode:(BOOL)isInFullscreen {
_inFullscreenMode = isInFullscreen;
- (NSWindow*)window {
return _browserView->GetNativeWindow().GetNativeNSWindow();
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_CONTROLLER_VIEWS_H_
#define CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_CONTROLLER_VIEWS_H_
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h"
#include "base/mac/scoped_nsobject.h"
@class BridgedContentView;
class BrowserView;
// Provides a controller to the fullscreen toolbar for a single Views based
// browser window.
@interface FullscreenToolbarControllerViews
: FullscreenToolbarController<FullscreenToolbarContextDelegate> {
@private
BrowserView* _browserView; // weak
// Since dealloc() may need to access the native view, we retain it here.
base::scoped_nsobject<BridgedContentView> _ns_view;
}
// Designated initializer.
- (id)initWithBrowserView:(BrowserView*)browserView;
// Updates the toolbar by updating the layout.
- (void)layoutToolbar;
@end
#endif //
CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_CONTROLLER_VIEWS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller_views.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
#include "ui/views/cocoa/native_widget_mac_ns_window_host.h"
@implementation FullscreenToolbarControllerViews
- (id)initWithBrowserView:(BrowserView*)browserView {
if ((self = [super initWithDelegate:self]))
_browserView = browserView;
return self;
}
- (void)layoutToolbar {
_browserView->Layout();
[super layoutToolbar];
}
- (BOOL)isInAnyFullscreenMode {
return _browserView->IsFullscreen();
}
- (BOOL)isFullscreenTransitionInProgress {
auto* host =
views::NativeWidgetMacNSWindowHost::GetFromNativeWindow([self window]);
if (auto* bridge = host->GetInProcessNSWindowBridge())
return bridge->in_fullscreen_transition();
DLOG(ERROR) << "TODO(https://crbug.com/915110): Support fullscreen "
"transitions for RemoteMacViews PWA windows.";
return false;
}
- (NSWindow*)window {
NSWindow* ns_window = _browserView->GetNativeWindow().GetNativeNSWindow();
if (!_ns_view) {
auto* host =
views::NativeWidgetMacNSWindowHost::GetFromNativeWindow(ns_window);
if (host) {
if (auto* bridge = host->GetInProcessNSWindowBridge())
_ns_view.reset([bridge->ns_view() retain]);
else
DLOG(ERROR) << "Cannot retain remote NSView.";
}
}
return ns_window;
}
@end
......@@ -70,7 +70,7 @@ const CGFloat kTrackingAreaAdditionalThreshold = 50;
[self removeTrackingArea];
}
_contentView = [[[_controller delegate] window] contentView];
_contentView = [[_controller window] contentView];
_trackingArea.reset([[CrTrackingArea alloc]
initWithRect:_trackingAreaFrame
......@@ -82,7 +82,7 @@ const CGFloat kTrackingAreaAdditionalThreshold = 50;
}
- (void)updateToolbarFrame:(NSRect)frame {
NSRect contentBounds = [[[[_controller delegate] window] contentView] bounds];
NSRect contentBounds = [[[_controller window] contentView] bounds];
_trackingAreaFrame = frame;
_trackingAreaFrame.origin.y -= kTrackingAreaAdditionalThreshold;
_trackingAreaFrame.size.height =
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_VISIBILITY_LOCK_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_VISIBILITY_LOCK_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
class FullscreenToolbarAnimationController;
@class FullscreenToolbarController;
// Various UI elements/events may want to ensure that the toolbar is visible in
// fullscreen mode. Whenever an object requires toolbar visibility, it locks
// it. When it no longer requires it, it releases it. This class manages the
// toolbar visibility locks.
@interface FullscreenToolbarVisibilityLockController : NSObject
// The designated initializer.
- (instancetype)
initWithFullscreenToolbarController:(FullscreenToolbarController*)controller
animationController:
(FullscreenToolbarAnimationController*)animationController;
// Returns true if the toolbar visibility is locked.
- (BOOL)isToolbarVisibilityLocked;
// Returns true if the toolbar visibility is locked by |owner|.
- (BOOL)isToolbarVisibilityLockedForOwner:(id)owner;
// Methods for locking and releasing the toolbar visibility. If |animate| is
// true, the toolbar will animate in/out.
- (void)lockToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate;
- (void)releaseToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate;
@end
#endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_FULLSCREEN_TOOLBAR_VISIBILITY_LOCK_CONTROLLER_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.h"
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_controller.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h"
@interface FullscreenToolbarVisibilityLockController () {
// Stores the objects that are locking the toolbar visibility.
base::scoped_nsobject<NSMutableSet> _visibilityLocks;
// Our owner.
FullscreenToolbarController* _owner; // weak
// The object managing the fullscreen toolbar's animations.
FullscreenToolbarAnimationController* _animationController; // weak
}
@end
@implementation FullscreenToolbarVisibilityLockController
- (instancetype)
initWithFullscreenToolbarController:(FullscreenToolbarController*)owner
animationController:
(FullscreenToolbarAnimationController*)animationController {
if ((self = [super init])) {
_animationController = animationController;
_owner = owner;
// Create the toolbar visibility lock set; 10 is arbitrary, but should
// hopefully be big enough to hold all locks that'll ever be needed.
_visibilityLocks.reset([[NSMutableSet setWithCapacity:10] retain]);
}
return self;
}
- (BOOL)isToolbarVisibilityLocked {
return [_visibilityLocks count];
}
- (BOOL)isToolbarVisibilityLockedForOwner:(id)owner {
return [_visibilityLocks containsObject:owner];
}
- (void)lockToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate {
if ([self isToolbarVisibilityLockedForOwner:owner])
return;
[_visibilityLocks addObject:owner];
if (animate)
_animationController->AnimateToolbarIn();
else
[_owner layoutToolbar];
}
- (void)releaseToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate {
if (![self isToolbarVisibilityLockedForOwner:owner])
return;
[_visibilityLocks removeObject:owner];
if (animate)
_animationController->AnimateToolbarOutIfPossible();
else
[_owner layoutToolbar];
}
@end
......@@ -16,7 +16,7 @@ namespace views {
class Label;
}
@class FullscreenToolbarControllerViews;
@class FullscreenToolbarController;
class BrowserNonClientFrameViewMac : public BrowserNonClientFrameView {
public:
......@@ -77,7 +77,7 @@ class BrowserNonClientFrameViewMac : public BrowserNonClientFrameView {
views::Label* window_title_ = nullptr;
base::scoped_nsobject<FullscreenToolbarControllerViews>
base::scoped_nsobject<FullscreenToolbarController>
fullscreen_toolbar_controller_;
DISALLOW_COPY_AND_ASSIGN(BrowserNonClientFrameViewMac);
......
......@@ -12,7 +12,7 @@
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h"
#include "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller_views.h"
#include "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/view_ids.h"
......@@ -61,8 +61,7 @@ BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac(
base::Unretained(this), true));
if (!base::FeatureList::IsEnabled(features::kImmersiveFullscreen)) {
fullscreen_toolbar_controller_.reset(
[[FullscreenToolbarControllerViews alloc]
initWithBrowserView:browser_view]);
[[FullscreenToolbarController alloc] initWithBrowserView:browser_view]);
[fullscreen_toolbar_controller_
setToolbarStyle:GetUserPreferredToolbarStyle(
*show_fullscreen_toolbar_)];
......
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