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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm

Issue 10915069: Add Copy URL option to Omnibox context menu when URL is replaced by Instant Extended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fixes Created 8 years, 3 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 (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
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 && observer->CanCopy())
dhollowa 2012/09/05 21:22:34 nit: No need to handle DCHECK failure. Prefer: if
dominich 2012/09/05 21:30:54 Done.
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
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 && observer->ShouldAddCopyURL()) {
dhollowa 2012/09/05 21:22:34 nit: No need to handle DCHECK failure. Prefer: if
dominich 2012/09/05 21:30:54 Done.
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
235
dhollowa 2012/09/05 21:22:34 nit: remove extra line.
dominich 2012/09/05 21:30:54 Done.
215 // TODO(shess): If the control is not editable, should we show a 236 // TODO(shess): If the control is not editable, should we show a
216 // greyed-out "Paste and Go"? 237 // greyed-out "Paste and Go"?
217 if ([self isEditable]) { 238 if ([self isEditable]) {
218 // Paste and go/search. 239 // Paste and go/search.
219 AutocompleteTextFieldObserver* observer = [self observer]; 240 AutocompleteTextFieldObserver* observer = [self observer];
220 DCHECK(observer); 241 DCHECK(observer);
221 if (observer && observer->CanPasteAndGo()) { 242 if (observer && observer->CanPasteAndGo()) {
222 const int string_id = observer->GetPasteActionStringId(); 243 const int string_id = observer->GetPasteActionStringId();
223 NSString* label = l10n_util::GetNSStringWithFixup(string_id); 244 NSString* label = l10n_util::GetNSStringWithFixup(string_id);
224 245
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 NSAttributedString* selection = 502 NSAttributedString* selection =
482 [self attributedSubstringForProposedRange:selectedRange 503 [self attributedSubstringForProposedRange:selectedRange
483 actualRange:NULL]; 504 actualRange:NULL];
484 if (!selection) 505 if (!selection)
485 return; 506 return;
486 507
487 [[FindPasteboard sharedInstance] setFindText:[selection string]]; 508 [[FindPasteboard sharedInstance] setFindText:[selection string]];
488 } 509 }
489 510
490 @end 511 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698