Commit 09ea24c7 authored by dmaclach@chromium.org's avatar dmaclach@chromium.org

Add support for receiving text from system services on Mac.

BUG=20868
TEST=manual

Review: http://codereview.chromium.org/3158026

Review URL: http://codereview.chromium.org/3158026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57087 0039d316-1c4b-4281-b951-d872f2087c98
parent 17168e2b
...@@ -882,14 +882,10 @@ void RecordLastRunAppBundlePath() { ...@@ -882,14 +882,10 @@ void RecordLastRunAppBundlePath() {
} }
- (void)registerServicesMenuTypesTo:(NSApplication*)app { - (void)registerServicesMenuTypesTo:(NSApplication*)app {
// Currently we only support one-way service requests and don't // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which
// support services that have return values such as the PGP // handles requests from services.
// encryption service. NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
// Also note that RenderWidgetHostViewCocoa implements [app registerServicesMenuSendTypes:types returnTypes:types];
// NSServicesRequests which handles requests from services.
NSArray* sendTypes = [NSArray arrayWithObjects:NSStringPboardType, nil];
NSArray* returnTypes = [NSArray array];
[app registerServicesMenuSendTypes:sendTypes returnTypes:returnTypes];
} }
- (Profile*)defaultProfile { - (Profile*)defaultProfile {
......
...@@ -2273,12 +2273,24 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -2273,12 +2273,24 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
- (id)validRequestorForSendType:(NSString*)sendType - (id)validRequestorForSendType:(NSString*)sendType
returnType:(NSString*)returnType { returnType:(NSString*)returnType {
if ([sendType isEqual:NSStringPboardType] && !returnType && id requestor = nil;
!renderWidgetHostView_->selected_text().empty()) { BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType];
return self; BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType];
BOOL hasText = !renderWidgetHostView_->selected_text().empty();
BOOL takesText =
renderWidgetHostView_->text_input_type_ != WebKit::WebTextInputTypeNone;
if (sendTypeIsString && hasText && !returnType) {
requestor = self;
} else if (!sendType && returnTypeIsString && takesText) {
requestor = self;
} else if (sendTypeIsString && returnTypeIsString && hasText && takesText) {
requestor = self;
} else {
requestor = [super validRequestorForSendType:sendType
returnType:returnType];
} }
return requestor;
return [super validRequestorForSendType:sendType returnType:returnType];
} }
@end @end
...@@ -2290,11 +2302,9 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -2290,11 +2302,9 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
- (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
types:(NSArray*)types { types:(NSArray*)types {
if (![types containsObject:NSStringPboardType] ||
renderWidgetHostView_->selected_text().empty())
return NO;
const std::string& str = renderWidgetHostView_->selected_text(); const std::string& str = renderWidgetHostView_->selected_text();
if (![types containsObject:NSStringPboardType] || str.empty()) return NO;
scoped_nsobject<NSString> text([[NSString alloc] scoped_nsobject<NSString> text([[NSString alloc]
initWithUTF8String:str.c_str()]); initWithUTF8String:str.c_str()]);
NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType];
...@@ -2303,7 +2313,14 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -2303,7 +2313,14 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
} }
- (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard { - (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard {
return NO; NSString *string = [pboard stringForType:NSStringPboardType];
if (!string) return NO;
// If the user is currently using an IME, confirm the IME input,
// and then insert the text from the service, the same as TextEdit and Safari.
[self confirmComposition];
[self insertText:string];
return YES;
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment