Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // ====== New Architecture ===== | 5 // ====== New Architecture ===== |
| 6 // = This code is only used in the new iOS Chrome architecture. = | 6 // = This code is only used in the new iOS Chrome architecture. = |
| 7 // ============================================================================ | 7 // ============================================================================ |
| 8 | 8 |
| 9 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" | 9 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 @property(nonatomic, strong) Constraints* contentConstraintsWithToolbar; | 28 @property(nonatomic, strong) Constraints* contentConstraintsWithToolbar; |
| 29 @property(nonatomic, strong) Constraints* contentConstraintsWithoutToolbar; | 29 @property(nonatomic, strong) Constraints* contentConstraintsWithoutToolbar; |
| 30 @property(nonatomic, strong) Constraints* toolbarConstraints; | 30 @property(nonatomic, strong) Constraints* toolbarConstraints; |
| 31 | 31 |
| 32 // Cache for forwarding methods to child view controllers. | 32 // Cache for forwarding methods to child view controllers. |
| 33 @property(nonatomic, assign) SEL actionToForward; | 33 @property(nonatomic, assign) SEL actionToForward; |
| 34 @property(nonatomic, weak) UIResponder* forwardingTarget; | 34 @property(nonatomic, weak) UIResponder* forwardingTarget; |
| 35 | 35 |
| 36 // Contained view controller utility methods. | 36 // Contained view controller utility methods. |
| 37 - (void)removeChildViewController:(UIViewController*)viewController; | 37 - (void)removeChildViewControllerFromParent:(UIViewController*)viewController; |
|
edchin
2017/02/21 23:28:16
This looks like the parameter is the parent, not t
edchin
2017/02/22 00:34:46
I suggest namespacing with a prefix. -(void)cr_rem
marq (ping after 24h)
2017/02/22 09:13:44
I agree. How about -detachChildViewController: ?,
justincohen
2017/02/22 12:48:35
Done.
| |
| 38 | 38 |
| 39 // Called after a new content view controller is set, but before | 39 // Called after a new content view controller is set, but before |
| 40 // |-didMoveToParentViewController:| is called on that view controller. | 40 // |-didMoveToParentViewController:| is called on that view controller. |
| 41 - (void)didAddContentViewController; | 41 - (void)didAddContentViewController; |
| 42 | 42 |
| 43 // Called after a new toolbar view controller is set, but before | 43 // Called after a new toolbar view controller is set, but before |
| 44 // |-didMoveToParentViewController:| is called on that view controller. | 44 // |-didMoveToParentViewController:| is called on that view controller. |
| 45 - (void)didAddToolbarViewController; | 45 - (void)didAddToolbarViewController; |
| 46 | 46 |
| 47 // Methods to populate the constraint properties. | 47 // Methods to populate the constraint properties. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 66 #pragma mark - Public properties | 66 #pragma mark - Public properties |
| 67 | 67 |
| 68 - (void)setContentViewController:(UIViewController*)contentViewController { | 68 - (void)setContentViewController:(UIViewController*)contentViewController { |
| 69 if (self.contentViewController == contentViewController) | 69 if (self.contentViewController == contentViewController) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 // Remove the current content view controller, if any. | 72 // Remove the current content view controller, if any. |
| 73 [NSLayoutConstraint | 73 [NSLayoutConstraint |
| 74 deactivateConstraints:self.contentConstraintsWithoutToolbar]; | 74 deactivateConstraints:self.contentConstraintsWithoutToolbar]; |
| 75 [NSLayoutConstraint deactivateConstraints:self.contentConstraintsWithToolbar]; | 75 [NSLayoutConstraint deactivateConstraints:self.contentConstraintsWithToolbar]; |
| 76 [self removeChildViewController:self.contentViewController]; | 76 [self removeChildViewControllerFromParent:self.contentViewController]; |
| 77 | 77 |
| 78 // Add the new content view controller. | 78 // Add the new content view controller. |
| 79 [self addChildViewController:contentViewController]; | 79 [self addChildViewController:contentViewController]; |
| 80 contentViewController.view.translatesAutoresizingMaskIntoConstraints = NO; | 80 contentViewController.view.translatesAutoresizingMaskIntoConstraints = NO; |
| 81 [self.view addSubview:contentViewController.view]; | 81 [self.view addSubview:contentViewController.view]; |
| 82 _contentViewController = contentViewController; | 82 _contentViewController = contentViewController; |
| 83 [self didAddContentViewController]; | 83 [self didAddContentViewController]; |
| 84 [self.view setNeedsUpdateConstraints]; | 84 [self.view setNeedsUpdateConstraints]; |
| 85 [self.contentViewController didMoveToParentViewController:self]; | 85 [self.contentViewController didMoveToParentViewController:self]; |
| 86 } | 86 } |
| 87 | 87 |
| 88 - (void)setToolbarViewController:(UIViewController*)toolbarViewController { | 88 - (void)setToolbarViewController:(UIViewController*)toolbarViewController { |
| 89 if (self.toolbarViewController == toolbarViewController) | 89 if (self.toolbarViewController == toolbarViewController) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 // Remove the current toolbar view controller, if any. | 92 // Remove the current toolbar view controller, if any. |
| 93 [NSLayoutConstraint deactivateConstraints:self.toolbarConstraints]; | 93 [NSLayoutConstraint deactivateConstraints:self.toolbarConstraints]; |
| 94 [NSLayoutConstraint deactivateConstraints:self.contentConstraintsWithToolbar]; | 94 [NSLayoutConstraint deactivateConstraints:self.contentConstraintsWithToolbar]; |
| 95 [self removeChildViewController:self.toolbarViewController]; | 95 [self removeChildViewControllerFromParent:self.toolbarViewController]; |
| 96 | 96 |
| 97 // Add the new toolbar view controller. | 97 // Add the new toolbar view controller. |
| 98 [self addChildViewController:toolbarViewController]; | 98 [self addChildViewController:toolbarViewController]; |
| 99 toolbarViewController.view.translatesAutoresizingMaskIntoConstraints = NO; | 99 toolbarViewController.view.translatesAutoresizingMaskIntoConstraints = NO; |
| 100 [self.view addSubview:toolbarViewController.view]; | 100 [self.view addSubview:toolbarViewController.view]; |
| 101 _toolbarViewController = toolbarViewController; | 101 _toolbarViewController = toolbarViewController; |
| 102 [self didAddToolbarViewController]; | 102 [self didAddToolbarViewController]; |
| 103 [self.view setNeedsUpdateConstraints]; | 103 [self.view setNeedsUpdateConstraints]; |
| 104 [self.toolbarViewController didMoveToParentViewController:self]; | 104 [self.toolbarViewController didMoveToParentViewController:self]; |
| 105 } | 105 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 | 194 |
| 195 - (id)forwardingTargetForSelector:(SEL)aSelector { | 195 - (id)forwardingTargetForSelector:(SEL)aSelector { |
| 196 if (aSelector == self.actionToForward) { | 196 if (aSelector == self.actionToForward) { |
| 197 return self.forwardingTarget; | 197 return self.forwardingTarget; |
| 198 } | 198 } |
| 199 return nil; | 199 return nil; |
| 200 } | 200 } |
| 201 | 201 |
| 202 #pragma mark - Private methods | 202 #pragma mark - Private methods |
| 203 | 203 |
| 204 - (void)removeChildViewController:(UIViewController*)viewController { | 204 - (void)removeChildViewControllerFromParent:(UIViewController*)viewController { |
| 205 if (viewController.parentViewController != self) | 205 if (viewController.parentViewController != self) |
| 206 return; | 206 return; |
| 207 [viewController willMoveToParentViewController:nil]; | 207 [viewController willMoveToParentViewController:nil]; |
| 208 [viewController.view removeFromSuperview]; | 208 [viewController.view removeFromSuperview]; |
| 209 [viewController removeFromParentViewController]; | 209 [viewController removeFromParentViewController]; |
| 210 } | 210 } |
| 211 | 211 |
| 212 - (void)didAddContentViewController { | 212 - (void)didAddContentViewController { |
| 213 if (self.toolbarViewController) { | 213 if (self.toolbarViewController) { |
| 214 [self updateContentConstraintsWithToolbar]; | 214 [self updateContentConstraintsWithToolbar]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 self.toolbarConstraints = @[ | 321 self.toolbarConstraints = @[ |
| 322 [toolbarView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], | 322 [toolbarView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], |
| 323 [toolbarView.heightAnchor constraintEqualToConstant:kToolbarHeight], | 323 [toolbarView.heightAnchor constraintEqualToConstant:kToolbarHeight], |
| 324 [toolbarView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], | 324 [toolbarView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], |
| 325 [toolbarView.trailingAnchor | 325 [toolbarView.trailingAnchor |
| 326 constraintEqualToAnchor:self.view.trailingAnchor], | 326 constraintEqualToAnchor:self.view.trailingAnchor], |
| 327 ]; | 327 ]; |
| 328 } | 328 } |
| 329 | 329 |
| 330 @end | 330 @end |
| OLD | NEW |