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

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: fix for rsesek 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
« no previous file with comments | « chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_);
82 [super dealloc]; 81 [super dealloc];
83 } 82 }
84 83
85 - (void)enterFullscreenMode { 84 - (void)enterFullscreenMode {
86 DCHECK(!inFullscreenMode_); 85 DCHECK(!inFullscreenMode_);
87 inFullscreenMode_ = YES; 86 inFullscreenMode_ = YES;
88 87
88 [self updateToolbarStyle];
89
89 menubarTracker_.reset([[FullscreenMenubarTracker alloc] 90 menubarTracker_.reset([[FullscreenMenubarTracker alloc]
90 initWithFullscreenToolbarController:self]); 91 initWithFullscreenToolbarController:self]);
91 mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc] 92 mouseTracker_.reset([[FullscreenToolbarMouseTracker alloc]
92 initWithFullscreenToolbarController:self 93 initWithFullscreenToolbarController:self
93 animationController:animationController_.get()]); 94 animationController:animationController_.get()]);
94 95
95 [self updateMenuBarAndDockVisibility]; 96 [self updateMenuBarAndDockVisibility];
96 97
97 // Register for notifications. Self is removed as an observer in |-cleanup|. 98 // Register for notifications. Self is removed as an observer in |-cleanup|.
98 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 99 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
99 NSWindow* window = [browserController_ window]; 100 NSWindow* window = [browserController_ window];
100 101
101 [nc addObserver:self 102 [nc addObserver:self
102 selector:@selector(windowDidBecomeMain:) 103 selector:@selector(windowDidBecomeMain:)
103 name:NSWindowDidBecomeMainNotification 104 name:NSWindowDidBecomeMainNotification
104 object:window]; 105 object:window];
105 106
106 [nc addObserver:self 107 [nc addObserver:self
107 selector:@selector(windowDidResignMain:) 108 selector:@selector(windowDidResignMain:)
108 name:NSWindowDidResignMainNotification 109 name:NSWindowDidResignMainNotification
109 object:window]; 110 object:window];
110 } 111 }
111 112
112 - (void)exitFullscreenMode { 113 - (void)exitFullscreenMode {
113 DCHECK(inFullscreenMode_); 114 DCHECK(inFullscreenMode_);
114 inFullscreenMode_ = NO; 115 inFullscreenMode_ = NO;
115
116 [self cleanup]; 116 [self cleanup];
117 } 117 }
118 118
119 - (void)windowDidChangeScreen:(NSNotification*)notification { 119 - (void)windowDidChangeScreen:(NSNotification*)notification {
120 [browserController_ resizeFullscreenWindow]; 120 [browserController_ resizeFullscreenWindow];
121 } 121 }
122 122
123 - (void)windowDidMove:(NSNotification*)notification { 123 - (void)windowDidMove:(NSNotification*)notification {
124 [browserController_ resizeFullscreenWindow]; 124 [browserController_ resizeFullscreenWindow];
125 } 125 }
(...skipping 25 matching lines...) Expand all
151 return; 151 return;
152 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal) 152 if (systemFullscreenMode_ == base::mac::kFullScreenModeNormal)
153 base::mac::RequestFullScreen(mode); 153 base::mac::RequestFullScreen(mode);
154 else if (mode == base::mac::kFullScreenModeNormal) 154 else if (mode == base::mac::kFullScreenModeNormal)
155 base::mac::ReleaseFullScreen(systemFullscreenMode_); 155 base::mac::ReleaseFullScreen(systemFullscreenMode_);
156 else 156 else
157 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode); 157 base::mac::SwitchFullScreenModes(systemFullscreenMode_, mode);
158 systemFullscreenMode_ = mode; 158 systemFullscreenMode_ = mode;
159 } 159 }
160 160
161 - (void)updateToolbarStyle {
162 FullscreenToolbarStyle oldStyle = toolbarStyle_;
163
164 if ([browserController_ isFullscreenForTabContentOrExtension]) {
165 toolbarStyle_ = FullscreenToolbarStyle::TOOLBAR_NONE;
166 } else {
167 PrefService* prefs = [browserController_ profile]->GetPrefs();
168 toolbarStyle_ = prefs->GetBoolean(prefs::kShowFullscreenToolbar)
169 ? FullscreenToolbarStyle::TOOLBAR_PRESENT
170 : FullscreenToolbarStyle::TOOLBAR_HIDDEN;
171 }
172
173 if (oldStyle != toolbarStyle_)
174 [self updateToolbar];
175 }
176
161 - (void)updateToolbar { 177 - (void)updateToolbar {
162 [browserController_ layoutSubviews]; 178 [browserController_ layoutSubviews];
163 animationController_->ToolbarDidUpdate(); 179 animationController_->ToolbarDidUpdate();
164 [mouseTracker_ updateTrackingArea]; 180 [mouseTracker_ updateTrackingArea];
165 181
166 // In AppKit fullscreen, moving the mouse to the top of the screen toggles 182 // In AppKit fullscreen, moving the mouse to the top of the screen toggles
167 // menu visibility. Replicate the same effect for immersive fullscreen. 183 // menu visibility. Replicate the same effect for immersive fullscreen.
168 if ([browserController_ isInImmersiveFullscreen]) 184 if ([browserController_ isInImmersiveFullscreen])
169 [self updateMenuBarAndDockVisibility]; 185 [self updateMenuBarAndDockVisibility];
170 } 186 }
(...skipping 24 matching lines...) Expand all
195 } 211 }
196 212
197 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset 213 return [self shouldShowMenubarInImmersiveFullscreen] ? -kToolbarVerticalOffset
198 : 0; 214 : 0;
199 } 215 }
200 216
201 - (CGFloat)toolbarFraction { 217 - (CGFloat)toolbarFraction {
202 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 218 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
203 return kHideFraction; 219 return kHideFraction;
204 220
205 switch (slidingStyle_) { 221 switch (toolbarStyle_) {
206 case FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT: 222 case FullscreenToolbarStyle::TOOLBAR_PRESENT:
207 return kShowFraction; 223 return kShowFraction;
208 case FullscreenSlidingStyle::OMNIBOX_TABS_NONE: 224 case FullscreenToolbarStyle::TOOLBAR_NONE:
209 return kHideFraction; 225 return kHideFraction;
210 case FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN: 226 case FullscreenToolbarStyle::TOOLBAR_HIDDEN:
211 if ([self mustShowFullscreenToolbar]) 227 if ([self mustShowFullscreenToolbar])
212 return kShowFraction; 228 return kShowFraction;
213 229
214 if (animationController_->IsAnimationRunning()) 230 if (animationController_->IsAnimationRunning())
215 return animationController_->GetToolbarFractionFromProgress(); 231 return animationController_->GetToolbarFractionFromProgress();
216 232
217 return [menubarTracker_ menubarFraction]; 233 return [menubarTracker_ menubarFraction];
218 } 234 }
219 } 235 }
220 236
221 - (BOOL)mustShowFullscreenToolbar { 237 - (BOOL)mustShowFullscreenToolbar {
222 if (!inFullscreenMode_) 238 if (!inFullscreenMode_)
223 return NO; 239 return NO;
224 240
225 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT) 241 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_PRESENT)
226 return YES; 242 return YES;
227 243
228 if (slidingStyle_ == FullscreenSlidingStyle::OMNIBOX_TABS_NONE) 244 if (toolbarStyle_ == FullscreenToolbarStyle::TOOLBAR_NONE)
229 return NO; 245 return NO;
230 246
231 FullscreenMenubarState menubarState = [menubarTracker_ state]; 247 FullscreenMenubarState menubarState = [menubarTracker_ state];
232 return menubarState == FullscreenMenubarState::SHOWN || 248 return menubarState == FullscreenMenubarState::SHOWN ||
233 [mouseTracker_ mouseInsideTrackingArea] || 249 [mouseTracker_ mouseInsideTrackingArea] ||
234 [visibilityLockController_ isToolbarVisibilityLocked]; 250 [visibilityLockController_ isToolbarVisibilityLocked];
235 } 251 }
236 252
237 - (BOOL)isFullscreenTransitionInProgress { 253 - (BOOL)isFullscreenTransitionInProgress {
238 return [browserController_ isFullscreenTransitionInProgress]; 254 return [browserController_ isFullscreenTransitionInProgress];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 311
296 - (void)cleanup { 312 - (void)cleanup {
297 animationController_->StopAnimationAndTimer(); 313 animationController_->StopAnimationAndTimer();
298 [[NSNotificationCenter defaultCenter] removeObserver:self]; 314 [[NSNotificationCenter defaultCenter] removeObserver:self];
299 315
300 // Call the main status resignation code to perform the associated cleanup, 316 // Call the main status resignation code to perform the associated cleanup,
301 // since we will no longer be receiving actual status resignation 317 // since we will no longer be receiving actual status resignation
302 // notifications. 318 // notifications.
303 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal]; 319 [self setSystemFullscreenModeTo:base::mac::kFullScreenModeNormal];
304 320
321 // No more calls back up to the BWC.
322 browserController_ = nil;
323
305 menubarTracker_.reset(); 324 menubarTracker_.reset();
306 mouseTracker_.reset(); 325 mouseTracker_.reset();
307
308 // No more calls back up to the BWC.
309 browserController_ = nil;
310 } 326 }
311 327
312 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 328 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
313 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99; 329 return [self doesScreenHaveMenuBar] && [self toolbarFraction] > 0.99;
314 } 330 }
315 331
316 @end 332 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698