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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 DCHECK(observer); | 89 DCHECK(observer); |
90 if (observer && observer->CanCopy()) | 90 if (observer && observer->CanCopy()) |
91 observer->CopyToPasteboard([NSPasteboard generalPasteboard]); | 91 observer->CopyToPasteboard([NSPasteboard generalPasteboard]); |
92 } | 92 } |
93 | 93 |
94 - (void)cut:(id)sender { | 94 - (void)cut:(id)sender { |
95 [self copy:sender]; | 95 [self copy:sender]; |
96 [self delete:nil]; | 96 [self delete:nil]; |
97 } | 97 } |
98 | 98 |
| 99 - (void)copyURL:(id)sender { |
| 100 AutocompleteTextFieldObserver* observer = [self observer]; |
| 101 DCHECK(observer); |
| 102 if (observer->CanCopy()) |
| 103 observer->CopyURLToPasteboard([NSPasteboard generalPasteboard]); |
| 104 } |
| 105 |
99 // This class assumes that the delegate is an AutocompleteTextField. | 106 // This class assumes that the delegate is an AutocompleteTextField. |
100 // Enforce that assumption. | 107 // Enforce that assumption. |
101 - (AutocompleteTextField*)delegate { | 108 - (AutocompleteTextField*)delegate { |
102 AutocompleteTextField* delegate = | 109 AutocompleteTextField* delegate = |
103 static_cast<AutocompleteTextField*>([super delegate]); | 110 static_cast<AutocompleteTextField*>([super delegate]); |
104 DCHECK(delegate == nil || | 111 DCHECK(delegate == nil || |
105 [delegate isKindOfClass:[AutocompleteTextField class]]); | 112 [delegate isKindOfClass:[AutocompleteTextField class]]); |
106 return delegate; | 113 return delegate; |
107 } | 114 } |
108 | 115 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (actionMenu) | 208 if (actionMenu) |
202 return actionMenu; | 209 return actionMenu; |
203 | 210 |
204 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; | 211 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; |
205 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) | 212 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) |
206 action:@selector(cut:) | 213 action:@selector(cut:) |
207 keyEquivalent:@""]; | 214 keyEquivalent:@""]; |
208 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) | 215 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) |
209 action:@selector(copy:) | 216 action:@selector(copy:) |
210 keyEquivalent:@""]; | 217 keyEquivalent:@""]; |
| 218 |
| 219 if ([self isEditable]) { |
| 220 // Copy URL if the URL has been replaced by the Extended Instant API. |
| 221 AutocompleteTextFieldObserver* observer = [self observer]; |
| 222 DCHECK(observer); |
| 223 if (observer->ShouldAddCopyURL()) { |
| 224 NSString* label = l10n_util::GetNSStringWithFixup(IDS_COPY_URL_MAC); |
| 225 [menu addItemWithTitle:label |
| 226 action:@selector(copyURL:) |
| 227 keyEquivalent:@""]; |
| 228 } |
| 229 } |
| 230 |
211 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) | 231 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) |
212 action:@selector(paste:) | 232 action:@selector(paste:) |
213 keyEquivalent:@""]; | 233 keyEquivalent:@""]; |
214 | 234 |
215 // TODO(shess): If the control is not editable, should we show a | 235 // TODO(shess): If the control is not editable, should we show a |
216 // greyed-out "Paste and Go"? | 236 // greyed-out "Paste and Go"? |
217 if ([self isEditable]) { | 237 if ([self isEditable]) { |
218 // Paste and go/search. | 238 // Paste and go/search. |
219 AutocompleteTextFieldObserver* observer = [self observer]; | 239 AutocompleteTextFieldObserver* observer = [self observer]; |
220 DCHECK(observer); | 240 DCHECK(observer); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 NSAttributedString* selection = | 501 NSAttributedString* selection = |
482 [self attributedSubstringForProposedRange:selectedRange | 502 [self attributedSubstringForProposedRange:selectedRange |
483 actualRange:NULL]; | 503 actualRange:NULL]; |
484 if (!selection) | 504 if (!selection) |
485 return; | 505 return; |
486 | 506 |
487 [[FindPasteboard sharedInstance] setFindText:[selection string]]; | 507 [[FindPasteboard sharedInstance] setFindText:[selection string]]; |
488 } | 508 } |
489 | 509 |
490 @end | 510 @end |
OLD | NEW |