| OLD | NEW |
| 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" |
| 13 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
| 14 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 15 | 17 |
| 16 class PopupBlockedAnimationObserver; | 18 class PopupBlockedAnimationObserver; |
| 17 | 19 |
| 18 // A class for managing the Core Animation popup blocked animation. | 20 // A class for managing the Core Animation popup blocked animation. |
| 19 @interface PopupBlockedAnimationMac : NSObject { | 21 @interface PopupBlockedAnimationMac : NSObject { |
| 20 @private | 22 @private |
| 21 // The observer for the TabContents we are drawing on. | 23 // The observer for the TabContents we are drawing on. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 NSRect contentFrame = [[animation_ contentView] frame]; | 111 NSRect contentFrame = [[animation_ contentView] frame]; |
| 110 [animation_ setStartFrame:CGRectMake(0, | 112 [animation_ setStartFrame:CGRectMake(0, |
| 111 imageHeight / 2, | 113 imageHeight / 2, |
| 112 imageWidth, | 114 imageWidth, |
| 113 imageHeight)]; | 115 imageHeight)]; |
| 114 | 116 |
| 115 // Set the end frame to be small (a la the actual blocked icon) and inset | 117 // Set the end frame to be small (a la the actual blocked icon) and inset |
| 116 // slightly to the Omnibox. While the geometry won't align perfectly, it's | 118 // slightly to the Omnibox. While the geometry won't align perfectly, it's |
| 117 // close enough for the user to take note of the new icon. These numbers | 119 // close enough for the user to take note of the new icon. These numbers |
| 118 // come from measuring the Omnibox without any page actions. | 120 // come from measuring the Omnibox without any page actions. |
| 119 [animation_ setEndFrame:CGRectMake(animationFrame.size.width - 115, | 121 CGRect endFrame = CGRectMake(animationFrame.size.width - 115, |
| 120 animationFrame.size.height - 50, | 122 animationFrame.size.height - 50, |
| 121 16, 16)]; | 123 16, 16); |
| 124 |
| 125 // If the location-bar can be found, ask it for better |
| 126 // coordinates. |
| 127 BrowserWindowController* bwc = [parentWindow windowController]; |
| 128 if ([bwc isKindOfClass:[BrowserWindowController class]]) { |
| 129 LocationBarViewMac* lbvm = [bwc locationBarBridge]; |
| 130 if (lbvm) { |
| 131 NSRect frame = lbvm->GetBlockedPopupRect(); |
| 132 if (!NSIsEmptyRect(frame)) { |
| 133 // Convert up to the screen, then back down to the animation |
| 134 // window. |
| 135 NSPoint screenPoint = [parentWindow convertBaseToScreen:frame.origin]; |
| 136 frame.origin = [animation_ convertScreenToBase:screenPoint]; |
| 137 endFrame = NSRectToCGRect(frame); |
| 138 } |
| 139 } |
| 140 } |
| 141 |
| 142 [animation_ setEndFrame:endFrame]; |
| 122 [animation_ setStartOpacity:1.0]; | 143 [animation_ setStartOpacity:1.0]; |
| 123 [animation_ setEndOpacity:0.2]; | 144 [animation_ setEndOpacity:0.2]; |
| 124 [animation_ setDuration:0.7]; | 145 [animation_ setDuration:0.7]; |
| 125 | 146 |
| 126 observer_.reset(new PopupBlockedAnimationObserver(self, tabContents)); | 147 observer_.reset(new PopupBlockedAnimationObserver(self, tabContents)); |
| 127 | 148 |
| 128 // When the window is about to close, release this object and remove the | 149 // When the window is about to close, release this object and remove the |
| 129 // animation from the parent window. | 150 // animation from the parent window. |
| 130 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 151 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 131 [center addObserver:self | 152 [center addObserver:self |
| (...skipping 19 matching lines...) Expand all Loading... |
| 151 [[animation_ parentWindow] removeChildWindow:animation_]; | 172 [[animation_ parentWindow] removeChildWindow:animation_]; |
| 152 [self release]; | 173 [self release]; |
| 153 } | 174 } |
| 154 | 175 |
| 155 @end | 176 @end |
| 156 | 177 |
| 157 void PopupBlockedAnimation::Show(TabContents* tab_contents) { | 178 void PopupBlockedAnimation::Show(TabContents* tab_contents) { |
| 158 // 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. |
| 159 [[PopupBlockedAnimationMac alloc] initWithTabContents:tab_contents]; | 180 [[PopupBlockedAnimationMac alloc] initWithTabContents:tab_contents]; |
| 160 } | 181 } |
| OLD | NEW |