| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" |
| 6 | |
| 7 #include <algorithm> | |
| 8 | 6 |
| 9 #include "base/command_line.h" | 7 #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" | 8 #include "chrome/browser/profiles/profile.h" |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" | 10 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" |
| 15 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control
ler.h" | 11 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control
ler.h" |
| 16 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h" | 12 #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" | 13 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" |
| 18 #import "chrome/browser/ui/cocoa/fullscreen/immersive_fullscreen_controller.h" | 14 #import "chrome/browser/ui/cocoa/fullscreen/immersive_fullscreen_controller.h" |
| 19 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 21 #include "ui/base/cocoa/appkit_utils.h" | |
| 22 #import "ui/base/cocoa/nsview_additions.h" | |
| 23 | 17 |
| 24 namespace { | 18 namespace { |
| 25 | 19 |
| 26 // Visibility fractions for the menubar and toolbar. | 20 // Visibility fractions for the menubar and toolbar. |
| 27 const CGFloat kHideFraction = 0.0; | 21 const CGFloat kHideFraction = 0.0; |
| 28 const CGFloat kShowFraction = 1.0; | 22 const CGFloat kShowFraction = 1.0; |
| 29 | 23 |
| 30 // The amount by which the toolbar is offset downwards (to avoid the menu) | 24 // 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 | 25 // when the toolbar style is TOOLBAR_HIDDEN. (We can't use |
| 32 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) | 26 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) |
| 33 const CGFloat kToolbarVerticalOffset = 22; | 27 const CGFloat kToolbarVerticalOffset = -22; |
| 34 | 28 |
| 35 } // end namespace | 29 } // end namespace |
| 36 | 30 |
| 37 @implementation FullscreenToolbarController | 31 @implementation FullscreenToolbarController |
| 38 | 32 |
| 39 @synthesize toolbarStyle = toolbarStyle_; | |
| 40 | |
| 41 - (id)initWithBrowserController:(BrowserWindowController*)controller { | 33 - (id)initWithBrowserController:(BrowserWindowController*)controller { |
| 42 if ((self = [super init])) { | 34 if ((self = [super init])) { |
| 43 browserController_ = controller; | 35 browserController_ = controller; |
| 44 animationController_.reset(new FullscreenToolbarAnimationController(self)); | 36 animationController_.reset(new FullscreenToolbarAnimationController(self)); |
| 45 visibilityLockController_.reset( | 37 visibilityLockController_.reset( |
| 46 [[FullscreenToolbarVisibilityLockController alloc] | 38 [[FullscreenToolbarVisibilityLockController alloc] |
| 47 initWithFullscreenToolbarController:self | 39 initWithFullscreenToolbarController:self |
| 48 animationController:animationController_.get()]); | 40 animationController:animationController_.get()]); |
| 49 } | 41 } |
| 50 | 42 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 89 |
| 98 - (void)revealToolbarForTabStripChanges { | 90 - (void)revealToolbarForTabStripChanges { |
| 99 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 91 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 100 switches::kEnableFullscreenToolbarReveal)) { | 92 switches::kEnableFullscreenToolbarReveal)) { |
| 101 return; | 93 return; |
| 102 } | 94 } |
| 103 | 95 |
| 104 animationController_->AnimateToolbarForTabstripChanges(); | 96 animationController_->AnimateToolbarForTabstripChanges(); |
| 105 } | 97 } |
| 106 | 98 |
| 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 { | 99 - (CGFloat)toolbarFraction { |
| 161 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 100 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 162 return kHideFraction; | 101 return kHideFraction; |
| 163 | 102 |
| 164 switch (toolbarStyle_) { | 103 switch (toolbarStyle_) { |
| 165 case FullscreenToolbarStyle::TOOLBAR_PRESENT: | 104 case FullscreenToolbarStyle::TOOLBAR_PRESENT: |
| 166 return kShowFraction; | 105 return kShowFraction; |
| 167 case FullscreenToolbarStyle::TOOLBAR_NONE: | 106 case FullscreenToolbarStyle::TOOLBAR_NONE: |
| 168 return kHideFraction; | 107 return kHideFraction; |
| 169 case FullscreenToolbarStyle::TOOLBAR_HIDDEN: | 108 case FullscreenToolbarStyle::TOOLBAR_HIDDEN: |
| 170 if ([self mustShowFullscreenToolbar]) | 109 if ([self mustShowFullscreenToolbar]) |
| 171 return kShowFraction; | 110 return kShowFraction; |
| 172 | 111 |
| 173 if (animationController_->IsAnimationRunning()) | 112 if (animationController_->IsAnimationRunning()) |
| 174 return animationController_->GetToolbarFractionFromProgress(); | 113 return animationController_->GetToolbarFractionFromProgress(); |
| 175 | 114 |
| 176 return [menubarTracker_ menubarFraction]; | 115 return [menubarTracker_ menubarFraction]; |
| 177 } | 116 } |
| 178 } | 117 } |
| 179 | 118 |
| 119 - (FullscreenToolbarLayout)computeLayout { |
| 120 FullscreenToolbarLayout layout; |
| 121 layout.toolbarStyle = toolbarStyle_; |
| 122 layout.toolbarFraction = [self toolbarFraction]; |
| 123 |
| 124 if ([browserController_ isInAppKitFullscreen]) { |
| 125 layout.menubarOffset = [menubarTracker_ menubarFraction]; |
| 126 } else { |
| 127 layout.menubarOffset = |
| 128 [immersiveFullscreenController_ shouldShowMenubar] ? 1 : 0; |
| 129 } |
| 130 layout.menubarOffset *= kToolbarVerticalOffset; |
| 131 |
| 132 return layout; |
| 133 } |
| 134 |
| 180 - (BOOL)mustShowFullscreenToolbar { | 135 - (BOOL)mustShowFullscreenToolbar { |
| 181 if (!inFullscreenMode_) | 136 if (!inFullscreenMode_) |
| 182 return NO; | 137 return NO; |
| 183 | 138 |
| 184 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_PRESENT) | 139 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_PRESENT) |
| 185 return YES; | 140 return YES; |
| 186 | 141 |
| 187 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_NONE) | 142 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_NONE) |
| 188 return NO; | 143 return NO; |
| 189 | 144 |
| 190 FullscreenMenubarState menubarState = [menubarTracker_ state]; | 145 FullscreenMenubarState menubarState = [menubarTracker_ state]; |
| 191 return menubarState == FullscreenMenubarState::SHOWN || | 146 return menubarState == FullscreenMenubarState::SHOWN || |
| 192 [mouseTracker_ mouseInsideTrackingArea] || | 147 [mouseTracker_ mouseInsideTrackingArea] || |
| 193 [visibilityLockController_ isToolbarVisibilityLocked]; | 148 [visibilityLockController_ isToolbarVisibilityLocked]; |
| 194 } | 149 } |
| 195 | 150 |
| 196 - (BOOL)isInFullscreen { | |
| 197 return inFullscreenMode_; | |
| 198 } | |
| 199 | |
| 200 - (void)updateToolbarFrame:(NSRect)frame { | 151 - (void)updateToolbarFrame:(NSRect)frame { |
| 201 if (mouseTracker_.get()) | 152 if (mouseTracker_.get()) |
| 202 [mouseTracker_ updateToolbarFrame:frame]; | 153 [mouseTracker_ updateToolbarFrame:frame]; |
| 203 } | 154 } |
| 204 | 155 |
| 156 - (void)updateToolbarStyleExitingTabFullscreen:(BOOL)isExitingTabFullscreen { |
| 157 FullscreenToolbarStyle oldStyle = toolbarStyle_; |
| 158 |
| 159 if ([browserController_ isFullscreenForTabContentOrExtension] && |
| 160 !isExitingTabFullscreen) { |
| 161 toolbarStyle_ = FullscreenToolbarStyle::TOOLBAR_NONE; |
| 162 } else { |
| 163 PrefService* prefs = [browserController_ profile]->GetPrefs(); |
| 164 toolbarStyle_ = prefs->GetBoolean(prefs::kShowFullscreenToolbar) |
| 165 ? FullscreenToolbarStyle::TOOLBAR_PRESENT |
| 166 : FullscreenToolbarStyle::TOOLBAR_HIDDEN; |
| 167 } |
| 168 |
| 169 if (oldStyle != toolbarStyle_) |
| 170 [self updateToolbarLayout]; |
| 171 } |
| 172 |
| 173 - (void)updateToolbarLayout { |
| 174 [browserController_ layoutSubviews]; |
| 175 animationController_->ToolbarDidUpdate(); |
| 176 [mouseTracker_ updateTrackingArea]; |
| 177 } |
| 178 |
| 179 - (BOOL)isInFullscreen { |
| 180 return inFullscreenMode_; |
| 181 } |
| 182 |
| 183 - (BrowserWindowController*)browserWindowController { |
| 184 return browserController_; |
| 185 } |
| 186 |
| 187 - (FullscreenToolbarVisibilityLockController*)visibilityLockController { |
| 188 return visibilityLockController_.get(); |
| 189 } |
| 190 |
| 205 @end | 191 @end |
| 206 | |
| OLD | NEW |