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 #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 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 9 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
| 10 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 10 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| 11 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h" | 11 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h" |
| 12 #import "ui/base/cocoa/cocoa_event_utils.h" | 12 #import "ui/base/cocoa/cocoa_event_utils.h" |
| 13 #include "ui/base/window_open_disposition.h" | 13 #include "ui/base/window_open_disposition.h" |
| 14 | 14 |
| 15 @implementation AlternateNavInfoBarController | 15 @implementation AlternateNavInfoBarController |
| 16 | 16 |
| 17 // Link infobars have a text message, of which part is linkified. We | 17 // Link infobars have a text message, of which part is linkified. We |
| 18 // use an NSAttributedString to display styled text, and we set a | 18 // use an NSAttributedString to display styled text, and we set a |
| 19 // NSLink attribute on the hyperlink portion of the message. Infobars | 19 // NSLink attribute on the hyperlink portion of the message. Infobars |
| 20 // use a custom NSTextField subclass, which allows us to override | 20 // use a custom NSTextField subclass, which allows us to override |
| 21 // textView:clickedOnLink:atIndex: and intercept clicks. | 21 // textView:clickedOnLink:atIndex: and intercept clicks. |
| 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*>(delegate_); | 28 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); |
| 29 DCHECK(delegate); | 29 DCHECK(delegate); |
| 30 size_t offset = string16::npos; | 30 size_t offset = string16::npos; |
| 31 string16 message = delegate->GetMessageTextWithOffset(&offset); | 31 string16 message = delegate->GetMessageTextWithOffset(&offset); |
| 32 string16 link = delegate->GetLinkText(); | 32 string16 link = delegate->GetLinkText(); |
| 33 NSFont* font = [NSFont labelFontOfSize: | 33 NSFont* font = [NSFont labelFontOfSize: |
| 34 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 34 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
| 35 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); | 35 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); |
| 36 [view setMessageAndLink:base::SysUTF16ToNSString(message) | 36 [view setMessageAndLink:base::SysUTF16ToNSString(message) |
| 37 withLink:base::SysUTF16ToNSString(link) | 37 withLink:base::SysUTF16ToNSString(link) |
| 38 atOffset:offset | 38 atOffset:offset |
| 39 font:font | 39 font:font |
| 40 messageColor:[NSColor blackColor] | 40 messageColor:[NSColor blackColor] |
| 41 linkColor:[NSColor blueColor]]; | 41 linkColor:[NSColor blueColor]]; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Called when someone clicks on the link in the infobar. This method | 44 // Called when someone clicks on the link in the infobar. This method |
| 45 // is called by the InfobarTextField on its delegate (the | 45 // is called by the InfobarTextField on its delegate (the |
| 46 // AlternateNavInfoBarController). | 46 // AlternateNavInfoBarController). |
| 47 - (void)linkClicked { | 47 - (void)linkClicked { |
| 48 if (![self isOwned]) | 48 if (![self isOwned]) |
| 49 return; | 49 return; |
| 50 WindowOpenDisposition disposition = | 50 WindowOpenDisposition disposition = |
| 51 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 51 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 52 AlternateNavInfoBarDelegate* delegate = | 52 AlternateNavInfoBarDelegate* delegate = |
| 53 static_cast<AlternateNavInfoBarDelegate*>(delegate_); | 53 static_cast<AlternateNavInfoBarDelegate*>([self delegate]); |
| 54 if (delegate->LinkClicked(disposition)) | 54 if (delegate->LinkClicked(disposition)) |
| 55 [self removeSelf]; | 55 [self removeSelf]; |
| 56 } | 56 } |
| 57 | 57 |
| 58 @end | 58 @end |
| 59 | 59 |
| 60 InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 60 InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
| 61 AlternateNavInfoBarController* controller = | 61 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); |
|
Robert Sesek
2013/08/26 14:06:56
Why keep this in a scoped_ptr<> if you're just goi
sail
2013/08/26 18:32:23
I really like avoiding raw pointers. Similar to us
| |
| 62 [[AlternateNavInfoBarController alloc] initWithDelegate:this owner:owner]; | 62 base::scoped_nsobject<AlternateNavInfoBarController> controller( |
| 63 return new InfoBar(controller, this); | 63 [[AlternateNavInfoBarController alloc] initWithInfoBar:infobar.get()]); |
| 64 infobar->set_controller(controller); | |
| 65 return infobar.release(); | |
| 64 } | 66 } |
| OLD | NEW |