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/after_translate_infobar_controller.h" | 5 #include "ios/chrome/browser/translate/after_translate_infobar_controller.h" |
6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
7 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
10 #include "components/translate/core/browser/translate_infobar_delegate.h" | 11 #include "components/translate/core/browser/translate_infobar_delegate.h" |
11 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | 12 #include "ios/chrome/browser/translate/translate_infobar_tags.h" |
12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 13 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
13 #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h" | 14 #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h" |
14 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | 15 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 | 18 |
18 @interface AfterTranslateInfoBarController () { | 19 @interface AfterTranslateInfoBarController () { |
19 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak | 20 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak |
20 } | 21 } |
21 | 22 |
22 // Action for any of the user defined buttons. | 23 // Action for any of the user defined buttons. |
23 - (void)infoBarButtonDidPress:(id)sender; | 24 - (void)infoBarButtonDidPress:(id)sender; |
24 | 25 |
25 @end | 26 @end |
26 | 27 |
27 @implementation AfterTranslateInfoBarController | 28 @implementation AfterTranslateInfoBarController |
28 | 29 |
29 #pragma mark - | 30 #pragma mark - |
30 #pragma mark InfoBarControllerProtocol | 31 #pragma mark InfoBarControllerProtocol |
31 | 32 |
32 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>) | 33 - (UIView<InfoBarViewProtocol>*)viewForDelegate: |
33 viewForDelegate:(infobars::InfoBarDelegate*)delegate | 34 (infobars::InfoBarDelegate*)delegate |
34 frame:(CGRect)frame { | 35 frame:(CGRect)frame { |
35 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; | 36 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; |
36 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate(); | 37 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate(); |
37 DCHECK(_translateInfoBarDelegate); | 38 DCHECK(_translateInfoBarDelegate); |
38 infoBarView.reset( | 39 infoBarView.reset( |
39 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); | 40 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); |
40 // Icon | 41 // Icon |
41 gfx::Image icon = _translateInfoBarDelegate->GetIcon(); | 42 gfx::Image icon = _translateInfoBarDelegate->GetIcon(); |
42 if (!icon.IsEmpty()) | 43 if (!icon.IsEmpty()) |
43 [infoBarView addLeftIcon:icon.ToUIImage()]; | 44 [infoBarView addLeftIcon:icon.ToUIImage()]; |
44 // Main text. | 45 // Main text. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 base::string16 alwaysTranslate = l10n_util::GetStringFUTF16( | 83 base::string16 alwaysTranslate = l10n_util::GetStringFUTF16( |
83 IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, stdOriginal); | 84 IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, stdOriginal); |
84 const BOOL switchValue = _translateInfoBarDelegate->ShouldAlwaysTranslate(); | 85 const BOOL switchValue = _translateInfoBarDelegate->ShouldAlwaysTranslate(); |
85 [infoBarView | 86 [infoBarView |
86 addSwitchWithLabel:base::SysUTF16ToNSString(alwaysTranslate) | 87 addSwitchWithLabel:base::SysUTF16ToNSString(alwaysTranslate) |
87 isOn:switchValue | 88 isOn:switchValue |
88 tag:TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH | 89 tag:TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH |
89 target:self | 90 target:self |
90 action:@selector(infoBarSwitchDidPress:)]; | 91 action:@selector(infoBarSwitchDidPress:)]; |
91 } | 92 } |
92 return infoBarView; | 93 return [[infoBarView retain] autorelease]; |
93 } | 94 } |
94 | 95 |
95 #pragma mark - Handling of User Events | 96 #pragma mark - Handling of User Events |
96 | 97 |
97 - (void)infoBarButtonDidPress:(id)sender { | 98 - (void)infoBarButtonDidPress:(id)sender { |
98 // This press might have occurred after the user has already pressed a button, | 99 // This press might have occurred after the user has already pressed a button, |
99 // in which case the view has been detached from the delegate and this press | 100 // in which case the view has been detached from the delegate and this press |
100 // should be ignored. | 101 // should be ignored. |
101 if (!self.delegate) { | 102 if (!self.delegate) { |
102 return; | 103 return; |
(...skipping 11 matching lines...) Expand all Loading... |
114 } | 115 } |
115 | 116 |
116 - (void)infoBarSwitchDidPress:(id)sender { | 117 - (void)infoBarSwitchDidPress:(id)sender { |
117 DCHECK_EQ(TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH, [sender tag]); | 118 DCHECK_EQ(TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH, [sender tag]); |
118 DCHECK([sender respondsToSelector:@selector(isOn)]); | 119 DCHECK([sender respondsToSelector:@selector(isOn)]); |
119 if (_translateInfoBarDelegate->ShouldAlwaysTranslate() != [sender isOn]) | 120 if (_translateInfoBarDelegate->ShouldAlwaysTranslate() != [sender isOn]) |
120 _translateInfoBarDelegate->ToggleAlwaysTranslate(); | 121 _translateInfoBarDelegate->ToggleAlwaysTranslate(); |
121 } | 122 } |
122 | 123 |
123 @end | 124 @end |
OLD | NEW |