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

Unified Diff: chrome/browser/cocoa/tab_strip_controller.mm

Issue 243049: Cancel previous new tab "submarine" animations when starting the animation fo... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/tab_strip_controller.mm
===================================================================
--- chrome/browser/cocoa/tab_strip_controller.mm (revision 28808)
+++ chrome/browser/cocoa/tab_strip_controller.mm (working copy)
@@ -360,6 +360,9 @@
// tabs would cause an overflow.
- (void)layoutTabsWithAnimation:(BOOL)animate
regenerateSubviews:(BOOL)doUpdate {
+ // A very short duration used to cancel in-progress animations by making the
+ // new animation happen "instantly".
+ const float kInstantly = 0.000001;
Mark Mentovai 2009/10/13 17:30:23 Can you #include <limits> and use the std::numeric
const float kTabOverlap = 20.0;
const float kNewTabButtonOffset = 8.0;
const float kMaxTabWidth = [TabController maxTabWidth];
@@ -417,7 +420,7 @@
// Move the current tab to the correct location instantly.
// We need a duration or else it doesn't cancel an inflight animation.
[NSAnimationContext beginGrouping];
- [[NSAnimationContext currentContext] setDuration:0.000001];
+ [[NSAnimationContext currentContext] setDuration:kInstantly];
Mark Mentovai 2009/10/13 17:30:23 Seems kind of funny to say "set duration to instan
tabFrame.origin.x = placeholderFrame_.origin.x;
// TODO(alcor): reenable this
//tabFrame.size.height += 10.0 * placeholderStretchiness_;
@@ -440,19 +443,19 @@
tabFrame.origin.x = offset;
}
- // Animate the tab in by putting it below the horizon, but don't bother
+ // Set the width. Selected tabs are slightly wider when things get
+ // really small and thus we enforce a different minimum width.
+ tabFrame.size.width =
+ [tab selected] ? MAX(baseTabWidth, kMinSelectedTabWidth) :
+ baseTabWidth;
+
+ // Animate a new tab in by putting it below the horizon, but don't bother
// if we only have 1 tab.
BOOL shouldAnimate = animate && [tabContentsArray_ count] > 1;
if (newTab && visible && shouldAnimate) {
[[tab view] setFrame:NSOffsetRect(tabFrame, 0, -NSHeight(tabFrame))];
}
- // Set the width. Selected tabs are slightly wider when things get
- // really small and thus we enforce a different minimum width.
- tabFrame.size.width =
- [tab selected] ? MAX(baseTabWidth, kMinSelectedTabWidth) :
- baseTabWidth;
-
// Check the frame by identifier to avoid redundant calls to animator.
id frameTarget = visible && animate ? [[tab view] animator] : [tab view];
NSValue* identifier = [NSValue valueWithPointer:[tab view]];
@@ -463,6 +466,7 @@
[targetFrames_ setObject:[NSValue valueWithRect:tabFrame]
forKey:identifier];
}
+
enclosingRect = NSUnionRect(tabFrame, enclosingRect);
}
@@ -489,9 +493,19 @@
[newTabButton_ setHidden:NO];
if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) {
- [newTabButton_ setFrame:newTabNewFrame];
+ // Move the new tab button into place. We want to animate the new tab
+ // button if it's moving to the left (closing a tab), but not when it's
+ // moving to the right (inserting a new tab). If moving right, we need
+ // to use a very small duration to make sure we cancel any in-flight
+ // animation to the left.
+ BOOL movingLeft = NSMinX(newTabNewFrame) < NSMinX(newTabTargetFrame_);
+ id target = animate ? [newTabButton_ animator] : newTabButton_;
+ [NSAnimationContext beginGrouping];
Mark Mentovai 2009/10/13 17:30:23 Adding this is what fixed the bug I was seeing ear
+ if (!movingLeft)
+ [[NSAnimationContext currentContext] setDuration:kInstantly];
+ [target setFrame:newTabNewFrame];
+ [NSAnimationContext endGrouping];
newTabTargetFrame_ = newTabNewFrame;
- // Move the new tab button into place.
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698