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

Side by Side Diff: ios/chrome/browser/ui/settings/settings_navigation_controller.mm

Issue 2589193002: Revert to the old back arrow style with NavigationBar (Closed)
Patch Set: Created 4 years 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 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 5 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
6 6
7 #include "base/ios/ios_util.h" 7 #include "base/ios/ios_util.h"
8 #import "base/ios/weak_nsobject.h" 8 #import "base/ios/weak_nsobject.h"
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 @end 71 @end
72 72
73 @interface SettingsNavigationController ()<UIGestureRecognizerDelegate> 73 @interface SettingsNavigationController ()<UIGestureRecognizerDelegate>
74 74
75 // Sets up the UI. Used by both initializers. 75 // Sets up the UI. Used by both initializers.
76 - (void)configureUI; 76 - (void)configureUI;
77 77
78 // Closes the settings by calling |closeSettings| on |delegate|. 78 // Closes the settings by calling |closeSettings| on |delegate|.
79 - (void)closeSettings; 79 - (void)closeSettings;
80 80
81 // Creates an autoreleased Back button for a UINavigationItem which will pop the
82 // top view controller when it is pressed. Should only be called by view
83 // controllers owned by SettingsNavigationController.
84 - (UIBarButtonItem*)backButton;
85
81 // Creates an autoreleased "X" button that closes the settings when tapped. 86 // Creates an autoreleased "X" button that closes the settings when tapped.
82 - (UIBarButtonItem*)closeButton; 87 - (UIBarButtonItem*)closeButton;
83 88
84 // Creates an autoreleased "CANCEL" button that closes the settings when tapped. 89 // Creates an autoreleased "CANCEL" button that closes the settings when tapped.
85 - (UIBarButtonItem*)cancelButton; 90 - (UIBarButtonItem*)cancelButton;
86 91
87 // Intercepts the chrome command |sender|. If |sender| is an 92 // Intercepts the chrome command |sender|. If |sender| is an
88 // |IDC_CLOSE_SETTINGS_AND_OPEN_URL| and |delegate_| is not nil, then it 93 // |IDC_CLOSE_SETTINGS_AND_OPEN_URL| and |delegate_| is not nil, then it
89 // calls [delegate closeSettingsAndOpenUrl:sender], otherwise it forwards the 94 // calls [delegate closeSettingsAndOpenUrl:sender], otherwise it forwards the
90 // command up the responder chain. 95 // command up the responder chain.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 317
313 // Reset the delegate to prevent any queued transitions from attempting to 318 // Reset the delegate to prevent any queued transitions from attempting to
314 // close the settings. 319 // close the settings.
315 delegate_.reset(); 320 delegate_.reset();
316 } 321 }
317 322
318 - (void)closeSettings { 323 - (void)closeSettings {
319 [delegate_ closeSettings]; 324 [delegate_ closeSettings];
320 } 325 }
321 326
327 - (void)back {
328 [self popViewControllerAnimated:YES];
329 }
330
322 - (void)popViewControllerOrCloseSettingsAnimated:(BOOL)animated { 331 - (void)popViewControllerOrCloseSettingsAnimated:(BOOL)animated {
323 if (self.viewControllers.count > 1) { 332 if (self.viewControllers.count > 1) {
324 // Pop the top view controller to reveal the view controller underneath. 333 // Pop the top view controller to reveal the view controller underneath.
325 [self popViewControllerAnimated:animated]; 334 [self popViewControllerAnimated:animated];
326 } else { 335 } else {
327 // If there is only one view controller in the navigation stack, 336 // If there is only one view controller in the navigation stack,
328 // simply close settings. 337 // simply close settings.
329 [self closeSettings]; 338 [self closeSettings];
330 } 339 }
331 } 340 }
(...skipping 12 matching lines...) Expand all
344 - (BOOL)hasRightDoneButton { 353 - (BOOL)hasRightDoneButton {
345 UIBarButtonItem* rightButton = 354 UIBarButtonItem* rightButton =
346 self.topViewController.navigationItem.rightBarButtonItem; 355 self.topViewController.navigationItem.rightBarButtonItem;
347 if (!rightButton) 356 if (!rightButton)
348 return NO; 357 return NO;
349 base::scoped_nsobject<UIBarButtonItem> doneButton([self doneButton]); 358 base::scoped_nsobject<UIBarButtonItem> doneButton([self doneButton]);
350 return [rightButton style] == [doneButton style] && 359 return [rightButton style] == [doneButton style] &&
351 [[rightButton title] compare:[doneButton title]] == NSOrderedSame; 360 [[rightButton title] compare:[doneButton title]] == NSOrderedSame;
352 } 361 }
353 362
363 - (UIBarButtonItem*)backButton {
364 // Create a custom Back bar button item, as Material Navigation Bar deprecated
365 // the back arrow with a shaft.
366 return [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon]
367 target:self
368 action:@selector(back)];
369 }
370
354 - (UIBarButtonItem*)doneButton { 371 - (UIBarButtonItem*)doneButton {
355 // Create a custom Done bar button item, as Material Navigation Bar does not 372 // Create a custom Done bar button item, as Material Navigation Bar does not
356 // handle a system UIBarButtonSystemItemDone item. 373 // handle a system UIBarButtonSystemItemDone item.
357 return [[[UIBarButtonItem alloc] 374 return [[[UIBarButtonItem alloc]
358 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) 375 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)
359 style:UIBarButtonItemStyleDone 376 style:UIBarButtonItemStyleDone
360 target:self 377 target:self
361 action:@selector(closeSettings)] autorelease]; 378 action:@selector(closeSettings)] autorelease];
362 } 379 }
363 380
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 UIViewController* poppedController = [self popViewControllerAnimated:YES]; 418 UIViewController* poppedController = [self popViewControllerAnimated:YES];
402 if (!poppedController) 419 if (!poppedController)
403 [self closeSettings]; 420 [self closeSettings];
404 return YES; 421 return YES;
405 } 422 }
406 423
407 #pragma mark - UINavigationController 424 #pragma mark - UINavigationController
408 425
409 - (void)pushViewController:(UIViewController*)viewController 426 - (void)pushViewController:(UIViewController*)viewController
410 animated:(BOOL)animated { 427 animated:(BOOL)animated {
428 // Add a back button if the view controller is not the root view controller
429 // and doesn’t already have a left bar button item.
430 if (self.viewControllers.count > 0 &&
431 viewController.navigationItem.leftBarButtonItems.count == 0) {
432 viewController.navigationItem.leftBarButtonItem = [self backButton];
433 }
411 // Wrap the view controller in an MDCAppBarContainerViewController if needed. 434 // Wrap the view controller in an MDCAppBarContainerViewController if needed.
412 [super pushViewController:[self wrappedControllerIfNeeded:viewController] 435 [super pushViewController:[self wrappedControllerIfNeeded:viewController]
413 animated:animated]; 436 animated:animated];
414 } 437 }
415 438
416 - (UIViewController*)popViewControllerAnimated:(BOOL)animated { 439 - (UIViewController*)popViewControllerAnimated:(BOOL)animated {
417 UIViewController* viewController = [super popViewControllerAnimated:animated]; 440 UIViewController* viewController = [super popViewControllerAnimated:animated];
418 // Unwrap the view controller from its MDCAppBarContainerViewController if 441 // Unwrap the view controller from its MDCAppBarContainerViewController if
419 // needed. 442 // needed.
420 return [self unwrappedControllerIfNeeded:viewController]; 443 return [self unwrappedControllerIfNeeded:viewController];
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 NSValue* key = [self keyForController:controller]; 650 NSValue* key = [self keyForController:controller];
628 return [appBarContainedViewControllers_ objectForKey:key]; 651 return [appBarContainedViewControllers_ objectForKey:key];
629 } 652 }
630 653
631 // Returns the dictionary key to use when dealing with |controller|. 654 // Returns the dictionary key to use when dealing with |controller|.
632 - (NSValue*)keyForController:(UIViewController*)controller { 655 - (NSValue*)keyForController:(UIViewController*)controller {
633 return [NSValue valueWithPointer:controller]; 656 return [NSValue valueWithPointer:controller];
634 } 657 }
635 658
636 @end 659 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/settings/settings_egtest.mm ('k') | ios/chrome/browser/ui/settings/translate_ui_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698