| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tab_strip_controller.h" | 5 #import "chrome/browser/cocoa/tab_strip_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } else { | 412 } else { |
| 413 // If our left edge is to the left of the placeholder's left, but our mid | 413 // If our left edge is to the left of the placeholder's left, but our mid |
| 414 // is to the right of it we should slide over to make space for it. | 414 // is to the right of it we should slide over to make space for it. |
| 415 if (placeholderTab_ && gap < 0 && NSMidX(tabFrame) > minX) { | 415 if (placeholderTab_ && gap < 0 && NSMidX(tabFrame) > minX) { |
| 416 gap = i; | 416 gap = i; |
| 417 offset += NSWidth(tabFrame); | 417 offset += NSWidth(tabFrame); |
| 418 offset -= kTabOverlap; | 418 offset -= kTabOverlap; |
| 419 tabFrame.origin.x = offset; | 419 tabFrame.origin.x = offset; |
| 420 } | 420 } |
| 421 | 421 |
| 422 // Animate the tab in by putting it below the horizon, but don't bother | 422 // Animate the tab in by putting it below the horizon. |
| 423 // if we only have 1 tab. | 423 if (newTab && visible && animate) { |
| 424 BOOL shouldAnimate = animate && [tabContentsArray_ count] > 1; | |
| 425 if (newTab && visible && shouldAnimate) { | |
| 426 [[tab view] setFrame:NSOffsetRect(tabFrame, 0, -NSHeight(tabFrame))]; | 424 [[tab view] setFrame:NSOffsetRect(tabFrame, 0, -NSHeight(tabFrame))]; |
| 427 } | 425 } |
| 428 | 426 |
| 429 // Set the width. Selected tabs are slightly wider when things get | 427 // Set the width. Selected tabs are slightly wider when things get |
| 430 // really small and thus we enforce a different minimum width. | 428 // really small and thus we enforce a different minimum width. |
| 431 tabFrame.size.width = | 429 tabFrame.size.width = |
| 432 [tab selected] ? MAX(baseTabWidth, kMinSelectedTabWidth) : | 430 [tab selected] ? MAX(baseTabWidth, kMinSelectedTabWidth) : |
| 433 baseTabWidth; | 431 baseTabWidth; |
| 434 | 432 |
| 435 // Check the frame by identifier to avoid redundant calls to animator. | 433 // Check the frame by identifier to avoid redundant calls to animator. |
| 436 id frameTarget = visible && animate ? [[tab view] animator] : [tab view]; | 434 id frameTarget = visible && animate ? [[tab view] animator] : [tab view]; |
| 437 NSValue *identifier = [NSValue valueWithPointer:[tab view]]; | 435 NSValue *identifier = [NSValue valueWithPointer:[tab view]]; |
| 438 NSValue *oldTargetValue = [targetFrames_ objectForKey:identifier]; | 436 NSValue *oldTargetValue = [targetFrames_ objectForKey:identifier]; |
| 439 if (!oldTargetValue || | 437 if (!oldTargetValue || |
| 440 !NSEqualRects([oldTargetValue rectValue], tabFrame)) { | 438 !NSEqualRects([oldTargetValue rectValue], tabFrame)) { |
| 441 [frameTarget setFrame:tabFrame]; | 439 [frameTarget setFrame:tabFrame]; |
| 442 [targetFrames_ setObject:[NSValue valueWithRect:tabFrame] | 440 [targetFrames_ setObject:[NSValue valueWithRect:tabFrame] |
| 443 forKey:identifier]; | 441 forKey:identifier]; |
| 444 } | 442 } |
| 445 enclosingRect = NSUnionRect(tabFrame, enclosingRect); | 443 enclosingRect = NSUnionRect(tabFrame, enclosingRect); |
| 446 } | 444 } |
| 447 | 445 |
| 448 offset += NSWidth(tabFrame); | 446 offset += NSWidth(tabFrame); |
| 449 offset -= kTabOverlap; | 447 offset -= kTabOverlap; |
| 450 i++; | 448 i++; |
| 451 } | 449 } |
| 452 | 450 |
| 453 // Hide the new tab button if we're explicitly told to. It may already | 451 // Hide the new tab button if we're explicitly told to. It may already |
| 454 // be hidden, doing it again doesn't hurt. Otherwise position it | 452 // be hidden, doing it again doesn't hurt. |
| 455 // appropriately, showing it if necessary. | |
| 456 if (forceNewTabButtonHidden_) { | 453 if (forceNewTabButtonHidden_) { |
| 457 [newTabButton_ setHidden:YES]; | 454 [newTabButton_ setHidden:YES]; |
| 458 } else { | 455 } else { |
| 459 NSRect newTabNewFrame = [newTabButton_ frame]; | 456 NSRect newTabNewFrame = [newTabButton_ frame]; |
| 460 // We've already ensured there's enough space for the new tab button | 457 // We've already ensured there's enough space for the new tab button |
| 461 // so we don't have to check it against the available width. We do need | 458 // so we don't have to check it against the available width. We do need |
| 462 // to make sure we put it after any placeholder. | 459 // to make sure we put it after any placeholder. |
| 463 newTabNewFrame.origin = NSMakePoint(offset, 0); | 460 newTabNewFrame.origin = NSMakePoint(offset, 0); |
| 464 newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x, | 461 newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x, |
| 465 NSMaxX(placeholderFrame_)) + | 462 NSMaxX(placeholderFrame_)) + |
| 466 kNewTabButtonOffset; | 463 kNewTabButtonOffset; |
| 467 if ([tabContentsArray_ count]) | 464 if (i > 0 && [newTabButton_ isHidden]) { |
| 468 [newTabButton_ setHidden:NO]; | 465 id target = animate ? [newTabButton_ animator] : newTabButton_; |
| 466 [target setHidden:NO]; |
| 467 } |
| 469 | 468 |
| 470 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { | 469 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { |
| 471 [newTabButton_ setFrame:newTabNewFrame]; | 470 [newTabButton_ setFrame:newTabNewFrame]; |
| 472 newTabTargetFrame_ = newTabNewFrame; | 471 newTabTargetFrame_ = newTabNewFrame; |
| 473 // Move the new tab button into place. | 472 // Move the new tab button into place. |
| 474 } | 473 } |
| 475 } | 474 } |
| 476 | 475 |
| 477 [NSAnimationContext endGrouping]; | 476 [NSAnimationContext endGrouping]; |
| 478 [dragBlockingView_ setFrame:enclosingRect]; | 477 [dragBlockingView_ setFrame:enclosingRect]; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 BrowserWindowController* controller = | 954 BrowserWindowController* controller = |
| 956 (BrowserWindowController*)[[switchView_ window] windowController]; | 955 (BrowserWindowController*)[[switchView_ window] windowController]; |
| 957 DCHECK(index >= 0); | 956 DCHECK(index >= 0); |
| 958 if (index >= 0) { | 957 if (index >= 0) { |
| 959 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 958 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
| 960 } | 959 } |
| 961 } | 960 } |
| 962 | 961 |
| 963 | 962 |
| 964 @end | 963 @end |
| OLD | NEW |