OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/clean/chrome/browser/ui/root/root_container_view_controller.h" | |
6 | |
7 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
8 #error "This file requires ARC support." | |
9 #endif | |
10 | |
11 @implementation RootContainerViewController | |
12 @synthesize contentViewController = _contentViewController; | |
13 | |
14 #pragma mark - UIViewController | |
15 | |
16 - (void)viewDidLoad { | |
17 [super viewDidLoad]; | |
18 self.view.backgroundColor = [UIColor blackColor]; | |
19 [self attachChildViewController:self.contentViewController]; | |
20 } | |
21 | |
22 #pragma mark - Public properties | |
23 | |
24 - (void)setContentViewController:(UIViewController*)contentViewController { | |
25 if (self.contentViewController == contentViewController) | |
26 return; | |
27 if ([self isViewLoaded]) { | |
28 [self detachChildViewController:self.contentViewController]; | |
29 [self attachChildViewController:contentViewController]; | |
30 } | |
31 _contentViewController = contentViewController; | |
32 } | |
33 | |
34 #pragma mark - ChildViewController helper methods | |
35 | |
36 - (void)attachChildViewController:(UIViewController*)viewController { | |
37 if (!viewController) { | |
38 return; | |
39 } | |
40 [self addChildViewController:viewController]; | |
41 viewController.view.autoresizingMask = | |
42 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
43 viewController.view.frame = self.view.bounds; | |
44 [self.view addSubview:viewController.view]; | |
45 [viewController didMoveToParentViewController:self]; | |
46 } | |
47 | |
48 - (void)detachChildViewController:(UIViewController*)viewController { | |
49 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.
| |
50 return; | |
51 [viewController willMoveToParentViewController:nil]; | |
52 [viewController.view removeFromSuperview]; | |
53 [viewController removeFromParentViewController]; | |
54 } | |
55 | |
56 #pragma mark - ZoomTransitionDelegate | |
57 | |
58 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | |
59 if ([self.contentViewController | |
60 conformsToProtocol:@protocol(ZoomTransitionDelegate)]) { | |
61 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.
| |
62 rectForZoomWithKey:key | |
63 inView:view]; | |
64 } | |
65 return CGRectNull; | |
66 } | |
67 | |
68 @end | |
OLD | NEW |