OLD | NEW |
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/browser_window_controller_private.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Space between the incognito badge and the right edge of the window. | 52 // Space between the incognito badge and the right edge of the window. |
53 const CGFloat kAvatarRightOffset = 4; | 53 const CGFloat kAvatarRightOffset = 4; |
54 | 54 |
55 // The amount by which to shrink the tab strip (on the right) when the | 55 // The amount by which to shrink the tab strip (on the right) when the |
56 // incognito badge is present. | 56 // incognito badge is present. |
57 const CGFloat kAvatarTabStripShrink = 18; | 57 const CGFloat kAvatarTabStripShrink = 18; |
58 | 58 |
| 59 // Width of the full screen icon. Used to position the NewAvatarButton to the |
| 60 // left of the icon. |
| 61 const CGFloat kFullscreenIconWidth = 30; |
| 62 |
59 // Insets for the location bar, used when the full toolbar is hidden. | 63 // Insets for the location bar, used when the full toolbar is hidden. |
60 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the | 64 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the |
61 // following best, though arguably 0 inset is better/more correct. | 65 // following best, though arguably 0 inset is better/more correct. |
62 const CGFloat kLocBarLeftRightInset = 1; | 66 const CGFloat kLocBarLeftRightInset = 1; |
63 const CGFloat kLocBarTopInset = 0; | 67 const CGFloat kLocBarTopInset = 0; |
64 const CGFloat kLocBarBottomInset = 1; | 68 const CGFloat kLocBarBottomInset = 1; |
65 | 69 |
66 } // namespace | 70 } // namespace |
67 | 71 |
68 @implementation BrowserWindowController(Private) | 72 @implementation BrowserWindowController(Private) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 maxY -= tabStripHeight; | 312 maxY -= tabStripHeight; |
309 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)]; | 313 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)]; |
310 | 314 |
311 // Set left indentation based on fullscreen mode status. | 315 // Set left indentation based on fullscreen mode status. |
312 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 : | 316 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 : |
313 [[tabStripController_ class] defaultLeftIndentForControls])]; | 317 [[tabStripController_ class] defaultLeftIndentForControls])]; |
314 | 318 |
315 // Lay out the icognito/avatar badge because calculating the indentation on | 319 // Lay out the icognito/avatar badge because calculating the indentation on |
316 // the right depends on it. | 320 // the right depends on it. |
317 if ([self shouldShowAvatar]) { | 321 if ([self shouldShowAvatar]) { |
318 NSView* avatarButton = [avatarButtonController_ view]; | 322 NSView* avatarButton; |
319 CGFloat buttonHeight = std::min( | 323 CGFloat badgeXOffset = -kAvatarRightOffset; |
| 324 CGFloat badgeYOffset = 0; |
| 325 |
| 326 if ([self shouldUseNewAvatarButton]) { |
| 327 avatarButton = [newAvatarButtonController_ view]; |
| 328 |
| 329 // The fullscreen icon is displayed to the right of the avatar button. |
| 330 if (![self isFullscreen]) |
| 331 badgeXOffset -= kFullscreenIconWidth; |
| 332 |
| 333 // Center the button vertically on the tabstrip. |
| 334 badgeYOffset = (tabStripHeight - [avatarButton frame].size.height) /2; |
| 335 } else { |
| 336 avatarButton = [avatarButtonController_ view]; |
| 337 |
| 338 CGFloat buttonHeight = std::min( |
320 static_cast<CGFloat>(profiles::kAvatarIconHeight), tabStripHeight); | 339 static_cast<CGFloat>(profiles::kAvatarIconHeight), tabStripHeight); |
321 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), | 340 // Actually place the badge *above* |maxY|, by +2 to miss the divider. |
322 buttonHeight)]; | 341 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; |
323 | 342 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), |
324 // Actually place the badge *above* |maxY|, by +2 to miss the divider. | 343 buttonHeight)]; |
325 CGFloat badgeXOffset = -kAvatarRightOffset; | 344 } |
326 CGFloat badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; | |
327 NSPoint origin = | 345 NSPoint origin = |
328 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, | 346 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, |
329 maxY + badgeYOffset); | 347 maxY + badgeYOffset); |
330 [avatarButton setFrameOrigin:origin]; | 348 [avatarButton setFrameOrigin:origin]; |
331 [avatarButton setHidden:NO]; // Make sure it's shown. | 349 [avatarButton setHidden:NO]; // Make sure it's shown. |
332 } | 350 } |
333 | 351 |
334 // Calculate the right indentation. The default indentation built into the | 352 // Calculate the right indentation. The default indentation built into the |
335 // tabstrip leaves enough room for the fullscreen button or presentation mode | 353 // tabstrip leaves enough room for the fullscreen button or presentation mode |
336 // toggle button on Lion. On non-Lion systems, the right indent needs to be | 354 // toggle button on Lion. On non-Lion systems, the right indent needs to be |
337 // adjusted to make room for the new tab button when an avatar is present. | 355 // adjusted to make room for the new tab button when an avatar is present. |
338 CGFloat rightIndent = 0; | 356 CGFloat rightIndent = 0; |
339 if (base::mac::IsOSLionOrLater() && | 357 if (base::mac::IsOSLionOrLater() && |
340 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { | 358 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { |
341 FramedBrowserWindow* window = | 359 FramedBrowserWindow* window = |
342 static_cast<FramedBrowserWindow*>([self window]); | 360 static_cast<FramedBrowserWindow*>([self window]); |
343 rightIndent += -[window fullScreenButtonOriginAdjustment].x; | 361 rightIndent += -[window fullScreenButtonOriginAdjustment].x; |
344 } else if ([self shouldShowAvatar]) { | 362 } else if ([self shouldShowAvatar]) { |
345 rightIndent += kAvatarTabStripShrink; | 363 rightIndent += kAvatarTabStripShrink; |
346 NSButton* labelButton = [avatarButtonController_ labelButtonView]; | 364 NSButton* labelButton = nil; |
| 365 if (![self shouldUseNewAvatarButton]) |
| 366 labelButton = [avatarButtonController_ labelButtonView]; |
347 if (labelButton) | 367 if (labelButton) |
348 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; | 368 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; |
349 } | 369 } |
| 370 |
| 371 // If the new avatar button is displayed, we need to account for its width. |
| 372 if ([self shouldShowAvatar] && [self shouldUseNewAvatarButton]) { |
| 373 rightIndent += NSWidth([[newAvatarButtonController_ view] frame]) |
| 374 + kAvatarTabStripShrink; |
| 375 } |
| 376 |
350 [tabStripController_ setRightIndentForControls:rightIndent]; | 377 [tabStripController_ setRightIndentForControls:rightIndent]; |
351 | 378 |
352 // Go ahead and layout the tabs. | 379 // Go ahead and layout the tabs. |
353 [tabStripController_ layoutTabsWithoutAnimation]; | 380 [tabStripController_ layoutTabsWithoutAnimation]; |
354 | 381 |
355 return maxY; | 382 return maxY; |
356 } | 383 } |
357 | 384 |
358 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX | 385 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX |
359 maxY:(CGFloat)maxY | 386 maxY:(CGFloat)maxY |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 // With this call, valgrind complains that a "Conditional jump or move depends | 584 // With this call, valgrind complains that a "Conditional jump or move depends |
558 // on uninitialised value(s)". The error happens in -[NSThemeFrame | 585 // on uninitialised value(s)". The error happens in -[NSThemeFrame |
559 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is | 586 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is |
560 // no visual impact. I have been unable to tickle it away with other window | 587 // no visual impact. I have been unable to tickle it away with other window |
561 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. | 588 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. |
562 [contentView setAutoresizesSubviews:YES]; | 589 [contentView setAutoresizesSubviews:YES]; |
563 [destWindow setContentView:contentView]; | 590 [destWindow setContentView:contentView]; |
564 | 591 |
565 // Move the incognito badge if present. | 592 // Move the incognito badge if present. |
566 if ([self shouldShowAvatar]) { | 593 if ([self shouldShowAvatar]) { |
567 [[avatarButtonController_ view] removeFromSuperview]; | 594 NSView* avatarButtonView; |
568 [[avatarButtonController_ view] setHidden:YES]; // Will be shown in layout. | 595 if ([self shouldUseNewAvatarButton]) |
569 [[[destWindow contentView] superview] addSubview: | 596 avatarButtonView = [newAvatarButtonController_ view]; |
570 [avatarButtonController_ view]]; | 597 else |
| 598 avatarButtonView = [avatarButtonController_ view]; |
| 599 |
| 600 [avatarButtonView removeFromSuperview]; |
| 601 [avatarButtonView setHidden:YES]; // Will be shown in layout. |
| 602 [[[destWindow contentView] superview] addSubview: avatarButtonView]; |
571 } | 603 } |
572 | 604 |
573 // Add the tab strip after setting the content view and moving the incognito | 605 // Add the tab strip after setting the content view and moving the incognito |
574 // badge (if any), so that the tab strip will be on top (in the z-order). | 606 // badge (if any), so that the tab strip will be on top (in the z-order). |
575 if ([self hasTabStrip]) | 607 if ([self hasTabStrip]) |
576 [[[destWindow contentView] superview] addSubview:tabStripView]; | 608 [[[destWindow contentView] superview] addSubview:tabStripView]; |
577 | 609 |
578 [sourceWindow setWindowController:nil]; | 610 [sourceWindow setWindowController:nil]; |
579 [self setWindow:destWindow]; | 611 [self setWindow:destWindow]; |
580 [destWindow setWindowController:self]; | 612 [destWindow setWindowController:self]; |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 return browser_window_controller::kCoreAnimationEnabledLazy; | 1043 return browser_window_controller::kCoreAnimationEnabledLazy; |
1012 } | 1044 } |
1013 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 1045 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
1014 switches::kUseCoreAnimation) == "disabled") { | 1046 switches::kUseCoreAnimation) == "disabled") { |
1015 return browser_window_controller::kCoreAnimationDisabled; | 1047 return browser_window_controller::kCoreAnimationDisabled; |
1016 } | 1048 } |
1017 return browser_window_controller::kCoreAnimationEnabledAlways; | 1049 return browser_window_controller::kCoreAnimationEnabledAlways; |
1018 } | 1050 } |
1019 | 1051 |
1020 @end // @implementation BrowserWindowController(Private) | 1052 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |