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

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: Created 6 years, 6 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') | ui/views/controls/menu/menu_runner.h » ('J')
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 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*)
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_runner.h » ('j') | ui/views/controls/menu/menu_runner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698