| 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 1f2ef37586b69e889e95eb39a0d0449ed9532cfb..953916b8811c54259edea19ae354dc334354137e 100644
|
| --- a/ui/views/cocoa/bridged_content_view.mm
|
| +++ b/ui/views/cocoa/bridged_content_view.mm
|
| @@ -90,6 +90,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*)
|
|
|