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

Side by Side Diff: chrome/browser/cocoa/browser_window_controller_private.mm

Issue 747001: Mac: fix fullscreen floating bar in popup windows. (Closed)
Patch Set: changes per review Created 10 years, 9 months 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cocoa/browser_window_controller_private.h" 5 #import "chrome/browser/cocoa/browser_window_controller_private.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #import "base/scoped_nsobject.h" 8 #import "base/scoped_nsobject.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 NSRect contentBounds = [contentView bounds]; 133 NSRect contentBounds = [contentView bounds];
134 CGFloat minY = NSMinY(contentBounds); 134 CGFloat minY = NSMinY(contentBounds);
135 CGFloat width = NSWidth(contentBounds); 135 CGFloat width = NSWidth(contentBounds);
136 136
137 // Suppress title drawing if necessary. 137 // Suppress title drawing if necessary.
138 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) 138 if ([window respondsToSelector:@selector(setShouldHideTitle:)])
139 [(id)window setShouldHideTitle:![self hasTitleBar]]; 139 [(id)window setShouldHideTitle:![self hasTitleBar]];
140 140
141 BOOL isFullscreen = [self isFullscreen]; 141 BOOL isFullscreen = [self isFullscreen];
142 CGFloat floatingBarHeight = [self floatingBarHeight]; 142 CGFloat floatingBarHeight = [self floatingBarHeight];
143 CGFloat yOffset = floor( 143 // In fullscreen mode, |yOffset| accounts for the sliding position of the
144 isFullscreen ? (1 - floatingBarShownFraction_) * floatingBarHeight : 0); 144 // floating bar and the extra offset needed to dodge the menu bar.
145 CGFloat yOffset = isFullscreen ?
146 (floor((1 - floatingBarShownFraction_) * floatingBarHeight) -
147 [fullscreenController_ floatingBarVerticalOffset]) : 0;
145 CGFloat maxY = NSMaxY(contentBounds) + yOffset; 148 CGFloat maxY = NSMaxY(contentBounds) + yOffset;
146 CGFloat startMaxY = maxY; 149 CGFloat startMaxY = maxY;
147 150
148 if ([self hasTabStrip]) { 151 if ([self hasTabStrip]) {
149 // If we need to lay out the tab strip, replace |maxY| and |startMaxY| with 152 // If we need to lay out the tab strip, replace |maxY| and |startMaxY| with
150 // higher values, and then lay out the tab strip. 153 // higher values, and then lay out the tab strip.
151 startMaxY = maxY = NSHeight([window frame]) + yOffset; 154 startMaxY = maxY = NSHeight([window frame]) + yOffset;
152 maxY = [self layoutTabStripAtMaxY:maxY width:width fullscreen:isFullscreen]; 155 maxY = [self layoutTabStripAtMaxY:maxY width:width fullscreen:isFullscreen];
153 } 156 }
154 157
155 // Sanity-check |maxY|. 158 // Sanity-check |maxY|.
156 DCHECK_GE(maxY, minY); 159 DCHECK_GE(maxY, minY);
157 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset); 160 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset);
158 161
159 // Place the toolbar at the top of the reserved area. 162 // Place the toolbar at the top of the reserved area.
160 maxY = [self layoutToolbarAtMaxY:maxY width:width]; 163 maxY = [self layoutToolbarAtMaxY:maxY width:width];
161 164
162 // If we're not displaying the bookmark bar below the infobar, then it goes 165 // If we're not displaying the bookmark bar below the infobar, then it goes
163 // immediately below the toolbar. 166 // immediately below the toolbar.
164 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; 167 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar];
165 if (!placeBookmarkBarBelowInfoBar) 168 if (!placeBookmarkBarBelowInfoBar)
166 maxY = [self layoutBookmarkBarAtMaxY:maxY width:width]; 169 maxY = [self layoutBookmarkBarAtMaxY:maxY width:width];
167 170
168 // The floating bar backing view doesn't actually add any height. 171 // The floating bar backing view doesn't actually add any height.
169 [self layoutFloatingBarBackingViewAtY:maxY 172 [self layoutFloatingBarBackingViewAtY:maxY
170 width:width 173 width:width
171 height:floatingBarHeight 174 height:floatingBarHeight
172 fullscreen:isFullscreen]; 175 fullscreen:isFullscreen];
173 176
174 [fullscreenController_ overlayFrameChanged:[floatingBarBackingView_ frame]];
175
176 // Place the find bar immediately below the toolbar/attached bookmark bar. In 177 // Place the find bar immediately below the toolbar/attached bookmark bar. In
177 // fullscreen mode, it hangs off the top of the screen when the bar is hidden. 178 // fullscreen mode, it hangs off the top of the screen when the bar is hidden.
178 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width]; 179 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width];
179 180
180 // If in fullscreen mode, reset |maxY| to top of screen, so that the floating 181 // If in fullscreen mode, reset |maxY| to top of screen, so that the floating
181 // bar slides over the things which appear to be in the content area. 182 // bar slides over the things which appear to be in the content area.
182 if (isFullscreen) 183 if (isFullscreen)
183 maxY = NSMaxY(contentBounds); 184 maxY = NSMaxY(contentBounds);
184 185
185 // Also place the infobar container immediate below the toolbar, except in 186 // Also place the infobar container immediate below the toolbar, except in
(...skipping 16 matching lines...) Expand all
202 // Normally, we don't need to tell the toolbar whether or not to show the 203 // Normally, we don't need to tell the toolbar whether or not to show the
203 // divider, but things break down during animation. 204 // divider, but things break down during animation.
204 [toolbarController_ 205 [toolbarController_
205 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 206 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
206 } 207 }
207 208
208 - (CGFloat)floatingBarHeight { 209 - (CGFloat)floatingBarHeight {
209 if (![self isFullscreen]) 210 if (![self isFullscreen])
210 return 0; 211 return 0;
211 212
212 CGFloat totalHeight = [fullscreenController_ tabStripVerticalOffset]; 213 CGFloat totalHeight = [fullscreenController_ floatingBarVerticalOffset];
213 214
214 if ([self hasTabStrip]) 215 if ([self hasTabStrip])
215 totalHeight += NSHeight([[self tabStripView] frame]); 216 totalHeight += NSHeight([[self tabStripView] frame]);
216 217
217 if ([self hasToolbar]) { 218 if ([self hasToolbar]) {
218 totalHeight += NSHeight([[toolbarController_ view] frame]); 219 totalHeight += NSHeight([[toolbarController_ view] frame]);
219 } else if ([self hasLocationBar]) { 220 } else if ([self hasLocationBar]) {
220 totalHeight += NSHeight([[toolbarController_ view] frame]) + 221 totalHeight += NSHeight([[toolbarController_ view] frame]) +
221 kLocBarTopInset + kLocBarBottomInset; 222 kLocBarTopInset + kLocBarBottomInset;
222 } 223 }
223 224
224 if (![self placeBookmarkBarBelowInfoBar]) 225 if (![self placeBookmarkBarBelowInfoBar])
225 totalHeight += NSHeight([[bookmarkBarController_ view] frame]); 226 totalHeight += NSHeight([[bookmarkBarController_ view] frame]);
226 227
227 return totalHeight; 228 return totalHeight;
228 } 229 }
229 230
230 - (CGFloat)layoutTabStripAtMaxY:(CGFloat)maxY 231 - (CGFloat)layoutTabStripAtMaxY:(CGFloat)maxY
231 width:(CGFloat)width 232 width:(CGFloat)width
232 fullscreen:(BOOL)fullscreen { 233 fullscreen:(BOOL)fullscreen {
233 // Nothing to do if no tab strip. 234 // Nothing to do if no tab strip.
234 if (![self hasTabStrip]) 235 if (![self hasTabStrip])
235 return maxY; 236 return maxY;
236 237
237 NSView* tabStripView = [self tabStripView]; 238 NSView* tabStripView = [self tabStripView];
238 CGFloat tabStripHeight = NSHeight([tabStripView frame]); 239 CGFloat tabStripHeight = NSHeight([tabStripView frame]);
239 // In fullscreen mode, push the tab strip down so that the main menu (which
240 // also slides down) doesn't run it over.
241 if (fullscreen)
242 maxY -= [fullscreenController_ tabStripVerticalOffset];
243 maxY -= tabStripHeight; 240 maxY -= tabStripHeight;
244 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)]; 241 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)];
245 242
246 // Set indentation. 243 // Set indentation.
247 [tabStripController_ setIndentForControls:(fullscreen ? 0 : 244 [tabStripController_ setIndentForControls:(fullscreen ? 0 :
248 [[tabStripController_ class] defaultIndentForControls])]; 245 [[tabStripController_ class] defaultIndentForControls])];
249 246
250 // TODO(viettrungluu): Seems kind of bad -- shouldn't |-layoutSubviews| do 247 // TODO(viettrungluu): Seems kind of bad -- shouldn't |-layoutSubviews| do
251 // this? Moreover, |-layoutTabs| will try to animate.... 248 // this? Moreover, |-layoutTabs| will try to animate....
252 [tabStripController_ layoutTabs]; 249 [tabStripController_ layoutTabs];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 317
321 return maxY; 318 return maxY;
322 } 319 }
323 320
324 - (void)layoutFloatingBarBackingViewAtY:(CGFloat)y 321 - (void)layoutFloatingBarBackingViewAtY:(CGFloat)y
325 width:(CGFloat)width 322 width:(CGFloat)width
326 height:(CGFloat)height 323 height:(CGFloat)height
327 fullscreen:(BOOL)fullscreen { 324 fullscreen:(BOOL)fullscreen {
328 // Only display when in fullscreen mode. 325 // Only display when in fullscreen mode.
329 if (fullscreen) { 326 if (fullscreen) {
330 DCHECK(floatingBarBackingView_.get()); 327 // For certain window types such as app windows (e.g., the dev tools
331 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar]; 328 // window), there's no actual overlay. (Displaying one would result in an
329 // overly sliding in only under the menu, which gives an ugly effect.)
330 NSRect frame = NSMakeRect(0, y, width, height);
331 if (floatingBarBackingView_.get()) {
332 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar];
332 333
333 // Insert it into the view hierarchy if necessary. 334 // Insert it into the view hierarchy if necessary.
334 if (![floatingBarBackingView_ superview] || 335 if (![floatingBarBackingView_ superview] ||
335 aboveBookmarkBar != floatingBarAboveBookmarkBar_) { 336 aboveBookmarkBar != floatingBarAboveBookmarkBar_) {
336 NSView* contentView = [[self window] contentView]; 337 NSView* contentView = [[self window] contentView];
337 // z-order gets messed up unless we explicitly remove the floatingbar view 338 // z-order gets messed up unless we explicitly remove the floatingbar
338 // and re-add it. 339 // view and re-add it.
339 [floatingBarBackingView_ removeFromSuperview]; 340 [floatingBarBackingView_ removeFromSuperview];
340 [contentView addSubview:floatingBarBackingView_ 341 [contentView addSubview:floatingBarBackingView_
341 positioned:(aboveBookmarkBar ? 342 positioned:(aboveBookmarkBar ?
342 NSWindowAbove : NSWindowBelow) 343 NSWindowAbove : NSWindowBelow)
343 relativeTo:[bookmarkBarController_ view]]; 344 relativeTo:[bookmarkBarController_ view]];
344 floatingBarAboveBookmarkBar_ = aboveBookmarkBar; 345 floatingBarAboveBookmarkBar_ = aboveBookmarkBar;
346 }
347
348 // Set its frame.
349 [floatingBarBackingView_ setFrame:frame];
345 } 350 }
346 351
347 // Set its frame. 352 // But we want the logic to work as usual (for show/hide/etc. purposes).
348 [floatingBarBackingView_ setFrame:NSMakeRect(0, y, width, height)]; 353 [fullscreenController_ overlayFrameChanged:frame];
349 } else { 354 } else {
350 // Okay to call even if |floatingBarBackingView_| is nil. 355 // Okay to call even if |floatingBarBackingView_| is nil.
351 if ([floatingBarBackingView_ superview]) 356 if ([floatingBarBackingView_ superview])
352 [floatingBarBackingView_ removeFromSuperview]; 357 [floatingBarBackingView_ removeFromSuperview];
353 } 358 }
354 } 359 }
355 360
356 - (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width { 361 - (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width {
357 NSView* infoBarView = [infoBarContainerController_ view]; 362 NSView* infoBarView = [infoBarContainerController_ view];
358 NSRect infoBarFrame = [infoBarView frame]; 363 NSRect infoBarFrame = [infoBarView frame];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 [[toolbarController_ view] setFrame:toolbarFrame]; 429 [[toolbarController_ view] setFrame:toolbarFrame];
425 [[bookmarkBarController_ view] setFrame:bookmarkFrame]; 430 [[bookmarkBarController_ view] setFrame:bookmarkFrame];
426 [self layoutSubviews]; 431 [self layoutSubviews];
427 } 432 }
428 433
429 // TODO(rohitrao): This function has shrunk into uselessness, and 434 // TODO(rohitrao): This function has shrunk into uselessness, and
430 // |-setFullscreen:| has grown rather large. Find a good way to break up 435 // |-setFullscreen:| has grown rather large. Find a good way to break up
431 // |-setFullscreen:| into smaller pieces. http://crbug.com/36449 436 // |-setFullscreen:| into smaller pieces. http://crbug.com/36449
432 - (void)adjustUIForFullscreen:(BOOL)fullscreen { 437 - (void)adjustUIForFullscreen:(BOOL)fullscreen {
433 // Create the floating bar backing view if necessary. 438 // Create the floating bar backing view if necessary.
434 if (fullscreen && !floatingBarBackingView_.get()) { 439 if (fullscreen && !floatingBarBackingView_.get() &&
440 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) {
435 floatingBarBackingView_.reset( 441 floatingBarBackingView_.reset(
436 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); 442 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]);
437 } 443 }
438 } 444 }
439 445
440 - (void)enableBarVisibilityUpdates { 446 - (void)enableBarVisibilityUpdates {
441 // Early escape if there's nothing to do. 447 // Early escape if there's nothing to do.
442 if (barVisibilityUpdatesEnabled_) 448 if (barVisibilityUpdatesEnabled_)
443 return; 449 return;
444 450
445 barVisibilityUpdatesEnabled_ = YES; 451 barVisibilityUpdatesEnabled_ = YES;
446 452
447 if ([barVisibilityLocks_ count]) 453 if ([barVisibilityLocks_ count])
448 [fullscreenController_ ensureOverlayShownWithAnimation:NO delay:NO]; 454 [fullscreenController_ ensureOverlayShownWithAnimation:NO delay:NO];
449 else 455 else
450 [fullscreenController_ ensureOverlayHiddenWithAnimation:NO delay:NO]; 456 [fullscreenController_ ensureOverlayHiddenWithAnimation:NO delay:NO];
451 } 457 }
452 458
453 - (void)disableBarVisibilityUpdates { 459 - (void)disableBarVisibilityUpdates {
454 // Early escape if there's nothing to do. 460 // Early escape if there's nothing to do.
455 if (!barVisibilityUpdatesEnabled_) 461 if (!barVisibilityUpdatesEnabled_)
456 return; 462 return;
457 463
458 barVisibilityUpdatesEnabled_ = NO; 464 barVisibilityUpdatesEnabled_ = NO;
459 [fullscreenController_ cancelAnimationAndTimers]; 465 [fullscreenController_ cancelAnimationAndTimers];
460 } 466 }
461 467
462 @end // @implementation BrowserWindowController(Private) 468 @end // @implementation BrowserWindowController(Private)
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | chrome/browser/cocoa/fullscreen_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698