| 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/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_view.h" |
| 22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 24 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 24 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 25 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 27 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 28 | 29 |
| 29 class DownloadAnimationWebObserver; | 30 class DownloadAnimationWebObserver; |
| 30 | 31 |
| 31 using content::WebContents; | 32 using content::WebContents; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Load the image of the download arrow. | 99 // Load the image of the download arrow. |
| 99 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); | 100 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); |
| 100 NSImage* image = | 101 NSImage* image = |
| 101 bundle.GetNativeImageNamed(IDR_DOWNLOAD_ANIMATION_BEGIN).ToNSImage(); | 102 bundle.GetNativeImageNamed(IDR_DOWNLOAD_ANIMATION_BEGIN).ToNSImage(); |
| 102 | 103 |
| 103 // Figure out the positioning in the current tab. Try to position the layer | 104 // Figure out the positioning in the current tab. Try to position the layer |
| 104 // against the left edge, and three times the download image's height from | 105 // against the left edge, and three times the download image's height from |
| 105 // the bottom of the tab, assuming there is enough room. If there isn't | 106 // the bottom of the tab, assuming there is enough room. If there isn't |
| 106 // enough, don't show the animation and let the shelf speak for itself. | 107 // enough, don't show the animation and let the shelf speak for itself. |
| 107 gfx::Rect bounds; | 108 gfx::Rect bounds; |
| 108 webContents->GetContainerBounds(&bounds); | 109 webContents->GetView()->GetContainerBounds(&bounds); |
| 109 imageWidth_ = [image size].width; | 110 imageWidth_ = [image size].width; |
| 110 CGFloat imageHeight = [image size].height; | 111 CGFloat imageHeight = [image size].height; |
| 111 | 112 |
| 112 // Sanity check the size in case there's no room to display the animation. | 113 // Sanity check the size in case there's no room to display the animation. |
| 113 if (bounds.height() < imageHeight) { | 114 if (bounds.height() < imageHeight) { |
| 114 [self release]; | 115 [self release]; |
| 115 return nil; | 116 return nil; |
| 116 } | 117 } |
| 117 | 118 |
| 118 NSView* tabContentsView = webContents->GetNativeView(); | 119 NSView* tabContentsView = webContents->GetView()->GetNativeView(); |
| 119 NSWindow* parentWindow = [tabContentsView window]; | 120 NSWindow* parentWindow = [tabContentsView window]; |
| 120 if (!parentWindow) { | 121 if (!parentWindow) { |
| 121 // The tab is no longer frontmost. | 122 // The tab is no longer frontmost. |
| 122 [self release]; | 123 [self release]; |
| 123 return nil; | 124 return nil; |
| 124 } | 125 } |
| 125 | 126 |
| 126 NSPoint origin = [tabContentsView frame].origin; | 127 NSPoint origin = [tabContentsView frame].origin; |
| 127 origin = [tabContentsView convertPoint:origin toView:nil]; | 128 origin = [tabContentsView convertPoint:origin toView:nil]; |
| 128 origin = [parentWindow convertBaseToScreen:origin]; | 129 origin = [parentWindow convertBaseToScreen:origin]; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 201 } |
| 201 | 202 |
| 202 @end | 203 @end |
| 203 | 204 |
| 204 void DownloadStartedAnimation::Show(WebContents* web_contents) { | 205 void DownloadStartedAnimation::Show(WebContents* web_contents) { |
| 205 DCHECK(web_contents); | 206 DCHECK(web_contents); |
| 206 | 207 |
| 207 // Will be deleted when the animation is complete. | 208 // Will be deleted when the animation is complete. |
| 208 [DownloadStartedAnimationMac startAnimationWithWebContents:web_contents]; | 209 [DownloadStartedAnimationMac startAnimationWithWebContents:web_contents]; |
| 209 } | 210 } |
| OLD | NEW |