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 #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/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 if (delegate_->GetIcon()) { | 71 if (delegate_->GetIcon()) { |
72 [image_ setImage:*(delegate_->GetIcon())]; | 72 [image_ setImage:*(delegate_->GetIcon())]; |
73 } else { | 73 } else { |
74 // No icon, remove it from the view and grow the textfield to include the | 74 // No icon, remove it from the view and grow the textfield to include the |
75 // space. | 75 // space. |
76 NSRect imageFrame = [image_ frame]; | 76 NSRect imageFrame = [image_ frame]; |
77 NSRect labelFrame = [labelPlaceholder_ frame]; | 77 NSRect labelFrame = [labelPlaceholder_ frame]; |
78 labelFrame.size.width += NSMinX(imageFrame) - NSMinX(labelFrame); | 78 labelFrame.size.width += NSMinX(imageFrame) - NSMinX(labelFrame); |
79 labelFrame.origin.x = imageFrame.origin.x; | 79 labelFrame.origin.x = imageFrame.origin.x; |
80 [image_ removeFromSuperview]; | 80 [image_ removeFromSuperview]; |
| 81 image_ = nil; |
81 [labelPlaceholder_ setFrame:labelFrame]; | 82 [labelPlaceholder_ setFrame:labelFrame]; |
82 } | 83 } |
83 [self initializeLabel]; | 84 [self initializeLabel]; |
84 | 85 |
85 [self addAdditionalControls]; | 86 [self addAdditionalControls]; |
86 | 87 |
87 infoBarView_.tipApex = [self pointForTipApex]; | 88 infoBarView_.tipApex = [self pointForTipApex]; |
88 [infoBarView_ setInfobarType:delegate_->GetInfoBarType()]; | 89 [infoBarView_ setInfobarType:delegate_->GetInfoBarType()]; |
89 } | 90 } |
90 | 91 |
| 92 - (void)dealloc { |
| 93 [okButton_ setTarget:nil]; |
| 94 [cancelButton_ setTarget:nil]; |
| 95 [closeButton_ setTarget:nil]; |
| 96 [super dealloc]; |
| 97 } |
| 98 |
91 // Called when someone clicks on the embedded link. | 99 // Called when someone clicks on the embedded link. |
92 - (BOOL) textView:(NSTextView*)textView | 100 - (BOOL) textView:(NSTextView*)textView |
93 clickedOnLink:(id)link | 101 clickedOnLink:(id)link |
94 atIndex:(NSUInteger)charIndex { | 102 atIndex:(NSUInteger)charIndex { |
95 if ([self respondsToSelector:@selector(linkClicked)]) | 103 if ([self respondsToSelector:@selector(linkClicked)]) |
96 [self performSelector:@selector(linkClicked)]; | 104 [self performSelector:@selector(linkClicked)]; |
97 return YES; | 105 return YES; |
98 } | 106 } |
99 | 107 |
100 // Called when someone clicks on the ok button. | 108 // Called when someone clicks on the ok button. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 177 |
170 - (void)infobarWillClose { | 178 - (void)infobarWillClose { |
171 // Default implementation does nothing. | 179 // Default implementation does nothing. |
172 } | 180 } |
173 | 181 |
174 - (void)removeButtons { | 182 - (void)removeButtons { |
175 // Extend the label all the way across. | 183 // Extend the label all the way across. |
176 NSRect labelFrame = [label_.get() frame]; | 184 NSRect labelFrame = [label_.get() frame]; |
177 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); | 185 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); |
178 [okButton_ removeFromSuperview]; | 186 [okButton_ removeFromSuperview]; |
| 187 okButton_ = nil; |
179 [cancelButton_ removeFromSuperview]; | 188 [cancelButton_ removeFromSuperview]; |
| 189 cancelButton_ = nil; |
180 [label_.get() setFrame:labelFrame]; | 190 [label_.get() setFrame:labelFrame]; |
181 } | 191 } |
182 | 192 |
183 @end | 193 @end |
184 | 194 |
185 @implementation InfoBarController (PrivateMethods) | 195 @implementation InfoBarController (PrivateMethods) |
186 | 196 |
187 - (void)initializeLabel { | 197 - (void)initializeLabel { |
188 // Replace the label placeholder NSTextField with the real label NSTextView. | 198 // Replace the label placeholder NSTextField with the real label NSTextView. |
189 // The former doesn't show links in a nice way, but the latter can't be added | 199 // The former doesn't show links in a nice way, but the latter can't be added |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 okButtonFrame = [okButton_ frame]; | 362 okButtonFrame = [okButton_ frame]; |
353 | 363 |
354 // Position the ok button to the left of the Close button. | 364 // Position the ok button to the left of the Close button. |
355 okButtonFrame.origin.x = rightEdge - okButtonFrame.size.width; | 365 okButtonFrame.origin.x = rightEdge - okButtonFrame.size.width; |
356 [okButton_ setFrame:okButtonFrame]; | 366 [okButton_ setFrame:okButtonFrame]; |
357 | 367 |
358 // Update the rightEdge | 368 // Update the rightEdge |
359 rightEdge = NSMinX(okButtonFrame); | 369 rightEdge = NSMinX(okButtonFrame); |
360 } else { | 370 } else { |
361 [okButton_ removeFromSuperview]; | 371 [okButton_ removeFromSuperview]; |
| 372 okButton_ = nil; |
362 } | 373 } |
363 | 374 |
364 // Update and position the Cancel button if needed. Otherwise, hide it. | 375 // Update and position the Cancel button if needed. Otherwise, hide it. |
365 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 376 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
366 [cancelButton_ setTitle:base::SysUTF16ToNSString( | 377 [cancelButton_ setTitle:base::SysUTF16ToNSString( |
367 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))]; | 378 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))]; |
368 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; | 379 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; |
369 cancelButtonFrame = [cancelButton_ frame]; | 380 cancelButtonFrame = [cancelButton_ frame]; |
370 | 381 |
371 // If we had a Ok button, leave space between the buttons. | 382 // If we had a Ok button, leave space between the buttons. |
372 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { | 383 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { |
373 rightEdge -= spaceBetweenButtons; | 384 rightEdge -= spaceBetweenButtons; |
374 } | 385 } |
375 | 386 |
376 // Position the Cancel button on our current right edge. | 387 // Position the Cancel button on our current right edge. |
377 cancelButtonFrame.origin.x = rightEdge - cancelButtonFrame.size.width; | 388 cancelButtonFrame.origin.x = rightEdge - cancelButtonFrame.size.width; |
378 [cancelButton_ setFrame:cancelButtonFrame]; | 389 [cancelButton_ setFrame:cancelButtonFrame]; |
379 | 390 |
380 // Update the rightEdge. | 391 // Update the rightEdge. |
381 rightEdge = NSMinX(cancelButtonFrame); | 392 rightEdge = NSMinX(cancelButtonFrame); |
382 } else { | 393 } else { |
383 [cancelButton_ removeFromSuperview]; | 394 [cancelButton_ removeFromSuperview]; |
| 395 cancelButton_ = nil; |
384 } | 396 } |
385 | 397 |
386 // If we had either button, leave space before the edge of the textfield. | 398 // If we had either button, leave space before the edge of the textfield. |
387 if ((visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) || | 399 if ((visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) || |
388 (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) { | 400 (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) { |
389 rightEdge -= spaceBeforeButtons; | 401 rightEdge -= spaceBeforeButtons; |
390 } | 402 } |
391 | 403 |
392 NSRect frame = [label_.get() frame]; | 404 NSRect frame = [label_.get() frame]; |
393 DCHECK(rightEdge > NSMinX(frame)) | 405 DCHECK(rightEdge > NSMinX(frame)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 LinkInfoBarController* controller = | 446 LinkInfoBarController* controller = |
435 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; | 447 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; |
436 return new InfoBar(controller, this); | 448 return new InfoBar(controller, this); |
437 } | 449 } |
438 | 450 |
439 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { | 451 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { |
440 ConfirmInfoBarController* controller = | 452 ConfirmInfoBarController* controller = |
441 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; | 453 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; |
442 return new InfoBar(controller, this); | 454 return new InfoBar(controller, this); |
443 } | 455 } |
OLD | NEW |