| 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/mac/scoped_nsobject.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
| 11 #include "components/translate/core/browser/translate_infobar_delegate.h" | 11 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 12 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | 12 #include "ios/chrome/browser/translate/translate_infobar_tags.h" |
| 13 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 13 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
| 14 #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h" | 14 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" |
| 15 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | 15 #import "ios/chrome/browser/ui/infobars/infobar_view_protocol.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
| 18 | 18 |
| 19 @interface AfterTranslateInfoBarController () { | 19 @interface AfterTranslateInfoBarController () { |
| 20 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak | 20 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Action for any of the user defined buttons. | 23 // Action for any of the user defined buttons. |
| 24 - (void)infoBarButtonDidPress:(id)sender; | 24 - (void)infoBarButtonDidPress:(id)sender; |
| 25 | 25 |
| 26 @end | 26 @end |
| 27 | 27 |
| 28 @implementation AfterTranslateInfoBarController | 28 @implementation AfterTranslateInfoBarController |
| 29 | 29 |
| 30 #pragma mark - | 30 #pragma mark - |
| 31 #pragma mark InfoBarControllerProtocol | 31 #pragma mark InfoBarControllerProtocol |
| 32 | 32 |
| 33 - (UIView<InfoBarViewProtocol>*)viewForDelegate: | 33 - (UIView<InfoBarViewProtocol>*)viewForDelegate: |
| 34 (infobars::InfoBarDelegate*)delegate | 34 (infobars::InfoBarDelegate*)delegate |
| 35 frame:(CGRect)frame { | 35 frame:(CGRect)frame { |
| 36 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; | 36 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; |
| 37 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate(); | 37 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate(); |
| 38 DCHECK(_translateInfoBarDelegate); | 38 DCHECK(_translateInfoBarDelegate); |
| 39 infoBarView.reset( | 39 infoBarView.reset( |
| 40 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); | 40 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]); |
| 41 // Icon | 41 // Icon |
| 42 gfx::Image icon = _translateInfoBarDelegate->GetIcon(); | 42 gfx::Image icon = _translateInfoBarDelegate->GetIcon(); |
| 43 if (!icon.IsEmpty()) | 43 if (!icon.IsEmpty()) |
| 44 [infoBarView addLeftIcon:icon.ToUIImage()]; | 44 [infoBarView addLeftIcon:icon.ToUIImage()]; |
| 45 // Main text. | 45 // Main text. |
| 46 const bool autodeterminedSourceLanguage = | 46 const bool autodeterminedSourceLanguage = |
| 47 _translateInfoBarDelegate->original_language_code() == | 47 _translateInfoBarDelegate->original_language_code() == |
| 48 translate::kUnknownLanguageCode; | 48 translate::kUnknownLanguageCode; |
| 49 bool swappedLanguageButtons; | 49 bool swappedLanguageButtons; |
| 50 std::vector<base::string16> strings; | 50 std::vector<base::string16> strings; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 | 116 |
| 117 - (void)infoBarSwitchDidPress:(id)sender { | 117 - (void)infoBarSwitchDidPress:(id)sender { |
| 118 DCHECK_EQ(TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH, [sender tag]); | 118 DCHECK_EQ(TranslateInfoBarIOSTag::ALWAYS_TRANSLATE_SWITCH, [sender tag]); |
| 119 DCHECK([sender respondsToSelector:@selector(isOn)]); | 119 DCHECK([sender respondsToSelector:@selector(isOn)]); |
| 120 if (_translateInfoBarDelegate->ShouldAlwaysTranslate() != [sender isOn]) | 120 if (_translateInfoBarDelegate->ShouldAlwaysTranslate() != [sender isOn]) |
| 121 _translateInfoBarDelegate->ToggleAlwaysTranslate(); | 121 _translateInfoBarDelegate->ToggleAlwaysTranslate(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 @end | 124 @end |
| OLD | NEW |