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

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

Issue 793463004: Fix crash when using the language picker on iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::scoped_nsobject<UIView> blockLanguagePicker(_languagePicker); 219 auto blockLanguagePicker(_languagePicker);
220 base::scoped_nsobject<UIView> blockNavigationBar(_navigationBar); 220 auto blockNavigationBar(_navigationBar);
221 _languagePicker.reset(); 221 _languagePicker.reset();
222 _navigationBar.reset(); 222 _navigationBar.reset();
223 void (^animations)(void) = ^{ 223 void (^animations)(void) = ^{
224 blockLanguagePicker.get().frame = languagePickerFrame; 224 blockLanguagePicker.get().frame = languagePickerFrame;
225 blockNavigationBar.get().frame = navigationBarFrame; 225 blockNavigationBar.get().frame = navigationBarFrame;
226 }; 226 };
227 base::scoped_nsobject<UIView> blockSelectionView(_languageSelectionView); 227 auto blockSelectionView(_languageSelectionView);
228 _languageSelectionView.reset(); 228 _languageSelectionView.reset();
229 void (^completion)(BOOL finished) = ^(BOOL finished) { 229 void (^completion)(BOOL finished) = ^(BOOL finished) {
230 [blockSelectionView removeFromSuperview]; 230 [blockSelectionView removeFromSuperview];
231 }; 231 };
232 [UIView animateWithDuration:kPickerAnimationDurationInSeconds 232 [UIView animateWithDuration:kPickerAnimationDurationInSeconds
233 animations:animations 233 animations:animations
234 completion:completion]; 234 completion:completion];
235 } 235 }
236 236
237 #pragma mark - Handling of User Events 237 #pragma mark - Handling of User Events
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 _languagePicker.reset( 329 _languagePicker.reset(
330 [[UIPickerView alloc] initWithFrame:initialPickerFrame]); 330 [[UIPickerView alloc] initWithFrame:initialPickerFrame]);
331 [_languagePicker setAutoresizingMask:resizingMask]; 331 [_languagePicker setAutoresizingMask:resizingMask];
332 [_languagePicker setShowsSelectionIndicator:YES]; 332 [_languagePicker setShowsSelectionIndicator:YES];
333 [_languagePicker setDataSource:_languagePickerController]; 333 [_languagePicker setDataSource:_languagePickerController];
334 [_languagePicker setDelegate:_languagePickerController]; 334 [_languagePicker setDelegate:_languagePickerController];
335 [_languagePicker setShowsSelectionIndicator:YES]; 335 [_languagePicker setShowsSelectionIndicator:YES];
336 [_languagePicker setBackgroundColor:[infoBarView_ backgroundColor]]; 336 [_languagePicker setBackgroundColor:[infoBarView_ backgroundColor]];
337 [_languagePicker selectRow:selectedRow inComponent:0 animated:NO]; 337 [_languagePicker selectRow:selectedRow inComponent:0 animated:NO];
338 338
339 base::scoped_nsobject<UIView> blockLanguagePicker(_languagePicker); 339 auto blockLanguagePicker(_languagePicker);
340 base::scoped_nsobject<UIView> blockNavigationBar(_navigationBar); 340 auto blockNavigationBar(_navigationBar);
341 [UIView animateWithDuration:kPickerAnimationDurationInSeconds 341 [UIView animateWithDuration:kPickerAnimationDurationInSeconds
342 animations:^{ 342 animations:^{
343 blockLanguagePicker.get().frame = finalPickerFrame; 343 blockLanguagePicker.get().frame = finalPickerFrame;
344 blockNavigationBar.get().frame = finalNavigationBarFrame; 344 blockNavigationBar.get().frame = finalNavigationBarFrame;
345 }]; 345 }];
346 346
347 // Add the subviews. 347 // Add the subviews.
348 [_languageSelectionView addSubview:_languagePicker]; 348 [_languageSelectionView addSubview:_languagePicker];
349 [_languageSelectionView addSubview:_navigationBar]; 349 [_languageSelectionView addSubview:_navigationBar];
350 } 350 }
351 351
352 - (void)removeView { 352 - (void)removeView {
353 [super removeView]; 353 [super removeView];
354 [self dismissLanguageSelectionView]; 354 [self dismissLanguageSelectionView];
355 } 355 }
356 356
357 - (void)detachView { 357 - (void)detachView {
358 [super detachView]; 358 [super detachView];
359 [self dismissLanguageSelectionView]; 359 [self dismissLanguageSelectionView];
360 } 360 }
361 361
362 @end 362 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698