| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #import "base/mac/mac_util.h" | |
| 11 #include "base/mac/sdk_forward_declarations.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" | |
| 15 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control
ler.h" | |
| 16 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h" | |
| 17 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" | |
| 18 #import "chrome/browser/ui/cocoa/fullscreen/immersive_fullscreen_controller.h" | |
| 19 #include "chrome/common/chrome_switches.h" | |
| 20 #include "chrome/common/pref_names.h" | |
| 21 #include "ui/base/cocoa/appkit_utils.h" | |
| 22 #import "ui/base/cocoa/nsview_additions.h" | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 // Visibility fractions for the menubar and toolbar. | |
| 27 const CGFloat kHideFraction = 0.0; | |
| 28 const CGFloat kShowFraction = 1.0; | |
| 29 | |
| 30 // The amount by which the toolbar is offset downwards (to avoid the menu) | |
| 31 // when the toolbar style is TOOLBAR_HIDDEN. (We can't use | |
| 32 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) | |
| 33 const CGFloat kToolbarVerticalOffset = 22; | |
| 34 | |
| 35 } // end namespace | |
| 36 | |
| 37 @implementation FullscreenToolbarController | |
| 38 | |
| 39 @synthesize toolbarStyle = toolbarStyle_; | |
| 40 | |
| 41 - (id)initWithBrowserController:(BrowserWindowController*)controller { | |
| 42 if ((self = [super init])) { | |
| 43 browserController_ = controller; | |
| 44 animationController_.reset(new FullscreenToolbarAnimationController(self)); | |
| 45 visibilityLockController_.reset( | |
| 46 [[FullscreenToolbarVisibilityLockController alloc] | |
| 47 initWithFullscreenToolbarController:self | |
| 48 animationController:animationController_.get()]); | |
| 49 } | |
| 50 | |
| 51 return self; | |
| 52 } | |
| 53 | |
| 54 - (void)dealloc { | |
| 55 DCHECK(!inFullscreenMode_); | |
| 56 [super dealloc]; | |
| 57 } | |
| 58 | |
| 59 - (void)enterFullscreenMode { | |
| 60 DCHECK(!inFullscreenMode_); | |
| 61 inFullscreenMode_ = YES; | |
| 62 | |
| 63 [self updateToolbarStyleExitingTabFullscreen:NO]; | |
| 64 | |
| 65 if ([browserController_ isInImmersiveFullscreen]) { | |
| 66 immersiveFullscreenController_.reset([[ImmersiveFullscreenController alloc] | |
| 67 initWithBrowserController:browserController_]); | |
| 68 [immersiveFullscreenController_ updateMenuBarAndDockVisibility]; | |
| 69 } else { | |
| 70 menubarTracker_.reset([[FullscreenMenubarTracker alloc] | |
| 71 initWithFullscreenToolbarController:self]); | |
| 72 mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc] | |
| 73 initWithFullscreenToolbarController:self | |
| 74 animationController:animationController_.get()]); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 - (void)exitFullscreenMode { | |
| 79 DCHECK(inFullscreenMode_); | |
| 80 inFullscreenMode_ = NO; | |
| 81 | |
| 82 animationController_->StopAnimationAndTimer(); | |
| 83 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 84 | |
| 85 menubarTracker_.reset(); | |
| 86 mouseTracker_.reset(); | |
| 87 immersiveFullscreenController_.reset(); | |
| 88 | |
| 89 // No more calls back up to the BWC. | |
| 90 browserController_ = nil; | |
| 91 } | |
| 92 | |
| 93 // Cancels any running animation and timers. | |
| 94 - (void)cancelAnimationAndTimer { | |
| 95 animationController_->StopAnimationAndTimer(); | |
| 96 } | |
| 97 | |
| 98 - (void)revealToolbarForTabStripChanges { | |
| 99 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 100 switches::kEnableFullscreenToolbarReveal)) { | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 animationController_->AnimateToolbarForTabstripChanges(); | |
| 105 } | |
| 106 | |
| 107 - (void)updateToolbarStyleExitingTabFullscreen:(BOOL)isExitingTabFullscreen { | |
| 108 FullscreenToolbarStyle oldStyle = toolbarStyle_; | |
| 109 | |
| 110 if ([browserController_ isFullscreenForTabContentOrExtension] && | |
| 111 !isExitingTabFullscreen) { | |
| 112 toolbarStyle_ = FullscreenToolbarStyle::TOOLBAR_NONE; | |
| 113 } else { | |
| 114 PrefService* prefs = [browserController_ profile]->GetPrefs(); | |
| 115 toolbarStyle_ = prefs->GetBoolean(prefs::kShowFullscreenToolbar) | |
| 116 ? FullscreenToolbarStyle::TOOLBAR_PRESENT | |
| 117 : FullscreenToolbarStyle::TOOLBAR_HIDDEN; | |
| 118 } | |
| 119 | |
| 120 if (oldStyle != toolbarStyle_) | |
| 121 [self updateToolbar]; | |
| 122 } | |
| 123 | |
| 124 - (void)updateToolbar { | |
| 125 [browserController_ layoutSubviews]; | |
| 126 animationController_->ToolbarDidUpdate(); | |
| 127 [mouseTracker_ updateTrackingArea]; | |
| 128 } | |
| 129 | |
| 130 - (BrowserWindowController*)browserWindowController { | |
| 131 return browserController_; | |
| 132 } | |
| 133 | |
| 134 - (FullscreenToolbarVisibilityLockController*)visibilityLockController { | |
| 135 return visibilityLockController_.get(); | |
| 136 } | |
| 137 | |
| 138 // This method works, but is fragile. | |
| 139 // | |
| 140 // It gets used during view layout, which sometimes needs to be done at the | |
| 141 // beginning of an animation. As such, this method needs to reflect the | |
| 142 // menubarOffset expected at the end of the animation. This information is not | |
| 143 // readily available. (The layout logic needs a refactor). | |
| 144 // | |
| 145 // For AppKit Fullscreen, the menubar always starts hidden, and | |
| 146 // menubarFraction_ always starts at 0, so the logic happens to work. For | |
| 147 // Immersive Fullscreen, this class controls the visibility of the menu bar, so | |
| 148 // the logic is correct and not fragile. | |
| 149 - (CGFloat)menubarOffset { | |
| 150 if ([browserController_ isInAppKitFullscreen]) { | |
| 151 return -std::floor([menubarTracker_ menubarFraction] * | |
| 152 kToolbarVerticalOffset); | |
| 153 } | |
| 154 | |
| 155 return [immersiveFullscreenController_ shouldShowMenubar] | |
| 156 ? -kToolbarVerticalOffset | |
| 157 : 0; | |
| 158 } | |
| 159 | |
| 160 - (CGFloat)toolbarFraction { | |
| 161 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | |
| 162 return kHideFraction; | |
| 163 | |
| 164 switch (toolbarStyle_) { | |
| 165 case FullscreenToolbarStyle::TOOLBAR_PRESENT: | |
| 166 return kShowFraction; | |
| 167 case FullscreenToolbarStyle::TOOLBAR_NONE: | |
| 168 return kHideFraction; | |
| 169 case FullscreenToolbarStyle::TOOLBAR_HIDDEN: | |
| 170 if ([self mustShowFullscreenToolbar]) | |
| 171 return kShowFraction; | |
| 172 | |
| 173 if (animationController_->IsAnimationRunning()) | |
| 174 return animationController_->GetToolbarFractionFromProgress(); | |
| 175 | |
| 176 return [menubarTracker_ menubarFraction]; | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 - (BOOL)mustShowFullscreenToolbar { | |
| 181 if (!inFullscreenMode_) | |
| 182 return NO; | |
| 183 | |
| 184 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_PRESENT) | |
| 185 return YES; | |
| 186 | |
| 187 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_NONE) | |
| 188 return NO; | |
| 189 | |
| 190 FullscreenMenubarState menubarState = [menubarTracker_ state]; | |
| 191 return menubarState == FullscreenMenubarState::SHOWN || | |
| 192 [mouseTracker_ mouseInsideTrackingArea] || | |
| 193 [visibilityLockController_ isToolbarVisibilityLocked]; | |
| 194 } | |
| 195 | |
| 196 - (BOOL)isInFullscreen { | |
| 197 return inFullscreenMode_; | |
| 198 } | |
| 199 | |
| 200 - (void)updateToolbarFrame:(NSRect)frame { | |
| 201 if (mouseTracker_.get()) | |
| 202 [mouseTracker_ updateToolbarFrame:frame]; | |
| 203 } | |
| 204 | |
| 205 @end | |
| 206 | |
| OLD | NEW |