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

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. Fixes for sky. 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
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*)
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_runner.h » ('j') | ui/views/controls/menu/menu_runner_impl_interface.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698