OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/translate/never_translate_infobar_controller.h" | 5 #include "ios/chrome/browser/translate/never_translate_infobar_controller.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/translate/core/browser/translate_infobar_delegate.h" | 9 #include "components/translate/core/browser/translate_infobar_delegate.h" |
10 #include "grit/components_strings.h" | 10 #include "grit/components_strings.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Action for any of the user defined buttons. | 21 // Action for any of the user defined buttons. |
22 - (void)infoBarButtonDidPress:(id)sender; | 22 - (void)infoBarButtonDidPress:(id)sender; |
23 | 23 |
24 @end | 24 @end |
25 | 25 |
26 @implementation NeverTranslateInfoBarController | 26 @implementation NeverTranslateInfoBarController |
27 | 27 |
28 #pragma mark - | 28 #pragma mark - |
29 #pragma mark InfoBarControllerProtocol | 29 #pragma mark InfoBarControllerProtocol |
30 | 30 |
31 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate | 31 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>) |
32 frame:(CGRect)frame { | 32 viewForDelegate:(infobars::InfoBarDelegate*)delegate |
| 33 frame:(CGRect)frame { |
| 34 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; |
33 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = | 35 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = |
34 delegate->AsTranslateInfoBarDelegate(); | 36 delegate->AsTranslateInfoBarDelegate(); |
35 DCHECK(!infoBarView_); | |
36 ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider(); | 37 ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider(); |
37 infoBarView_.reset([provider->CreateInfoBarView() | 38 infoBarView.reset( |
38 initWithFrame:frame | 39 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); |
39 delegate:delegate_]); | |
40 // Icon | 40 // Icon |
41 gfx::Image icon = translateInfoBarDelegate->GetIcon(); | 41 gfx::Image icon = translateInfoBarDelegate->GetIcon(); |
42 if (!icon.IsEmpty()) | 42 if (!icon.IsEmpty()) |
43 [infoBarView_ addLeftIcon:icon.ToUIImage()]; | 43 [infoBarView addLeftIcon:icon.ToUIImage()]; |
44 // Main text. | 44 // Main text. |
45 base::string16 originalLanguage = translateInfoBarDelegate->language_name_at( | 45 base::string16 originalLanguage = translateInfoBarDelegate->language_name_at( |
46 translateInfoBarDelegate->original_language_index()); | 46 translateInfoBarDelegate->original_language_index()); |
47 [infoBarView_ addLabel:l10n_util::GetNSStringF( | 47 [infoBarView addLabel:l10n_util::GetNSStringF( |
48 IDS_TRANSLATE_INFOBAR_NEVER_MESSAGE_IOS, | 48 IDS_TRANSLATE_INFOBAR_NEVER_MESSAGE_IOS, |
49 provider->GetStringProvider()->GetProductName(), | 49 provider->GetStringProvider()->GetProductName(), |
50 originalLanguage)]; | 50 originalLanguage)]; |
51 // Close button. | 51 // Close button. |
52 [infoBarView_ addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE | 52 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE |
53 target:self | 53 target:self |
54 action:@selector(infoBarButtonDidPress:)]; | 54 action:@selector(infoBarButtonDidPress:)]; |
55 // Other buttons. | 55 // Other buttons. |
56 NSString* buttonLanguage = l10n_util::GetNSStringF( | 56 NSString* buttonLanguage = l10n_util::GetNSStringF( |
57 IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, originalLanguage); | 57 IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, originalLanguage); |
58 NSString* buttonSite = l10n_util::GetNSString( | 58 NSString* buttonSite = l10n_util::GetNSString( |
59 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE); | 59 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE); |
60 [infoBarView_ addButton1:buttonLanguage | 60 [infoBarView addButton1:buttonLanguage |
61 tag1:TranslateInfoBarIOSTag::DENY_LANGUAGE | 61 tag1:TranslateInfoBarIOSTag::DENY_LANGUAGE |
62 button2:buttonSite | 62 button2:buttonSite |
63 tag2:TranslateInfoBarIOSTag::DENY_WEBSITE | 63 tag2:TranslateInfoBarIOSTag::DENY_WEBSITE |
64 target:self | 64 target:self |
65 action:@selector(infoBarButtonDidPress:)]; | 65 action:@selector(infoBarButtonDidPress:)]; |
| 66 return infoBarView; |
66 } | 67 } |
67 | 68 |
68 #pragma mark - Handling of User Events | 69 #pragma mark - Handling of User Events |
69 | 70 |
70 - (void)infoBarButtonDidPress:(id)sender { | 71 - (void)infoBarButtonDidPress:(id)sender { |
71 // This press might have occurred after the user has already pressed a button, | 72 // This press might have occurred after the user has already pressed a button, |
72 // in which case the view has been detached from the delegate and this press | 73 // in which case the view has been detached from the delegate and this press |
73 // should be ignored. | 74 // should be ignored. |
74 if (!delegate_) { | 75 if (!self.delegate) { |
75 return; | 76 return; |
76 } | 77 } |
77 if ([sender isKindOfClass:[UIButton class]]) { | 78 if ([sender isKindOfClass:[UIButton class]]) { |
78 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; | 79 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; |
79 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { | 80 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { |
80 delegate_->InfoBarDidCancel(); | 81 self.delegate->InfoBarDidCancel(); |
81 } else { | 82 } else { |
82 DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE || | 83 DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE || |
83 buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE); | 84 buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE); |
84 delegate_->InfoBarButtonDidPress(buttonId); | 85 self.delegate->InfoBarButtonDidPress(buttonId); |
85 } | 86 } |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 @end | 90 @end |
OLD | NEW |