| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/mac/mac_util.h" | 6 #include "base/mac/mac_util.h" |
| 7 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 7 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 8 #include "chrome/browser/tab_contents/infobar.h" | 8 #include "chrome/browser/tab_contents/infobar.h" |
| 9 #import "chrome/browser/ui/cocoa/animatable_view.h" | 9 #import "chrome/browser/ui/cocoa/animatable_view.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 11 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 12 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/view_id_util.h" | 13 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
| 16 #include "content/common/notification_source.h" | 17 #include "content/common/notification_source.h" |
| 17 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
| 18 | 19 |
| 19 // C++ class that receives INFOBAR_ADDED and INFOBAR_REMOVED | 20 // C++ class that receives INFOBAR_ADDED and INFOBAR_REMOVED |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // This code can be executed while InfoBarController is still on the stack, so | 119 // This code can be executed while InfoBarController is still on the stack, so |
| 119 // we retain and autorelease the controller to prevent it from being | 120 // we retain and autorelease the controller to prevent it from being |
| 120 // dealloc'ed too early. | 121 // dealloc'ed too early. |
| 121 [[controller retain] autorelease]; | 122 [[controller retain] autorelease]; |
| 122 [[controller view] removeFromSuperview]; | 123 [[controller view] removeFromSuperview]; |
| 123 [infobarControllers_ removeObject:controller]; | 124 [infobarControllers_ removeObject:controller]; |
| 124 [closingInfoBars_ removeObject:controller]; | 125 [closingInfoBars_ removeObject:controller]; |
| 125 [self positionInfoBarsAndRedraw]; | 126 [self positionInfoBarsAndRedraw]; |
| 126 } | 127 } |
| 127 | 128 |
| 129 - (BrowserWindowController*)browserWindowController { |
| 130 id controller = [[[self view] window] windowController]; |
| 131 if (![controller isKindOfClass:[BrowserWindowController class]]) |
| 132 return nil; |
| 133 return controller; |
| 134 } |
| 135 |
| 128 - (void)changeTabContents:(TabContentsWrapper*)contents { | 136 - (void)changeTabContents:(TabContentsWrapper*)contents { |
| 129 registrar_.RemoveAll(); | 137 registrar_.RemoveAll(); |
| 130 [self removeAllInfoBars]; | 138 [self removeAllInfoBars]; |
| 131 | 139 |
| 132 currentTabContents_ = contents; | 140 currentTabContents_ = contents; |
| 133 if (currentTabContents_) { | 141 if (currentTabContents_) { |
| 134 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { | 142 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { |
| 135 InfoBar* infobar = currentTabContents_->GetInfoBarDelegateAt(i)-> | 143 InfoBar* infobar = currentTabContents_->GetInfoBarDelegateAt(i)-> |
| 136 CreateInfoBar(currentTabContents_); | 144 CreateInfoBar(currentTabContents_); |
| 137 [self addInfoBar:infobar animate:NO]; | 145 [self addInfoBar:infobar animate:NO]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 | 159 |
| 152 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents { | 160 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents { |
| 153 if (currentTabContents_ == contents) | 161 if (currentTabContents_ == contents) |
| 154 [self changeTabContents:NULL]; | 162 [self changeTabContents:NULL]; |
| 155 } | 163 } |
| 156 | 164 |
| 157 - (NSUInteger)infobarCount { | 165 - (NSUInteger)infobarCount { |
| 158 return [infobarControllers_ count] - [closingInfoBars_ count]; | 166 return [infobarControllers_ count] - [closingInfoBars_ count]; |
| 159 } | 167 } |
| 160 | 168 |
| 161 - (CGFloat)antiSpoofHeight { | 169 - (CGFloat)overlappingTipHeight { |
| 162 return 0; | 170 return [self infobarCount] ? infobars::kTipHeight : 0; |
| 163 } | 171 } |
| 164 | 172 |
| 165 - (void)resizeView:(NSView*)view newHeight:(CGFloat)height { | 173 - (void)resizeView:(NSView*)view newHeight:(CGFloat)height { |
| 166 NSRect frame = [view frame]; | 174 NSRect frame = [view frame]; |
| 167 frame.size.height = height; | 175 frame.size.height = height; |
| 168 [view setFrame:frame]; | 176 [view setFrame:frame]; |
| 169 [self positionInfoBarsAndRedraw]; | 177 [self positionInfoBarsAndRedraw]; |
| 170 } | 178 } |
| 171 | 179 |
| 172 - (void)setAnimationInProgress:(BOOL)inProgress { | 180 - (void)setAnimationInProgress:(BOOL)inProgress { |
| 173 if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) | 181 if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) |
| 174 [resizeDelegate_ setAnimationInProgress:inProgress]; | 182 [resizeDelegate_ setAnimationInProgress:inProgress]; |
| 175 } | 183 } |
| 176 | 184 |
| 177 @end | 185 @end |
| 178 | 186 |
| 179 @implementation InfoBarContainerController (PrivateMethods) | 187 @implementation InfoBarContainerController (PrivateMethods) |
| 180 | 188 |
| 181 - (CGFloat)desiredHeight { | 189 - (CGFloat)desiredHeight { |
| 182 CGFloat height = 0; | 190 CGFloat height = 0; |
| 191 |
| 192 // Take out the height of the tip from the total size of the infobar so that |
| 193 // the tip overlaps the preceding infobar when there is more than one infobar. |
| 183 for (InfoBarController* controller in infobarControllers_.get()) | 194 for (InfoBarController* controller in infobarControllers_.get()) |
| 184 height += NSHeight([[controller view] frame]); | 195 height += NSHeight([[controller view] frame]) - infobars::kTipHeight; |
| 196 |
| 197 // If there are any infobars, add a little extra room for the tip of the first |
| 198 // infobar. |
| 199 if (height) |
| 200 height += infobars::kTipHeight; |
| 201 |
| 185 return height; | 202 return height; |
| 186 } | 203 } |
| 187 | 204 |
| 188 - (void)addInfoBar:(InfoBar*)infobar animate:(BOOL)animate { | 205 - (void)addInfoBar:(InfoBar*)infobar animate:(BOOL)animate { |
| 189 InfoBarController* controller = infobar->controller(); | 206 InfoBarController* controller = infobar->controller(); |
| 190 [controller setContainerController:self]; | 207 [controller setContainerController:self]; |
| 191 [[controller animatableView] setResizeDelegate:self]; | 208 [[controller animatableView] setResizeDelegate:self]; |
| 192 [[self view] addSubview:[controller view]]; | 209 [[self view] addSubview:[controller view]]; |
| 193 [infobarControllers_ addObject:[controller autorelease]]; | 210 [infobarControllers_ addObject:[controller autorelease]]; |
| 194 | 211 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // the others below. | 253 // the others below. |
| 237 for (InfoBarController* controller in | 254 for (InfoBarController* controller in |
| 238 [infobarControllers_ reverseObjectEnumerator]) { | 255 [infobarControllers_ reverseObjectEnumerator]) { |
| 239 NSView* view = [controller view]; | 256 NSView* view = [controller view]; |
| 240 NSRect frame = [view frame]; | 257 NSRect frame = [view frame]; |
| 241 frame.origin.x = NSMinX(containerBounds); | 258 frame.origin.x = NSMinX(containerBounds); |
| 242 frame.origin.y = minY; | 259 frame.origin.y = minY; |
| 243 frame.size.width = NSWidth(containerBounds); | 260 frame.size.width = NSWidth(containerBounds); |
| 244 [view setFrame:frame]; | 261 [view setFrame:frame]; |
| 245 | 262 |
| 246 minY += NSHeight(frame); | 263 minY += NSHeight(frame) - infobars::kTipHeight; |
| 247 } | 264 } |
| 248 | 265 |
| 249 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; | 266 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; |
| 250 } | 267 } |
| 251 | 268 |
| 252 @end | 269 @end |
| OLD | NEW |