| 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 // This file contains the Mac implementation the download animation, displayed | 5 // This file contains the Mac implementation the download animation, displayed |
| 6 // at the start of a download. The animation produces an arrow pointing | 6 // at the start of a download. The animation produces an arrow pointing |
| 7 // downwards and animates towards the bottom of the window where the new | 7 // downwards and animates towards the bottom of the window where the new |
| 8 // download appears in the download shelf. | 8 // download appears in the download shelf. |
| 9 | 9 |
| 10 #include "chrome/browser/download/download_started_animation.h" | 10 #include "chrome/browser/download/download_started_animation.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(DownloadAnimationTabObserver); | 78 DISALLOW_COPY_AND_ASSIGN(DownloadAnimationTabObserver); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 @implementation DownloadStartedAnimationMac | 81 @implementation DownloadStartedAnimationMac |
| 82 | 82 |
| 83 - (id)initWithTabContents:(TabContents*)tabContents { | 83 - (id)initWithTabContents:(TabContents*)tabContents { |
| 84 if ((self = [super init])) { | 84 if ((self = [super init])) { |
| 85 // Load the image of the download arrow. | 85 // Load the image of the download arrow. |
| 86 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); | 86 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); |
| 87 SkBitmap* imageBitmap = bundle.GetBitmapNamed(IDR_DOWNLOAD_ANIMATION_BEGIN); | 87 NSImage* image = bundle.GetNSImageNamed(IDR_DOWNLOAD_ANIMATION_BEGIN); |
| 88 scoped_cftyperef<CGImageRef> image(SkCreateCGImageRef(*imageBitmap)); | |
| 89 | 88 |
| 90 // Figure out the positioning in the current tab. Try to position the layer | 89 // Figure out the positioning in the current tab. Try to position the layer |
| 91 // against the left edge, and three times the download image's height from | 90 // against the left edge, and three times the download image's height from |
| 92 // the bottom of the tab, assuming there is enough room. If there isn't | 91 // the bottom of the tab, assuming there is enough room. If there isn't |
| 93 // enough, don't show the animation and let the shelf speak for itself. | 92 // enough, don't show the animation and let the shelf speak for itself. |
| 94 gfx::Rect bounds; | 93 gfx::Rect bounds; |
| 95 tabContents->GetContainerBounds(&bounds); | 94 tabContents->GetContainerBounds(&bounds); |
| 96 imageWidth_ = CGImageGetWidth(image); | 95 imageWidth_ = [image size].width; |
| 97 CGFloat imageHeight = CGImageGetHeight(image); | 96 CGFloat imageHeight = [image size].height; |
| 98 | 97 |
| 99 // Sanity check the size in case there's no room to display the animation. | 98 // Sanity check the size in case there's no room to display the animation. |
| 100 if (bounds.height() < imageHeight) { | 99 if (bounds.height() < imageHeight) { |
| 101 [self release]; | 100 [self release]; |
| 102 return nil; | 101 return nil; |
| 103 } | 102 } |
| 104 | 103 |
| 105 NSView* tabContentsView = tabContents->GetNativeView(); | 104 NSView* tabContentsView = tabContents->GetNativeView(); |
| 106 NSWindow* parentWindow = [tabContentsView window]; | 105 NSWindow* parentWindow = [tabContentsView window]; |
| 107 if (!parentWindow) { | 106 if (!parentWindow) { |
| 108 // The tab is no longer frontmost. | 107 // The tab is no longer frontmost. |
| 109 [self release]; | 108 [self release]; |
| 110 return nil; | 109 return nil; |
| 111 } | 110 } |
| 112 | 111 |
| 113 NSPoint origin = [tabContentsView frame].origin; | 112 NSPoint origin = [tabContentsView frame].origin; |
| 114 origin = [tabContentsView convertPoint:origin toView:nil]; | 113 origin = [tabContentsView convertPoint:origin toView:nil]; |
| 115 origin = [parentWindow convertBaseToScreen:origin]; | 114 origin = [parentWindow convertBaseToScreen:origin]; |
| 116 | 115 |
| 117 // Create the animation object to assist in animating and fading. | 116 // Create the animation object to assist in animating and fading. |
| 118 CGFloat animationHeight = MIN(bounds.height(), 4 * imageHeight); | 117 CGFloat animationHeight = MIN(bounds.height(), 4 * imageHeight); |
| 119 NSRect frame = NSMakeRect(origin.x, origin.y, imageWidth_, animationHeight); | 118 NSRect frame = NSMakeRect(origin.x, origin.y, imageWidth_, animationHeight); |
| 120 animation_ = [[AnimatableImage alloc] initWithImage:(id)image.get() | 119 animation_ = [[AnimatableImage alloc] initWithImage:image |
| 121 animationFrame:frame]; | 120 animationFrame:frame]; |
| 122 [parentWindow addChildWindow:animation_ ordered:NSWindowAbove]; | 121 [parentWindow addChildWindow:animation_ ordered:NSWindowAbove]; |
| 123 | 122 |
| 124 animationHeight = MIN(bounds.height(), 3 * imageHeight); | 123 animationHeight = MIN(bounds.height(), 3 * imageHeight); |
| 125 [animation_ setStartFrame:CGRectMake(0, animationHeight, | 124 [animation_ setStartFrame:CGRectMake(0, animationHeight, |
| 126 imageWidth_, imageHeight)]; | 125 imageWidth_, imageHeight)]; |
| 127 [animation_ setEndFrame:CGRectMake(0, imageHeight, | 126 [animation_ setEndFrame:CGRectMake(0, imageHeight, |
| 128 imageWidth_, imageHeight)]; | 127 imageWidth_, imageHeight)]; |
| 129 [animation_ setStartOpacity:1.0]; | 128 [animation_ setStartOpacity:1.0]; |
| 130 [animation_ setEndOpacity:0.4]; | 129 [animation_ setEndOpacity:0.4]; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 181 } |
| 183 | 182 |
| 184 @end | 183 @end |
| 185 | 184 |
| 186 void DownloadStartedAnimation::Show(TabContents* tab_contents) { | 185 void DownloadStartedAnimation::Show(TabContents* tab_contents) { |
| 187 DCHECK(tab_contents); | 186 DCHECK(tab_contents); |
| 188 | 187 |
| 189 // Will be deleted when the animation is complete. | 188 // Will be deleted when the animation is complete. |
| 190 [DownloadStartedAnimationMac startAnimationWithTabContents:tab_contents]; | 189 [DownloadStartedAnimationMac startAnimationWithTabContents:tab_contents]; |
| 191 } | 190 } |
| OLD | NEW |