| 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/chrome_style.h" |
| 10 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" | 11 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| 11 #include "components/infobars/core/confirm_infobar_delegate.h" | 12 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 13 #include "skia/ext/skia_utils_mac.h" |
| 12 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" | 14 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" |
| 13 #import "ui/base/cocoa/cocoa_base_utils.h" | 15 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 14 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 16 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 15 #include "ui/base/window_open_disposition.h" | 17 #include "ui/base/window_open_disposition.h" |
| 16 | 18 |
| 17 @implementation ConfirmInfoBarController | 19 @implementation ConfirmInfoBarController |
| 18 | 20 |
| 19 // Called when someone clicks on the "OK" button. | 21 // Called when someone clicks on the "OK" button. |
| 20 - (IBAction)ok:(id)sender { | 22 - (IBAction)ok:(id)sender { |
| 21 if (![self isOwned]) | 23 if (![self isOwned]) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) { | 101 (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) { |
| 100 rightEdge -= spaceBeforeButtons; | 102 rightEdge -= spaceBeforeButtons; |
| 101 } | 103 } |
| 102 | 104 |
| 103 NSRect frame = [label_.get() frame]; | 105 NSRect frame = [label_.get() frame]; |
| 104 DCHECK(rightEdge > NSMinX(frame)) | 106 DCHECK(rightEdge > NSMinX(frame)) |
| 105 << "Need to make the xib larger to handle buttons with text this long"; | 107 << "Need to make the xib larger to handle buttons with text this long"; |
| 106 frame.size.width = rightEdge - NSMinX(frame); | 108 frame.size.width = rightEdge - NSMinX(frame); |
| 107 [label_.get() setFrame:frame]; | 109 [label_.get() setFrame:frame]; |
| 108 | 110 |
| 109 // Set the text and link. | 111 // Set the text and links. |
| 110 NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText()); | 112 NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText()); |
| 113 // Set the trailing link. |
| 111 NSString* link = base::SysUTF16ToNSString(delegate->GetLinkText()); | 114 NSString* link = base::SysUTF16ToNSString(delegate->GetLinkText()); |
| 112 NSUInteger linkOffset = [message length]; | 115 NSUInteger linkOffset = [message length]; |
| 113 NSUInteger linkLength = [link length]; | 116 NSUInteger linkLength = [link length]; |
| 114 if (linkLength != 0) { | 117 if (linkLength != 0) { |
| 115 // Add spacing between the label and the link. | 118 // Add spacing between the label and the link. |
| 116 message = [message stringByAppendingFormat:@" %@", link]; | 119 message = [message stringByAppendingFormat:@" %@", link]; |
| 117 linkOffset = [message length] - [link length]; | 120 linkOffset = [message length] - [link length]; |
| 118 } | 121 } |
| 119 NSFont* font = [NSFont labelFontOfSize: | 122 NSFont* font = [NSFont labelFontOfSize: |
| 120 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 123 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
| 121 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); | 124 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); |
| 122 [view setMessage:message withFont:font messageColor:[NSColor blackColor]]; | 125 [view setMessage:message withFont:font messageColor:[NSColor blackColor]]; |
| 123 if (linkLength != 0) { | 126 if (linkLength != 0) { |
| 127 NSColor* linkColor = |
| 128 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 124 [view addLinkRange:NSMakeRange(linkOffset, linkLength) | 129 [view addLinkRange:NSMakeRange(linkOffset, linkLength) |
| 125 withName:@"" | 130 withName:@"" |
| 126 linkColor:[NSColor blueColor]]; | 131 linkColor:linkColor]; |
| 132 } |
| 133 // Set the link inside the message. |
| 134 gfx::Range linkRange = delegate->GetMessageLinkRange(); |
| 135 if (!linkRange.is_empty()) { |
| 136 NSColor* linkColor = |
| 137 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 138 [view addLinkRange:linkRange.ToNSRange() |
| 139 withName:@"" |
| 140 linkColor:linkColor]; |
| 127 } | 141 } |
| 128 } | 142 } |
| 129 | 143 |
| 130 // Called when someone clicks on the link in the infobar. This method | 144 // Called when someone clicks on the link in the infobar. This method |
| 131 // is called by the InfobarTextField on its delegate (the | 145 // is called by the InfobarTextField on its delegate (the |
| 132 // AlternateNavInfoBarController). | 146 // AlternateNavInfoBarController). |
| 133 - (void)linkClicked { | 147 - (void)linkClicked { |
| 134 if (![self isOwned]) | 148 if (![self isOwned]) |
| 135 return; | 149 return; |
| 136 WindowOpenDisposition disposition = | 150 WindowOpenDisposition disposition = |
| 137 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 151 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 138 if ([self delegate]->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) | 152 if ([self delegate]->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) |
| 139 [self removeSelf]; | 153 [self removeSelf]; |
| 140 } | 154 } |
| 141 | 155 |
| 142 @end | 156 @end |
| 143 | 157 |
| 144 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( | 158 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( |
| 145 scoped_ptr<ConfirmInfoBarDelegate> delegate) { | 159 scoped_ptr<ConfirmInfoBarDelegate> delegate) { |
| 146 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); | 160 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); |
| 147 base::scoped_nsobject<ConfirmInfoBarController> controller( | 161 base::scoped_nsobject<ConfirmInfoBarController> controller( |
| 148 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); | 162 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); |
| 149 infobar->set_controller(controller); | 163 infobar->set_controller(controller); |
| 150 return infobar.Pass(); | 164 return infobar.Pass(); |
| 151 } | 165 } |
| OLD | NEW |