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/translate_message_infobar_controller.h" | 5 #include "ios/chrome/browser/translate/translate_message_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 "components/translate/core/browser/translate_infobar_delegate.h" | 9 #include "components/translate/core/browser/translate_infobar_delegate.h" |
9 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | 10 #include "ios/chrome/browser/translate/translate_infobar_tags.h" |
10 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 11 #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_delegate.h" |
12 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | 13 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" |
13 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
14 | 15 |
15 @interface TranslateMessageInfoBarController () | 16 @interface TranslateMessageInfoBarController () |
16 | 17 |
17 // Action for any of the user defined buttons. | 18 // Action for any of the user defined buttons. |
18 - (void)infoBarButtonDidPress:(id)sender; | 19 - (void)infoBarButtonDidPress:(id)sender; |
19 | 20 |
20 @end | 21 @end |
21 | 22 |
22 @implementation TranslateMessageInfoBarController | 23 @implementation TranslateMessageInfoBarController |
23 | 24 |
24 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>) | 25 - (UIView<InfoBarViewProtocol>*)viewForDelegate: |
25 viewForDelegate:(infobars::InfoBarDelegate*)delegate | 26 (infobars::InfoBarDelegate*)delegate |
26 frame:(CGRect)frame { | 27 frame:(CGRect)frame { |
27 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; | 28 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; |
28 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = | 29 translate::TranslateInfoBarDelegate* translateInfoBarDelegate = |
29 delegate->AsTranslateInfoBarDelegate(); | 30 delegate->AsTranslateInfoBarDelegate(); |
30 infoBarView.reset( | 31 infoBarView.reset( |
31 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); | 32 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); |
32 // Icon | 33 // Icon |
33 gfx::Image icon = translateInfoBarDelegate->GetIcon(); | 34 gfx::Image icon = translateInfoBarDelegate->GetIcon(); |
34 if (!icon.IsEmpty()) | 35 if (!icon.IsEmpty()) |
35 [infoBarView addLeftIcon:icon.ToUIImage()]; | 36 [infoBarView addLeftIcon:icon.ToUIImage()]; |
36 // Text. | 37 // Text. |
37 [infoBarView addLabel:base::SysUTF16ToNSString( | 38 [infoBarView addLabel:base::SysUTF16ToNSString( |
38 translateInfoBarDelegate->GetMessageInfoBarText())]; | 39 translateInfoBarDelegate->GetMessageInfoBarText())]; |
39 // Close button. | 40 // Close button. |
40 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE | 41 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE |
41 target:self | 42 target:self |
42 action:@selector(infoBarButtonDidPress:)]; | 43 action:@selector(infoBarButtonDidPress:)]; |
43 // Other button. | 44 // Other button. |
44 base::string16 buttonText( | 45 base::string16 buttonText( |
45 translateInfoBarDelegate->GetMessageInfoBarButtonText()); | 46 translateInfoBarDelegate->GetMessageInfoBarButtonText()); |
46 if (!buttonText.empty()) { | 47 if (!buttonText.empty()) { |
47 [infoBarView addButton:base::SysUTF16ToNSString(buttonText) | 48 [infoBarView addButton:base::SysUTF16ToNSString(buttonText) |
48 tag:TranslateInfoBarIOSTag::MESSAGE | 49 tag:TranslateInfoBarIOSTag::MESSAGE |
49 target:self | 50 target:self |
50 action:@selector(infoBarButtonDidPress:)]; | 51 action:@selector(infoBarButtonDidPress:)]; |
51 } | 52 } |
52 return infoBarView; | 53 return infoBarView; |
noyau (Ping after 24h)
2016/12/13 12:13:12
rince, repeat.
stkhapugin
2016/12/13 13:53:20
Done.
| |
53 } | 54 } |
54 | 55 |
55 #pragma mark - Handling of User Events | 56 #pragma mark - Handling of User Events |
56 | 57 |
57 - (void)infoBarButtonDidPress:(id)sender { | 58 - (void)infoBarButtonDidPress:(id)sender { |
58 // This press might have occurred after the user has already pressed a button, | 59 // This press might have occurred after the user has already pressed a button, |
59 // in which case the view has been detached from the delegate and this press | 60 // in which case the view has been detached from the delegate and this press |
60 // should be ignored. | 61 // should be ignored. |
61 if (!self.delegate) { | 62 if (!self.delegate) { |
62 return; | 63 return; |
63 } | 64 } |
64 if ([sender isKindOfClass:[UIButton class]]) { | 65 if ([sender isKindOfClass:[UIButton class]]) { |
65 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; | 66 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; |
66 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { | 67 if (buttonId == TranslateInfoBarIOSTag::CLOSE) { |
67 self.delegate->InfoBarDidCancel(); | 68 self.delegate->InfoBarDidCancel(); |
68 } else { | 69 } else { |
69 DCHECK(buttonId == TranslateInfoBarIOSTag::MESSAGE); | 70 DCHECK(buttonId == TranslateInfoBarIOSTag::MESSAGE); |
70 self.delegate->InfoBarButtonDidPress(buttonId); | 71 self.delegate->InfoBarButtonDidPress(buttonId); |
71 } | 72 } |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 @end | 76 @end |
OLD | NEW |