1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
// Copyright 2016 The Chromium Authors
// 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.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.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/views/frame/browser_view.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/gfx/native_widget_types.h"
#include "ui/views/cocoa/native_widget_mac_ns_window_host.h"
@implementation FullscreenToolbarController {
// 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.
FullscreenMenubarTracker* __strong _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.
FullscreenToolbarMouseTracker* __strong _mouseTracker;
// The style of the fullscreen toolbar.
FullscreenToolbarStyle _toolbarStyle;
raw_ptr<BrowserView> _browserView; // weak
}
- (instancetype)initWithBrowserView:(BrowserView*)browserView {
if ((self = [super init])) {
_browserView = browserView;
_animationController =
std::make_unique<FullscreenToolbarAnimationController>(self);
}
return self;
}
- (void)dealloc {
DCHECK(!_inFullscreenMode);
}
- (void)enterFullscreenMode {
if (_inFullscreenMode) {
return;
}
_inFullscreenMode = YES;
_menubarTracker = [[FullscreenMenubarTracker alloc]
initWithFullscreenToolbarController:self];
_mouseTracker = [[FullscreenToolbarMouseTracker alloc]
initWithFullscreenToolbarController:self];
}
- (void)exitFullscreenMode {
if (!_inFullscreenMode) {
return;
}
_inFullscreenMode = NO;
_animationController->StopAnimationAndTimer();
[[NSNotificationCenter defaultCenter] removeObserver:self];
_menubarTracker = nil;
_mouseTracker = nil;
}
- (void)revealToolbarForWebContents:(content::WebContents*)contents
inForeground:(BOOL)inForeground {
_animationController->AnimateToolbarForTabstripChanges(contents,
inForeground);
}
- (CGFloat)toolbarFraction {
// Visibility fractions for the menubar and toolbar.
constexpr CGFloat kHideFraction = 0.0;
constexpr CGFloat kShowFraction = 1.0;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) {
return kHideFraction;
}
switch (_toolbarStyle) {
case FullscreenToolbarStyle::TOOLBAR_PRESENT:
return kShowFraction;
case FullscreenToolbarStyle::TOOLBAR_NONE:
return kHideFraction;
case FullscreenToolbarStyle::TOOLBAR_HIDDEN:
if (_animationController->IsAnimationRunning()) {
return _animationController->GetToolbarFractionFromProgress();
}
if ([self mustShowFullscreenToolbar]) {
return kShowFraction;
}
return [_menubarTracker menubarFraction];
}
}
- (FullscreenToolbarStyle)toolbarStyle {
return _toolbarStyle;
}
- (BOOL)mustShowFullscreenToolbar {
if (!_inFullscreenMode) {
return NO;
}
if (_toolbarStyle == FullscreenToolbarStyle::TOOLBAR_PRESENT) {
return YES;
}
if (_toolbarStyle == FullscreenToolbarStyle::TOOLBAR_NONE) {
return NO;
}
return [_menubarTracker state] == FullscreenMenubarState::SHOWN;
}
- (void)updateToolbarFrame:(NSRect)frame {
if (_mouseTracker) {
[_mouseTracker updateToolbarFrame:frame];
}
}
- (void)layoutToolbar {
_browserView->DeprecatedLayoutImmediately();
_animationController->ToolbarDidUpdate();
[_mouseTracker updateTrackingArea];
}
- (BOOL)isInFullscreen {
return _inFullscreenMode;
}
- (FullscreenMenubarTracker*)menubarTracker {
return _menubarTracker;
}
- (void)setToolbarStyle:(FullscreenToolbarStyle)style {
_toolbarStyle = style;
}
- (BOOL)isInAnyFullscreenMode {
return _browserView->IsFullscreen();
}
- (BOOL)isFullscreenTransitionInProgress {
auto* host = views::NativeWidgetMacNSWindowHost::GetFromNativeWindow(
gfx::NativeWindow([self window]));
if (auto* bridge = host->GetInProcessNSWindowBridge()) {
return bridge->in_fullscreen_transition();
}
DLOG(ERROR) << "TODO(crbug.com/41431787): Support fullscreen "
"transitions for RemoteMacViews PWA windows.";
return false;
}
- (NSWindow*)window {
return _browserView->GetNativeWindow().GetNativeNSWindow();
}
@end
|