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

Side by Side Diff: ios/web_view/shell/shell_translation_delegate.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/web_view/shell/shell_translation_delegate.h"
6
7 #import <UIKit/UIKit.h>
8
9 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support."
11 #endif
12
13 @interface ShellTranslationDelegate ()
14 // Action Sheet to prompt user whether or not the page should be translated.
15 @property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet;
16 @end
17
18 @implementation ShellTranslationDelegate
19
20 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet;
21
22 - (void)dealloc {
23 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES
24 completion:nil];
25 }
26
27 #pragma mark - CWVTranslationDelegate methods
28
29 - (void)translationController:(CWVTranslationController*)controller
30 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
31 error:(NSError*)error {
32 __weak ShellTranslationDelegate* weakSelf = self;
33
34 self.beforeTranslateActionSheet = [UIAlertController
35 alertControllerWithTitle:nil
36 message:@"Translate?"
37 preferredStyle:UIAlertControllerStyleActionSheet];
38 UIAlertAction* cancelAction =
39 [UIAlertAction actionWithTitle:@"Nope."
40 style:UIAlertActionStyleCancel
41 handler:^(UIAlertAction* action) {
42 weakSelf.beforeTranslateActionSheet = nil;
43 }];
44 [_beforeTranslateActionSheet addAction:cancelAction];
45
46 UIAlertAction* translateAction = [UIAlertAction
47 actionWithTitle:@"Yes!"
48 style:UIAlertActionStyleDefault
49 handler:^(UIAlertAction* action) {
50 weakSelf.beforeTranslateActionSheet = nil;
51 CWVTranslationLanguage* source = result.pageLanguage;
52 CWVTranslationLanguage* target = result.suggestedTargetLanguage;
53 [controller translatePageFromLanguage:source toLanguage:target];
54 }];
55 [_beforeTranslateActionSheet addAction:translateAction];
56
57 [[UIApplication sharedApplication].keyWindow.rootViewController
58 presentViewController:_beforeTranslateActionSheet
59 animated:YES
60 completion:nil];
61 }
62
63 @end
OLDNEW
« no previous file with comments | « ios/web_view/shell/shell_translation_delegate.h ('k') | ios/web_view/shell/shell_view_controller.m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698