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

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

Issue 839733004: Style fixes in //ios (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile Created 5 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 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 13 matching lines...) Expand all
24 CGFloat kUIPickerHeight = 216; 24 CGFloat kUIPickerHeight = 216;
25 CGFloat kUIPickerFontSize = 26; 25 CGFloat kUIPickerFontSize = 26;
26 NSTimeInterval kPickerAnimationDurationInSeconds = 0.2; 26 NSTimeInterval kPickerAnimationDurationInSeconds = 0.2;
27 27
28 } // namespace 28 } // namespace
29 29
30 // The class is a data source and delegate to the UIPickerView that contains the 30 // The class is a data source and delegate to the UIPickerView that contains the
31 // language list. 31 // language list.
32 @interface LanguagePickerController 32 @interface LanguagePickerController
33 : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate> { 33 : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate> {
34 __weak translate::TranslateInfoBarDelegate* translateInfoBarDelegate_; 34 __weak translate::TranslateInfoBarDelegate* _translateInfoBarDelegate;
35 NSInteger initialRow_; // Displayed in bold font. 35 NSInteger _initialRow; // Displayed in bold font.
36 NSInteger disabledRow_; // Grayed out. 36 NSInteger _disabledRow; // Grayed out.
37 } 37 }
38 @end 38 @end
39 39
40 @implementation LanguagePickerController 40 @implementation LanguagePickerController
41 41
42 - (instancetype)initWithDelegate:(translate::TranslateInfoBarDelegate*) 42 - (instancetype)initWithDelegate:(translate::TranslateInfoBarDelegate*)
43 translateInfoBarDelegate 43 translateInfoBarDelegate
44 initialRow:(NSInteger)initialRow 44 initialRow:(NSInteger)initialRow
45 disabledRow:(NSInteger)disabledRow { 45 disabledRow:(NSInteger)disabledRow {
46 if ((self = [super init])) { 46 if ((self = [super init])) {
47 translateInfoBarDelegate_ = translateInfoBarDelegate; 47 _translateInfoBarDelegate = translateInfoBarDelegate;
48 initialRow_ = initialRow; 48 _initialRow = initialRow;
49 disabledRow_ = disabledRow; 49 _disabledRow = disabledRow;
50 } 50 }
51 return self; 51 return self;
52 } 52 }
53 53
54 #pragma mark - 54 #pragma mark -
55 #pragma mark UIPickerViewDataSource 55 #pragma mark UIPickerViewDataSource
56 56
57 - (NSInteger)pickerView:(UIPickerView*)pickerView 57 - (NSInteger)pickerView:(UIPickerView*)pickerView
58 numberOfRowsInComponent:(NSInteger)component { 58 numberOfRowsInComponent:(NSInteger)component {
59 NSUInteger numRows = translateInfoBarDelegate_->num_languages(); 59 NSUInteger numRows = _translateInfoBarDelegate->num_languages();
60 return numRows; 60 return numRows;
61 } 61 }
62 62
63 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView { 63 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView {
64 return 1; 64 return 1;
65 } 65 }
66 66
67 #pragma mark - 67 #pragma mark -
68 #pragma mark UIPickerViewDelegate 68 #pragma mark UIPickerViewDelegate
69 69
70 - (UIView*)pickerView:(UIPickerView*)pickerView 70 - (UIView*)pickerView:(UIPickerView*)pickerView
71 viewForRow:(NSInteger)row 71 viewForRow:(NSInteger)row
72 forComponent:(NSInteger)component 72 forComponent:(NSInteger)component
73 reusingView:(UIView*)view { 73 reusingView:(UIView*)view {
74 DCHECK_EQ(0, component); 74 DCHECK_EQ(0, component);
75 UILabel* label = [view isKindOfClass:[UILabel class]] 75 UILabel* label = [view isKindOfClass:[UILabel class]]
76 ? (UILabel*)view 76 ? (UILabel*)view
77 : [[[UILabel alloc] init] autorelease]; 77 : [[[UILabel alloc] init] autorelease];
78 [label setText:base::SysUTF16ToNSString( 78 [label setText:base::SysUTF16ToNSString(
79 translateInfoBarDelegate_->language_name_at(row))]; 79 _translateInfoBarDelegate->language_name_at(row))];
80 [label setTextAlignment:NSTextAlignmentCenter]; 80 [label setTextAlignment:NSTextAlignmentCenter];
81 UIFont* font = [UIFont systemFontOfSize:kUIPickerFontSize]; 81 UIFont* font = [UIFont systemFontOfSize:kUIPickerFontSize];
82 BOOL enabled = YES; 82 BOOL enabled = YES;
83 if (row == initialRow_) 83 if (row == _initialRow)
84 font = [UIFont boldSystemFontOfSize:kUIPickerFontSize]; 84 font = [UIFont boldSystemFontOfSize:kUIPickerFontSize];
85 else if (row == disabledRow_) 85 else if (row == _disabledRow)
86 enabled = NO; 86 enabled = NO;
87 [label setFont:font]; 87 [label setFont:font];
88 [label setEnabled:enabled]; 88 [label setEnabled:enabled];
89 return label; 89 return label;
90 } 90 }
91 91
92 @end 92 @end
93 93
94 @interface BeforeTranslateInfoBarController () 94 @interface BeforeTranslateInfoBarController ()
95 95
96 // Action for any of the user defined buttons. 96 // Action for any of the user defined buttons.
97 - (void)infoBarButtonDidPress:(id)sender; 97 - (void)infoBarButtonDidPress:(id)sender;
98 // Action for any of the user defined links. 98 // Action for any of the user defined links.
99 - (void)infobarLinkDidPress:(NSNumber*)tag; 99 - (void)infobarLinkDidPress:(NSNumber*)tag;
100 // Action for the language selection "Done" button. 100 // Action for the language selection "Done" button.
101 - (void)languageSelectionDone; 101 - (void)languageSelectionDone;
102 // Dismisses the language selection view. 102 // Dismisses the language selection view.
103 - (void)dismissLanguageSelectionView; 103 - (void)dismissLanguageSelectionView;
104 104
105 @end 105 @end
106 106
107 @implementation BeforeTranslateInfoBarController { 107 @implementation BeforeTranslateInfoBarController {
108 __weak translate::TranslateInfoBarDelegate* translateInfoBarDelegate_; 108 __weak translate::TranslateInfoBarDelegate* _translateInfoBarDelegate;
109 // A fullscreen view that catches all touch events and contains a UIPickerView 109 // A fullscreen view that catches all touch events and contains a UIPickerView
110 // and a UINavigationBar. 110 // and a UINavigationBar.
111 base::scoped_nsobject<UIView> languageSelectionView_; 111 base::scoped_nsobject<UIView> _languageSelectionView;
112 // Stores whether the user is currently choosing in the UIPickerView the 112 // Stores whether the user is currently choosing in the UIPickerView the
113 // original language, or the target language. 113 // original language, or the target language.
114 NSUInteger languageSelectionType_; 114 NSUInteger _languageSelectionType;
115 // The language picker. 115 // The language picker.
116 base::scoped_nsobject<UIPickerView> languagePicker_; 116 base::scoped_nsobject<UIPickerView> _languagePicker;
117 // Navigation bar associated with the picker with "Done" and "Cancel" buttons. 117 // Navigation bar associated with the picker with "Done" and "Cancel" buttons.
118 base::scoped_nsobject<UINavigationBar> navigationBar_; 118 base::scoped_nsobject<UINavigationBar> _navigationBar;
119 // The controller of the languagePicker. Needs to be an ivar because 119 // The controller of the languagePicker. Needs to be an ivar because
120 // |languagePicker_| does not retain it. 120 // |_languagePicker| does not retain it.
121 base::scoped_nsobject<LanguagePickerController> languagePickerController_; 121 base::scoped_nsobject<LanguagePickerController> _languagePickerController;
122 } 122 }
123 123
124 #pragma mark - 124 #pragma mark -
125 #pragma mark InfoBarControllerProtocol 125 #pragma mark InfoBarControllerProtocol
126 126
127 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate 127 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate
128 frame:(CGRect)frame { 128 frame:(CGRect)frame {
129 translateInfoBarDelegate_ = delegate->AsTranslateInfoBarDelegate(); 129 _translateInfoBarDelegate = delegate->AsTranslateInfoBarDelegate();
130 infobars::InfoBarDelegate* infoBarDelegate = 130 infobars::InfoBarDelegate* infoBarDelegate =
131 static_cast<infobars::InfoBarDelegate*>(translateInfoBarDelegate_); 131 static_cast<infobars::InfoBarDelegate*>(_translateInfoBarDelegate);
132 DCHECK(!infoBarView_); 132 DCHECK(!infoBarView_);
133 infoBarView_.reset([ios::GetChromeBrowserProvider()->CreateInfoBarView() 133 infoBarView_.reset([ios::GetChromeBrowserProvider()->CreateInfoBarView()
134 initWithFrame:frame 134 initWithFrame:frame
135 delegate:delegate_ 135 delegate:delegate_
136 isWarning:infoBarDelegate->GetInfoBarType() == 136 isWarning:infoBarDelegate->GetInfoBarType() ==
137 infobars::InfoBarDelegate::WARNING_TYPE]); 137 infobars::InfoBarDelegate::WARNING_TYPE]);
138 // Icon 138 // Icon
139 gfx::Image icon = translateInfoBarDelegate_->GetIcon(); 139 gfx::Image icon = _translateInfoBarDelegate->GetIcon();
140 if (!icon.IsEmpty()) 140 if (!icon.IsEmpty())
141 [infoBarView_ addLeftIcon:icon.ToUIImage()]; 141 [infoBarView_ addLeftIcon:icon.ToUIImage()];
142 142
143 // Main text. 143 // Main text.
144 [self updateInfobarLabel]; 144 [self updateInfobarLabel];
145 145
146 // Close button. 146 // Close button.
147 [infoBarView_ addCloseButtonWithTag:TranslateInfoBarIOSTag::BEFORE_DENY 147 [infoBarView_ addCloseButtonWithTag:TranslateInfoBarIOSTag::BEFORE_DENY
148 target:self 148 target:self
149 action:@selector(infoBarButtonDidPress:)]; 149 action:@selector(infoBarButtonDidPress:)];
150 // Other buttons. 150 // Other buttons.
151 NSString* buttonAccept = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_ACCEPT); 151 NSString* buttonAccept = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_ACCEPT);
152 NSString* buttonDeny = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_DENY); 152 NSString* buttonDeny = l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_DENY);
153 [infoBarView_ addButton1:buttonAccept 153 [infoBarView_ addButton1:buttonAccept
154 tag1:TranslateInfoBarIOSTag::BEFORE_ACCEPT 154 tag1:TranslateInfoBarIOSTag::BEFORE_ACCEPT
155 button2:buttonDeny 155 button2:buttonDeny
156 tag2:TranslateInfoBarIOSTag::BEFORE_DENY 156 tag2:TranslateInfoBarIOSTag::BEFORE_DENY
157 target:self 157 target:self
158 action:@selector(infoBarButtonDidPress:)]; 158 action:@selector(infoBarButtonDidPress:)];
159 } 159 }
160 160
161 - (void)updateInfobarLabel { 161 - (void)updateInfobarLabel {
162 NSString* originalLanguage = 162 NSString* originalLanguage =
163 base::SysUTF16ToNSString(translateInfoBarDelegate_->language_name_at( 163 base::SysUTF16ToNSString(_translateInfoBarDelegate->language_name_at(
164 translateInfoBarDelegate_->original_language_index())); 164 _translateInfoBarDelegate->original_language_index()));
165 NSString* targetLanguage = 165 NSString* targetLanguage =
166 base::SysUTF16ToNSString(translateInfoBarDelegate_->language_name_at( 166 base::SysUTF16ToNSString(_translateInfoBarDelegate->language_name_at(
167 translateInfoBarDelegate_->target_language_index())); 167 _translateInfoBarDelegate->target_language_index()));
168 base::string16 originalLanguageWithLink = 168 base::string16 originalLanguageWithLink =
169 base::SysNSStringToUTF16([[infoBarView_ class] 169 base::SysNSStringToUTF16([[infoBarView_ class]
170 stringAsLink:originalLanguage 170 stringAsLink:originalLanguage
171 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); 171 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]);
172 base::string16 targetLanguageWithLink = 172 base::string16 targetLanguageWithLink =
173 base::SysNSStringToUTF16([[infoBarView_ class] 173 base::SysNSStringToUTF16([[infoBarView_ class]
174 stringAsLink:targetLanguage 174 stringAsLink:targetLanguage
175 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]); 175 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]);
176 NSString* label = 176 NSString* label =
177 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, 177 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS,
178 originalLanguageWithLink, targetLanguageWithLink); 178 originalLanguageWithLink, targetLanguageWithLink);
179 [infoBarView_ addLabel:label 179 [infoBarView_ addLabel:label
180 target:self 180 target:self
181 action:@selector(infobarLinkDidPress:)]; 181 action:@selector(infobarLinkDidPress:)];
182 } 182 }
183 183
184 - (void)languageSelectionDone { 184 - (void)languageSelectionDone {
185 size_t selectedRow = [languagePicker_ selectedRowInComponent:0]; 185 size_t selectedRow = [_languagePicker selectedRowInComponent:0];
186 if (languageSelectionType_ == 186 if (_languageSelectionType ==
187 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE && 187 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE &&
188 selectedRow != translateInfoBarDelegate_->target_language_index()) { 188 selectedRow != _translateInfoBarDelegate->target_language_index()) {
189 translateInfoBarDelegate_->UpdateOriginalLanguageIndex(selectedRow); 189 _translateInfoBarDelegate->UpdateOriginalLanguageIndex(selectedRow);
190 } 190 }
191 if (languageSelectionType_ == 191 if (_languageSelectionType ==
192 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE && 192 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE &&
193 selectedRow != translateInfoBarDelegate_->original_language_index()) { 193 selectedRow != _translateInfoBarDelegate->original_language_index()) {
194 translateInfoBarDelegate_->UpdateTargetLanguageIndex(selectedRow); 194 _translateInfoBarDelegate->UpdateTargetLanguageIndex(selectedRow);
195 } 195 }
196 [self updateInfobarLabel]; 196 [self updateInfobarLabel];
197 [self dismissLanguageSelectionView]; 197 [self dismissLanguageSelectionView];
198 } 198 }
199 199
200 - (void)dismissLanguageSelectionView { 200 - (void)dismissLanguageSelectionView {
201 DCHECK_EQ(languagePicker_ == nil, navigationBar_ == nil); 201 DCHECK_EQ(_languagePicker == nil, _navigationBar == nil);
202 if (languagePicker_ == nil) 202 if (_languagePicker == nil)
203 return; 203 return;
204 // Sets the picker's delegate and data source to nil, because the 204 // Sets the picker's delegate and data source to nil, because the
205 // |languagePickerController_| may be destroyed before the picker is hidden, 205 // |_languagePickerController| may be destroyed before the picker is hidden,
206 // and even though the interactions with the picker are disabled, it might 206 // and even though the interactions with the picker are disabled, it might
207 // still be turning and requesting data from the data source or calling the 207 // still be turning and requesting data from the data source or calling the
208 // delegate. 208 // delegate.
209 [languagePicker_ setDataSource:nil]; 209 [_languagePicker setDataSource:nil];
210 [languagePicker_ setDelegate:nil]; 210 [_languagePicker setDelegate:nil];
211 languagePickerController_.reset(); 211 _languagePickerController.reset();
212 // Animate the picker away. 212 // Animate the picker away.
213 CGRect languagePickerFrame = [languagePicker_ frame]; 213 CGRect languagePickerFrame = [_languagePicker frame];
214 CGRect navigationBarFrame = [navigationBar_ frame]; 214 CGRect navigationBarFrame = [_navigationBar frame];
215 const CGFloat animationHeight = 215 const CGFloat animationHeight =
216 languagePickerFrame.size.height + navigationBarFrame.size.height; 216 languagePickerFrame.size.height + navigationBarFrame.size.height;
217 languagePickerFrame.origin.y += animationHeight; 217 languagePickerFrame.origin.y += animationHeight;
218 navigationBarFrame.origin.y += animationHeight; 218 navigationBarFrame.origin.y += animationHeight;
219 UIView* blockLanguagePicker = languagePicker_.get(); 219 base::scoped_nsobject<UIView> blockLanguagePicker(_languagePicker);
220 UIView* blockNavigationBar = navigationBar_.get(); 220 base::scoped_nsobject<UIView> blockNavigationBar(_navigationBar);
221 _languagePicker.reset();
222 _navigationBar.reset();
221 void (^animations)(void) = ^{ 223 void (^animations)(void) = ^{
222 blockLanguagePicker.frame = languagePickerFrame; 224 [blockLanguagePicker setFrame:languagePickerFrame];
223 blockNavigationBar.frame = navigationBarFrame; 225 [blockNavigationBar setFrame:navigationBarFrame];
224 }; 226 };
225 languagePicker_.reset(); 227 base::scoped_nsobject<UIView> blockSelectionView(_languageSelectionView);
226 navigationBar_.reset(); 228 _languageSelectionView.reset();
227 void (^completion)(BOOL finished) = ^(BOOL finished) { 229 void (^completion)(BOOL finished) = ^(BOOL finished) {
228 [languageSelectionView_ removeFromSuperview]; 230 [blockSelectionView removeFromSuperview];
229 languageSelectionView_.reset();
230 }; 231 };
231 [UIView animateWithDuration:kPickerAnimationDurationInSeconds 232 [UIView animateWithDuration:kPickerAnimationDurationInSeconds
232 animations:animations 233 animations:animations
233 completion:completion]; 234 completion:completion];
234 } 235 }
235 236
236 #pragma mark - Handling of User Events 237 #pragma mark - Handling of User Events
237 238
238 - (void)infoBarButtonDidPress:(id)sender { 239 - (void)infoBarButtonDidPress:(id)sender {
239 // This press might have occurred after the user has already pressed a button, 240 // This press might have occurred after the user has already pressed a button,
240 // in which case the view has been detached from the delegate and this press 241 // in which case the view has been detached from the delegate and this press
241 // should be ignored. 242 // should be ignored.
242 if (!delegate_) { 243 if (!delegate_) {
243 return; 244 return;
244 } 245 }
245 if ([sender isKindOfClass:[UIButton class]]) { 246 if ([sender isKindOfClass:[UIButton class]]) {
246 NSUInteger buttonId = static_cast<UIButton*>(sender).tag; 247 NSUInteger buttonId = static_cast<UIButton*>(sender).tag;
247 DCHECK(buttonId == TranslateInfoBarIOSTag::BEFORE_ACCEPT || 248 DCHECK(buttonId == TranslateInfoBarIOSTag::BEFORE_ACCEPT ||
248 buttonId == TranslateInfoBarIOSTag::BEFORE_DENY); 249 buttonId == TranslateInfoBarIOSTag::BEFORE_DENY);
249 delegate_->InfoBarButtonDidPress(buttonId); 250 delegate_->InfoBarButtonDidPress(buttonId);
250 } 251 }
251 } 252 }
252 253
253 - (void)infobarLinkDidPress:(NSNumber*)tag { 254 - (void)infobarLinkDidPress:(NSNumber*)tag {
254 DCHECK([tag isKindOfClass:[NSNumber class]]); 255 DCHECK([tag isKindOfClass:[NSNumber class]]);
255 languageSelectionType_ = [tag unsignedIntegerValue]; 256 _languageSelectionType = [tag unsignedIntegerValue];
256 DCHECK(languageSelectionType_ == 257 DCHECK(_languageSelectionType ==
257 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE || 258 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE ||
258 languageSelectionType_ == 259 _languageSelectionType ==
259 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE); 260 TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE);
260 if (languagePicker_ != nil) 261 if (_languagePicker != nil)
261 return; // The UIPickerView is already up. 262 return; // The UIPickerView is already up.
262 263
263 // Creates and adds the view containing the UIPickerView and the 264 // Creates and adds the view containing the UIPickerView and the
264 // UINavigationBar. 265 // UINavigationBar.
265 UIView* parentView = 266 UIView* parentView =
266 [[UIApplication sharedApplication] keyWindow].rootViewController.view; 267 [[UIApplication sharedApplication] keyWindow].rootViewController.view;
267 // Convert the parent frame to handle device rotation. 268 // Convert the parent frame to handle device rotation.
268 CGRect parentFrame = 269 CGRect parentFrame =
269 CGRectApplyAffineTransform([parentView frame], [parentView transform]); 270 CGRectApplyAffineTransform([parentView frame], [parentView transform]);
270 const CGFloat totalPickerHeight = kUIPickerHeight + kNavigationBarHeight; 271 const CGFloat totalPickerHeight = kUIPickerHeight + kNavigationBarHeight;
271 CGRect languageSelectionViewFrame = 272 CGRect languageSelectionViewFrame =
272 CGRectMake(0, parentFrame.size.height - totalPickerHeight, 273 CGRectMake(0, parentFrame.size.height - totalPickerHeight,
273 parentFrame.size.width, totalPickerHeight); 274 parentFrame.size.width, totalPickerHeight);
274 languageSelectionView_.reset( 275 _languageSelectionView.reset(
275 [[UIView alloc] initWithFrame:languageSelectionViewFrame]); 276 [[UIView alloc] initWithFrame:languageSelectionViewFrame]);
276 [languageSelectionView_ 277 [_languageSelectionView
277 setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 278 setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
278 UIViewAutoresizingFlexibleTopMargin]; 279 UIViewAutoresizingFlexibleTopMargin];
279 [parentView addSubview:languageSelectionView_]; 280 [parentView addSubview:_languageSelectionView];
280 281
281 // Creates the navigation bar and its buttons. 282 // Creates the navigation bar and its buttons.
282 CGRect finalPickerFrame = CGRectMake( 283 CGRect finalPickerFrame = CGRectMake(
283 0, [languageSelectionView_ frame].size.height - kUIPickerHeight, 284 0, [_languageSelectionView frame].size.height - kUIPickerHeight,
284 [languageSelectionView_ frame].size.width, kUIPickerHeight); 285 [_languageSelectionView frame].size.width, kUIPickerHeight);
285 CGRect finalNavigationBarFrame = CGRectMake( 286 CGRect finalNavigationBarFrame = CGRectMake(
286 0, 0, [languageSelectionView_ frame].size.width, kNavigationBarHeight); 287 0, 0, [_languageSelectionView frame].size.width, kNavigationBarHeight);
287 // The language picker animates from the bottom of the screen. 288 // The language picker animates from the bottom of the screen.
288 CGRect initialPickerFrame = finalPickerFrame; 289 CGRect initialPickerFrame = finalPickerFrame;
289 initialPickerFrame.origin.y += totalPickerHeight; 290 initialPickerFrame.origin.y += totalPickerHeight;
290 CGRect initialNavigationBarFrame = finalNavigationBarFrame; 291 CGRect initialNavigationBarFrame = finalNavigationBarFrame;
291 initialNavigationBarFrame.origin.y += totalPickerHeight; 292 initialNavigationBarFrame.origin.y += totalPickerHeight;
292 293
293 navigationBar_.reset( 294 _navigationBar.reset(
294 [[UINavigationBar alloc] initWithFrame:initialNavigationBarFrame]); 295 [[UINavigationBar alloc] initWithFrame:initialNavigationBarFrame]);
295 const UIViewAutoresizing resizingMask = 296 const UIViewAutoresizing resizingMask =
296 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 297 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
297 [navigationBar_ setAutoresizingMask:resizingMask]; 298 [_navigationBar setAutoresizingMask:resizingMask];
298 base::scoped_nsobject<UIBarButtonItem> doneButton([[UIBarButtonItem alloc] 299 base::scoped_nsobject<UIBarButtonItem> doneButton([[UIBarButtonItem alloc]
299 initWithBarButtonSystemItem:UIBarButtonSystemItemDone 300 initWithBarButtonSystemItem:UIBarButtonSystemItemDone
300 target:self 301 target:self
301 action:@selector(languageSelectionDone)]); 302 action:@selector(languageSelectionDone)]);
302 base::scoped_nsobject<UIBarButtonItem> cancelButton([[UIBarButtonItem alloc] 303 base::scoped_nsobject<UIBarButtonItem> cancelButton([[UIBarButtonItem alloc]
303 initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 304 initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
304 target:self 305 target:self
305 action:@selector(dismissLanguageSelectionView)]); 306 action:@selector(dismissLanguageSelectionView)]);
306 base::scoped_nsobject<UINavigationItem> item( 307 base::scoped_nsobject<UINavigationItem> item(
307 [[UINavigationItem alloc] initWithTitle:nil]); 308 [[UINavigationItem alloc] initWithTitle:nil]);
308 [item setRightBarButtonItem:doneButton]; 309 [item setRightBarButtonItem:doneButton];
309 [item setLeftBarButtonItem:cancelButton]; 310 [item setLeftBarButtonItem:cancelButton];
310 [item setHidesBackButton:YES]; 311 [item setHidesBackButton:YES];
311 [navigationBar_ pushNavigationItem:item animated:NO]; 312 [_navigationBar pushNavigationItem:item animated:NO];
312 313
313 // Creates the PickerView and its controller. 314 // Creates the PickerView and its controller.
314 NSInteger selectedRow; 315 NSInteger selectedRow;
315 NSInteger disabledRow; 316 NSInteger disabledRow;
316 if (languageSelectionType_ == 317 if (_languageSelectionType ==
317 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE) { 318 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE) {
318 selectedRow = translateInfoBarDelegate_->original_language_index(); 319 selectedRow = _translateInfoBarDelegate->original_language_index();
319 disabledRow = translateInfoBarDelegate_->target_language_index(); 320 disabledRow = _translateInfoBarDelegate->target_language_index();
320 } else { 321 } else {
321 selectedRow = translateInfoBarDelegate_->target_language_index(); 322 selectedRow = _translateInfoBarDelegate->target_language_index();
322 disabledRow = translateInfoBarDelegate_->original_language_index(); 323 disabledRow = _translateInfoBarDelegate->original_language_index();
323 } 324 }
324 languagePickerController_.reset([[LanguagePickerController alloc] 325 _languagePickerController.reset([[LanguagePickerController alloc]
325 initWithDelegate:translateInfoBarDelegate_ 326 initWithDelegate:_translateInfoBarDelegate
326 initialRow:selectedRow 327 initialRow:selectedRow
327 disabledRow:disabledRow]); 328 disabledRow:disabledRow]);
328 languagePicker_.reset( 329 _languagePicker.reset(
329 [[UIPickerView alloc] initWithFrame:initialPickerFrame]); 330 [[UIPickerView alloc] initWithFrame:initialPickerFrame]);
330 [languagePicker_ setAutoresizingMask:resizingMask]; 331 [_languagePicker setAutoresizingMask:resizingMask];
331 [languagePicker_ setShowsSelectionIndicator:YES]; 332 [_languagePicker setShowsSelectionIndicator:YES];
332 [languagePicker_ setDataSource:languagePickerController_]; 333 [_languagePicker setDataSource:_languagePickerController];
333 [languagePicker_ setDelegate:languagePickerController_]; 334 [_languagePicker setDelegate:_languagePickerController];
334 [languagePicker_ setShowsSelectionIndicator:YES]; 335 [_languagePicker setShowsSelectionIndicator:YES];
335 [languagePicker_ setBackgroundColor:[infoBarView_ backgroundColor]]; 336 [_languagePicker setBackgroundColor:[infoBarView_ backgroundColor]];
336 [languagePicker_ selectRow:selectedRow inComponent:0 animated:NO]; 337 [_languagePicker selectRow:selectedRow inComponent:0 animated:NO];
337 338
338 [UIView animateWithDuration:kPickerAnimationDurationInSeconds 339 [UIView animateWithDuration:kPickerAnimationDurationInSeconds
sdefresne 2015/01/09 13:47:57 nit: can you also change this block not to capture
339 animations:^{ 340 animations:^{
340 languagePicker_.get().frame = finalPickerFrame; 341 _languagePicker.get().frame = finalPickerFrame;
341 navigationBar_.get().frame = finalNavigationBarFrame; 342 _navigationBar.get().frame = finalNavigationBarFrame;
342 }]; 343 }];
343 344
344 // Add the subviews. 345 // Add the subviews.
345 [languageSelectionView_ addSubview:languagePicker_]; 346 [_languageSelectionView addSubview:_languagePicker];
346 [languageSelectionView_ addSubview:navigationBar_]; 347 [_languageSelectionView addSubview:_navigationBar];
347 } 348 }
348 349
349 - (void)removeView { 350 - (void)removeView {
350 [super removeView]; 351 [super removeView];
351 [self dismissLanguageSelectionView]; 352 [self dismissLanguageSelectionView];
352 } 353 }
353 354
354 - (void)detachView { 355 - (void)detachView {
355 [super detachView]; 356 [super detachView];
356 [self dismissLanguageSelectionView]; 357 [self dismissLanguageSelectionView];
357 } 358 }
358 359
359 @end 360 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698