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 #import "chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.h" | 5 #import "chrome/browser/ui/cocoa/infobars/alternate_nav_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/ui/cocoa/infobars/infobar_cocoa.h" | 9 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
10 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h" | 10 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 // | 22 // |
23 - (void)addAdditionalControls { | 23 - (void)addAdditionalControls { |
24 // No buttons. | 24 // No buttons. |
25 [self removeButtons]; | 25 [self removeButtons]; |
26 | 26 |
27 AlternateNavInfoBarDelegate* delegate = | 27 AlternateNavInfoBarDelegate* delegate = |
28 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); | 28 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); |
29 DCHECK(delegate); | 29 DCHECK(delegate); |
30 size_t offset = base::string16::npos; | 30 size_t offset = base::string16::npos; |
31 base::string16 message = delegate->GetMessageTextWithOffset(&offset); | 31 base::string16 message = delegate->GetMessageTextWithOffset(&offset); |
32 base::string16 link = delegate->GetLinkText(); | 32 NSMutableString* finalMessage = |
groby-ooo-7-16
2015/01/30 23:08:39
I'd suggest doing the string composition in C++ in
shrike
2015/02/02 17:39:13
I agree. Done.
| |
33 [NSMutableString stringWithString:base::SysUTF16ToNSString(message)]; | |
34 NSString* link = base::SysUTF16ToNSString(delegate->GetLinkText()); | |
35 [finalMessage insertString:link atIndex:offset]; | |
33 NSFont* font = [NSFont labelFontOfSize: | 36 NSFont* font = [NSFont labelFontOfSize: |
34 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 37 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
35 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); | 38 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); |
36 [view setMessageAndLink:base::SysUTF16ToNSString(message) | 39 [view setMessage:finalMessage withFont:font messageColor:[NSColor blackColor]] ; |
37 withLink:base::SysUTF16ToNSString(link) | 40 [view addLinkRange:NSMakeRange(offset, [link length]) |
38 atOffset:offset | 41 withName:@"" |
39 font:font | 42 linkColor:[NSColor blueColor]]; |
40 messageColor:[NSColor blackColor] | |
41 linkColor:[NSColor blueColor]]; | |
42 } | 43 } |
43 | 44 |
44 // Called when someone clicks on the link in the infobar. This method | 45 // Called when someone clicks on the link in the infobar. This method |
45 // is called by the InfobarTextField on its delegate (the | 46 // is called by the InfobarTextField on its delegate (the |
46 // AlternateNavInfoBarController). | 47 // AlternateNavInfoBarController). |
47 - (void)linkClicked { | 48 - (void)linkClicked { |
48 if (![self isOwned]) | 49 if (![self isOwned]) |
49 return; | 50 return; |
50 WindowOpenDisposition disposition = | 51 WindowOpenDisposition disposition = |
51 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 52 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
52 AlternateNavInfoBarDelegate* delegate = | 53 AlternateNavInfoBarDelegate* delegate = |
53 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); | 54 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); |
54 if (delegate->LinkClicked(disposition)) | 55 if (delegate->LinkClicked(disposition)) |
55 [self removeSelf]; | 56 [self removeSelf]; |
56 } | 57 } |
57 | 58 |
58 @end | 59 @end |
59 | 60 |
60 // static | 61 // static |
61 scoped_ptr<infobars::InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( | 62 scoped_ptr<infobars::InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( |
62 scoped_ptr<AlternateNavInfoBarDelegate> delegate) { | 63 scoped_ptr<AlternateNavInfoBarDelegate> delegate) { |
63 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); | 64 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(delegate.Pass())); |
64 base::scoped_nsobject<AlternateNavInfoBarController> controller( | 65 base::scoped_nsobject<AlternateNavInfoBarController> controller( |
65 [[AlternateNavInfoBarController alloc] initWithInfoBar:infobar.get()]); | 66 [[AlternateNavInfoBarController alloc] initWithInfoBar:infobar.get()]); |
66 infobar->set_controller(controller); | 67 infobar->set_controller(controller); |
67 return infobar.Pass(); | 68 return infobar.Pass(); |
68 } | 69 } |
OLD | NEW |