diff options
author | melandory <melandory@chromium.org> | 2015-06-09 01:04:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-09 08:05:42 +0000 |
commit | 6d2c201ab862b89ad2bcb162093c5244b0525d5c (patch) | |
tree | 1853ddf46c68261ab14a20264c201aa0a88ba9a4 | |
parent | 582c9cedbf4fa60162fca35251b1244f5ba3b2de (diff) | |
download | chromium_src-6d2c201ab862b89ad2bcb162093c5244b0525d5c.zip chromium_src-6d2c201ab862b89ad2bcb162093c5244b0525d5c.tar.gz chromium_src-6d2c201ab862b89ad2bcb162093c5244b0525d5c.tar.bz2 |
[Smart Lock, ios] Introduce ability to have a link in ConfirmInfobar title.
Google Smart Lock in save passwords infobar should be a link to help
center article about Smart Lock for passwords. This CL adds ability
to ConfirmInfobar to contain a link in title.
BUG=493276
Review URL: https://codereview.chromium.org/1156833005
Cr-Commit-Position: refs/heads/master@{#333461}
-rw-r--r-- | ios/chrome/browser/infobars/confirm_infobar_controller.mm | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/ios/chrome/browser/infobars/confirm_infobar_controller.mm b/ios/chrome/browser/infobars/confirm_infobar_controller.mm index 1727876..9e93848 100644 --- a/ios/chrome/browser/infobars/confirm_infobar_controller.mm +++ b/ios/chrome/browser/infobars/confirm_infobar_controller.mm @@ -5,17 +5,20 @@ #include "ios/chrome/browser/infobars/confirm_infobar_controller.h" #include "base/mac/foundation_util.h" +#include "base/strings/string_util.h" #include "base/strings/sys_string_conversions.h" #include "components/infobars/core/confirm_infobar_delegate.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h" #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/window_open_disposition.h" #include "ui/gfx/image/image.h" namespace { -// UI Tags for the infobar buttons -enum ConfirmInfoBarUITags { OK = 1, CANCEL, CLOSE }; +// UI Tags for the infobar elements. +enum ConfirmInfoBarUITags { OK = 1, CANCEL, CLOSE, TITLE_LINK }; // Converts a UI button tag to the corresponding InfoBarButton. ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { @@ -39,10 +42,13 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { // Action for any of the user defined buttons. - (void)infoBarButtonDidPress:(id)sender; - +// Action for any of the user defined links. +- (void)infobarLinkDidPress:(NSNumber*)tag; +- (void)updateInfobarLabel:(UIView<InfoBarViewProtocol>*)view; @end @implementation ConfirmInfoBarController { + __weak ConfirmInfoBarDelegate* confirmInfobarDelegate_; } #pragma mark - @@ -52,24 +58,22 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { viewForDelegate:(infobars::InfoBarDelegate*)delegate frame:(CGRect)frame { base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; - ConfirmInfoBarDelegate* infoBarModel = delegate->AsConfirmInfoBarDelegate(); + confirmInfobarDelegate_ = delegate->AsConfirmInfoBarDelegate(); infoBarView.reset( ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); // Model data. - NSString* modelMsg = nil; - if (infoBarModel->GetMessageText().length()) - modelMsg = base::SysUTF16ToNSString(infoBarModel->GetMessageText()); - gfx::Image modelIcon = infoBarModel->GetIcon(); - int buttons = infoBarModel->GetButtons(); + gfx::Image modelIcon = confirmInfobarDelegate_->GetIcon(); + int buttons = confirmInfobarDelegate_->GetButtons(); NSString* buttonOK = nil; if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { - buttonOK = base::SysUTF16ToNSString( - infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); + buttonOK = base::SysUTF16ToNSString(confirmInfobarDelegate_->GetButtonLabel( + ConfirmInfoBarDelegate::BUTTON_OK)); } NSString* buttonCancel = nil; if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { - buttonCancel = base::SysUTF16ToNSString( - infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); + buttonCancel = + base::SysUTF16ToNSString(confirmInfobarDelegate_->GetButtonLabel( + ConfirmInfoBarDelegate::BUTTON_CANCEL)); } [infoBarView addCloseButtonWithTag:ConfirmInfoBarUITags::CLOSE @@ -81,8 +85,7 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { [infoBarView addLeftIcon:modelIcon.ToUIImage()]; // Optional message. - if (modelMsg) - [infoBarView addLabel:modelMsg]; + [self updateInfobarLabel:infoBarView]; if (buttonOK && buttonCancel) { [infoBarView addButton1:buttonOK @@ -98,11 +101,33 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { action:@selector(infoBarButtonDidPress:)]; } else { // No buttons, only message. - DCHECK(modelMsg && !buttonCancel); + DCHECK(!confirmInfobarDelegate_->GetMessageText().empty() && !buttonCancel); } return infoBarView; } +- (void)updateInfobarLabel:(UIView<InfoBarViewProtocol>*)view { + if (!confirmInfobarDelegate_->GetMessageText().length()) + return; + if (confirmInfobarDelegate_->GetLinkText().length()) { + base::string16 msgLink = base::SysNSStringToUTF16( + [[view class] stringAsLink:base::SysUTF16ToNSString( + confirmInfobarDelegate_->GetLinkText()) + tag:ConfirmInfoBarUITags::TITLE_LINK]); + base::string16 messageText = confirmInfobarDelegate_->GetMessageText(); + ReplaceFirstSubstringAfterOffset( + &messageText, 0, confirmInfobarDelegate_->GetLinkText(), msgLink); + + [view addLabel:base::SysUTF16ToNSString(messageText) + target:self + action:@selector(infobarLinkDidPress:)]; + } else { + NSString* label = + base::SysUTF16ToNSString(confirmInfobarDelegate_->GetMessageText()); + [view addLabel:label]; + } +} + #pragma mark - Handling of User Events - (void)infoBarButtonDidPress:(id)sender { @@ -121,4 +146,15 @@ ConfirmInfoBarDelegate::InfoBarButton UITagToButton(NSUInteger tag) { } } +// Title link was clicked. +- (void)infobarLinkDidPress:(NSNumber*)tag { + DCHECK([tag isKindOfClass:[NSNumber class]]); + if (!self.delegate) { + return; + } + if ([tag unsignedIntegerValue] == ConfirmInfoBarUITags::TITLE_LINK) { + confirmInfobarDelegate_->LinkClicked(NEW_FOREGROUND_TAB); + } +} + @end |