Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" // IDC_* | 9 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 } | 268 } |
| 269 | 269 |
| 270 // (URLDropTarget protocol) | 270 // (URLDropTarget protocol) |
| 271 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 271 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 272 return [dropHandler_ performDragOperation:sender]; | 272 return [dropHandler_ performDragOperation:sender]; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Prevent control characters from being entered into the Omnibox. | 275 // Prevent control characters from being entered into the Omnibox. |
| 276 // This is invoked for keyboard entry, not for pasting. | 276 // This is invoked for keyboard entry, not for pasting. |
| 277 - (void)insertText:(id)aString { | 277 - (void)insertText:(id)aString { |
| 278 // This method is documented as received either |NSString| or | |
| 279 // |NSAttributedString|. The autocomplete code will restyle the | |
| 280 // results in any case, so simplify by always using |NSString|. | |
| 281 if ([aString isKindOfClass:[NSAttributedString class]]) | |
| 282 aString = [aString string]; | |
| 283 | |
| 284 // Repeatedly remove control characters. The loop will only ever | 278 // Repeatedly remove control characters. The loop will only ever |
| 285 // execute at allwhen the user enters control characters (using | 279 // execute at all when the user enters control characters (using |
| 286 // Ctrl-Alt- or Ctrl-Q). Making this generally efficient would | 280 // Ctrl-Alt- or Ctrl-Q). Making this generally efficient would |
| 287 // probably be a loss, since the input always seems to be a single | 281 // probably be a loss, since the input always seems to be a single |
| 288 // character. | 282 // character. |
| 289 NSRange range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; | 283 if ([aString isKindOfClass:[NSAttributedString class]]) { |
| 290 while (range.location != NSNotFound) { | 284 NSRange range = |
| 291 aString = [aString stringByReplacingCharactersInRange:range withString:@""]; | 285 [[aString string] rangeOfCharacterFromSet:forbiddenCharacters_]; |
| 292 range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; | 286 while (range.location != NSNotFound) { |
| 287 aString = [[aString mutableCopy] autorelease]; | |
|
Mark Mentovai
2011/08/12 19:49:24
Technically you only need to make the copy the fir
Avi (use Gerrit)
2011/08/12 19:55:16
True, but...
99.99999% of the time there are no c
Mark Mentovai
2011/08/12 19:57:02
Avi wrote:
| |
| 288 [aString deleteCharactersInRange:range]; | |
| 289 range = [[aString string] rangeOfCharacterFromSet:forbiddenCharacters_]; | |
| 290 } | |
| 291 DCHECK_EQ(range.length, 0U); | |
| 292 } else { | |
| 293 NSRange range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; | |
| 294 while (range.location != NSNotFound) { | |
| 295 aString = | |
| 296 [aString stringByReplacingCharactersInRange:range withString:@""]; | |
| 297 range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; | |
| 298 } | |
| 299 DCHECK_EQ(range.length, 0U); | |
| 293 } | 300 } |
| 294 DCHECK_EQ(range.length, 0U); | |
| 295 | 301 |
| 296 // NOTE: If |aString| is empty, this intentionally replaces the | 302 // NOTE: If |aString| is empty, this intentionally replaces the |
| 297 // selection with empty. This seems consistent with the case where | 303 // selection with empty. This seems consistent with the case where |
| 298 // the input contained a mixture of characters and the string ended | 304 // the input contained a mixture of characters and the string ended |
| 299 // up not empty. | 305 // up not empty. |
| 300 [super insertText:aString]; | 306 [super insertText:aString]; |
| 301 } | 307 } |
| 302 | 308 |
| 303 - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange { | 309 - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange { |
| 304 if (![self hasMarkedText]) { | 310 if (![self hasMarkedText]) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 - (void)mouseDown:(NSEvent*)theEvent { | 433 - (void)mouseDown:(NSEvent*)theEvent { |
| 428 // Close the popup before processing the event. | 434 // Close the popup before processing the event. |
| 429 AutocompleteTextFieldObserver* observer = [self observer]; | 435 AutocompleteTextFieldObserver* observer = [self observer]; |
| 430 if (observer) | 436 if (observer) |
| 431 observer->ClosePopup(); | 437 observer->ClosePopup(); |
| 432 | 438 |
| 433 [super mouseDown:theEvent]; | 439 [super mouseDown:theEvent]; |
| 434 } | 440 } |
| 435 | 441 |
| 436 @end | 442 @end |
| OLD | NEW |