| OLD | NEW |
| 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/logging.h" // for NOTREACHED() | 7 #include "base/logging.h" // for NOTREACHED() |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/cocoa/animatable_view.h" | 10 #import "chrome/browser/cocoa/animatable_view.h" |
| 11 #include "chrome/browser/cocoa/event_utils.h" | 11 #include "chrome/browser/cocoa/event_utils.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 // Asks the container controller to remove the infobar for this delegate. This | 80 // Asks the container controller to remove the infobar for this delegate. This |
| 81 // call will trigger a notification that starts the infobar animating closed. | 81 // call will trigger a notification that starts the infobar animating closed. |
| 82 - (void)removeInfoBar; | 82 - (void)removeInfoBar; |
| 83 | 83 |
| 84 // Performs final cleanup after an animation is finished or stopped, including | 84 // Performs final cleanup after an animation is finished or stopped, including |
| 85 // notifying the InfoBarDelegate that the infobar was closed and removing the | 85 // notifying the InfoBarDelegate that the infobar was closed and removing the |
| 86 // infobar from its container, if necessary. | 86 // infobar from its container, if necessary. |
| 87 - (void)cleanUpAfterAnimation:(BOOL)finished; | 87 - (void)cleanUpAfterAnimation:(BOOL)finished; |
| 88 | 88 |
| 89 // Removes the ok and cancel buttons, and resizes the textfield to use the | |
| 90 // space. | |
| 91 - (void)removeButtons; | |
| 92 | |
| 93 // Sets the info bar message to the specified |message|, with a hypertext | 89 // Sets the info bar message to the specified |message|, with a hypertext |
| 94 // style link. |link| will be inserted into message at |linkOffset|. | 90 // style link. |link| will be inserted into message at |linkOffset|. |
| 95 - (void)setLabelToMessage:(NSString*)message | 91 - (void)setLabelToMessage:(NSString*)message |
| 96 withLink:(NSString*)link | 92 withLink:(NSString*)link |
| 97 atOffset:(NSUInteger)linkOffset; | 93 atOffset:(NSUInteger)linkOffset; |
| 98 @end | 94 @end |
| 99 | 95 |
| 100 @implementation InfoBarController | 96 @implementation InfoBarController |
| 101 | 97 |
| 102 @synthesize containerController = containerController_; | 98 @synthesize containerController = containerController_; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 [attributes setObject:font | 204 [attributes setObject:font |
| 209 forKey:NSFontAttributeName]; | 205 forKey:NSFontAttributeName]; |
| 210 [attributes setObject:[NSCursor arrowCursor] | 206 [attributes setObject:[NSCursor arrowCursor] |
| 211 forKey:NSCursorAttributeName]; | 207 forKey:NSCursorAttributeName]; |
| 212 scoped_nsobject<NSAttributedString> attributedString( | 208 scoped_nsobject<NSAttributedString> attributedString( |
| 213 [[NSAttributedString alloc] initWithString:message | 209 [[NSAttributedString alloc] initWithString:message |
| 214 attributes:attributes]); | 210 attributes:attributes]); |
| 215 [[label_.get() textStorage] setAttributedString:attributedString]; | 211 [[label_.get() textStorage] setAttributedString:attributedString]; |
| 216 } | 212 } |
| 217 | 213 |
| 214 - (void)removeButtons { |
| 215 // Extend the label all the way across. |
| 216 NSRect labelFrame = [label_.get() frame]; |
| 217 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); |
| 218 [okButton_ removeFromSuperview]; |
| 219 [cancelButton_ removeFromSuperview]; |
| 220 [label_.get() setFrame:labelFrame]; |
| 221 } |
| 222 |
| 218 @end | 223 @end |
| 219 | 224 |
| 220 @implementation InfoBarController (PrivateMethods) | 225 @implementation InfoBarController (PrivateMethods) |
| 221 | 226 |
| 222 - (void)initializeLabel { | 227 - (void)initializeLabel { |
| 223 // Replace the label placeholder NSTextField with the real label NSTextView. | 228 // Replace the label placeholder NSTextField with the real label NSTextView. |
| 224 // The former doesn't show links in a nice way, but the latter can't be added | 229 // The former doesn't show links in a nice way, but the latter can't be added |
| 225 // in IB without a containing scroll view, so create the NSTextView | 230 // in IB without a containing scroll view, so create the NSTextView |
| 226 // programmatically. | 231 // programmatically. |
| 227 label_.reset([[InfoBarTextView alloc] | 232 label_.reset([[InfoBarTextView alloc] |
| 228 initWithFrame:[labelPlaceholder_ frame]]); | 233 initWithFrame:[labelPlaceholder_ frame]]); |
| 229 [label_.get() setAutoresizingMask:[labelPlaceholder_ autoresizingMask]]; | 234 [label_.get() setAutoresizingMask:[labelPlaceholder_ autoresizingMask]]; |
| 230 [[labelPlaceholder_ superview] | 235 [[labelPlaceholder_ superview] |
| 231 replaceSubview:labelPlaceholder_ with:label_.get()]; | 236 replaceSubview:labelPlaceholder_ with:label_.get()]; |
| 232 labelPlaceholder_ = nil; // Now released. | 237 labelPlaceholder_ = nil; // Now released. |
| 233 [label_.get() setDelegate:self]; | 238 [label_.get() setDelegate:self]; |
| 234 [label_.get() setEditable:NO]; | 239 [label_.get() setEditable:NO]; |
| 235 [label_.get() setDrawsBackground:NO]; | 240 [label_.get() setDrawsBackground:NO]; |
| 236 [label_.get() setHorizontallyResizable:NO]; | 241 [label_.get() setHorizontallyResizable:NO]; |
| 237 [label_.get() setVerticallyResizable:NO]; | 242 [label_.get() setVerticallyResizable:NO]; |
| 238 } | 243 } |
| 239 | 244 |
| 240 - (void)removeInfoBar { | 245 - (void)removeInfoBar { |
| 241 DCHECK(delegate_); | 246 DCHECK(delegate_); |
| 242 [containerController_ removeDelegate:delegate_]; | 247 [containerController_ removeDelegate:delegate_]; |
| 243 } | 248 } |
| 244 | 249 |
| 245 - (void)removeButtons { | |
| 246 // Extend the label all the way across. | |
| 247 // Remove the ok and cancel buttons, since they are not needed. | |
| 248 NSRect labelFrame = [label_.get() frame]; | |
| 249 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); | |
| 250 [okButton_ removeFromSuperview]; | |
| 251 [cancelButton_ removeFromSuperview]; | |
| 252 [label_.get() setFrame:labelFrame]; | |
| 253 } | |
| 254 | |
| 255 - (void)cleanUpAfterAnimation:(BOOL)finished { | 250 - (void)cleanUpAfterAnimation:(BOOL)finished { |
| 256 // Don't need to do any cleanup if the bar was animating open. | 251 // Don't need to do any cleanup if the bar was animating open. |
| 257 if (!infoBarClosing_) | 252 if (!infoBarClosing_) |
| 258 return; | 253 return; |
| 259 | 254 |
| 260 // Notify the delegate that the infobar was closed. The delegate may delete | 255 // Notify the delegate that the infobar was closed. The delegate may delete |
| 261 // itself as a result of InfoBarClosed(), so we null out its pointer. | 256 // itself as a result of InfoBarClosed(), so we null out its pointer. |
| 262 if (delegate_) { | 257 if (delegate_) { |
| 263 delegate_->InfoBarClosed(); | 258 delegate_->InfoBarClosed(); |
| 264 delegate_ = NULL; | 259 delegate_ = NULL; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 LinkInfoBarController* controller = | 515 LinkInfoBarController* controller = |
| 521 [[LinkInfoBarController alloc] initWithDelegate:this]; | 516 [[LinkInfoBarController alloc] initWithDelegate:this]; |
| 522 return new InfoBar(controller); | 517 return new InfoBar(controller); |
| 523 } | 518 } |
| 524 | 519 |
| 525 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 520 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 526 ConfirmInfoBarController* controller = | 521 ConfirmInfoBarController* controller = |
| 527 [[ConfirmInfoBarController alloc] initWithDelegate:this]; | 522 [[ConfirmInfoBarController alloc] initWithDelegate:this]; |
| 528 return new InfoBar(controller); | 523 return new InfoBar(controller); |
| 529 } | 524 } |
| OLD | NEW |