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