Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/cocoa/infobars/confirm_infobar_controller.h" | 5 #include "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" | 10 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 101 } |
| 102 | 102 |
| 103 NSRect frame = [label_.get() frame]; | 103 NSRect frame = [label_.get() frame]; |
| 104 DCHECK(rightEdge > NSMinX(frame)) | 104 DCHECK(rightEdge > NSMinX(frame)) |
| 105 << "Need to make the xib larger to handle buttons with text this long"; | 105 << "Need to make the xib larger to handle buttons with text this long"; |
| 106 frame.size.width = rightEdge - NSMinX(frame); | 106 frame.size.width = rightEdge - NSMinX(frame); |
| 107 [label_.get() setFrame:frame]; | 107 [label_.get() setFrame:frame]; |
| 108 | 108 |
| 109 // Set the text and link. | 109 // Set the text and link. |
| 110 NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText()); | 110 NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText()); |
| 111 base::string16 link = delegate->GetLinkText(); | 111 NSString* link = base::SysUTF16ToNSString(delegate->GetLinkText()); |
| 112 if (!link.empty()) { | 112 NSUInteger linkOffset = [message length]; |
| 113 NSUInteger linkLength = [link length]; | |
| 114 if (linkLength != 0) { | |
| 113 // Add spacing between the label and the link. | 115 // Add spacing between the label and the link. |
| 114 message = [message stringByAppendingString:@" "]; | 116 message = [message stringByAppendingFormat:@" %@", link]; |
| 115 } | 117 } |
| 116 NSFont* font = [NSFont labelFontOfSize: | 118 NSFont* font = [NSFont labelFontOfSize: |
| 117 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 119 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
|
groby-ooo-7-16
2015/01/30 23:08:39
I suppose this is "git cl format"'s doing?
shrike
2015/02/02 17:39:13
No - me learning the style guide. Done.
| |
| 118 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); | 120 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); |
| 119 [view setMessageAndLink:message | 121 [view setMessage:message withFont:font messageColor:[NSColor blackColor]]; |
| 120 withLink:base::SysUTF16ToNSString(link) | 122 if (linkLength != 0) { |
| 121 atOffset:[message length] | 123 [view addLinkRange:NSMakeRange(linkOffset, linkLength) |
| 122 font:font | 124 withName:@"" |
| 123 messageColor:[NSColor blackColor] | 125 linkColor:[NSColor blueColor]]; |
| 124 linkColor:[NSColor blueColor]]; | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 // Called when someone clicks on the link in the infobar. This method | 129 // Called when someone clicks on the link in the infobar. This method |
| 128 // is called by the InfobarTextField on its delegate (the | 130 // is called by the InfobarTextField on its delegate (the |
| 129 // AlternateNavInfoBarController). | 131 // AlternateNavInfoBarController). |
| 130 - (void)linkClicked { | 132 - (void)linkClicked { |
| 131 if (![self isOwned]) | 133 if (![self isOwned]) |
| 132 return; | 134 return; |
| 133 WindowOpenDisposition disposition = | 135 WindowOpenDisposition disposition = |
| 134 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 136 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 135 if ([self delegate]->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) | 137 if ([self delegate]->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) |
| 136 [self removeSelf]; | 138 [self removeSelf]; |
| 137 } | 139 } |
| 138 | 140 |
| 139 @end | 141 @end |
| 140 | 142 |
| 141 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( | 143 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( |
| 142 scoped_ptr<ConfirmInfoBarDelegate> delegate) { | 144 scoped_ptr<ConfirmInfoBarDelegate> delegate) { |
| 143 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); | 145 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); |
| 144 base::scoped_nsobject<ConfirmInfoBarController> controller( | 146 base::scoped_nsobject<ConfirmInfoBarController> controller( |
| 145 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); | 147 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); |
| 146 infobar->set_controller(controller); | 148 infobar->set_controller(controller); |
| 147 return infobar.Pass(); | 149 return infobar.Pass(); |
| 148 } | 150 } |
| OLD | NEW |