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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "grit/ui_strings.h" 9 #include "grit/ui_strings.h"
10 #include "ui/base/ime/text_input_client.h" 10 #include "ui/base/ime/text_input_client.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 - (void)moveLeft:(id)sender { 166 - (void)moveLeft:(id)sender {
167 [self doCommandByID:IDS_MOVE_LEFT]; 167 [self doCommandByID:IDS_MOVE_LEFT];
168 } 168 }
169 169
170 - (void)moveRight:(id)sender { 170 - (void)moveRight:(id)sender {
171 [self doCommandByID:IDS_MOVE_RIGHT]; 171 [self doCommandByID:IDS_MOVE_RIGHT];
172 } 172 }
173 173
174 - (void)insertText:(id)text {
175 if (textInputClient_)
176 textInputClient_->InsertText(base::SysNSStringToUTF16(text));
177 }
178
179 // Support for Services in context menus.
180 // Currently we only support reading and writing plain strings.
181 - (id)validRequestorForSendType:(NSString*)sendType
182 returnType:(NSString*)returnType {
183 BOOL canWrite = [sendType isEqualToString:NSStringPboardType] &&
184 [self selectedRange].length > 0;
185 BOOL canRead = [returnType isEqualToString:NSStringPboardType];
186 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
187 (canRead && (canWrite || !sendType)));
188 return valid ? self : [super validRequestorForSendType:sendType
189 returnType:returnType];
190 }
191
192 // NSServicesRequests informal protocol.
193
194 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard types:(NSArray*)types {
195 DCHECK([types containsObject:NSStringPboardType]);
196 if (!textInputClient_)
197 return NO;
198
199 gfx::Range selectionRange;
200 if (!textInputClient_->GetSelectionRange(&selectionRange))
201 return NO;
202
203 base::string16 text;
204 textInputClient_->GetTextFromRange(selectionRange, &text);
205 return [pboard writeObjects:@[ base::SysUTF16ToNSString(text) ]];
206 }
207
208 - (BOOL)readSelectionFromPasteboard:(NSPasteboard*)pboard {
209 NSArray* objects =
210 [pboard readObjectsForClasses:@[ [NSString class] ] options:0];
211 DCHECK([objects count] == 1);
212 [self insertText:[objects lastObject]];
213 return YES;
214 }
215
174 // NSTextInputClient protocol implementation. 216 // NSTextInputClient protocol implementation.
175 217
176 - (NSAttributedString*) 218 - (NSAttributedString*)
177 attributedSubstringForProposedRange:(NSRange)range 219 attributedSubstringForProposedRange:(NSRange)range
178 actualRange:(NSRangePointer)actualRange { 220 actualRange:(NSRangePointer)actualRange {
179 base::string16 substring; 221 base::string16 substring;
180 if (textInputClient_) { 222 if (textInputClient_) {
181 gfx::Range textRange; 223 gfx::Range textRange;
182 textInputClient_->GetTextRange(&textRange); 224 textInputClient_->GetTextRange(&textRange);
183 gfx::Range subrange = textRange.Intersect(gfx::Range(range)); 225 gfx::Range subrange = textRange.Intersect(gfx::Range(range));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 - (void)unmarkText { 298 - (void)unmarkText {
257 if (textInputClient_) 299 if (textInputClient_)
258 textInputClient_->ConfirmCompositionText(); 300 textInputClient_->ConfirmCompositionText();
259 } 301 }
260 302
261 - (NSArray*)validAttributesForMarkedText { 303 - (NSArray*)validAttributesForMarkedText {
262 return @[]; 304 return @[];
263 } 305 }
264 306
265 @end 307 @end
OLDNEW
« 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