| 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 #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" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 @implementation AlertInfoBarController | 337 @implementation AlertInfoBarController |
| 338 | 338 |
| 339 // Alert infobars have a text message. | 339 // Alert infobars have a text message. |
| 340 - (void)addAdditionalControls { | 340 - (void)addAdditionalControls { |
| 341 // No buttons. | 341 // No buttons. |
| 342 [self removeButtons]; | 342 [self removeButtons]; |
| 343 | 343 |
| 344 // Insert the text. | 344 // Insert the text. |
| 345 AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate(); | 345 AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate(); |
| 346 DCHECK(delegate); | 346 DCHECK(delegate); |
| 347 [self setLabelToMessage:base::SysWideToNSString(delegate->GetMessageText())]; | 347 [self setLabelToMessage:base::SysUTF16ToNSString(delegate->GetMessageText())]; |
| 348 } | 348 } |
| 349 | 349 |
| 350 @end | 350 @end |
| 351 | 351 |
| 352 | 352 |
| 353 ///////////////////////////////////////////////////////////////////////// | 353 ///////////////////////////////////////////////////////////////////////// |
| 354 // LinkInfoBarController implementation | 354 // LinkInfoBarController implementation |
| 355 | 355 |
| 356 @implementation LinkInfoBarController | 356 @implementation LinkInfoBarController |
| 357 | 357 |
| 358 // Link infobars have a text message, of which part is linkified. We | 358 // Link infobars have a text message, of which part is linkified. We |
| 359 // use an NSAttributedString to display styled text, and we set a | 359 // use an NSAttributedString to display styled text, and we set a |
| 360 // NSLink attribute on the hyperlink portion of the message. Infobars | 360 // NSLink attribute on the hyperlink portion of the message. Infobars |
| 361 // use a custom NSTextField subclass, which allows us to override | 361 // use a custom NSTextField subclass, which allows us to override |
| 362 // textView:clickedOnLink:atIndex: and intercept clicks. | 362 // textView:clickedOnLink:atIndex: and intercept clicks. |
| 363 // | 363 // |
| 364 - (void)addAdditionalControls { | 364 - (void)addAdditionalControls { |
| 365 // No buttons. | 365 // No buttons. |
| 366 [self removeButtons]; | 366 [self removeButtons]; |
| 367 | 367 |
| 368 LinkInfoBarDelegate* delegate = delegate_->AsLinkInfoBarDelegate(); | 368 LinkInfoBarDelegate* delegate = delegate_->AsLinkInfoBarDelegate(); |
| 369 DCHECK(delegate); | 369 DCHECK(delegate); |
| 370 size_t offset = std::wstring::npos; | 370 size_t offset = std::wstring::npos; |
| 371 std::wstring message = delegate->GetMessageTextWithOffset(&offset); | 371 string16 message = delegate->GetMessageTextWithOffset(&offset); |
| 372 [self setLabelToMessage:base::SysWideToNSString(message) | 372 [self setLabelToMessage:base::SysUTF16ToNSString(message) |
| 373 withLink:base::SysWideToNSString(delegate->GetLinkText()) | 373 withLink:base::SysUTF16ToNSString(delegate->GetLinkText()) |
| 374 atOffset:offset]; | 374 atOffset:offset]; |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Called when someone clicks on the link in the infobar. This method | 377 // Called when someone clicks on the link in the infobar. This method |
| 378 // is called by the InfobarTextField on its delegate (the | 378 // is called by the InfobarTextField on its delegate (the |
| 379 // LinkInfoBarController). | 379 // LinkInfoBarController). |
| 380 - (void)linkClicked { | 380 - (void)linkClicked { |
| 381 WindowOpenDisposition disposition = | 381 WindowOpenDisposition disposition = |
| 382 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 382 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 383 if (delegate_ && delegate_->AsLinkInfoBarDelegate()->LinkClicked(disposition)) | 383 if (delegate_ && delegate_->AsLinkInfoBarDelegate()->LinkClicked(disposition)) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 << "Cancel button expected to be on the right of the Ok button in nib"; | 419 << "Cancel button expected to be on the right of the Ok button in nib"; |
| 420 | 420 |
| 421 CGFloat rightEdge = NSMaxX(cancelButtonFrame); | 421 CGFloat rightEdge = NSMaxX(cancelButtonFrame); |
| 422 CGFloat spaceBetweenButtons = | 422 CGFloat spaceBetweenButtons = |
| 423 NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame); | 423 NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame); |
| 424 CGFloat spaceBeforeButtons = | 424 CGFloat spaceBeforeButtons = |
| 425 NSMinX(okButtonFrame) - NSMaxX([label_.get() frame]); | 425 NSMinX(okButtonFrame) - NSMaxX([label_.get() frame]); |
| 426 | 426 |
| 427 // Update and position the Cancel button if needed. Otherwise, hide it. | 427 // Update and position the Cancel button if needed. Otherwise, hide it. |
| 428 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 428 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 429 [cancelButton_ setTitle:base::SysWideToNSString( | 429 [cancelButton_ setTitle:base::SysUTF16ToNSString( |
| 430 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))]; | 430 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))]; |
| 431 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; | 431 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; |
| 432 cancelButtonFrame = [cancelButton_ frame]; | 432 cancelButtonFrame = [cancelButton_ frame]; |
| 433 | 433 |
| 434 // Position the cancel button to the left of the Close button. | 434 // Position the cancel button to the left of the Close button. |
| 435 cancelButtonFrame.origin.x = rightEdge - cancelButtonFrame.size.width; | 435 cancelButtonFrame.origin.x = rightEdge - cancelButtonFrame.size.width; |
| 436 [cancelButton_ setFrame:cancelButtonFrame]; | 436 [cancelButton_ setFrame:cancelButtonFrame]; |
| 437 | 437 |
| 438 // Update the rightEdge | 438 // Update the rightEdge |
| 439 rightEdge = NSMinX(cancelButtonFrame); | 439 rightEdge = NSMinX(cancelButtonFrame); |
| 440 } else { | 440 } else { |
| 441 [cancelButton_ removeFromSuperview]; | 441 [cancelButton_ removeFromSuperview]; |
| 442 } | 442 } |
| 443 | 443 |
| 444 // Update and position the OK button if needed. Otherwise, hide it. | 444 // Update and position the OK button if needed. Otherwise, hide it. |
| 445 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { | 445 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 446 [okButton_ setTitle:base::SysWideToNSString( | 446 [okButton_ setTitle:base::SysUTF16ToNSString( |
| 447 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK))]; | 447 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK))]; |
| 448 [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_]; | 448 [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_]; |
| 449 okButtonFrame = [okButton_ frame]; | 449 okButtonFrame = [okButton_ frame]; |
| 450 | 450 |
| 451 // If we had a Cancel button, leave space between the buttons. | 451 // If we had a Cancel button, leave space between the buttons. |
| 452 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 452 if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 453 rightEdge -= spaceBetweenButtons; | 453 rightEdge -= spaceBetweenButtons; |
| 454 } | 454 } |
| 455 | 455 |
| 456 // Position the OK button on our current right edge. | 456 // Position the OK button on our current right edge. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 470 rightEdge -= spaceBeforeButtons; | 470 rightEdge -= spaceBeforeButtons; |
| 471 } | 471 } |
| 472 | 472 |
| 473 NSRect frame = [label_.get() frame]; | 473 NSRect frame = [label_.get() frame]; |
| 474 DCHECK(rightEdge > NSMinX(frame)) | 474 DCHECK(rightEdge > NSMinX(frame)) |
| 475 << "Need to make the xib larger to handle buttons with text this long"; | 475 << "Need to make the xib larger to handle buttons with text this long"; |
| 476 frame.size.width = rightEdge - NSMinX(frame); | 476 frame.size.width = rightEdge - NSMinX(frame); |
| 477 [label_.get() setFrame:frame]; | 477 [label_.get() setFrame:frame]; |
| 478 | 478 |
| 479 // Set the text and link. | 479 // Set the text and link. |
| 480 NSString* message = base::SysWideToNSString(delegate->GetMessageText()); | 480 NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText()); |
| 481 std::wstring link = delegate->GetLinkText(); | 481 string16 link = delegate->GetLinkText(); |
| 482 if (link.empty()) { | 482 if (link.empty()) { |
| 483 // Simple case: no link, so just set the message directly. | 483 // Simple case: no link, so just set the message directly. |
| 484 [self setLabelToMessage:message]; | 484 [self setLabelToMessage:message]; |
| 485 } else { | 485 } else { |
| 486 // Inserting the link unintentionally causes the text to have a slightly | 486 // Inserting the link unintentionally causes the text to have a slightly |
| 487 // different result to the simple case above: text is truncated on word | 487 // different result to the simple case above: text is truncated on word |
| 488 // boundaries (if needed) rather than elided with ellipses. | 488 // boundaries (if needed) rather than elided with ellipses. |
| 489 | 489 |
| 490 // Add spacing between the label and the link. | 490 // Add spacing between the label and the link. |
| 491 message = [message stringByAppendingString:@" "]; | 491 message = [message stringByAppendingString:@" "]; |
| 492 [self setLabelToMessage:message | 492 [self setLabelToMessage:message |
| 493 withLink:base::SysWideToNSString(link) | 493 withLink:base::SysUTF16ToNSString(link) |
| 494 atOffset:[message length]]; | 494 atOffset:[message length]]; |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 // Called when someone clicks on the link in the infobar. This method | 498 // Called when someone clicks on the link in the infobar. This method |
| 499 // is called by the InfobarTextField on its delegate (the | 499 // is called by the InfobarTextField on its delegate (the |
| 500 // LinkInfoBarController). | 500 // LinkInfoBarController). |
| 501 - (void)linkClicked { | 501 - (void)linkClicked { |
| 502 WindowOpenDisposition disposition = | 502 WindowOpenDisposition disposition = |
| 503 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 503 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 522 LinkInfoBarController* controller = | 522 LinkInfoBarController* controller = |
| 523 [[LinkInfoBarController alloc] initWithDelegate:this]; | 523 [[LinkInfoBarController alloc] initWithDelegate:this]; |
| 524 return new InfoBar(controller); | 524 return new InfoBar(controller); |
| 525 } | 525 } |
| 526 | 526 |
| 527 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 527 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 528 ConfirmInfoBarController* controller = | 528 ConfirmInfoBarController* controller = |
| 529 [[ConfirmInfoBarController alloc] initWithDelegate:this]; | 529 [[ConfirmInfoBarController alloc] initWithDelegate:this]; |
| 530 return new InfoBar(controller); | 530 return new InfoBar(controller); |
| 531 } | 531 } |
| OLD | NEW |