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 |
11 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_events.h" | 11 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_events.h" |
12 #import "ios/clean/chrome/browser/ui/ui_types.h" | 12 #import "ios/clean/chrome/browser/ui/ui_types.h" |
13 | 13 |
14 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
15 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
16 #endif | 16 #endif |
17 | 17 |
18 namespace { | 18 namespace { |
19 CGFloat kToolbarHeight = 44.0f; | 19 CGFloat kToolbarHeight = 44.0f; |
20 CGFloat kTabStripHeight = 90.0f; | 20 CGFloat kTabStripHeight = 90.0f; |
21 } | 21 } |
22 | 22 |
23 @interface TabContainerViewController () | 23 @interface TabContainerViewController () |
24 | 24 |
25 // Container views for child view controllers. The child view controller's | 25 // Container views for child view controllers. The child view controller's |
26 // view is added as a subview that fills it's container view via autoresizing. | 26 // view is added as a subview that fills its container view via autoresizing. |
27 @property(nonatomic, strong) UIView* findBarView; | |
27 @property(nonatomic, strong) UIView* tabStripView; | 28 @property(nonatomic, strong) UIView* tabStripView; |
28 @property(nonatomic, strong) UIView* toolbarView; | 29 @property(nonatomic, strong) UIView* toolbarView; |
29 @property(nonatomic, strong) UIView* contentView; | 30 @property(nonatomic, strong) UIView* contentView; |
30 | 31 |
31 // Height constraints for tabStripView and toolbarView. | 32 // Height constraints for tabStripView and toolbarView. |
32 @property(nonatomic, strong) NSLayoutConstraint* tabStripHeightConstraint; | 33 @property(nonatomic, strong) NSLayoutConstraint* tabStripHeightConstraint; |
33 @property(nonatomic, strong) NSLayoutConstraint* toolbarHeightConstraint; | 34 @property(nonatomic, strong) NSLayoutConstraint* toolbarHeightConstraint; |
34 | 35 |
35 // Cache for forwarding methods to child view controllers. | 36 // Cache for forwarding methods to child view controllers. |
36 @property(nonatomic, assign) SEL actionToForward; | 37 @property(nonatomic, assign) SEL actionToForward; |
37 @property(nonatomic, weak) UIResponder* forwardingTarget; | 38 @property(nonatomic, weak) UIResponder* forwardingTarget; |
38 | 39 |
39 // Abstract base method for subclasses to implement. | 40 // Abstract base method for subclasses to implement. |
40 // Returns constraints for tabStrip, toolbar, and content subviews. | 41 // Returns constraints for tabStrip, toolbar, and content subviews. |
41 - (Constraints*)subviewConstraints; | 42 - (Constraints*)subviewConstraints; |
42 | 43 |
43 @end | 44 @end |
44 | 45 |
45 @implementation TabContainerViewController | 46 @implementation TabContainerViewController |
46 | 47 |
47 @synthesize contentViewController = _contentViewController; | 48 @synthesize contentViewController = _contentViewController; |
49 @synthesize findBarView = _findBarView; | |
50 @synthesize findBarViewController = _findBarViewController; | |
48 @synthesize toolbarViewController = _toolbarViewController; | 51 @synthesize toolbarViewController = _toolbarViewController; |
49 @synthesize tabStripViewController = _tabStripViewController; | 52 @synthesize tabStripViewController = _tabStripViewController; |
50 @synthesize tabStripView = _tabStripView; | 53 @synthesize tabStripView = _tabStripView; |
51 @synthesize toolbarView = _toolbarView; | 54 @synthesize toolbarView = _toolbarView; |
52 @synthesize contentView = _contentView; | 55 @synthesize contentView = _contentView; |
53 @synthesize tabStripHeightConstraint = _tabStripHeightConstraint; | 56 @synthesize tabStripHeightConstraint = _tabStripHeightConstraint; |
54 @synthesize toolbarHeightConstraint = _toolbarHeightConstraint; | 57 @synthesize toolbarHeightConstraint = _toolbarHeightConstraint; |
55 @synthesize actionToForward = _actionToForward; | 58 @synthesize actionToForward = _actionToForward; |
56 @synthesize forwardingTarget = _forwardingTarget; | 59 @synthesize forwardingTarget = _forwardingTarget; |
57 | 60 |
58 #pragma mark - UIViewController | 61 #pragma mark - UIViewController |
59 | 62 |
60 - (void)viewDidLoad { | 63 - (void)viewDidLoad { |
61 [super viewDidLoad]; | 64 [super viewDidLoad]; |
65 self.findBarView = [[UIView alloc] init]; | |
62 self.tabStripView = [[UIView alloc] init]; | 66 self.tabStripView = [[UIView alloc] init]; |
63 self.toolbarView = [[UIView alloc] init]; | 67 self.toolbarView = [[UIView alloc] init]; |
64 self.contentView = [[UIView alloc] init]; | 68 self.contentView = [[UIView alloc] init]; |
65 [self.view addSubview:self.tabStripView]; | 69 self.findBarView.translatesAutoresizingMaskIntoConstraints = NO; |
66 [self.view addSubview:self.toolbarView]; | |
67 [self.view addSubview:self.contentView]; | |
68 self.tabStripView.translatesAutoresizingMaskIntoConstraints = NO; | 70 self.tabStripView.translatesAutoresizingMaskIntoConstraints = NO; |
69 self.toolbarView.translatesAutoresizingMaskIntoConstraints = NO; | 71 self.toolbarView.translatesAutoresizingMaskIntoConstraints = NO; |
70 self.contentView.translatesAutoresizingMaskIntoConstraints = NO; | 72 self.contentView.translatesAutoresizingMaskIntoConstraints = NO; |
71 self.view.backgroundColor = [UIColor blackColor]; | 73 self.view.backgroundColor = [UIColor blackColor]; |
74 self.findBarView.backgroundColor = [UIColor greenColor]; | |
lpromero
2017/03/14 17:17:57
Should it be removed now?
| |
72 self.tabStripView.backgroundColor = [UIColor blackColor]; | 75 self.tabStripView.backgroundColor = [UIColor blackColor]; |
73 self.toolbarView.backgroundColor = [UIColor blackColor]; | 76 self.toolbarView.backgroundColor = [UIColor blackColor]; |
74 self.contentView.backgroundColor = [UIColor blackColor]; | 77 self.contentView.backgroundColor = [UIColor blackColor]; |
75 | 78 |
79 // Views that are added last have the highest z-order. | |
80 [self.view addSubview:self.tabStripView]; | |
81 [self.view addSubview:self.toolbarView]; | |
82 [self.view addSubview:self.contentView]; | |
83 [self.view addSubview:self.findBarView]; | |
84 self.findBarView.hidden = YES; | |
85 | |
76 [self addChildViewController:self.tabStripViewController | 86 [self addChildViewController:self.tabStripViewController |
77 toSubview:self.tabStripView]; | 87 toSubview:self.tabStripView]; |
78 [self addChildViewController:self.toolbarViewController | 88 [self addChildViewController:self.toolbarViewController |
79 toSubview:self.toolbarView]; | 89 toSubview:self.toolbarView]; |
80 [self addChildViewController:self.contentViewController | 90 [self addChildViewController:self.contentViewController |
81 toSubview:self.contentView]; | 91 toSubview:self.contentView]; |
82 | 92 |
83 self.tabStripHeightConstraint = | 93 self.tabStripHeightConstraint = |
84 [self.tabStripView.heightAnchor constraintEqualToConstant:0.0f]; | 94 [self.tabStripView.heightAnchor constraintEqualToConstant:0.0f]; |
85 self.toolbarHeightConstraint = | 95 self.toolbarHeightConstraint = |
(...skipping 11 matching lines...) Expand all Loading... | |
97 if (self.contentViewController == contentViewController) | 107 if (self.contentViewController == contentViewController) |
98 return; | 108 return; |
99 if ([self isViewLoaded]) { | 109 if ([self isViewLoaded]) { |
100 [self detachChildViewController:self.contentViewController]; | 110 [self detachChildViewController:self.contentViewController]; |
101 [self addChildViewController:contentViewController | 111 [self addChildViewController:contentViewController |
102 toSubview:self.contentView]; | 112 toSubview:self.contentView]; |
103 } | 113 } |
104 _contentViewController = contentViewController; | 114 _contentViewController = contentViewController; |
105 } | 115 } |
106 | 116 |
117 - (void)setFindBarViewController:(UIViewController*)findBarViewController { | |
118 if (self.findBarViewController == findBarViewController) | |
119 return; | |
120 if ([self isViewLoaded]) { | |
121 [self detachChildViewController:self.findBarViewController]; | |
122 [self addChildViewController:findBarViewController | |
123 toSubview:self.findBarView]; | |
124 } | |
125 _findBarViewController = findBarViewController; | |
126 self.findBarView.hidden = (_findBarViewController == nil); | |
127 } | |
128 | |
107 - (void)setToolbarViewController:(UIViewController*)toolbarViewController { | 129 - (void)setToolbarViewController:(UIViewController*)toolbarViewController { |
108 if (self.toolbarViewController == toolbarViewController) | 130 if (self.toolbarViewController == toolbarViewController) |
109 return; | 131 return; |
110 if ([self isViewLoaded]) { | 132 if ([self isViewLoaded]) { |
111 [self detachChildViewController:self.toolbarViewController]; | 133 [self detachChildViewController:self.toolbarViewController]; |
112 [self addChildViewController:toolbarViewController | 134 [self addChildViewController:toolbarViewController |
113 toSubview:self.toolbarView]; | 135 toSubview:self.toolbarView]; |
114 } | 136 } |
115 _toolbarViewController = toolbarViewController; | 137 _toolbarViewController = toolbarViewController; |
116 } | 138 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 239 |
218 #pragma mark - NSObject method forwarding | 240 #pragma mark - NSObject method forwarding |
219 | 241 |
220 - (id)forwardingTargetForSelector:(SEL)aSelector { | 242 - (id)forwardingTargetForSelector:(SEL)aSelector { |
221 if (aSelector == self.actionToForward) { | 243 if (aSelector == self.actionToForward) { |
222 return self.forwardingTarget; | 244 return self.forwardingTarget; |
223 } | 245 } |
224 return nil; | 246 return nil; |
225 } | 247 } |
226 | 248 |
227 #pragma mark - TabStripActions | 249 #pragma mark - Action handling |
250 | |
228 - (void)showTabStrip:(id)sender { | 251 - (void)showTabStrip:(id)sender { |
229 self.tabStripHeightConstraint.constant = kTabStripHeight; | 252 self.tabStripHeightConstraint.constant = kTabStripHeight; |
230 // HACK: Remove fake action. | 253 // HACK: Remove fake action. |
231 [[UIApplication sharedApplication] sendAction:@selector(tabStripDidShow:) | 254 [[UIApplication sharedApplication] sendAction:@selector(tabStripDidShow:) |
232 to:nil | 255 to:nil |
233 from:sender | 256 from:sender |
234 forEvent:nil]; | 257 forEvent:nil]; |
235 } | 258 } |
236 | 259 |
237 - (void)hideTabStrip:(id)sender { | 260 - (void)hideTabStrip:(id)sender { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 constraintEqualToAnchor:self.view.trailingAnchor], | 297 constraintEqualToAnchor:self.view.trailingAnchor], |
275 self.toolbarHeightConstraint, | 298 self.toolbarHeightConstraint, |
276 [self.contentView.topAnchor | 299 [self.contentView.topAnchor |
277 constraintEqualToAnchor:self.toolbarView.bottomAnchor], | 300 constraintEqualToAnchor:self.toolbarView.bottomAnchor], |
278 [self.contentView.leadingAnchor | 301 [self.contentView.leadingAnchor |
279 constraintEqualToAnchor:self.view.leadingAnchor], | 302 constraintEqualToAnchor:self.view.leadingAnchor], |
280 [self.contentView.trailingAnchor | 303 [self.contentView.trailingAnchor |
281 constraintEqualToAnchor:self.view.trailingAnchor], | 304 constraintEqualToAnchor:self.view.trailingAnchor], |
282 [self.contentView.bottomAnchor | 305 [self.contentView.bottomAnchor |
283 constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor], | 306 constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor], |
307 | |
308 [self.findBarView.topAnchor | |
309 constraintEqualToAnchor:self.toolbarView.topAnchor], | |
310 [self.findBarView.bottomAnchor | |
311 constraintEqualToAnchor:self.toolbarView.bottomAnchor], | |
312 [self.findBarView.leadingAnchor | |
313 constraintEqualToAnchor:self.toolbarView.leadingAnchor], | |
314 [self.findBarView.trailingAnchor | |
315 constraintEqualToAnchor:self.toolbarView.trailingAnchor], | |
284 ]; | 316 ]; |
285 } | 317 } |
286 | 318 |
287 @end | 319 @end |
288 | 320 |
289 @implementation BottomToolbarTabViewController | 321 @implementation BottomToolbarTabViewController |
290 | 322 |
291 // Override with constraints that place the toolbar on bottom. | 323 // Override with constraints that place the toolbar on bottom. |
292 - (Constraints*)subviewConstraints { | 324 - (Constraints*)subviewConstraints { |
293 return @[ | 325 return @[ |
(...skipping 16 matching lines...) Expand all Loading... | |
310 constraintEqualToAnchor:self.view.leadingAnchor], | 342 constraintEqualToAnchor:self.view.leadingAnchor], |
311 [self.toolbarView.trailingAnchor | 343 [self.toolbarView.trailingAnchor |
312 constraintEqualToAnchor:self.view.trailingAnchor], | 344 constraintEqualToAnchor:self.view.trailingAnchor], |
313 self.toolbarHeightConstraint, | 345 self.toolbarHeightConstraint, |
314 [self.toolbarView.bottomAnchor | 346 [self.toolbarView.bottomAnchor |
315 constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor], | 347 constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor], |
316 ]; | 348 ]; |
317 } | 349 } |
318 | 350 |
319 @end | 351 @end |
OLD | NEW |