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

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 331993009: MacViews: Run native Cocoa context menus to support Services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to master Created 6 years, 5 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 | « no previous file | ui/views/controls/menu/menu_runner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index 473adaa1fd77b46e29a9674e7e49a4e7bc1ceab9..8fc558fcb5af4684ac43bb004cb2474a2eb960c1 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -158,6 +158,50 @@
[self doCommandByID:IDS_MOVE_RIGHT];
}
+- (void)insertText:(id)text {
+ if (textInputClient_)
+ textInputClient_->InsertText(base::SysNSStringToUTF16(text));
+}
+
+// Support for Services in context menus.
+// Currently we only support reading and writing plain strings.
+- (id)validRequestorForSendType:(NSString*)sendType
+ returnType:(NSString*)returnType {
+ BOOL canWrite = [sendType isEqualToString:NSStringPboardType] &&
+ [self selectedRange].length > 0;
+ BOOL canRead = [returnType isEqualToString:NSStringPboardType];
+ // Valid if (sendType, returnType) is either (string, nil), (nil, string),
+ // or (string, string).
+ BOOL valid = textInputClient_ && ((canWrite && (canRead || !returnType)) ||
+ (canRead && (canWrite || !sendType)));
+ return valid ? self : [super validRequestorForSendType:sendType
+ returnType:returnType];
+}
+
+// NSServicesRequests informal protocol.
+
+- (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard types:(NSArray*)types {
+ DCHECK([types containsObject:NSStringPboardType]);
+ if (!textInputClient_)
+ return NO;
+
+ gfx::Range selectionRange;
+ if (!textInputClient_->GetSelectionRange(&selectionRange))
+ return NO;
+
+ base::string16 text;
+ textInputClient_->GetTextFromRange(selectionRange, &text);
+ return [pboard writeObjects:@[ base::SysUTF16ToNSString(text) ]];
+}
+
+- (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard {
+ NSArray* objects =
+ [pboard readObjectsForClasses:@[ [NSString class] ] options:0];
+ DCHECK([objects count] == 1);
+ [self insertText:[objects lastObject]];
+ return YES;
+}
+
// NSTextInputClient protocol implementation.
- (NSAttributedString*)
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698