| OLD | NEW |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 CGFloat minX = NSMinX(contentBounds); | 152 CGFloat minX = NSMinX(contentBounds); |
| 153 CGFloat minY = NSMinY(contentBounds); | 153 CGFloat minY = NSMinY(contentBounds); |
| 154 CGFloat width = NSWidth(contentBounds); | 154 CGFloat width = NSWidth(contentBounds); |
| 155 | 155 |
| 156 // Suppress title drawing if necessary. | 156 // Suppress title drawing if necessary. |
| 157 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) | 157 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) |
| 158 [(id)window setShouldHideTitle:![self hasTitleBar]]; | 158 [(id)window setShouldHideTitle:![self hasTitleBar]]; |
| 159 | 159 |
| 160 BOOL isFullscreen = [self isFullscreen]; | 160 BOOL isFullscreen = [self isFullscreen]; |
| 161 CGFloat floatingBarHeight = [self floatingBarHeight]; | 161 CGFloat floatingBarHeight = [self floatingBarHeight]; |
| 162 CGFloat floatingBarShownFraction = |
| 163 isFullscreen ? [fullscreenController_ floatingBarShownFraction] : 0; |
| 162 // In fullscreen mode, |yOffset| accounts for the sliding position of the | 164 // In fullscreen mode, |yOffset| accounts for the sliding position of the |
| 163 // floating bar and the extra offset needed to dodge the menu bar. | 165 // floating bar and the extra offset needed to dodge the menu bar. |
| 164 CGFloat yOffset = isFullscreen ? | 166 CGFloat yOffset = isFullscreen ? |
| 165 (floor((1 - floatingBarShownFraction_) * floatingBarHeight) - | 167 (floor((1 - floatingBarShownFraction) * floatingBarHeight) - |
| 166 [fullscreenController_ floatingBarVerticalOffset]) : 0; | 168 [fullscreenController_ floatingBarVerticalOffset]) : 0; |
| 167 CGFloat maxY = NSMaxY(contentBounds) + yOffset; | 169 CGFloat maxY = NSMaxY(contentBounds) + yOffset; |
| 168 CGFloat startMaxY = maxY; | 170 CGFloat startMaxY = maxY; |
| 169 | 171 |
| 170 if ([self hasTabStrip] && ![self useVerticalTabs]) { | 172 if ([self hasTabStrip] && ![self useVerticalTabs]) { |
| 171 // If we need to lay out the top tab strip, replace |maxY| and |startMaxY| | 173 // If we need to lay out the top tab strip, replace |maxY| and |startMaxY| |
| 172 // with higher values, and then lay out the tab strip. | 174 // with higher values, and then lay out the tab strip. |
| 173 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; | 175 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; |
| 174 startMaxY = maxY = NSHeight(windowFrame) + yOffset; | 176 startMaxY = maxY = NSHeight(windowFrame) + yOffset; |
| 175 maxY = [self layoutTabStripAtMaxY:maxY width:width fullscreen:isFullscreen]; | 177 maxY = [self layoutTabStripAtMaxY:maxY width:width fullscreen:isFullscreen]; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Normally, we don't need to tell the toolbar whether or not to show the | 237 // Normally, we don't need to tell the toolbar whether or not to show the |
| 236 // divider, but things break down during animation. | 238 // divider, but things break down during animation. |
| 237 [toolbarController_ | 239 [toolbarController_ |
| 238 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; | 240 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; |
| 239 } | 241 } |
| 240 | 242 |
| 241 - (CGFloat)floatingBarHeight { | 243 - (CGFloat)floatingBarHeight { |
| 242 if (![self isFullscreen]) | 244 if (![self isFullscreen]) |
| 243 return 0; | 245 return 0; |
| 244 | 246 |
| 247 // If there's nothing in the floating bar, it has zero height. |
| 248 // TODO(rohitrao): Should be possible to check [subviews count] here. |
| 249 if (!([self hasLocationBar] || [self hasTabStrip] || [self hasToolbar])) |
| 250 return 0; |
| 251 |
| 245 CGFloat totalHeight = [fullscreenController_ floatingBarVerticalOffset]; | 252 CGFloat totalHeight = [fullscreenController_ floatingBarVerticalOffset]; |
| 246 | 253 |
| 247 if ([self hasTabStrip]) | 254 if ([self hasTabStrip]) |
| 248 totalHeight += NSHeight([[self tabStripView] frame]); | 255 totalHeight += NSHeight([[self tabStripView] frame]); |
| 249 | 256 |
| 250 if ([self hasToolbar]) { | 257 if ([self hasToolbar]) { |
| 251 totalHeight += NSHeight([[toolbarController_ view] frame]); | 258 totalHeight += NSHeight([[toolbarController_ view] frame]); |
| 252 } else if ([self hasLocationBar]) { | 259 } else if ([self hasLocationBar]) { |
| 253 totalHeight += NSHeight([[toolbarController_ view] frame]) + | 260 totalHeight += NSHeight([[toolbarController_ view] frame]) + |
| 254 kLocBarTopInset + kLocBarBottomInset; | 261 kLocBarTopInset + kLocBarBottomInset; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be | 358 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be |
| 352 // necessary in the non-NTP case. | 359 // necessary in the non-NTP case. |
| 353 [bookmarkBarController_ layoutSubviews]; | 360 [bookmarkBarController_ layoutSubviews]; |
| 354 | 361 |
| 355 return maxY; | 362 return maxY; |
| 356 } | 363 } |
| 357 | 364 |
| 358 - (void)layoutFloatingBarBackingView:(NSRect)frame | 365 - (void)layoutFloatingBarBackingView:(NSRect)frame |
| 359 fullscreen:(BOOL)fullscreen { | 366 fullscreen:(BOOL)fullscreen { |
| 360 // Only display when in fullscreen mode. | 367 // Only display when in fullscreen mode. |
| 361 if (fullscreen) { | 368 if (!fullscreen) |
| 362 // For certain window types such as app windows (e.g., the dev tools | 369 return; |
| 363 // window), there's no actual overlay. (Displaying one would result in an | |
| 364 // overly sliding in only under the menu, which gives an ugly effect.) | |
| 365 if (floatingBarBackingView_.get()) { | |
| 366 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar]; | |
| 367 | 370 |
| 368 // Insert it into the view hierarchy if necessary. | 371 NSView* floatingBarBackingView = |
| 369 if (![floatingBarBackingView_ superview] || | 372 [fullscreenController_ floatingBarBackingView]; |
| 370 aboveBookmarkBar != floatingBarAboveBookmarkBar_) { | 373 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar]; |
| 371 NSView* contentView = [[self window] contentView]; | |
| 372 // z-order gets messed up unless we explicitly remove the floatingbar | |
| 373 // view and re-add it. | |
| 374 [floatingBarBackingView_ removeFromSuperview]; | |
| 375 [contentView addSubview:floatingBarBackingView_ | |
| 376 positioned:(aboveBookmarkBar ? | |
| 377 NSWindowAbove : NSWindowBelow) | |
| 378 relativeTo:[bookmarkBarController_ view]]; | |
| 379 floatingBarAboveBookmarkBar_ = aboveBookmarkBar; | |
| 380 } | |
| 381 | 374 |
| 382 // Set its frame. | 375 // Insert it into the view hierarchy if necessary. |
| 383 [floatingBarBackingView_ setFrame:frame]; | 376 if (![floatingBarBackingView superview] || |
| 384 } | 377 aboveBookmarkBar != floatingBarAboveBookmarkBar_) { |
| 378 NSView* contentView = [[self window] contentView]; |
| 379 // z-order gets messed up unless we explicitly remove the floatingbar |
| 380 // view and re-add it. |
| 381 [floatingBarBackingView removeFromSuperview]; |
| 382 [contentView addSubview:floatingBarBackingView |
| 383 positioned:(aboveBookmarkBar ? |
| 384 NSWindowAbove : NSWindowBelow) |
| 385 relativeTo:[bookmarkBarController_ view]]; |
| 386 floatingBarAboveBookmarkBar_ = aboveBookmarkBar; |
| 387 } |
| 385 | 388 |
| 386 // But we want the logic to work as usual (for show/hide/etc. purposes). | 389 // Set its frame. |
| 387 [fullscreenController_ overlayFrameChanged:frame]; | 390 [floatingBarBackingView setFrame:frame]; |
| 388 } else { | 391 [fullscreenController_ overlayFrameChanged:frame]; |
| 389 // Okay to call even if |floatingBarBackingView_| is nil. | |
| 390 if ([floatingBarBackingView_ superview]) | |
| 391 [floatingBarBackingView_ removeFromSuperview]; | |
| 392 } | |
| 393 } | 392 } |
| 394 | 393 |
| 395 - (CGFloat)layoutInfoBarAtMinX:(CGFloat)minX | 394 - (CGFloat)layoutInfoBarAtMinX:(CGFloat)minX |
| 396 maxY:(CGFloat)maxY | 395 maxY:(CGFloat)maxY |
| 397 width:(CGFloat)width { | 396 width:(CGFloat)width { |
| 398 NSView* infoBarView = [infoBarContainerController_ view]; | 397 NSView* infoBarView = [infoBarContainerController_ view]; |
| 399 NSRect infoBarFrame = [infoBarView frame]; | 398 NSRect infoBarFrame = [infoBarView frame]; |
| 400 infoBarFrame.origin.x = minX; | 399 infoBarFrame.origin.x = minX; |
| 401 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); | 400 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); |
| 402 infoBarFrame.size.width = width; | 401 infoBarFrame.size.width = width; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 return; | 461 return; |
| 463 | 462 |
| 464 toolbarFrame.size.height = newHeight; | 463 toolbarFrame.size.height = newHeight; |
| 465 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame]; | 464 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame]; |
| 466 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH; | 465 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH; |
| 467 [[toolbarController_ view] setFrame:toolbarFrame]; | 466 [[toolbarController_ view] setFrame:toolbarFrame]; |
| 468 [[bookmarkBarController_ view] setFrame:bookmarkFrame]; | 467 [[bookmarkBarController_ view] setFrame:bookmarkFrame]; |
| 469 [self layoutSubviews]; | 468 [self layoutSubviews]; |
| 470 } | 469 } |
| 471 | 470 |
| 472 // TODO(rohitrao): This function has shrunk into uselessness, and | |
| 473 // |-setFullscreen:| has grown rather large. Find a good way to break up | |
| 474 // |-setFullscreen:| into smaller pieces. http://crbug.com/36449 | |
| 475 - (void)adjustUIForFullscreen:(BOOL)fullscreen { | 471 - (void)adjustUIForFullscreen:(BOOL)fullscreen { |
| 476 // Create the floating bar backing view if necessary. | |
| 477 if (fullscreen && !floatingBarBackingView_.get() && | |
| 478 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) { | |
| 479 floatingBarBackingView_.reset( | |
| 480 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); | |
| 481 } | |
| 482 } | 472 } |
| 483 | 473 |
| 484 - (void)enableBarVisibilityUpdates { | 474 - (void)enableBarVisibilityUpdates { |
| 485 // Early escape if there's nothing to do. | 475 // Early escape if there's nothing to do. |
| 486 if (barVisibilityUpdatesEnabled_) | 476 if (barVisibilityUpdatesEnabled_) |
| 487 return; | 477 return; |
| 488 | 478 |
| 489 barVisibilityUpdatesEnabled_ = YES; | 479 barVisibilityUpdatesEnabled_ = YES; |
| 490 | 480 |
| 491 if ([barVisibilityLocks_ count]) | 481 if ([barVisibilityLocks_ count]) |
| 492 [fullscreenController_ ensureOverlayShownWithAnimation:NO delay:NO]; | 482 [fullscreenController_ ensureOverlayShownWithAnimation:NO delay:NO]; |
| 493 else | 483 else |
| 494 [fullscreenController_ ensureOverlayHiddenWithAnimation:NO delay:NO]; | 484 [fullscreenController_ ensureOverlayHiddenWithAnimation:NO delay:NO]; |
| 495 } | 485 } |
| 496 | 486 |
| 497 - (void)disableBarVisibilityUpdates { | 487 - (void)disableBarVisibilityUpdates { |
| 498 // Early escape if there's nothing to do. | 488 // Early escape if there's nothing to do. |
| 499 if (!barVisibilityUpdatesEnabled_) | 489 if (!barVisibilityUpdatesEnabled_) |
| 500 return; | 490 return; |
| 501 | 491 |
| 502 barVisibilityUpdatesEnabled_ = NO; | 492 barVisibilityUpdatesEnabled_ = NO; |
| 503 [fullscreenController_ cancelAnimationAndTimers]; | 493 [fullscreenController_ cancelAnimationAndTimers]; |
| 504 } | 494 } |
| 505 | 495 |
| 506 @end // @implementation BrowserWindowController(Private) | 496 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |