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

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

Issue 2723433004: Add CWVUIDelegate with method to customize context menu. (Closed)
Patch Set: Respond to comment. 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
« no previous file with comments | « ios/web_view/shell/shell_view_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..89f19d98f5dc9c8ef589bcd1753751770befe42e 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/MobileCoreServices.h>
+
#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"
@@ -12,7 +15,9 @@
#error "This file requires ARC support."
#endif
-@interface ShellViewController ()
+@interface ShellViewController ()<CWVUIDelegate,
+ CWVWebViewDelegate,
+ UITextFieldDelegate>
// Container for |webView|.
@property(nonatomic, strong) UIView* containerView;
// Text field used for navigating to URLs.
@@ -122,6 +127,7 @@
self.webView = [CWV webViewWithFrame:[_containerView bounds]];
[_webView setDelegate:self];
+ [_webView setUIDelegate:self];
[_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight];
[_containerView addSubview:_webView];
@@ -172,6 +178,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) {
+ 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 (^copyHandler)(UIAlertAction*) = ^(UIAlertAction* action) {
+ 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:copyHandler]];
+
+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:nil]];
+
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
#pragma mark CWVWebViewDelegate methods
- (void)webView:(CWVWebView*)webView
« no previous file with comments | « 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