Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: ios/chrome/browser/translate/before_translate_infobar_controller.mm

Issue 2592113002: Remove legacy InfoBarViewProtocol. (Closed)
Patch Set: Rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/mac/scoped_nsobject.h" 11 #include "base/mac/scoped_nsobject.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
15 #include "components/translate/core/browser/translate_infobar_delegate.h" 15 #include "components/translate/core/browser/translate_infobar_delegate.h"
16 #include "ios/chrome/browser/translate/translate_infobar_tags.h" 16 #include "ios/chrome/browser/translate/translate_infobar_tags.h"
17 #import "ios/chrome/browser/ui/infobars/infobar_view.h" 17 #import "ios/chrome/browser/ui/infobars/infobar_view.h"
18 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" 18 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h"
19 #import "ios/chrome/browser/ui/infobars/infobar_view_protocol.h"
20 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
22 21
23 namespace { 22 namespace {
24 23
25 CGFloat kNavigationBarHeight = 44; 24 CGFloat kNavigationBarHeight = 44;
26 CGFloat kUIPickerHeight = 216; 25 CGFloat kUIPickerHeight = 216;
27 CGFloat kUIPickerFontSize = 26; 26 CGFloat kUIPickerFontSize = 26;
28 NSTimeInterval kPickerAnimationDurationInSeconds = 0.2; 27 NSTimeInterval kPickerAnimationDurationInSeconds = 0.2;
29 28
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 96
98 // Action for any of the user defined buttons. 97 // Action for any of the user defined buttons.
99 - (void)infoBarButtonDidPress:(id)sender; 98 - (void)infoBarButtonDidPress:(id)sender;
100 // Action for any of the user defined links. 99 // Action for any of the user defined links.
101 - (void)infobarLinkDidPress:(NSNumber*)tag; 100 - (void)infobarLinkDidPress:(NSNumber*)tag;
102 // Action for the language selection "Done" button. 101 // Action for the language selection "Done" button.
103 - (void)languageSelectionDone; 102 - (void)languageSelectionDone;
104 // Dismisses the language selection view. 103 // Dismisses the language selection view.
105 - (void)dismissLanguageSelectionView; 104 - (void)dismissLanguageSelectionView;
106 // Changes the text on the view to match the language. 105 // Changes the text on the view to match the language.
107 - (void)updateInfobarLabelOnView:(UIView<InfoBarViewProtocol>*)view; 106 - (void)updateInfobarLabelOnView:(InfoBarView*)view;
108 107
109 @end 108 @end
110 109
111 @implementation BeforeTranslateInfoBarController { 110 @implementation BeforeTranslateInfoBarController {
112 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak 111 translate::TranslateInfoBarDelegate* _translateInfoBarDelegate; // weak
113 // A fullscreen view that catches all touch events and contains a UIPickerView 112 // A fullscreen view that catches all touch events and contains a UIPickerView
114 // and a UINavigationBar. 113 // and a UINavigationBar.
115 base::scoped_nsobject<UIView> _languageSelectionView; 114 base::scoped_nsobject<UIView> _languageSelectionView;
116 // Stores whether the user is currently choosing in the UIPickerView the 115 // Stores whether the user is currently choosing in the UIPickerView the
117 // original language, or the target language. 116 // original language, or the target language.
118 NSUInteger _languageSelectionType; 117 NSUInteger _languageSelectionType;
119 // The language picker. 118 // The language picker.
120 base::scoped_nsobject<UIPickerView> _languagePicker; 119 base::scoped_nsobject<UIPickerView> _languagePicker;
121 // Navigation bar associated with the picker with "Done" and "Cancel" buttons. 120 // Navigation bar associated with the picker with "Done" and "Cancel" buttons.
122 base::scoped_nsobject<UINavigationBar> _navigationBar; 121 base::scoped_nsobject<UINavigationBar> _navigationBar;
123 // The controller of the languagePicker. Needs to be an ivar because 122 // The controller of the languagePicker. Needs to be an ivar because
124 // |_languagePicker| does not retain it. 123 // |_languagePicker| does not retain it.
125 base::scoped_nsobject<LanguagePickerController> _languagePickerController; 124 base::scoped_nsobject<LanguagePickerController> _languagePickerController;
126 } 125 }
127 126
128 #pragma mark - 127 #pragma mark -
129 #pragma mark InfoBarControllerProtocol 128 #pragma mark InfoBarControllerProtocol
130 129
131 - (UIView<InfoBarViewProtocol>*)viewForDelegate: 130 - (InfoBarView*)viewForDelegate:(infobars::InfoBarDelegate*)delegate
132 (infobars::InfoBarDelegate*)delegate 131 frame:(CGRect)frame {
133 frame:(CGRect)frame { 132 base::scoped_nsobject<InfoBarView> infoBarView;
134 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView;
135 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate(); 133 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate();
136 infoBarView.reset( 134 infoBarView.reset(
137 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]); 135 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]);
138 // Icon 136 // Icon
139 gfx::Image icon = _translateInfoBarDelegate->GetIcon(); 137 gfx::Image icon = _translateInfoBarDelegate->GetIcon();
140 if (!icon.IsEmpty()) 138 if (!icon.IsEmpty())
141 [infoBarView addLeftIcon:icon.ToUIImage()]; 139 [infoBarView addLeftIcon:icon.ToUIImage()];
142 140
143 // Main text. 141 // Main text.
144 [self updateInfobarLabelOnView:infoBarView]; 142 [self updateInfobarLabelOnView:infoBarView];
145 143
146 // Close button. 144 // Close button.
147 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::BEFORE_DENY 145 [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::BEFORE_DENY
148 target:self 146 target:self
149 action:@selector(infoBarButtonDidPress:)]; 147 action:@selector(infoBarButtonDidPress:)];
150 // Other buttons. 148 // Other buttons.
151 NSString* buttonAccept = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_ACCEPT); 149 NSString* buttonAccept = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_ACCEPT);
152 NSString* buttonDeny = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_DENY); 150 NSString* buttonDeny = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_DENY);
153 [infoBarView addButton1:buttonAccept 151 [infoBarView addButton1:buttonAccept
154 tag1:TranslateInfoBarIOSTag::BEFORE_ACCEPT 152 tag1:TranslateInfoBarIOSTag::BEFORE_ACCEPT
155 button2:buttonDeny 153 button2:buttonDeny
156 tag2:TranslateInfoBarIOSTag::BEFORE_DENY 154 tag2:TranslateInfoBarIOSTag::BEFORE_DENY
157 target:self 155 target:self
158 action:@selector(infoBarButtonDidPress:)]; 156 action:@selector(infoBarButtonDidPress:)];
159 return [[infoBarView retain] autorelease]; 157 return [[infoBarView retain] autorelease];
160 } 158 }
161 159
162 - (void)updateInfobarLabelOnView:(UIView<InfoBarViewProtocol>*)view { 160 - (void)updateInfobarLabelOnView:(InfoBarView*)view {
163 NSString* originalLanguage = base::SysUTF16ToNSString( 161 NSString* originalLanguage = base::SysUTF16ToNSString(
164 _translateInfoBarDelegate->original_language_name()); 162 _translateInfoBarDelegate->original_language_name());
165 NSString* targetLanguage = base::SysUTF16ToNSString( 163 NSString* targetLanguage = base::SysUTF16ToNSString(
166 _translateInfoBarDelegate->target_language_name()); 164 _translateInfoBarDelegate->target_language_name());
167 base::string16 originalLanguageWithLink = 165 base::string16 originalLanguageWithLink =
168 base::SysNSStringToUTF16([[view class] 166 base::SysNSStringToUTF16([[view class]
169 stringAsLink:originalLanguage 167 stringAsLink:originalLanguage
170 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); 168 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]);
171 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class] 169 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class]
172 stringAsLink:targetLanguage 170 stringAsLink:targetLanguage
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 [super removeView]; 364 [super removeView];
367 [self dismissLanguageSelectionView]; 365 [self dismissLanguageSelectionView];
368 } 366 }
369 367
370 - (void)detachView { 368 - (void)detachView {
371 [super detachView]; 369 [super detachView];
372 [self dismissLanguageSelectionView]; 370 [self dismissLanguageSelectionView];
373 } 371 }
374 372
375 @end 373 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698