Chromium Code Reviews| Index: ios/web_view/shell/shell_view_controller.m |
| diff --git a/ios/web_view/shell/shell_view_controller.m b/ios/web_view/shell/shell_view_controller.m |
| index c95398b126c4221cde995e13b9bd8a5223cfd8c9..152279a665cf3fef3ca79ed4120b9b80b5098e49 100644 |
| --- a/ios/web_view/shell/shell_view_controller.m |
| +++ b/ios/web_view/shell/shell_view_controller.m |
| @@ -4,7 +4,10 @@ |
| #import "ios/web_view/shell/shell_view_controller.h" |
| +#import <MobileCoreServices/UTCoreTypes.h> |
|
Eugene But (OOO till 7-30)
2017/02/27 16:34:07
<MobileCoreServices/MobileCoreServices.h>
michaeldo
2017/02/27 19:02:06
Done.
|
| + |
| #import "ios/web_view/public/cwv.h" |
| +#import "ios/web_view/public/cwv_html_element.h" |
| #import "ios/web_view/public/cwv_web_view.h" |
| #import "ios/web_view/shell/translate_controller.h" |
| @@ -122,6 +125,7 @@ |
| self.webView = [CWV webViewWithFrame:[_containerView bounds]]; |
| [_webView setDelegate:self]; |
| + [_webView setUIDelegate:self]; |
| [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| UIViewAutoresizingFlexibleHeight]; |
| [_containerView addSubview:_webView]; |
| @@ -172,6 +176,44 @@ |
| [_field setText:[[_webView visibleURL] absoluteString]]; |
| } |
| +#pragma mark CWVUIDelegate methods |
| + |
| +- (void)webView:(CWVWebView*)webView |
| + runContextMenuWithTitle:(NSString*)menuTitle |
| + forHTMLElement:(CWVHTMLElement*)element |
| + inView:(UIView*)view |
| + userGestureLocation:(CGPoint)location { |
| + if (element.hyperlink == nil) { |
| + return; |
| + } |
| + |
| + UIAlertController* alert = [UIAlertController |
| + alertControllerWithTitle:menuTitle |
| + message:nil |
| + preferredStyle:UIAlertControllerStyleActionSheet]; |
| + alert.popoverPresentationController.sourceView = view; |
| + alert.popoverPresentationController.sourceRect = |
| + CGRectMake(location.x, location.y, 1.0, 1.0); |
| + |
| + void (^handler)(UIAlertAction*) = ^(UIAlertAction* action) { |
|
Eugene But (OOO till 7-30)
2017/02/27 16:34:07
nit: s/handler/copyHandler ?
michaeldo
2017/02/27 19:02:06
Done.
|
| + NSDictionary* item = @{ |
| + (NSString*)(kUTTypeURL) : element.hyperlink, |
| + (NSString*)(kUTTypeUTF8PlainText) : [[element.hyperlink absoluteString] |
| + dataUsingEncoding:NSUTF8StringEncoding], |
| + }; |
| + [[UIPasteboard generalPasteboard] setItems:@[ item ]]; |
| + }; |
| + [alert addAction:[UIAlertAction actionWithTitle:@"Copy Link" |
| + style:UIAlertActionStyleDefault |
| + handler:handler]]; |
| + |
| + [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" |
| + style:UIAlertActionStyleCancel |
| + handler:nil]]; |
| + |
| + [self presentViewController:alert animated:YES completion:nil]; |
| +} |
| + |
| #pragma mark CWVWebViewDelegate methods |
| - (void)webView:(CWVWebView*)webView |