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

Unified Diff: ios/web_view/shell/shell_view_controller.m

Issue 2723433004: Add CWVUIDelegate with method to customize context menu. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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
« ios/web_view/shell/shell_view_controller.h ('K') | « ios/web_view/shell/shell_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698