Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/root/root_container_view_controller.mm |
| diff --git a/ios/clean/chrome/browser/ui/root/root_container_view_controller.mm b/ios/clean/chrome/browser/ui/root/root_container_view_controller.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9e17588b3015ef7a582a97868c44d9bc95cf43f3 |
| --- /dev/null |
| +++ b/ios/clean/chrome/browser/ui/root/root_container_view_controller.mm |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/clean/chrome/browser/ui/root/root_container_view_controller.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@implementation RootContainerViewController |
| +@synthesize contentViewController = _contentViewController; |
| + |
| +#pragma mark - UIViewController |
| + |
| +- (void)viewDidLoad { |
| + [super viewDidLoad]; |
| + self.view.backgroundColor = [UIColor blackColor]; |
| + [self attachChildViewController:self.contentViewController]; |
| +} |
| + |
| +#pragma mark - Public properties |
| + |
| +- (void)setContentViewController:(UIViewController*)contentViewController { |
| + if (self.contentViewController == contentViewController) |
| + return; |
| + if ([self isViewLoaded]) { |
| + [self detachChildViewController:self.contentViewController]; |
| + [self attachChildViewController:contentViewController]; |
| + } |
| + _contentViewController = contentViewController; |
| +} |
| + |
| +#pragma mark - ChildViewController helper methods |
| + |
| +- (void)attachChildViewController:(UIViewController*)viewController { |
| + if (!viewController) { |
| + return; |
| + } |
| + [self addChildViewController:viewController]; |
| + viewController.view.autoresizingMask = |
| + UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| + viewController.view.frame = self.view.bounds; |
| + [self.view addSubview:viewController.view]; |
| + [viewController didMoveToParentViewController:self]; |
| +} |
| + |
| +- (void)detachChildViewController:(UIViewController*)viewController { |
| + if (viewController.parentViewController != self) |
|
lpromero
2017/04/11 15:20:39
Should this be a DCHECK?
edchin
2017/04/11 15:52:05
Yes, good suggestion. Will do.
edchin
2017/04/12 08:10:52
Done.
|
| + return; |
| + [viewController willMoveToParentViewController:nil]; |
| + [viewController.view removeFromSuperview]; |
| + [viewController removeFromParentViewController]; |
| +} |
| + |
| +#pragma mark - ZoomTransitionDelegate |
| + |
| +- (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { |
| + if ([self.contentViewController |
| + conformsToProtocol:@protocol(ZoomTransitionDelegate)]) { |
| + return [static_cast<id<ZoomTransitionDelegate>>(self.contentViewController) |
|
lpromero
2017/04/11 15:20:39
Could you add a unit tests file for all new files?
edchin
2017/04/11 15:52:05
Will do.
edchin
2017/04/12 08:10:52
Done.
|
| + rectForZoomWithKey:key |
| + inView:view]; |
| + } |
| + return CGRectNull; |
| +} |
| + |
| +@end |