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/mac/scoped_nsobject.h" | |
8 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
10 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
11 #include "components/translate/core/browser/translate_infobar_delegate.h" | 10 #include "components/translate/core/browser/translate_infobar_delegate.h" |
12 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | 11 #include "ios/chrome/browser/translate/translate_infobar_tags.h" |
13 #import "ios/chrome/browser/ui/infobars/infobar_view.h" | 12 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
14 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" | 13 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" |
15 #include "ios/chrome/grit/ios_chromium_strings.h" | 14 #include "ios/chrome/grit/ios_chromium_strings.h" |
16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
18 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
19 @interface NeverTranslateInfoBarController () | 22 @interface NeverTranslateInfoBarController () |
20 | 23 |
21 // Action for any of the user defined buttons. | 24 // Action for any of the user defined buttons. |
22 - (void)infoBarButtonDidPress:(id)sender; | 25 - (void)infoBarButtonDidPress:(id)sender; |
23 | 26 |
24 @end | 27 @end |
25 | 28 |
26 @implementation NeverTranslateInfoBarController | 29 @implementation NeverTranslateInfoBarController |
27 | 30 |
28 #pragma mark - | 31 #pragma mark - |
29 #pragma mark InfoBarControllerProtocol | 32 #pragma mark InfoBarControllerProtocol |
30 | 33 |
31 - (InfoBarView*)viewForDelegate:(infobars::InfoBarDelegate*)delegate | 34 - (InfoBarView*)viewForDelegate:(infobars::InfoBarDelegate*)delegate |
32 frame:(CGRect)frame { | 35 frame:(CGRect)frame { |
33 base::scoped_nsobject<InfoBarView> infoBarView; | 36 InfoBarView* infoBarView; |
34 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = | 37 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = |
35 delegate->AsTranslateInfoBarDelegate(); | 38 delegate->AsTranslateInfoBarDelegate(); |
36 infoBarView.reset( | 39 infoBarView = |
37 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]); | 40 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]; |
38 // Icon | 41 // Icon |
39 gfx::Image icon = translateInfoBarDelegate->GetIcon(); | 42 gfx::Image icon = translateInfoBarDelegate->GetIcon(); |
40 if (!icon.IsEmpty()) | 43 if (!icon.IsEmpty()) |
41 [infoBarView addLeftIcon:icon.ToUIImage()]; | 44 [infoBarView addLeftIcon:icon.ToUIImage()]; |
42 // Main text. | 45 // Main text. |
43 base::string16 originalLanguage = | 46 base::string16 originalLanguage = |
44 translateInfoBarDelegate->original_language_name(); | 47 translateInfoBarDelegate->original_language_name(); |
45 [infoBarView | 48 [infoBarView |
46 addLabel:l10n_util::GetNSStringF(IDS_IOS_TRANSLATE_INFOBAR_NEVER_MESSAGE, | 49 addLabel:l10n_util::GetNSStringF(IDS_IOS_TRANSLATE_INFOBAR_NEVER_MESSAGE, |
47 originalLanguage)]; | 50 originalLanguage)]; |
48 // Close button. | 51 // Close button. |
49 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE | 52 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE |
50 target:self | 53 target:self |
51 action:@selector(infoBarButtonDidPress:)]; | 54 action:@selector(infoBarButtonDidPress:)]; |
52 // Other buttons. | 55 // Other buttons. |
53 NSString* buttonLanguage = l10n_util::GetNSStringF( | 56 NSString* buttonLanguage = l10n_util::GetNSStringF( |
54 IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, originalLanguage); | 57 IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, originalLanguage); |
55 NSString* buttonSite = l10n_util::GetNSString( | 58 NSString* buttonSite = l10n_util::GetNSString( |
56 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE); | 59 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE); |
57 [infoBarView addButton1:buttonLanguage | 60 [infoBarView addButton1:buttonLanguage |
58 tag1:TranslateInfoBarIOSTag::DENY_LANGUAGE | 61 tag1:TranslateInfoBarIOSTag::DENY_LANGUAGE |
59 button2:buttonSite | 62 button2:buttonSite |
60 tag2:TranslateInfoBarIOSTag::DENY_WEBSITE | 63 tag2:TranslateInfoBarIOSTag::DENY_WEBSITE |
61 target:self | 64 target:self |
62 action:@selector(infoBarButtonDidPress:)]; | 65 action:@selector(infoBarButtonDidPress:)]; |
63 return [[infoBarView retain] autorelease]; | 66 return infoBarView; |
64 } | 67 } |
65 | 68 |
66 #pragma mark - Handling of User Events | 69 #pragma mark - Handling of User Events |
67 | 70 |
68 - (void)infoBarButtonDidPress:(id)sender { | 71 - (void)infoBarButtonDidPress:(id)sender { |
69 // 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, |
70 // 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 |
71 // should be ignored. | 74 // should be ignored. |
72 if (!self.delegate) { | 75 if (!self.delegate) { |
73 return; | 76 return; |
74 } | 77 } |
75 if ([sender isKindOfClass:[UIButton class]]) { | 78 if ([sender isKindOfClass:[UIButton class]]) { |
76 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; | 79 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; |
77 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { | 80 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { |
78 self.delegate->InfoBarDidCancel(); | 81 self.delegate->InfoBarDidCancel(); |
79 } else { | 82 } else { |
80 DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE || | 83 DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE || |
81 buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE); | 84 buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE); |
82 self.delegate->InfoBarButtonDidPress(buttonId); | 85 self.delegate->InfoBarButtonDidPress(buttonId); |
83 } | 86 } |
84 } | 87 } |
85 } | 88 } |
86 | 89 |
87 @end | 90 @end |
OLD | NEW |