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 7fa5e1bcd7bbbac82a89d689bcff93463f42c3ab..6903537ff3e97bde0186231e74e15cefa531c6fd 100644 |
--- a/ui/views/cocoa/bridged_content_view.mm |
+++ b/ui/views/cocoa/bridged_content_view.mm |
@@ -171,6 +171,48 @@ |
[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]; |
+ BOOL valid = textInputClient_ && ((canWrite && (canRead || !returnType)) || |
tapted
2014/06/25 08:30:28
This condition does my head in a bit ;)
Maybe (as
Andre
2014/06/27 01:18:08
Yeah I didn't really like it either, but I'm also
tapted
2014/06/27 11:14:35
hm I realised the alternative isn't quite the same
|
+ (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*) |