Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/ui/cocoa/fullscreen_toolbar_controller.mm

Issue 2467833003: [Mac] Move the fullscreen toolbar style to FullscreenToolbarController (Closed)
Patch Set: Updated comments and fixed tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/mac/mac_util.h" 10 #import "base/mac/mac_util.h"
11 #include "base/mac/sdk_forward_declarations.h" 11 #include "base/mac/sdk_forward_declarations.h"
12 #include "chrome/browser/profiles/profile.h"
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
13 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" 14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h"
14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control ler.h" 15 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control ler.h"
15 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h" 16 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h"
16 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c ontroller.h" 17 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c ontroller.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h"
18 #include "ui/base/cocoa/appkit_utils.h" 20 #include "ui/base/cocoa/appkit_utils.h"
19 #import "ui/base/cocoa/nsview_additions.h" 21 #import "ui/base/cocoa/nsview_additions.h"
20 #import "ui/base/cocoa/tracking_area.h"
21 22
22 namespace { 23 namespace {
23 24
24 // Visibility fractions for the menubar and toolbar. 25 // Visibility fractions for the menubar and toolbar.
25 const CGFloat kHideFraction = 0.0; 26 const CGFloat kHideFraction = 0.0;
26 const CGFloat kShowFraction = 1.0; 27 const CGFloat kShowFraction = 1.0;
27 28
28 // The amount by which the toolbar is offset downwards (to avoid the menu) 29 // The amount by which the toolbar is offset downwards (to avoid the menu)
29 // when the toolbar style is OMNIBOX_TABS_HIDDEN. (We can't use 30 // when the toolbar style is TOOLBAR_HIDDEN. (We can't use
30 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) 31 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.)
31 const CGFloat kToolbarVerticalOffset = 22; 32 const CGFloat kToolbarVerticalOffset = 22;
32 33
33 } // end namespace 34 } // end namespace
34 35
35 @interface FullscreenToolbarController (PrivateMethods) 36 @interface FullscreenToolbarController (PrivateMethods)
36 37
37 // Updates the visibility of the menu bar and the dock. 38 // Updates the visibility of the menu bar and the dock.
38 - (void)updateMenuBarAndDockVisibility; 39 - (void)updateMenuBarAndDockVisibility;
39 40
(...skipping 12 matching lines...) Expand all
52 - (void)cleanup; 53 - (void)cleanup;
53 54
54 // Whether the menu bar should be shown in immersive fullscreen for the screen 55 // Whether the menu bar should be shown in immersive fullscreen for the screen
55 // that contains the window. 56 // that contains the window.
56 - (BOOL)shouldShowMenubarInImmersiveFullscreen; 57 - (BOOL)shouldShowMenubarInImmersiveFullscreen;
57 58
58 @end 59 @end
59 60
60 @implementation FullscreenToolbarController 61 @implementation FullscreenToolbarController
61 62
62 @synthesize slidingStyle = slidingStyle_; 63 @synthesize toolbarStyle = toolbarStyle_;
63 64
64 - (id)initWithBrowserController:(BrowserWindowController*)controller 65 - (id)initWithBrowserController:(BrowserWindowController*)controller {
65 style:(FullscreenSlidingStyle)style {
66 if ((self = [super init])) { 66 if ((self = [super init])) {
67 browserController_ = controller; 67 browserController_ = controller;
68 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 68 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
69 slidingStyle_ = style;
70 animationController_.reset(new FullscreenToolbarAnimationController(self)); 69 animationController_.reset(new FullscreenToolbarAnimationController(self));
71 visibilityLockController_.reset( 70 visibilityLockController_.reset(
72 [[FullscreenToolbarVisibilityLockController alloc] 71 [[FullscreenToolbarVisibilityLockController alloc]
73 initWithFullscreenToolbarController:self 72 initWithFullscreenToolbarController:self
74 animationController:animationController_.get()]); 73 animationController:animationController_.get()]);
75 } 74 }
76 75
77 return self; 76 return self;
78 } 77 }
79 78
80 - (void)dealloc { 79 - (void)dealloc {
81 DCHECK(!inFullscreenMode_); 80 DCHECK(!inFullscreenMode_);
81 browserController_ = nil;
82 [super dealloc]; 82 [super dealloc];
83 } 83 }
84 84
85 - (void)enterFullscreenMode { 85 - (void)enterFullscreenMode {
86 DCHECK(!inFullscreenMode_); 86 DCHECK(!inFullscreenMode_);
87 inFullscreenMode_ = YES; 87 inFullscreenMode_ = YES;
88 88
89 [self updateToolbarStyle];
90
89 menubarTracker_.reset([[FullscreenMenubarTracker alloc] 91 menubarTracker_.reset([[FullscreenMenubarTracker alloc]
90 initWithFullscreenToolbarController:self]); 92 initWithFullscreenToolbarController:self]);
91 mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc] 93 mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc]
92 initWithFullscreenToolbarController:self 94 initWithFullscreenToolbarController:self
93 animationController:animationController_.get()]); 95 animationController:animationController_.get()]);
94 96
95 [self updateMenuBarAndDockVisibility]; 97 [self updateMenuBarAndDockVisibility];
96 98
97 // Register for notifications. Self is removed as an observer in |-cleanup|. 99 // Register for notifications. Self is removed as an observer in |-cleanup|.
98 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 100 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
99 NSWindow* window = [browserController_ window]; 101 NSWindow* window = [browserController_ window];
100 102
101 [nc addObserver:self 103 [nc addObserver:self
102 selector:@selector(windowDidBecomeMain:) 104 selector:@selector(windowDidBecomeMain:)
103 name:NSWindowDidBecomeMainNotification 105 name:NSWindowDidBecomeMainNotification
104 object:window]; 106 object:window];
105 107
106 [nc addObserver:self 108 [nc addObserver:self
107 selector:@selector(windowDidResignMain:) 109 selector:@selector(windowDidResignMain:)
108 name:NSWindowDidResignMainNotification 110 name:NSWindowDidResignMainNotification
109 object:window]; 111 object:window];
110 } 112 }
111 113
112 - (void)exitFullscreenMode { 114 - (void)exitFullscreenMode {
113 DCHECK(inFullscreenMode_); 115 if (!inFullscreenMode_)
erikchen 2016/11/02 00:25:36 why the move away from DCHECK?
spqchan 2016/11/02 20:00:27 Whoops, this shouldn't be here. Thanks for catchin
116 return;
117
114 inFullscreenMode_ = NO; 118 inFullscreenMode_ = NO;
115 119
116 [self cleanup]; 120 [self cleanup];
117 } 121 }
118 122
119 - (void)windowDidChangeScreen:(NSNotification*)notification { 123 - (void)windowDidChangeScreen:(NSNotification*)notification {
120 [browserController_ resizeFullscreenWindow]; 124 [browserController_ resizeFullscreenWindow];
121 } 125 }
122 126
123 - (void)windowDidMove:(NSNotification*)notification { 127 - (void)windowDidMove:(NSNotification*)notification {
(...skipping 27 matching lines...) Expand all
151 return; 155 return;
152 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) 156 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal)
153 base::mac::RequestFullScreen(mode); 157 base::mac::RequestFullScreen(mode);
154 else if (mode == base::mac::kFullScreenModeNormal) 158 else if (mode == base::mac::kFullScreenModeNormal)
155 base::mac::ReleaseFullScreen(systemFullscreenMode_); 159 base::mac::ReleaseFullScreen(systemFullscreenMode_);
156 else 160 else
157 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); 161 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode);
158 systemFullscreenMode_ = mode; 162 systemFullscreenMode_ = mode;
159 } 163 }
160 164
165 - (void)updateToolbarStyle {
166 FullscreenToolbarStyle oldStyle = toolbarStyle_;
167
168 if ([browserController_ isFullscreenForTabContentOrExtension]) {
169 toolbarStyle_ = FullscreenToolbarStyle::TOOLBAR_NONE;
170 } else {
171 PrefService* prefs = [browserController_ profile]->GetPrefs();
172 toolbarStyle_ = prefs->GetBoolean(prefs::kShowFullscreenToolbar)
173 ? FullscreenToolbarStyle::TOOLBAR_PRESENT
174 : FullscreenToolbarStyle::TOOLBAR_HIDDEN;
175 }
176
177 if (oldStyle != toolbarStyle_)
178 [self updateToolbar];
179 }
180
161 - (void)updateToolbar { 181 - (void)updateToolbar {
162 [browserController_ layoutSubviews]; 182 [browserController_ layoutSubviews];
163 animationController_->ToolbarDidUpdate(); 183 animationController_->ToolbarDidUpdate();
164 [mouseTracker_ updateTrackingArea]; 184 [mouseTracker_ updateTrackingArea];
165 185
166 // In AppKit fullscreen, moving the mouse to the top of the screen toggles 186 // In AppKit fullscreen, moving the mouse to the top of the screen toggles
167 // menu visibility. Replicate the same effect for immersive fullscreen. 187 // menu visibility. Replicate the same effect for immersive fullscreen.
168 if ([browserController_ isInImmersiveFullscreen]) 188 if ([browserController_ isInImmersiveFullscreen])
169 [self updateMenuBarAndDockVisibility]; 189 [self updateMenuBarAndDockVisibility];
170 } 190 }
(...skipping 24 matching lines...) Expand all
195 } 215 }
196 216
197 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset 217 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset
198 : 0; 218 : 0;
199 } 219 }
200 220
201 - (CGFloat)toolbarFraction { 221 - (CGFloat)toolbarFraction {
202 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 222 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
203 return kHideFraction; 223 return kHideFraction;
204 224
205 switch (slidingStyle_) { 225 switch (toolbarStyle_) {
206 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: 226 case FullscreenToolbarStyle::TOOLBAR_PRESENT:
207 return kShowFraction; 227 return kShowFraction;
208 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: 228 case FullscreenToolbarStyle::TOOLBAR_NONE:
209 return kHideFraction; 229 return kHideFraction;
210 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: 230 case FullscreenToolbarStyle::TOOLBAR_HIDDEN:
211 if ([self mustShowFullscreenToolbar]) 231 if ([self mustShowFullscreenToolbar])
212 return kShowFraction; 232 return kShowFraction;
213 233
214 if (animationController_->IsAnimationRunning()) 234 if (animationController_->IsAnimationRunning())
215 return animationController_->GetToolbarFractionFromProgress(); 235 return animationController_->GetToolbarFractionFromProgress();
216 236
217 return [menubarTracker_ menubarFraction]; 237 return [menubarTracker_ menubarFraction];
218 } 238 }
219 } 239 }
220 240
221 - (BOOL)mustShowFullscreenToolbar { 241 - (BOOL)mustShowFullscreenToolbar {
222 if (!inFullscreenMode_) 242 if (!inFullscreenMode_)
223 return NO; 243 return NO;
224 244
225 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT) 245 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_PRESENT)
226 return YES; 246 return YES;
227 247
228 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_NONE) 248 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_NONE)
229 return NO; 249 return NO;
230 250
231 FullscreenMenubarState menubarState = [menubarTracker_ state]; 251 FullscreenMenubarState menubarState = [menubarTracker_ state];
232 return menubarState == FullscreenMenubarState::SHOWN || 252 return menubarState == FullscreenMenubarState::SHOWN ||
233 [mouseTracker_ mouseInsideTrackingArea] || 253 [mouseTracker_ mouseInsideTrackingArea] ||
234 [visibilityLockController_ isToolbarVisibilityLocked]; 254 [visibilityLockController_ isToolbarVisibilityLocked];
235 } 255 }
236 256
237 - (BOOL)isFullscreenTransitionInProgress { 257 - (BOOL)isFullscreenTransitionInProgress {
238 return [browserController_ isFullscreenTransitionInProgress]; 258 return [browserController_ isFullscreenTransitionInProgress];
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 animationController_->StopAnimationAndTimer(); 317 animationController_->StopAnimationAndTimer();
298 [[NSNotificationCenter defaultCenter] removeObserver:self]; 318 [[NSNotificationCenter defaultCenter] removeObserver:self];
299 319
300 // Call the main status resignation code to perform the associated cleanup, 320 // Call the main status resignation code to perform the associated cleanup,
301 // since we will no longer be receiving actual status resignation 321 // since we will no longer be receiving actual status resignation
302 // notifications. 322 // notifications.
303 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; 323 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal];
304 324
305 menubarTracker_.reset(); 325 menubarTracker_.reset();
306 mouseTracker_.reset(); 326 mouseTracker_.reset();
307
308 // No more calls back up to the BWC.
309 browserController_ = nil;
erikchen 2016/11/02 00:25:36 why did you get rid of this? It seems important.
spqchan 2016/11/02 20:00:27 I didn't get rid of it, I moved it into dealloc. S
310 } 327 }
311 328
312 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 329 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
313 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; 330 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99;
314 } 331 }
315 332
316 @end 333 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698