| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| 11 | 11 |
| 12 #import <QuartzCore/QuartzCore.h> | 12 #import <QuartzCore/QuartzCore.h> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #import "chrome/browser/ui/cocoa/animatable_image.h" | 15 #import "chrome/browser/ui/cocoa/animatable_image.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 19 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 19 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 20 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 23 | 24 |
| 24 class DownloadAnimationWebObserver; | 25 class DownloadAnimationWebObserver; |
| 25 | 26 |
| 26 // A class for managing the Core Animation download animation. | 27 // A class for managing the Core Animation download animation. |
| 27 // Should be instantiated using +startAnimationWithWebContents:. | 28 // Should be instantiated using +startAnimationWithWebContents:. |
| 28 @interface DownloadStartedAnimationMac : NSObject { | 29 @interface DownloadStartedAnimationMac : NSObject { |
| 29 @private | 30 @private |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 NSView* tabContentsView = webContents->GetNativeView(); | 62 NSView* tabContentsView = webContents->GetNativeView(); |
| 62 NSWindow* parentWindow = [tabContentsView window]; | 63 NSWindow* parentWindow = [tabContentsView window]; |
| 63 if (!parentWindow) { | 64 if (!parentWindow) { |
| 64 // The tab is no longer frontmost. | 65 // The tab is no longer frontmost. |
| 65 [self release]; | 66 [self release]; |
| 66 return nil; | 67 return nil; |
| 67 } | 68 } |
| 68 | 69 |
| 69 NSPoint origin = [tabContentsView frame].origin; | 70 NSPoint origin = [tabContentsView frame].origin; |
| 70 origin = [tabContentsView convertPoint:origin toView:nil]; | 71 origin = [tabContentsView convertPoint:origin toView:nil]; |
| 71 origin = [parentWindow convertBaseToScreen:origin]; | 72 origin = ui::ConvertPointFromWindowToScreen(parentWindow, origin); |
| 72 | 73 |
| 73 // Create the animation object to assist in animating and fading. | 74 // Create the animation object to assist in animating and fading. |
| 74 CGFloat animationHeight = MIN(bounds.height(), 4 * imageHeight); | 75 CGFloat animationHeight = MIN(bounds.height(), 4 * imageHeight); |
| 75 NSRect frame = NSMakeRect(origin.x, origin.y, imageWidth_, animationHeight); | 76 NSRect frame = NSMakeRect(origin.x, origin.y, imageWidth_, animationHeight); |
| 76 animation_ = [[AnimatableImage alloc] initWithImage:image | 77 animation_ = [[AnimatableImage alloc] initWithImage:image |
| 77 animationFrame:frame]; | 78 animationFrame:frame]; |
| 78 [parentWindow addChildWindow:animation_ ordered:NSWindowAbove]; | 79 [parentWindow addChildWindow:animation_ ordered:NSWindowAbove]; |
| 79 | 80 |
| 80 animationHeight = MIN(bounds.height(), 3 * imageHeight); | 81 animationHeight = MIN(bounds.height(), 3 * imageHeight); |
| 81 [animation_ setStartFrame:CGRectMake(0, animationHeight, | 82 [animation_ setStartFrame:CGRectMake(0, animationHeight, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 142 } |
| 142 | 143 |
| 143 @end | 144 @end |
| 144 | 145 |
| 145 void DownloadStartedAnimation::Show(content::WebContents* web_contents) { | 146 void DownloadStartedAnimation::Show(content::WebContents* web_contents) { |
| 146 DCHECK(web_contents); | 147 DCHECK(web_contents); |
| 147 | 148 |
| 148 // Will be deleted when the animation is complete. | 149 // Will be deleted when the animation is complete. |
| 149 [DownloadStartedAnimationMac startAnimationWithWebContents:web_contents]; | 150 [DownloadStartedAnimationMac startAnimationWithWebContents:web_contents]; |
| 150 } | 151 } |
| OLD | NEW |