Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Side by Side Diff: ios/web_view/shell/shell_view_controller.m

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: merge Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <ChromeWebView/ChromeWebView.h> 7 #import <ChromeWebView/ChromeWebView.h>
8 #import <MobileCoreServices/MobileCoreServices.h> 8 #import <MobileCoreServices/MobileCoreServices.h>
9 9
10 #import "ios/web_view/shell/translate_controller.h" 10 #import "ios/web_view/shell/shell_translation_delegate.h"
11 11
12 #if !defined(__has_feature) || !__has_feature(objc_arc) 12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support." 13 #error "This file requires ARC support."
14 #endif 14 #endif
15 15
16 // Externed accessibility identifier. 16 // Externed accessibility identifier.
17 NSString* const kWebViewShellBackButtonAccessibilityLabel = @"Back"; 17 NSString* const kWebViewShellBackButtonAccessibilityLabel = @"Back";
18 NSString* const kWebViewShellForwardButtonAccessibilityLabel = @"Forward"; 18 NSString* const kWebViewShellForwardButtonAccessibilityLabel = @"Forward";
19 NSString* const kWebViewShellAddressFieldAccessibilityLabel = @"Address field"; 19 NSString* const kWebViewShellAddressFieldAccessibilityLabel = @"Address field";
20 NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = 20 NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
21 @"WebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier"; 21 @"WebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier";
22 22
23 @interface ShellViewController ()<CWVNavigationDelegate, 23 @interface ShellViewController ()<CWVNavigationDelegate,
24 CWVUIDelegate, 24 CWVUIDelegate,
25 UITextFieldDelegate> 25 UITextFieldDelegate>
26 // Container for |webView|. 26 // Container for |webView|.
27 @property(nonatomic, strong) UIView* containerView; 27 @property(nonatomic, strong) UIView* containerView;
28 // Text field used for navigating to URLs. 28 // Text field used for navigating to URLs.
29 @property(nonatomic, strong) UITextField* field; 29 @property(nonatomic, strong) UITextField* field;
30 // Toolbar containing navigation buttons and |field|. 30 // Toolbar containing navigation buttons and |field|.
31 @property(nonatomic, strong) UIToolbar* toolbar; 31 @property(nonatomic, strong) UIToolbar* toolbar;
32 // CWV view which renders the web page. 32 // CWV view which renders the web page.
33 @property(nonatomic, strong) CWVWebView* webView; 33 @property(nonatomic, strong) CWVWebView* webView;
34 // Handles the translation of the content displayed in |webView|. 34 // Handles the translation of the content displayed in |webView|.
35 @property(nonatomic, strong) TranslateController* translateController; 35 @property(nonatomic, strong) ShellTranslationDelegate* translationDelegate;
36 36
37 - (void)back; 37 - (void)back;
38 - (void)forward; 38 - (void)forward;
39 - (void)stopLoading; 39 - (void)stopLoading;
40 @end 40 @end
41 41
42 @implementation ShellViewController 42 @implementation ShellViewController
43 43
44 @synthesize containerView = _containerView; 44 @synthesize containerView = _containerView;
45 @synthesize field = _field; 45 @synthesize field = _field;
46 @synthesize toolbar = _toolbar; 46 @synthesize toolbar = _toolbar;
47 @synthesize webView = _webView; 47 @synthesize webView = _webView;
48 @synthesize translateController = _translateController; 48 @synthesize translationDelegate = _translationDelegate;
49 49
50 - (void)viewDidLoad { 50 - (void)viewDidLoad {
51 [super viewDidLoad]; 51 [super viewDidLoad];
52 52
53 CGRect bounds = self.view.bounds; 53 CGRect bounds = self.view.bounds;
54 54
55 // Set up the toolbar. 55 // Set up the toolbar.
56 self.toolbar = [[UIToolbar alloc] init]; 56 self.toolbar = [[UIToolbar alloc] init];
57 [_toolbar setBarTintColor:[UIColor colorWithRed:0.337 57 [_toolbar setBarTintColor:[UIColor colorWithRed:0.337
58 green:0.467 58 green:0.467
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 [CWVWebView setUserAgentProduct:@"Dummy/1.0"]; 148 [CWVWebView setUserAgentProduct:@"Dummy/1.0"];
149 149
150 CWVWebViewConfiguration* configuration = 150 CWVWebViewConfiguration* configuration =
151 [CWVWebViewConfiguration defaultConfiguration]; 151 [CWVWebViewConfiguration defaultConfiguration];
152 self.webView = [[CWVWebView alloc] initWithFrame:[_containerView bounds] 152 self.webView = [[CWVWebView alloc] initWithFrame:[_containerView bounds]
153 configuration:configuration]; 153 configuration:configuration];
154 // Gives a restoration identifier so that state restoration works. 154 // Gives a restoration identifier so that state restoration works.
155 _webView.restorationIdentifier = @"webView"; 155 _webView.restorationIdentifier = @"webView";
156 _webView.navigationDelegate = self; 156 _webView.navigationDelegate = self;
157 _webView.UIDelegate = self; 157 _webView.UIDelegate = self;
158 _translateController = [[TranslateController alloc] init]; 158 _translationDelegate = [[ShellTranslationDelegate alloc] init];
159 _webView.translationDelegate = _translateController; 159 _webView.translationController.delegate = _translationDelegate;
160 160
161 [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 161 [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
162 UIViewAutoresizingFlexibleHeight]; 162 UIViewAutoresizingFlexibleHeight];
163 [_containerView addSubview:_webView]; 163 [_containerView addSubview:_webView];
164 164
165 NSURLRequest* request = [NSURLRequest 165 NSURLRequest* request = [NSURLRequest
166 requestWithURL:[NSURL URLWithString:@"https://www.google.com/"]]; 166 requestWithURL:[NSURL URLWithString:@"https://www.google.com/"]];
167 [_webView loadRequest:request]; 167 [_webView loadRequest:request];
168 } 168 }
169 169
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // TODO(crbug.com/679895): Add some visual indication that the page load has 389 // TODO(crbug.com/679895): Add some visual indication that the page load has
390 // finished. 390 // finished.
391 [self updateToolbar]; 391 [self updateToolbar];
392 } 392 }
393 393
394 - (void)webViewWebContentProcessDidTerminate:(CWVWebView*)webView { 394 - (void)webViewWebContentProcessDidTerminate:(CWVWebView*)webView {
395 NSLog(@"webViewWebContentProcessDidTerminate"); 395 NSLog(@"webViewWebContentProcessDidTerminate");
396 } 396 }
397 397
398 @end 398 @end
OLDNEW
« no previous file with comments | « ios/web_view/shell/shell_translation_delegate.m ('k') | ios/web_view/shell/translate_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698