Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ios/web_view/shell/shell_view_controller.h" | 5 #import "ios/web_view/shell/shell_view_controller.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 9 #import "ios/web_view/public/criwv.h" | 8 #import "ios/web_view/public/criwv.h" |
| 10 #import "ios/web_view/public/criwv_web_view.h" | 9 #import "ios/web_view/public/criwv_web_view.h" |
| 11 #import "ios/web_view/shell/translate_controller.h" | 10 #import "ios/web_view/shell/translate_controller.h" |
| 12 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 13 namespace { | 16 namespace { |
| 14 const CGFloat kButtonSize = 44; | 17 const CGFloat kButtonSize = 44; |
| 15 } | 18 } |
| 16 | 19 |
| 17 @interface ShellViewController () { | 20 @interface ShellViewController () |
| 18 base::scoped_nsobject<UIView> _containerView; | 21 @property (nonatomic, strong) UIView* containerView; |
|
Eugene But (OOO till 7-30)
2017/01/30 17:53:39
Please add comments for properties.
michaeldo
2017/01/30 19:30:35
Done.
| |
| 19 base::scoped_nsobject<UITextField> _field; | 22 @property (nonatomic, strong) UITextField* field; |
| 20 base::scoped_nsobject<UIToolbar> _toolbar; | 23 @property (nonatomic, strong) UIToolbar* toolbar; |
| 21 base::scoped_nsprotocol<id<CRIWVWebView>> _webView; | 24 @property (nonatomic, strong) id<CRIWVWebView> webView; |
| 22 base::scoped_nsobject<TranslateController> _translateController; | 25 @property (nonatomic, strong) TranslateController* translateController; |
| 23 } | 26 |
| 24 - (void)back; | 27 - (void)back; |
| 25 - (void)forward; | 28 - (void)forward; |
| 26 - (void)stopLoading; | 29 - (void)stopLoading; |
| 27 @end | 30 @end |
| 28 | 31 |
| 29 @implementation ShellViewController | 32 @implementation ShellViewController |
| 30 | 33 |
| 34 @synthesize containerView = _containerView; | |
| 35 @synthesize field = _field; | |
| 36 @synthesize toolbar = _toolbar; | |
| 37 @synthesize webView = _webView; | |
| 38 @synthesize translateController = _translateController; | |
| 39 | |
| 31 - (void)viewDidLoad { | 40 - (void)viewDidLoad { |
| 32 [super viewDidLoad]; | 41 [super viewDidLoad]; |
| 33 | 42 |
| 34 CGRect bounds = self.view.bounds; | 43 CGRect bounds = self.view.bounds; |
| 35 | 44 |
| 36 // Set up the toolbar. | 45 // Set up the toolbar. |
| 37 _toolbar.reset([[UIToolbar alloc] init]); | 46 self.toolbar = [[UIToolbar alloc] init]; |
| 38 [_toolbar setBarTintColor:[UIColor colorWithRed:0.337 | 47 [_toolbar setBarTintColor:[UIColor colorWithRed:0.337 |
| 39 green:0.467 | 48 green:0.467 |
| 40 blue:0.988 | 49 blue:0.988 |
| 41 alpha:1.0]]; | 50 alpha:1.0]]; |
| 42 [_toolbar setFrame:CGRectMake(0, 20, CGRectGetWidth(bounds), 44)]; | 51 [_toolbar setFrame:CGRectMake(0, 20, CGRectGetWidth(bounds), 44)]; |
| 43 [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 52 [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 44 UIViewAutoresizingFlexibleBottomMargin]; | 53 UIViewAutoresizingFlexibleBottomMargin]; |
| 45 [self.view addSubview:_toolbar]; | 54 [self.view addSubview:_toolbar]; |
| 46 | 55 |
| 47 // Set up the container view. | 56 // Set up the container view. |
| 48 _containerView.reset([[UIView alloc] init]); | 57 self.containerView = [[UIView alloc] init]; |
| 49 [_containerView setFrame:CGRectMake(0, 64, CGRectGetWidth(bounds), | 58 [_containerView setFrame:CGRectMake(0, 64, CGRectGetWidth(bounds), |
| 50 CGRectGetHeight(bounds) - 64)]; | 59 CGRectGetHeight(bounds) - 64)]; |
| 51 [_containerView setBackgroundColor:[UIColor lightGrayColor]]; | 60 [_containerView setBackgroundColor:[UIColor lightGrayColor]]; |
| 52 [_containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 61 [_containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 53 UIViewAutoresizingFlexibleHeight]; | 62 UIViewAutoresizingFlexibleHeight]; |
| 54 [self.view addSubview:_containerView]; | 63 [self.view addSubview:_containerView]; |
| 55 | 64 |
| 56 // Text field. | 65 // Text field. |
| 57 const int kButtonCount = 3; | 66 const int kButtonCount = 3; |
| 58 _field.reset([[UITextField alloc] | 67 self.field = [[UITextField alloc] |
| 59 initWithFrame:CGRectMake(kButtonCount * kButtonSize, 6, | 68 initWithFrame:CGRectMake(kButtonCount * kButtonSize, 6, |
| 60 CGRectGetWidth([_toolbar frame]) - | 69 CGRectGetWidth([_toolbar frame]) - |
| 61 kButtonCount * kButtonSize - 10, | 70 kButtonCount * kButtonSize - 10, |
| 62 31)]); | 71 31)]; |
| 63 [_field setDelegate:self]; | 72 [_field setDelegate:self]; |
| 64 [_field setBackground:[[UIImage imageNamed:@"textfield_background"] | 73 [_field setBackground:[[UIImage imageNamed:@"textfield_background"] |
| 65 resizableImageWithCapInsets:UIEdgeInsetsMake( | 74 resizableImageWithCapInsets:UIEdgeInsetsMake( |
| 66 12, 12, 12, 12)]]; | 75 12, 12, 12, 12)]]; |
| 67 [_field setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 76 [_field setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
| 68 [_field setKeyboardType:UIKeyboardTypeWebSearch]; | 77 [_field setKeyboardType:UIKeyboardTypeWebSearch]; |
| 69 [_field setAutocorrectionType:UITextAutocorrectionTypeNo]; | 78 [_field setAutocorrectionType:UITextAutocorrectionTypeNo]; |
| 70 [_field setClearButtonMode:UITextFieldViewModeWhileEditing]; | 79 [_field setClearButtonMode:UITextFieldViewModeWhileEditing]; |
| 71 | 80 |
| 72 // Set up the toolbar buttons. | 81 // Set up the toolbar buttons. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 102 [stop setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; | 111 [stop setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; |
| 103 [stop addTarget:self | 112 [stop addTarget:self |
| 104 action:@selector(stopLoading) | 113 action:@selector(stopLoading) |
| 105 forControlEvents:UIControlEventTouchUpInside]; | 114 forControlEvents:UIControlEventTouchUpInside]; |
| 106 | 115 |
| 107 [_toolbar addSubview:back]; | 116 [_toolbar addSubview:back]; |
| 108 [_toolbar addSubview:forward]; | 117 [_toolbar addSubview:forward]; |
| 109 [_toolbar addSubview:stop]; | 118 [_toolbar addSubview:stop]; |
| 110 [_toolbar addSubview:_field]; | 119 [_toolbar addSubview:_field]; |
| 111 | 120 |
| 112 _webView.reset([[CRIWV webView] retain]); | 121 self.webView = [CRIWV webView]; |
| 113 [_webView setDelegate:self]; | 122 [_webView setDelegate:self]; |
| 114 UIView* view = [_webView view]; | 123 UIView* view = [_webView view]; |
| 115 [_containerView addSubview:view]; | 124 [_containerView addSubview:view]; |
| 116 [view setFrame:[_containerView bounds]]; | 125 [view setFrame:[_containerView bounds]]; |
| 117 [view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 126 [view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 118 UIViewAutoresizingFlexibleHeight]; | 127 UIViewAutoresizingFlexibleHeight]; |
| 119 | 128 |
| 120 [_webView loadURL:[NSURL URLWithString:@"https://www.google.com/"]]; | 129 [_webView loadURL:[NSURL URLWithString:@"https://www.google.com/"]]; |
| 121 } | 130 } |
| 122 | 131 |
| 123 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { | 132 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { |
| 124 if (bar == _toolbar.get()) { | 133 if (bar == _toolbar) { |
| 125 return UIBarPositionTopAttached; | 134 return UIBarPositionTopAttached; |
| 126 } | 135 } |
| 127 return UIBarPositionAny; | 136 return UIBarPositionAny; |
| 128 } | 137 } |
| 129 | 138 |
| 130 - (void)back { | 139 - (void)back { |
| 131 if ([_webView canGoBack]) { | 140 if ([_webView canGoBack]) { |
| 132 [_webView goBack]; | 141 [_webView goBack]; |
| 133 } | 142 } |
| 134 } | 143 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // TODO(crbug.com/679895): Add a title display. | 188 // TODO(crbug.com/679895): Add a title display. |
| 180 } | 189 } |
| 181 | 190 |
| 182 if (changes & CRIWVWebViewUpdateTypeURL) { | 191 if (changes & CRIWVWebViewUpdateTypeURL) { |
| 183 [self updateToolbar]; | 192 [self updateToolbar]; |
| 184 } | 193 } |
| 185 } | 194 } |
| 186 | 195 |
| 187 - (id<CRIWVTranslateDelegate>)translateDelegate { | 196 - (id<CRIWVTranslateDelegate>)translateDelegate { |
| 188 if (!_translateController) | 197 if (!_translateController) |
| 189 _translateController.reset([[TranslateController alloc] init]); | 198 self.translateController = [[TranslateController alloc] init]; |
| 190 return _translateController; | 199 return _translateController; |
| 191 } | 200 } |
| 192 | 201 |
| 193 @end | 202 @end |
| OLD | NEW |