Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/browser/cocoa/download_started_animation_mac.mm

Issue 3169030: Change the conditions on which the popup blocked animation is shown to be more reliable. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix compile Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 17 matching lines...) Expand all
28 // Should be instantiated using +startAnimationWithTabContents:. 28 // Should be instantiated using +startAnimationWithTabContents:.
29 @interface DownloadStartedAnimationMac : NSObject { 29 @interface DownloadStartedAnimationMac : NSObject {
30 @private 30 @private
31 // The observer for the TabContents we are drawing on. 31 // The observer for the TabContents we are drawing on.
32 scoped_ptr<DownloadAnimationTabObserver> observer_; 32 scoped_ptr<DownloadAnimationTabObserver> observer_;
33 CGFloat imageWidth_; 33 CGFloat imageWidth_;
34 AnimatableImage* animation_; 34 AnimatableImage* animation_;
35 }; 35 };
36 36
37 + (void)startAnimationWithTabContents:(TabContents*)tabContents; 37 + (void)startAnimationWithTabContents:(TabContents*)tabContents;
38 // Called by our DownloadAnimationTabObserver if the tab is hidden or closed. 38
39 - (void)animationComplete; 39 // Called by the Observer if the tab is hidden or closed.
40 - (void)closeAnimation;
40 41
41 @end 42 @end
42 43
43 // A helper class to monitor tab hidden and closed notifications. If we receive 44 // A helper class to monitor tab hidden and closed notifications. If we receive
44 // such a notification, we stop the animation. 45 // such a notification, we stop the animation.
45 class DownloadAnimationTabObserver : public NotificationObserver { 46 class DownloadAnimationTabObserver : public NotificationObserver {
46 public: 47 public:
47 DownloadAnimationTabObserver(DownloadStartedAnimationMac* owner, 48 DownloadAnimationTabObserver(DownloadStartedAnimationMac* owner,
48 TabContents* tab_contents) 49 TabContents* tab_contents)
49 : owner_(owner), 50 : owner_(owner),
50 tab_contents_(tab_contents) { 51 tab_contents_(tab_contents) {
51 registrar_.Add(this, 52 registrar_.Add(this,
52 NotificationType::TAB_CONTENTS_HIDDEN, 53 NotificationType::TAB_CONTENTS_HIDDEN,
53 Source<TabContents>(tab_contents_)); 54 Source<TabContents>(tab_contents_));
54 registrar_.Add(this, 55 registrar_.Add(this,
55 NotificationType::TAB_CONTENTS_DESTROYED, 56 NotificationType::TAB_CONTENTS_DESTROYED,
56 Source<TabContents>(tab_contents_)); 57 Source<TabContents>(tab_contents_));
57 } 58 }
58 59
59 // Runs when a tab is hidden or destroyed. Let our owner know we should end 60 // Runs when a tab is hidden or destroyed. Let our owner know we should end
60 // the animation. 61 // the animation.
61 void Observe(NotificationType type, 62 void Observe(NotificationType type,
62 const NotificationSource& source, 63 const NotificationSource& source,
63 const NotificationDetails& details) { 64 const NotificationDetails& details) {
64 // This ends up deleting us. 65 // This ends up deleting us.
65 [owner_ animationComplete]; 66 [owner_ closeAnimation];
66 } 67 }
67 68
68 private: 69 private:
69 // The object we need to inform when we get a notification. Weak. 70 // The object we need to inform when we get a notification. Weak.
70 DownloadStartedAnimationMac* owner_; 71 DownloadStartedAnimationMac* owner_;
71 72
72 // The tab we are observing. Weak. 73 // The tab we are observing. Weak.
73 TabContents* tab_contents_; 74 TabContents* tab_contents_;
74 75
75 // Used for registering to receive notifications and automatic clean up. 76 // Used for registering to receive notifications and automatic clean up.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Called when the parent window is resized. 156 // Called when the parent window is resized.
156 - (void)parentWindowChanged:(NSNotification*)notification { 157 - (void)parentWindowChanged:(NSNotification*)notification {
157 NSWindow* parentWindow = [animation_ parentWindow]; 158 NSWindow* parentWindow = [animation_ parentWindow];
158 DCHECK([[notification object] isEqual:parentWindow]); 159 DCHECK([[notification object] isEqual:parentWindow]);
159 NSRect parentFrame = [parentWindow frame]; 160 NSRect parentFrame = [parentWindow frame];
160 NSRect frame = parentFrame; 161 NSRect frame = parentFrame;
161 frame.size.width = MIN(imageWidth_, NSWidth(parentFrame)); 162 frame.size.width = MIN(imageWidth_, NSWidth(parentFrame));
162 [animation_ setFrame:frame display:YES]; 163 [animation_ setFrame:frame display:YES];
163 } 164 }
164 165
166 - (void)closeAnimation {
Scott Hess - ex-Googler 2010/08/31 14:29:48 +1 for the name change, -animationComplete never q
167 [animation_ close];
168 }
169
170 // When the animation closes, close the parent window.
Scott Hess - ex-Googler 2010/08/31 14:29:48 Either this comment is too subtle for me to unders
165 - (void)windowWillClose:(NSNotification*)notification { 171 - (void)windowWillClose:(NSNotification*)notification {
166 DCHECK([[notification object] isEqual:animation_]); 172 DCHECK([[notification object] isEqual:animation_]);
167 [self animationComplete];
168 }
169
170 - (void)animationComplete {
171 [[animation_ parentWindow] removeChildWindow:animation_]; 173 [[animation_ parentWindow] removeChildWindow:animation_];
172 [self release]; 174 [self release];
173 } 175 }
174 176
175 + (void)startAnimationWithTabContents:(TabContents*)contents { 177 + (void)startAnimationWithTabContents:(TabContents*)contents {
176 // Will be deleted when the animation is complete in -animationComplete. 178 // Will be deleted when the animation window closes.
177 DownloadStartedAnimationMac* controller = 179 DownloadStartedAnimationMac* controller =
178 [[self alloc] initWithTabContents:contents]; 180 [[self alloc] initWithTabContents:contents];
179 // The initializer can return nil. 181 // The initializer can return nil.
180 if (!controller) 182 if (!controller)
181 return; 183 return;
182 184
183 // The |animation_| releaes itself when done. 185 // The |animation_| releaes itself when done.
Scott Hess - ex-Googler 2010/08/31 14:29:48 "releases", while we're in here.
184 [controller->animation_ startAnimation]; 186 [controller->animation_ startAnimation];
185 } 187 }
186 188
187 @end 189 @end
188 190
189 void DownloadStartedAnimation::Show(TabContents* tab_contents) { 191 void DownloadStartedAnimation::Show(TabContents* tab_contents) {
190 DCHECK(tab_contents); 192 DCHECK(tab_contents);
191 193
192 // Will be deleted when the animation is complete. 194 // Will be deleted when the animation is complete.
193 [DownloadStartedAnimationMac startAnimationWithTabContents:tab_contents]; 195 [DownloadStartedAnimationMac startAnimationWithTabContents:tab_contents];
194 } 196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698