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/before_translate_infobar_controller.h" | 5 #include "ios/chrome/browser/translate/before_translate_infobar_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return label; | 90 return label; |
91 } | 91 } |
92 | 92 |
93 @end | 93 @end |
94 | 94 |
95 @interface BeforeTranslateInfoBarController () | 95 @interface BeforeTranslateInfoBarController () |
96 | 96 |
97 // Action for any of the user defined buttons. | 97 // Action for any of the user defined buttons. |
98 - (void)infoBarButtonDidPress:(id)sender; | 98 - (void)infoBarButtonDidPress:(id)sender; |
99 // Action for any of the user defined links. | 99 // Action for any of the user defined links. |
100 - (void)infobarLinkDidPress:(NSNumber*)tag; | 100 - (void)infobarLinkDidPress:(NSUInteger)tag; |
101 // Action for the language selection "Done" button. | 101 // Action for the language selection "Done" button. |
102 - (void)languageSelectionDone; | 102 - (void)languageSelectionDone; |
103 // Dismisses the language selection view. | 103 // Dismisses the language selection view. |
104 - (void)dismissLanguageSelectionView; | 104 - (void)dismissLanguageSelectionView; |
105 // Changes the text on the view to match the language. | 105 // Changes the text on the view to match the language. |
106 - (void)updateInfobarLabelOnView:(InfoBarView*)view; | 106 - (void)updateInfobarLabelOnView:(InfoBarView*)view; |
107 | 107 |
108 @end | 108 @end |
109 | 109 |
110 @implementation BeforeTranslateInfoBarController { | 110 @implementation BeforeTranslateInfoBarController { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 base::string16 originalLanguageWithLink = | 165 base::string16 originalLanguageWithLink = |
166 base::SysNSStringToUTF16([[view class] | 166 base::SysNSStringToUTF16([[view class] |
167 stringAsLink:originalLanguage | 167 stringAsLink:originalLanguage |
168 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); | 168 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); |
169 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class] | 169 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class] |
170 stringAsLink:targetLanguage | 170 stringAsLink:targetLanguage |
171 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]); | 171 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]); |
172 NSString* label = | 172 NSString* label = |
173 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, | 173 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, |
174 originalLanguageWithLink, targetLanguageWithLink); | 174 originalLanguageWithLink, targetLanguageWithLink); |
175 [view addLabel:label target:self action:@selector(infobarLinkDidPress:)]; | 175 [view addLabel:label |
| 176 action:^(NSUInteger tag) { |
| 177 [self infobarLinkDidPress:tag]; |
| 178 }]; |
176 } | 179 } |
177 | 180 |
178 - (void)languageSelectionDone { | 181 - (void)languageSelectionDone { |
179 size_t selectedRow = [_languagePicker selectedRowInComponent:0]; | 182 size_t selectedRow = [_languagePicker selectedRowInComponent:0]; |
180 std::string lang = _translateInfoBarDelegate->language_code_at(selectedRow); | 183 std::string lang = _translateInfoBarDelegate->language_code_at(selectedRow); |
181 if (_languageSelectionType == | 184 if (_languageSelectionType == |
182 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE && | 185 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE && |
183 lang != _translateInfoBarDelegate->target_language_code()) { | 186 lang != _translateInfoBarDelegate->target_language_code()) { |
184 _translateInfoBarDelegate->UpdateOriginalLanguage(lang); | 187 _translateInfoBarDelegate->UpdateOriginalLanguage(lang); |
185 } | 188 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return; | 242 return; |
240 } | 243 } |
241 if ([sender isKindOfClass:[UIButton class]]) { | 244 if ([sender isKindOfClass:[UIButton class]]) { |
242 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; | 245 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; |
243 DCHECK(buttonId == TranslateInfoBarIOSTag::BEFORE_ACCEPT || | 246 DCHECK(buttonId == TranslateInfoBarIOSTag::BEFORE_ACCEPT || |
244 buttonId == TranslateInfoBarIOSTag::BEFORE_DENY); | 247 buttonId == TranslateInfoBarIOSTag::BEFORE_DENY); |
245 self.delegate->InfoBarButtonDidPress(buttonId); | 248 self.delegate->InfoBarButtonDidPress(buttonId); |
246 } | 249 } |
247 } | 250 } |
248 | 251 |
249 - (void)infobarLinkDidPress:(NSNumber*)tag { | 252 - (void)infobarLinkDidPress:(NSUInteger)tag { |
250 DCHECK([tag isKindOfClass:[NSNumber class]]); | 253 _languageSelectionType = tag; |
251 _languageSelectionType = [tag unsignedIntegerValue]; | |
252 DCHECK(_languageSelectionType == | 254 DCHECK(_languageSelectionType == |
253 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE || | 255 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE || |
254 _languageSelectionType == | 256 _languageSelectionType == |
255 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE); | 257 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE); |
256 if (_languagePicker != nil) | 258 if (_languagePicker != nil) |
257 return; // The UIPickerView is already up. | 259 return; // The UIPickerView is already up. |
258 | 260 |
259 // Creates and adds the view containing the UIPickerView and the | 261 // Creates and adds the view containing the UIPickerView and the |
260 // UINavigationBar. | 262 // UINavigationBar. |
261 UIView* parentView = | 263 UIView* parentView = |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 [super removeView]; | 366 [super removeView]; |
365 [self dismissLanguageSelectionView]; | 367 [self dismissLanguageSelectionView]; |
366 } | 368 } |
367 | 369 |
368 - (void)detachView { | 370 - (void)detachView { |
369 [super detachView]; | 371 [super detachView]; |
370 [self dismissLanguageSelectionView]; | 372 [self dismissLanguageSelectionView]; |
371 } | 373 } |
372 | 374 |
373 @end | 375 @end |
OLD | NEW |