| 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/translate_controller.h" | 5 #import "ios/web_view/shell/translate_controller.h" |
| 6 | 6 |
| 7 #import <ChromeWebView/ChromeWebView.h> | 7 #import <ChromeWebView/ChromeWebView.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." | 11 #error "This file requires ARC support." |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 @interface TranslateController () | 14 @interface TranslateController () |
| 15 // Action Sheet to prompt user whether or not the page should be translated. | 15 // Action Sheet to prompt user whether or not the page should be translated. |
| 16 @property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet; | 16 @property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet; |
| 17 // Manager which performs the translation of the content. | |
| 18 @property(nonatomic, strong) id<CWVTranslateManager> translateManager; | |
| 19 @end | 17 @end |
| 20 | 18 |
| 21 @implementation TranslateController | 19 @implementation TranslateController |
| 22 | 20 |
| 23 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; | 21 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; |
| 24 @synthesize translateManager = _translateManager; | |
| 25 | 22 |
| 26 - (void)dealloc { | 23 - (void)dealloc { |
| 27 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES | 24 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES |
| 28 completion:nil]; | 25 completion:nil]; |
| 29 } | 26 } |
| 30 | 27 |
| 31 #pragma mark CWVTranslateDelegate methods | 28 #pragma mark - CWVTranslationDelegate methods |
| 32 | 29 |
| 33 - (void)translateStepChanged:(CRIWVTransateStep)step | 30 - (void)translationController:(CWVTranslationController*)controller |
| 34 manager:(id<CWVTranslateManager>)manager { | 31 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result |
| 35 if (step == CRIWVTransateStepBeforeTranslate) { | 32 error:(NSError*)error { |
| 36 self.translateManager = manager; | 33 self.beforeTranslateActionSheet = [UIAlertController |
| 37 self.beforeTranslateActionSheet = [UIAlertController | 34 alertControllerWithTitle:nil |
| 38 alertControllerWithTitle:nil | 35 message:@"Translate?" |
| 39 message:@"Translate?" | 36 preferredStyle:UIAlertControllerStyleActionSheet]; |
| 40 preferredStyle:UIAlertControllerStyleActionSheet]; | 37 UIAlertAction* cancelAction = |
| 41 UIAlertAction* cancelAction = | 38 [UIAlertAction actionWithTitle:@"Nope." |
| 42 [UIAlertAction actionWithTitle:@"Nope." | 39 style:UIAlertActionStyleCancel |
| 43 style:UIAlertActionStyleCancel | 40 handler:^(UIAlertAction* action) { |
| 44 handler:^(UIAlertAction* action) { | 41 self.beforeTranslateActionSheet = nil; |
| 45 self.beforeTranslateActionSheet = nil; | 42 }]; |
| 46 self.translateManager = nil; | 43 [_beforeTranslateActionSheet addAction:cancelAction]; |
| 47 }]; | |
| 48 [_beforeTranslateActionSheet addAction:cancelAction]; | |
| 49 | 44 |
| 50 UIAlertAction* translateAction = | 45 UIAlertAction* translateAction = [UIAlertAction |
| 51 [UIAlertAction actionWithTitle:@"Yes!" | 46 actionWithTitle:@"Yes!" |
| 52 style:UIAlertActionStyleDefault | 47 style:UIAlertActionStyleDefault |
| 53 handler:^(UIAlertAction* action) { | 48 handler:^(UIAlertAction* action) { |
| 54 self.beforeTranslateActionSheet = nil; | 49 self.beforeTranslateActionSheet = nil; |
| 55 [_translateManager translate]; | 50 CWVTranslationLanguage* source = result.sourceLanguage; |
| 56 self.translateManager = nil; | 51 CWVTranslationLanguage* target = result.targetLanguage; |
| 57 }]; | 52 [controller translatePageFromLanguage:source toLanguage:target]; |
| 58 [_beforeTranslateActionSheet addAction:translateAction]; | 53 }]; |
| 54 [_beforeTranslateActionSheet addAction:translateAction]; |
| 59 | 55 |
| 60 [[UIApplication sharedApplication].keyWindow.rootViewController | 56 [[UIApplication sharedApplication].keyWindow.rootViewController |
| 61 presentViewController:_beforeTranslateActionSheet | 57 presentViewController:_beforeTranslateActionSheet |
| 62 animated:YES | 58 animated:YES |
| 63 completion:nil]; | 59 completion:nil]; |
| 64 } | 60 } |
| 61 |
| 62 - (void)translationController:(CWVTranslationController*)controller |
| 63 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| 64 toLanguage:(CWVTranslationLanguage*)targetLanguage { |
| 65 } |
| 66 |
| 67 - (void)translationController:(CWVTranslationController*)controller |
| 68 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| 69 toLanguage:(CWVTranslationLanguage*)targetLanguage |
| 70 error:(NSError*)error { |
| 65 } | 71 } |
| 66 | 72 |
| 67 @end | 73 @end |
| OLD | NEW |