Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tabpose_window.h" | 5 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
| 31 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
| 32 #include "grit/app_resources.h" | 32 #include "grit/app_resources.h" |
| 33 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 34 #include "skia/ext/skia_utils_mac.h" | 34 #include "skia/ext/skia_utils_mac.h" |
| 35 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 35 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/gfx/image.h" | 37 #include "ui/gfx/image.h" |
| 38 #include "ui/gfx/scoped_cg_context_state_mac.h" | 38 #include "ui/gfx/scoped_cg_context_state_mac.h" |
| 39 | 39 |
| 40 const int kTopGradientHeight = 15; | 40 const int kBottomGradientHeight = 50; |
|
viettrungluu
2011/03/08 01:33:40
You really should have some comment about what the
viettrungluu
2011/03/08 01:33:40
Why not a CGFloat?
Nico
2011/03/08 01:47:02
Done. (I maintain that a variable name is a valid
| |
| 41 | |
| 42 const CGFloat kTopGray = 0.77; | |
| 43 const CGFloat kCentralGray = 0.6; | |
| 44 const CGFloat kBottomGray = 0.5; | |
| 41 | 45 |
| 42 NSString* const kAnimationIdKey = @"AnimationId"; | 46 NSString* const kAnimationIdKey = @"AnimationId"; |
| 43 NSString* const kAnimationIdFadeIn = @"FadeIn"; | 47 NSString* const kAnimationIdFadeIn = @"FadeIn"; |
| 44 NSString* const kAnimationIdFadeOut = @"FadeOut"; | 48 NSString* const kAnimationIdFadeOut = @"FadeOut"; |
| 45 | 49 |
| 46 const CGFloat kDefaultAnimationDuration = 0.25; // In seconds. | 50 const CGFloat kDefaultAnimationDuration = 0.25; // In seconds. |
| 47 const CGFloat kSlomoFactor = 4; | 51 const CGFloat kSlomoFactor = 4; |
| 48 const CGFloat kObserverChangeAnimationDuration = 0.25; // In seconds. | 52 const CGFloat kObserverChangeAnimationDuration = 0.25; // In seconds. |
| 49 const CGFloat kSelectionInset = 5; | 53 const CGFloat kSelectionInset = 5; |
| 50 | 54 |
| 51 // CAGradientLayer is 10.6-only -- roll our own. | 55 // CAGradientLayer is 10.6-only -- roll our own. |
| 52 @interface DarkGradientLayer : CALayer | 56 @interface GrayGradientLayer : CALayer { |
| 57 CGFloat startGray_; | |
|
viettrungluu
2011/03/08 01:33:40
@private?
Nico
2011/03/08 01:47:02
Done.
| |
| 58 CGFloat endGray_; | |
| 59 } | |
| 60 - (id)initWithStartGray:(CGFloat)startGray endGray:(CGFloat)endGray; | |
| 53 - (void)drawInContext:(CGContextRef)context; | 61 - (void)drawInContext:(CGContextRef)context; |
| 54 @end | 62 @end |
| 55 | 63 |
| 56 @implementation DarkGradientLayer | 64 @implementation GrayGradientLayer |
| 65 - (id)initWithStartGray:(CGFloat)startGray endGray:(CGFloat)endGray { | |
| 66 if ((self = [super init])) { | |
| 67 startGray_ = startGray; | |
| 68 endGray_ = endGray; | |
| 69 } | |
| 70 return self; | |
| 71 } | |
| 72 | |
| 57 - (void)drawInContext:(CGContextRef)context { | 73 - (void)drawInContext:(CGContextRef)context { |
| 58 base::mac::ScopedCFTypeRef<CGColorSpaceRef> grayColorSpace( | 74 base::mac::ScopedCFTypeRef<CGColorSpaceRef> grayColorSpace( |
| 59 CGColorSpaceCreateWithName(kCGColorSpaceGenericGray)); | 75 CGColorSpaceCreateWithName(kCGColorSpaceGenericGray)); |
| 60 CGFloat grays[] = { 0.277, 1.0, 0.39, 1.0 }; | 76 CGFloat grays[] = { startGray_, 1.0, endGray_, 1.0 }; |
| 61 CGFloat locations[] = { 0, 1 }; | 77 CGFloat locations[] = { 0, 1 }; |
| 62 base::mac::ScopedCFTypeRef<CGGradientRef> gradient( | 78 base::mac::ScopedCFTypeRef<CGGradientRef> gradient( |
| 63 CGGradientCreateWithColorComponents( | 79 CGGradientCreateWithColorComponents( |
| 64 grayColorSpace.get(), grays, locations, arraysize(locations))); | 80 grayColorSpace.get(), grays, locations, arraysize(locations))); |
| 65 CGPoint topLeft = CGPointMake(0.0, kTopGradientHeight); | 81 CGPoint topLeft = CGPointMake(0.0, self.bounds.size.height); |
|
viettrungluu
2011/03/08 01:33:40
NSHeight()?
viettrungluu
2011/03/08 01:44:58
Errr, never mind on that.
Nico
2011/03/08 01:47:02
NSHeight still doesn't work with CGRects
| |
| 66 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0); | 82 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0); |
| 67 } | 83 } |
| 68 @end | 84 @end |
| 69 | 85 |
| 70 namespace tabpose { | 86 namespace tabpose { |
| 71 class ThumbnailLoader; | 87 class ThumbnailLoader; |
| 72 } | 88 } |
| 73 | 89 |
| 74 // A CALayer that draws a thumbnail for a TabContents object. The layer tries | 90 // A CALayer that draws a thumbnail for a TabContents object. The layer tries |
| 75 // to draw the TabContents's backing store directly if possible, and requests | 91 // to draw the TabContents's backing store directly if possible, and requests |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1110 } | 1126 } |
| 1111 | 1127 |
| 1112 - (void)setUpLayersInSlomo:(BOOL)slomo { | 1128 - (void)setUpLayersInSlomo:(BOOL)slomo { |
| 1113 // Root layer -- covers whole window. | 1129 // Root layer -- covers whole window. |
| 1114 rootLayer_ = [CALayer layer]; | 1130 rootLayer_ = [CALayer layer]; |
| 1115 | 1131 |
| 1116 // In a block so that the layers don't fade in. | 1132 // In a block so that the layers don't fade in. |
| 1117 { | 1133 { |
| 1118 ScopedCAActionDisabler disabler; | 1134 ScopedCAActionDisabler disabler; |
| 1119 // Background layer -- the visible part of the window. | 1135 // Background layer -- the visible part of the window. |
| 1120 gray_.reset(CGColorCreateGenericGray(0.39, 1.0)); | 1136 gray_.reset(CGColorCreateGenericGray(kCentralGray, 1.0)); |
| 1121 bgLayer_ = [CALayer layer]; | 1137 bgLayer_ = [CALayer layer]; |
| 1122 bgLayer_.backgroundColor = gray_; | 1138 bgLayer_.backgroundColor = gray_; |
| 1123 bgLayer_.frame = NSRectToCGRect(containingRect_); | 1139 bgLayer_.frame = NSRectToCGRect(containingRect_); |
| 1124 bgLayer_.masksToBounds = YES; | 1140 bgLayer_.masksToBounds = YES; |
| 1125 [rootLayer_ addSublayer:bgLayer_]; | 1141 [rootLayer_ addSublayer:bgLayer_]; |
| 1126 | 1142 |
| 1127 // Selection highlight layer. | 1143 // Selection highlight layer. |
| 1128 darkBlue_.reset(CGColorCreateGenericRGB(0.25, 0.34, 0.86, 1.0)); | 1144 darkBlue_.reset(CGColorCreateGenericRGB(0.25, 0.34, 0.86, 1.0)); |
| 1129 selectionHighlight_ = [CALayer layer]; | 1145 selectionHighlight_ = [CALayer layer]; |
| 1130 selectionHighlight_.backgroundColor = darkBlue_; | 1146 selectionHighlight_.backgroundColor = darkBlue_; |
| 1131 selectionHighlight_.cornerRadius = 5.0; | 1147 selectionHighlight_.cornerRadius = 5.0; |
| 1132 selectionHighlight_.zPosition = -1; // Behind other layers. | 1148 selectionHighlight_.zPosition = -1; // Behind other layers. |
| 1133 selectionHighlight_.hidden = YES; | 1149 selectionHighlight_.hidden = YES; |
| 1134 [bgLayer_ addSublayer:selectionHighlight_]; | 1150 [bgLayer_ addSublayer:selectionHighlight_]; |
| 1135 | 1151 |
| 1136 // Top gradient. | 1152 // Bottom gradient. |
| 1137 CALayer* gradientLayer = [DarkGradientLayer layer]; | 1153 CALayer* gradientLayer = [[[GrayGradientLayer alloc] |
| 1154 initWithStartGray:kCentralGray endGray:kBottomGray] autorelease]; | |
| 1138 gradientLayer.frame = CGRectMake( | 1155 gradientLayer.frame = CGRectMake( |
| 1139 0, | 1156 0, |
| 1140 NSHeight(containingRect_) - kTopGradientHeight, | 1157 0, |
| 1141 NSWidth(containingRect_), | 1158 NSWidth(containingRect_), |
| 1142 kTopGradientHeight); | 1159 kBottomGradientHeight); |
| 1143 [gradientLayer setNeedsDisplay]; // Draw once. | 1160 [gradientLayer setNeedsDisplay]; // Draw once. |
| 1144 [bgLayer_ addSublayer:gradientLayer]; | 1161 [bgLayer_ addSublayer:gradientLayer]; |
| 1145 } | 1162 } |
| 1163 // Top gradient (fades in). | |
| 1164 CGFloat toolbarHeight = NSHeight([self frame]) - NSHeight(containingRect_); | |
| 1165 topGradient_ = [[[GrayGradientLayer alloc] | |
| 1166 initWithStartGray:kTopGray endGray:kCentralGray] autorelease]; | |
| 1167 topGradient_.frame = CGRectMake( | |
| 1168 0, | |
| 1169 NSHeight([self frame]) - toolbarHeight, | |
| 1170 NSWidth(containingRect_), | |
| 1171 toolbarHeight); | |
| 1172 [topGradient_ setNeedsDisplay]; // Draw once. | |
| 1173 [rootLayer_ addSublayer:topGradient_]; | |
| 1174 NSTimeInterval interval = | |
| 1175 kDefaultAnimationDuration * (slomo ? kSlomoFactor : 1); | |
| 1176 AnimateCALayerOpacityFromTo(topGradient_, 0, 1, interval); | |
| 1146 | 1177 |
| 1147 // Layers for the tab thumbnails. | 1178 // Layers for the tab thumbnails. |
| 1148 tileSet_->Build(tabStripModel_); | 1179 tileSet_->Build(tabStripModel_); |
| 1149 tileSet_->Layout(containingRect_); | 1180 tileSet_->Layout(containingRect_); |
| 1150 allThumbnailLayers_.reset( | 1181 allThumbnailLayers_.reset( |
| 1151 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); | 1182 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); |
| 1152 allFaviconLayers_.reset( | 1183 allFaviconLayers_.reset( |
| 1153 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); | 1184 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); |
| 1154 allTitleLayers_.reset( | 1185 allTitleLayers_.reset( |
| 1155 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); | 1186 [[NSMutableArray alloc] initWithCapacity:tabStripModel_->count()]); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1392 forKeyPath:@"transform.scale"]; | 1423 forKeyPath:@"transform.scale"]; |
| 1393 titleLayer.opacity = 0; | 1424 titleLayer.opacity = 0; |
| 1394 } | 1425 } |
| 1395 | 1426 |
| 1396 - (void)fadeAwayInSlomo:(BOOL)slomo { | 1427 - (void)fadeAwayInSlomo:(BOOL)slomo { |
| 1397 if (state_ == tabpose::kFadingOut) | 1428 if (state_ == tabpose::kFadingOut) |
| 1398 return; | 1429 return; |
| 1399 | 1430 |
| 1400 state_ = tabpose::kFadingOut; | 1431 state_ = tabpose::kFadingOut; |
| 1401 [self setAcceptsMouseMovedEvents:NO]; | 1432 [self setAcceptsMouseMovedEvents:NO]; |
| 1402 | 1433 |
|
viettrungluu
2011/03/08 01:33:40
wha?
| |
| 1434 | |
| 1403 // Select chosen tab. | 1435 // Select chosen tab. |
| 1404 if (tileSet_->selected_index() < tabStripModel_->count()) { | 1436 if (tileSet_->selected_index() < tabStripModel_->count()) { |
| 1405 tabStripModel_->SelectTabContentsAt(tileSet_->selected_index(), | 1437 tabStripModel_->SelectTabContentsAt(tileSet_->selected_index(), |
| 1406 /*user_gesture=*/true); | 1438 /*user_gesture=*/true); |
| 1407 } else { | 1439 } else { |
| 1408 DCHECK_EQ(tileSet_->selected_index(), 0); | 1440 DCHECK_EQ(tileSet_->selected_index(), 0); |
| 1409 } | 1441 } |
| 1410 | 1442 |
| 1411 { | 1443 { |
| 1412 ScopedCAActionDisabler disableCAActions; | 1444 ScopedCAActionDisabler disableCAActions; |
| 1413 | 1445 |
| 1414 // Move the selected layer on top of all other layers. | 1446 // Move the selected layer on top of all other layers. |
| 1415 [self selectedLayer].zPosition = 1; | 1447 [self selectedLayer].zPosition = 1; |
| 1416 | 1448 |
| 1417 selectionHighlight_.hidden = YES; | 1449 selectionHighlight_.hidden = YES; |
| 1418 // Running animations with shadows is slow, so turn shadows off before | 1450 // Running animations with shadows is slow, so turn shadows off before |
| 1419 // running the exit animation. | 1451 // running the exit animation. |
| 1420 for (CALayer* layer in allThumbnailLayers_.get()) | 1452 for (CALayer* layer in allThumbnailLayers_.get()) |
| 1421 layer.shadowOpacity = 0.0; | 1453 layer.shadowOpacity = 0.0; |
| 1422 | 1454 |
| 1423 [self updateClosebuttonLayersVisibility]; | 1455 [self updateClosebuttonLayersVisibility]; |
| 1424 } | 1456 } |
| 1425 | 1457 |
| 1426 // Animate layers out, all in one transaction. | 1458 // Animate layers out, all in one transaction. |
| 1427 CGFloat duration = | 1459 CGFloat duration = |
| 1428 1.3 * kDefaultAnimationDuration * (slomo ? kSlomoFactor : 1); | 1460 1.3 * kDefaultAnimationDuration * (slomo ? kSlomoFactor : 1); |
| 1429 ScopedCAActionSetDuration durationSetter(duration); | 1461 ScopedCAActionSetDuration durationSetter(duration); |
| 1430 for (int i = 0; i < tabStripModel_->count(); ++i) | 1462 for (int i = 0; i < tabStripModel_->count(); ++i) |
| 1431 [self fadeAwayTileAtIndex:i]; | 1463 [self fadeAwayTileAtIndex:i]; |
| 1464 AnimateCALayerOpacityFromTo(topGradient_, 1, 0, duration); | |
| 1432 } | 1465 } |
| 1433 | 1466 |
| 1434 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished { | 1467 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished { |
| 1435 NSString* animationId = [animation valueForKey:kAnimationIdKey]; | 1468 NSString* animationId = [animation valueForKey:kAnimationIdKey]; |
| 1436 if ([animationId isEqualToString:kAnimationIdFadeIn]) { | 1469 if ([animationId isEqualToString:kAnimationIdFadeIn]) { |
| 1437 if (finished && state_ == tabpose::kFadingIn) { | 1470 if (finished && state_ == tabpose::kFadingIn) { |
| 1438 // If the user clicks while the fade in animation is still running, | 1471 // If the user clicks while the fade in animation is still running, |
| 1439 // |state_| is already kFadingOut. In that case, don't do anything. | 1472 // |state_| is already kFadingOut. In that case, don't do anything. |
| 1440 state_ = tabpose::kFadedIn; | 1473 state_ = tabpose::kFadedIn; |
| 1441 | 1474 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1657 tile.set_tab_contents(contents->tab_contents()); | 1690 tile.set_tab_contents(contents->tab_contents()); |
| 1658 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; | 1691 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; |
| 1659 [thumbLayer setTabContents:contents->tab_contents()]; | 1692 [thumbLayer setTabContents:contents->tab_contents()]; |
| 1660 } | 1693 } |
| 1661 | 1694 |
| 1662 - (void)tabStripModelDeleted { | 1695 - (void)tabStripModelDeleted { |
| 1663 [self close]; | 1696 [self close]; |
| 1664 } | 1697 } |
| 1665 | 1698 |
| 1666 @end | 1699 @end |
| OLD | NEW |