Index: chrome/browser/ui/cocoa/tabpose_window.mm |
diff --git a/chrome/browser/ui/cocoa/tabpose_window.mm b/chrome/browser/ui/cocoa/tabpose_window.mm |
index 76865815c5d9be50e40d4a051d9b280f8be9d6b2..0f97cb380f2f0cd76db1f466eefbe2fcfae92507 100644 |
--- a/chrome/browser/ui/cocoa/tabpose_window.mm |
+++ b/chrome/browser/ui/cocoa/tabpose_window.mm |
@@ -432,9 +432,16 @@ NSRect Tile::GetStartRectRelativeTo(const Tile& tile) const { |
NSRect Tile::GetFaviconStartRectRelativeTo(const Tile& tile) const { |
NSRect thumb_start = GetStartRectRelativeTo(tile); |
+ CGFloat scale_small_to_big = NSWidth(thumb_start) / NSWidth(thumb_rect_); |
viettrungluu
2010/12/15 17:36:57
What is this scale and where does it come from?
A
Nico
2010/12/15 18:52:29
:-(
Renamed the variable. It's the ratio between
|
NSRect rect = favicon_rect_; |
- rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_); |
- rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_); |
+ rect.origin.x -= NSMinX(thumb_rect_); |
viettrungluu
2010/12/15 17:36:57
Just make a helper function and do:
x = ScaleRe
Nico
2010/12/15 18:52:29
Ah, but this doesn't do (x - origin) * scale + ori
|
+ rect.origin.x *= scale_small_to_big; |
+ rect.origin.x += NSMinX(thumb_start); |
+ rect.origin.y -= NSMinY(thumb_rect_); |
+ rect.origin.y *= scale_small_to_big; |
+ rect.origin.y += NSMinY(thumb_start); |
+ rect.size.width *= scale_small_to_big; |
+ rect.size.height *= scale_small_to_big; |
return rect; |
} |
@@ -449,9 +456,16 @@ SkBitmap Tile::favicon() const { |
NSRect Tile::GetTitleStartRectRelativeTo(const Tile& tile) const { |
NSRect thumb_start = GetStartRectRelativeTo(tile); |
+ CGFloat scale_small_to_big = NSWidth(thumb_start) / NSWidth(thumb_rect_); |
NSRect rect = title_rect_; |
- rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_); |
- rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_); |
+ rect.origin.x -= NSMinX(thumb_rect_); |
+ rect.origin.x *= scale_small_to_big; |
+ rect.origin.x += NSMinX(thumb_start); |
+ rect.origin.y -= NSMinY(thumb_rect_); |
+ rect.origin.y *= scale_small_to_big; |
+ rect.origin.y += NSMinY(thumb_start); |
+ rect.size.width *= scale_small_to_big; |
+ rect.size.height *= scale_small_to_big; |
return rect; |
} |
@@ -826,8 +840,10 @@ void TileSet::MoveTileFromTo(int from_index, int to_index) { |
} // namespace tabpose |
-void AnimateCALayerFrameFromTo( |
- CALayer* layer, const NSRect& from, const NSRect& to, |
+void AnimateScaledCALayerFrameFromTo( |
+ CALayer* layer, |
+ const NSRect& from, CGFloat from_scale, |
+ const NSRect& to, CGFloat to_scale, |
NSTimeInterval duration, id boundsAnimationDelegate) { |
// http://developer.apple.com/mac/library/qa/qa2008/qa1620.html |
CABasicAnimation* animation; |
@@ -852,10 +868,10 @@ void AnimateCALayerFrameFromTo( |
NSPoint point = to.origin; |
// Adapt to anchorPoint. |
- opoint.x += NSWidth(from) * layer.anchorPoint.x; |
- opoint.y += NSHeight(from) * layer.anchorPoint.y; |
- point.x += NSWidth(to) * layer.anchorPoint.x; |
- point.y += NSHeight(to) * layer.anchorPoint.y; |
+ opoint.x += NSWidth(from) * from_scale * layer.anchorPoint.x; |
+ opoint.y += NSHeight(from) * from_scale * layer.anchorPoint.y; |
+ point.x += NSWidth(to) * to_scale * layer.anchorPoint.x; |
+ point.y += NSHeight(to) * to_scale * layer.anchorPoint.y; |
animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
animation.fromValue = [NSValue valueWithPoint:opoint]; |
@@ -872,6 +888,13 @@ void AnimateCALayerFrameFromTo( |
[layer addAnimation:animation forKey:@"position"]; |
} |
+void AnimateCALayerFrameFromTo( |
+ CALayer* layer, const NSRect& from, const NSRect& to, |
+ NSTimeInterval duration, id boundsAnimationDelegate) { |
+ AnimateScaledCALayerFrameFromTo( |
+ layer, from, 1.0, to, 1.0, duration, boundsAnimationDelegate); |
+} |
+ |
void AnimateCALayerOpacityFromTo( |
CALayer* layer, double from, double to, NSTimeInterval duration) { |
CABasicAnimation* animation; |
@@ -1015,15 +1038,34 @@ void AnimateCALayerOpacityFromTo( |
[bgLayer_ addSublayer:faviconLayer]; |
[allFaviconLayers_ addObject:faviconLayer]; |
+ // CATextLayers can't animate their fontSize property, at least on 10.5. |
+ // Animate transform.scale instead. |
+ |
+ // The scaling should have its origin in the layer's upper left corner. |
+ // This needs to be set before |AnimateCALayerFrameFromTo()| is called. |
CATextLayer* titleLayer = [CATextLayer layer]; |
+ titleLayer.anchorPoint = CGPointMake(0, 1); |
if (showZoom) { |
- AnimateCALayerFrameFromTo( |
- titleLayer, |
- tile.GetTitleStartRectRelativeTo(tileSet_->selected_tile()), |
- tile.title_rect(), |
- interval, |
- nil); |
- AnimateCALayerOpacityFromTo(titleLayer, 0.0, 1.0, interval); |
+ NSRect fromRect = |
+ tile.GetTitleStartRectRelativeTo(tileSet_->selected_tile()); |
+ NSRect toRect = tile.title_rect(); |
+ CGFloat scale = NSWidth(fromRect) / NSWidth(toRect); |
+ fromRect.size = toRect.size; |
+ |
+ // Add scale animation. |
+ CABasicAnimation* scaleAnimation = |
+ [CABasicAnimation animationWithKeyPath:@"transform.scale"]; |
+ scaleAnimation.fromValue = [NSNumber numberWithDouble:scale]; |
+ scaleAnimation.toValue = [NSNumber numberWithDouble:1.0]; |
+ scaleAnimation.duration = interval; |
+ scaleAnimation.timingFunction = |
+ [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; |
+ [titleLayer addAnimation:scaleAnimation forKey:@"transform.scale"]; |
+ |
+ // Add the position and opacity animations. |
+ AnimateScaledCALayerFrameFromTo( |
+ titleLayer, fromRect, scale, toRect, 1.0, interval, nil); |
+ AnimateCALayerOpacityFromTo(faviconLayer, 0.0, 1.0, interval); |
} else { |
titleLayer.frame = NSRectToCGRect(tile.title_rect()); |
} |
@@ -1283,6 +1325,7 @@ void AnimateCALayerOpacityFromTo( |
[layer addAnimation:animation forKey:@"frame"]; |
} |
+ // Thumbnail. |
layer.frame = NSRectToCGRect( |
tile.GetStartRectRelativeTo(tileSet_->selected_tile())); |
@@ -1291,13 +1334,27 @@ void AnimateCALayerOpacityFromTo( |
[layer setNeedsDisplay]; |
} |
+ // Title. |
CALayer* faviconLayer = [allFaviconLayers_ objectAtIndex:i]; |
faviconLayer.frame = NSRectToCGRect( |
tile.GetFaviconStartRectRelativeTo(tileSet_->selected_tile())); |
faviconLayer.opacity = 0; |
+ |
+ // Favicon. |
+ // The |fontSize| cannot be animated directly, animate the layer's scale |
+ // instead. scale affects the rendered width, so keep the small bounds. |
viettrungluu
2010/12/15 17:36:57
"|scale|". Or should that be |transform.scale|? ("
Nico
2010/12/15 18:52:29
With "small", it's clear that it refers to the zoo
|
CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; |
- titleLayer.frame = NSRectToCGRect( |
- tile.GetTitleStartRectRelativeTo(tileSet_->selected_tile())); |
+ NSRect titleRect = tile.title_rect(); |
+ NSRect titleToRect = |
+ tile.GetTitleStartRectRelativeTo(tileSet_->selected_tile()); |
+ CGFloat scale = NSWidth(titleToRect) / NSWidth(titleRect); |
+ titleToRect.origin.x += |
+ NSWidth(titleRect) * scale * titleLayer.anchorPoint.x; |
+ titleToRect.origin.y += |
+ NSHeight(titleRect) * scale * titleLayer.anchorPoint.y; |
+ titleLayer.position = NSPointToCGPoint(titleToRect.origin); |
+ [titleLayer setValue:[NSNumber numberWithDouble:scale] |
+ forKeyPath:@"transform.scale"]; |
titleLayer.opacity = 0; |
} |
} |
viettrungluu
2010/12/15 17:36:57
This is getting ridiculously big. Please break it
Nico
2010/12/15 18:52:29
It's a sweet 77 lines short!
Alright, done.
|