OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/translate/translate_message_infobar_controller.h" | |
6 | |
7 #include "base/strings/sys_string_conversions.h" | |
8 #include "components/translate/core/browser/translate_infobar_delegate.h" | |
9 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | |
10 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | |
11 #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h" | |
12 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | |
13 #include "ui/gfx/image/image.h" | |
14 | |
15 @interface TranslateMessageInfoBarController () | |
16 | |
17 // Action for any of the user defined buttons. | |
18 - (void)infoBarButtonDidPress:(id)sender; | |
19 | |
20 @end | |
21 | |
22 @implementation TranslateMessageInfoBarController | |
23 | |
24 #pragma mark - | |
25 #pragma mark InfoBarControllerProtocol | |
26 | |
27 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate | |
28 frame:(CGRect)frame { | |
29 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = | |
30 delegate->AsTranslateInfoBarDelegate(); | |
31 infobars::InfoBarDelegate* infoBarDelegate = | |
32 static_cast<infobars::InfoBarDelegate*>(translateInfoBarDelegate); | |
33 DCHECK(!infoBarView_); | |
34 infoBarView_.reset([ios::GetChromeBrowserProvider()->CreateInfoBarView() | |
35 initWithFrame:frame | |
36 delegate:delegate_ | |
37 isWarning:infoBarDelegate->GetInfoBarType() == | |
38 infobars::InfoBarDelegate::WARNING_TYPE]); | |
39 // Icon | |
40 gfx::Image icon = translateInfoBarDelegate->GetIcon(); | |
41 if (!icon.IsEmpty()) | |
42 [infoBarView_ addLeftIcon:icon.ToUIImage()]; | |
43 // Text. | |
44 [infoBarView_ | |
45 addLabel:base::SysUTF16ToNSString( | |
46 translateInfoBarDelegate->GetMessageInfoBarText())]; | |
47 // Close button. | |
48 // TODO: Check if we should remove the close button. | |
sdefresne
2015/01/08 09:22:33
nit: same remark about the TODO.
| |
49 [infoBarView_ addCloseButtonWithTag:TranslateInfoBarIos::CLOSE | |
50 target:self | |
51 action:@selector(infoBarButtonDidPress:)]; | |
52 // Other button. | |
53 base::string16 buttonText( | |
54 translateInfoBarDelegate->GetMessageInfoBarButtonText()); | |
55 if (!buttonText.empty()) { | |
56 [infoBarView_ addButton:base::SysUTF16ToNSString(buttonText) | |
57 tag:TranslateInfoBarIos::MESSAGE | |
58 target:self | |
59 action:@selector(infoBarButtonDidPress:)]; | |
60 } | |
61 } | |
62 | |
63 #pragma mark - Handling of User Events | |
64 | |
65 - (void)infoBarButtonDidPress:(id)sender { | |
66 // This press might have occurred after the user has already pressed a button, | |
67 // in which case the view has been detached from the delegate and this press | |
68 // should be ignored. | |
69 if (!delegate_) { | |
70 return; | |
71 } | |
72 if ([sender isKindOfClass:[UIButton class]]) { | |
73 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; | |
74 if (buttonId == TranslateInfoBarIos::CLOSE) { | |
75 delegate_->InfoBarDidCancel(); | |
76 } else { | |
77 DCHECK(buttonId == TranslateInfoBarIos::MESSAGE); | |
78 delegate_->InfoBarButtonDidPress(buttonId); | |
79 } | |
80 } | |
81 } | |
82 | |
83 @end | |
OLD | NEW |