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

Side by Side Diff: chrome/browser/cocoa/popup_blocked_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 #include "chrome/browser/popup_blocked_animation.h" 5 #include "chrome/browser/popup_blocked_animation.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #import <QuartzCore/QuartzCore.h> 8 #import <QuartzCore/QuartzCore.h>
9 9
10 #import "base/nsimage_cache_mac.h" 10 #import "base/nsimage_cache_mac.h"
11 #import "chrome/browser/cocoa/animatable_image.h" 11 #import "chrome/browser/cocoa/animatable_image.h"
12 #import "chrome/browser/cocoa/browser_window_controller.h" 12 #import "chrome/browser/cocoa/browser_window_controller.h"
13 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" 13 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/common/notification_registrar.h" 15 #include "chrome/common/notification_registrar.h"
16 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
17 17
18 class PopupBlockedAnimationObserver; 18 class PopupBlockedAnimationObserver;
19 19
20 // A class for managing the Core Animation popup blocked animation. 20 // A class for managing the Core Animation popup blocked animation.
21 @interface PopupBlockedAnimationMac : NSObject { 21 @interface PopupBlockedAnimationMac : NSObject {
22 @private 22 @private
23 // The observer for the TabContents we are drawing on. 23 // The observer for the TabContents we are drawing on.
24 scoped_ptr<PopupBlockedAnimationObserver> observer_; 24 scoped_ptr<PopupBlockedAnimationObserver> observer_;
25 AnimatableImage* animation_; 25 AnimatableImage* animation_;
26 }; 26 };
27 27
28 // Called by our the Observer if the tab is hidden or closed. 28 // Called by the Observer if the tab is hidden or closed.
29 - (void)animationComplete; 29 - (void)closeAnimation;
30 30
31 @end 31 @end
32 32
33 // A helper class to monitor tab hidden and closed notifications. If we receive 33 // A helper class to monitor tab hidden and closed notifications. If we receive
34 // such a notification, we stop the animation. 34 // such a notification, we stop the animation.
35 class PopupBlockedAnimationObserver : public NotificationObserver { 35 class PopupBlockedAnimationObserver : public NotificationObserver {
36 public: 36 public:
37 PopupBlockedAnimationObserver(PopupBlockedAnimationMac* owner, 37 PopupBlockedAnimationObserver(PopupBlockedAnimationMac* owner,
38 TabContents* tab_contents) 38 TabContents* tab_contents)
39 : owner_(owner), 39 : owner_(owner),
40 tab_contents_(tab_contents) { 40 tab_contents_(tab_contents) {
41 registrar_.Add(this, 41 registrar_.Add(this,
42 NotificationType::TAB_CONTENTS_HIDDEN, 42 NotificationType::TAB_CONTENTS_HIDDEN,
43 Source<TabContents>(tab_contents_)); 43 Source<TabContents>(tab_contents_));
44 registrar_.Add(this, 44 registrar_.Add(this,
45 NotificationType::TAB_CONTENTS_DESTROYED, 45 NotificationType::TAB_CONTENTS_DESTROYED,
46 Source<TabContents>(tab_contents_)); 46 Source<TabContents>(tab_contents_));
47 } 47 }
48 48
49 // Runs when a tab is hidden or destroyed. Let our owner know we should end 49 // Runs when a tab is hidden or destroyed. Let our owner know we should end
50 // the animation. 50 // the animation.
51 void Observe(NotificationType type, 51 void Observe(NotificationType type,
52 const NotificationSource& source, 52 const NotificationSource& source,
53 const NotificationDetails& details) { 53 const NotificationDetails& details) {
54 // This ends up deleting us. 54 // This ends up deleting us.
55 [owner_ animationComplete]; 55 [owner_ closeAnimation];
56 } 56 }
57 57
58 private: 58 private:
59 // The object we need to inform when we get a notification. Weak. 59 // The object we need to inform when we get a notification. Weak.
60 PopupBlockedAnimationMac* owner_; 60 PopupBlockedAnimationMac* owner_;
61 61
62 // The tab we are observing. Weak. 62 // The tab we are observing. Weak.
63 TabContents* tab_contents_; 63 TabContents* tab_contents_;
64 64
65 // Used for registering to receive notifications and automatic clean up. 65 // Used for registering to receive notifications and automatic clean up.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 [animation_ startAnimation]; 155 [animation_ startAnimation];
156 } 156 }
157 return self; 157 return self;
158 } 158 }
159 159
160 - (void)dealloc { 160 - (void)dealloc {
161 [[NSNotificationCenter defaultCenter] removeObserver:self]; 161 [[NSNotificationCenter defaultCenter] removeObserver:self];
162 [super dealloc]; 162 [super dealloc];
163 } 163 }
164 164
165 - (void)closeAnimation {
166 [animation_ close];
167 }
168
169 // When the animation window closes, release self.
165 - (void)windowWillClose:(NSNotification*)notification { 170 - (void)windowWillClose:(NSNotification*)notification {
166 DCHECK([[notification object] isEqual:animation_]); 171 DCHECK([[notification object] isEqual:animation_]);
167 [self animationComplete];
168 }
169
170 - (void)animationComplete {
171 [[animation_ parentWindow] removeChildWindow:animation_]; 172 [[animation_ parentWindow] removeChildWindow:animation_];
172 [self release]; 173 [self release];
173 } 174 }
174 175
175 @end 176 @end
176 177
177 void PopupBlockedAnimation::Show(TabContents* tab_contents) { 178 void PopupBlockedAnimation::Show(TabContents* tab_contents) {
178 // The object will clean up itself at the end of the animation. 179 // The object will clean up itself at the end of the animation.
179 [[PopupBlockedAnimationMac alloc] initWithTabContents:tab_contents]; 180 [[PopupBlockedAnimationMac alloc] initWithTabContents:tab_contents];
180 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698