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/web_contents/web_contents_view_controller.h " | 9 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h " |
10 | 10 |
11 #import "ios/web/public/navigation_manager.h" | |
12 #include "ios/web/public/web_state/web_state.h" | |
13 #include "ui/base/page_transition_types.h" | |
14 #include "url/gurl.h" | |
15 | 11 |
16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
17 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
18 #endif | 14 #endif |
19 | 15 |
16 @interface WebContentsViewController () | |
17 @property(nonatomic, strong) UIView* contentView; | |
18 @end | |
19 | |
20 @implementation WebContentsViewController | 20 @implementation WebContentsViewController |
21 | 21 |
22 @synthesize webState = _webState; | 22 @synthesize contentView = _contentView; |
23 | |
24 - (instancetype)initWithWebState:(web::WebState*)webState { | |
25 if ((self = [super initWithNibName:nil bundle:nil])) { | |
26 DCHECK(webState); | |
27 _webState = webState; | |
28 } | |
29 return self; | |
30 } | |
31 | 23 |
32 - (void)viewDidLoad { | 24 - (void)viewDidLoad { |
33 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; | 25 self.view.backgroundColor = [UIColor colorWithWhite:0.75 alpha:1.0]; |
34 | 26 |
35 UIView* webContentsView = self.webState->GetView(); | 27 if (!self.contentView) { |
36 webContentsView.translatesAutoresizingMaskIntoConstraints = NO; | 28 self.contentView = [[UIView alloc] init]; |
37 [self.view addSubview:webContentsView]; | 29 } |
38 [NSLayoutConstraint activateConstraints:@[ | |
39 [webContentsView.topAnchor constraintEqualToAnchor:self.view.topAnchor], | |
40 [webContentsView.bottomAnchor | |
41 constraintEqualToAnchor:self.view.bottomAnchor], | |
42 [webContentsView.leadingAnchor | |
43 constraintEqualToAnchor:self.view.leadingAnchor], | |
44 [webContentsView.trailingAnchor | |
45 constraintEqualToAnchor:self.view.trailingAnchor], | |
46 ]]; | |
47 | 30 |
48 if (!self.webState->GetNavigationManager()->GetItemCount()) { | 31 [self updateContentView]; |
49 web::NavigationManager::WebLoadParams params( | 32 } |
50 GURL("https://dev.chromium.org/")); | 33 |
51 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 34 #pragma mark - WebContentsConsumer |
52 _webState->GetNavigationManager()->LoadURLWithParams(params); | 35 |
36 - (void)contentViewDidChange:(UIView*)contentView { | |
37 if (contentView == self.contentView) | |
38 return; | |
39 [self.contentView removeFromSuperview]; | |
40 self.contentView = contentView; | |
41 if (self.viewIfLoaded) { | |
42 [self updateContentView]; | |
edchin
2017/02/02 22:17:52
It's better balanced if you [self.view addSubview:
marq (ping after 24h)
2017/02/03 09:48:10
I'll spell out why I did it this way in comments.
edchin
2017/02/03 15:33:38
My suggestion is to simply pull a line out from wi
marq (ping after 24h)
2017/02/07 14:33:11
We still need to add the subview in -updateContent
| |
53 } | 43 } |
54 } | 44 } |
55 | 45 |
46 #pragma mark - Private methods | |
47 | |
48 - (void)updateContentView { | |
49 self.contentView.translatesAutoresizingMaskIntoConstraints = NO; | |
edchin
2017/02/02 22:17:53
Using autoresizing masks would be clearer and more
marq (ping after 24h)
2017/02/03 09:48:10
I agree, I've been using constraints for everythin
| |
50 [self.view addSubview:self.contentView]; | |
51 [NSLayoutConstraint activateConstraints:@[ | |
52 [self.contentView.topAnchor constraintEqualToAnchor:self.view.topAnchor], | |
53 [self.contentView.bottomAnchor | |
54 constraintEqualToAnchor:self.view.bottomAnchor], | |
55 [self.contentView.leadingAnchor | |
56 constraintEqualToAnchor:self.view.leadingAnchor], | |
57 [self.contentView.trailingAnchor | |
58 constraintEqualToAnchor:self.view.trailingAnchor], | |
59 ]]; | |
60 } | |
61 | |
56 @end | 62 @end |
OLD | NEW |