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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_mac.mm

Issue 3158026: Add support for receiving text from system services on Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <QuartzCore/QuartzCore.h> 5 #include <QuartzCore/QuartzCore.h>
6 6
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
8 8
9 #include "app/surface/io_surface_support_mac.h" 9 #include "app/surface/io_surface_support_mac.h"
10 #import "base/chrome_application_mac.h" 10 #import "base/chrome_application_mac.h"
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 } 2252 }
2253 2253
2254 - (ViewID)viewID { 2254 - (ViewID)viewID {
2255 return VIEW_ID_TAB_CONTAINER_FOCUS_VIEW; 2255 return VIEW_ID_TAB_CONTAINER_FOCUS_VIEW;
2256 } 2256 }
2257 2257
2258 // Overriding a NSResponder method to support application services. 2258 // Overriding a NSResponder method to support application services.
2259 2259
2260 - (id)validRequestorForSendType:(NSString*)sendType 2260 - (id)validRequestorForSendType:(NSString*)sendType
2261 returnType:(NSString*)returnType { 2261 returnType:(NSString*)returnType {
2262 if ([sendType isEqual:NSStringPboardType] && !returnType && 2262 id requestor = nil;
2263 !renderWidgetHostView_->selected_text().empty()) { 2263 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType];
2264 return self; 2264 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType];
2265 BOOL hasText = !renderWidgetHostView_->selected_text().empty();
2266 BOOL takesText =
2267 renderWidgetHostView_->text_input_type_ != WebKit::WebTextInputTypeNone;
2268
2269 if (sendTypeIsString && hasText && !returnType) {
2270 requestor = self;
2271 } else if (!sendType && returnTypeIsString && takesText) {
2272 requestor = self;
2273 } else if (sendTypeIsString && returnTypeIsString && hasText && takesText) {
2274 requestor = self;
2275 } else {
2276 requestor = [super validRequestorForSendType:sendType
2277 returnType:returnType];
2265 } 2278 }
2266 2279 return requestor;
2267 return [super validRequestorForSendType:sendType returnType:returnType];
2268 } 2280 }
2269 2281
2270 @end 2282 @end
2271 2283
2272 // 2284 //
2273 // Supporting application services 2285 // Supporting application services
2274 // 2286 //
2275 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 2287 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
2276 2288
2277 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 2289 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
2278 types:(NSArray*)types { 2290 types:(NSArray*)types {
2279 if (![types containsObject:NSStringPboardType] || 2291 const std::string& str = renderWidgetHostView_->selected_text();
2280 renderWidgetHostView_->selected_text().empty()) 2292 if (![types containsObject:NSStringPboardType] || str.empty()) return NO;
2281 return NO;
2282 2293
2283 const std::string& str = renderWidgetHostView_->selected_text();
2284 scoped_nsobject<NSString> text([[NSString alloc] 2294 scoped_nsobject<NSString> text([[NSString alloc]
2285 initWithUTF8String:str.c_str()]); 2295 initWithUTF8String:str.c_str()]);
2286 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; 2296 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType];
2287 [pboard declareTypes:toDeclare owner:nil]; 2297 [pboard declareTypes:toDeclare owner:nil];
2288 return [pboard setString:text forType:NSStringPboardType]; 2298 return [pboard setString:text forType:NSStringPboardType];
2289 } 2299 }
2290 2300
2291 - (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard { 2301 - (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard {
2292 return NO; 2302 NSString *string = [pboard stringForType:NSStringPboardType];
2303 if (!string) return NO;
2304
2305 // If the user is currently using an IME, confirm the IME input,
2306 // and then insert the text from the service, the same as TextEdit and Safari.
2307 [self confirmComposition];
2308 [self insertText:string];
2309 return YES;
2293 } 2310 }
2294 2311
2295 @end 2312 @end
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698