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

Unified 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: ShouldAllowCopyURLMenu fix 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
index deb9b2d6ef362d65c0bd8b97d6b8273cd378325a..7eb7606405741d554dc1c2869515367ac0c2881f 100644
--- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
+++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
@@ -96,6 +96,13 @@ BOOL ThePasteboardIsTooDamnBig() {
[self delete:nil];
}
+- (void)copyURL:(id)sender {
+ AutocompleteTextFieldObserver* observer = [self observer];
+ DCHECK(observer);
+ if (observer->CanCopy())
+ observer->CopyURLToPasteboard([NSPasteboard generalPasteboard]);
+}
+
// This class assumes that the delegate is an AutocompleteTextField.
// Enforce that assumption.
- (AutocompleteTextField*)delegate {
@@ -208,6 +215,17 @@ BOOL ThePasteboardIsTooDamnBig() {
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY)
action:@selector(copy:)
keyEquivalent:@""];
+
+ if ([self isEditable]) {
+ // Copy URL if the URL has been replaced by the Extended Instant API.
+ AutocompleteTextFieldObserver* observer = [self observer];
dhollowa 2012/09/11 20:25:34 |observer| is not used here except in DCHECK.
dominich 2012/09/12 15:23:09 Done.
+ DCHECK(observer);
+ NSString* label = l10n_util::GetNSStringWithFixup(IDS_COPY_URL_MAC);
+ [menu addItemWithTitle:label
+ action:@selector(copyURL:)
+ keyEquivalent:@""];
+ }
+
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE)
action:@selector(paste:)
keyEquivalent:@""];
@@ -218,24 +236,21 @@ BOOL ThePasteboardIsTooDamnBig() {
// Paste and go/search.
AutocompleteTextFieldObserver* observer = [self observer];
DCHECK(observer);
- if (observer && observer->CanPasteAndGo()) {
- const int string_id = observer->GetPasteActionStringId();
- NSString* label = l10n_util::GetNSStringWithFixup(string_id);
-
- // TODO(rohitrao): If the clipboard is empty, should we show a
- // greyed-out "Paste and Go" or nothing at all?
- if ([label length]) {
- [menu addItemWithTitle:label
- action:@selector(pasteAndGo:)
- keyEquivalent:@""];
- }
- }
+ const int string_id = observer->GetPasteActionStringId();
+ NSString* label = l10n_util::GetNSStringWithFixup(string_id);
- NSString* label = l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES);
- DCHECK([label length]);
if ([label length]) {
+ [menu addItemWithTitle:label
+ action:@selector(pasteAndGo:)
+ keyEquivalent:@""];
+ }
+
+ NSString* search_engine_label =
+ l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES);
+ DCHECK([search_engine_label length]);
+ if ([search_engine_label length]) {
dhollowa 2012/09/11 20:25:34 nit: No need to test for same thing as DCHECK.
Peter Kasting 2012/09/11 21:52:59 Nit: Also, be consistent in this function about wh
dominich 2012/09/12 15:23:09 Done.
dominich 2012/09/12 15:23:09 Done.
[menu addItem:[NSMenuItem separatorItem]];
- NSMenuItem* item = [menu addItemWithTitle:label
+ NSMenuItem* item = [menu addItemWithTitle:search_engine_label
action:@selector(commandDispatch:)
keyEquivalent:@""];
[item setTag:IDC_EDIT_SEARCH_ENGINES];
@@ -471,6 +486,18 @@ BOOL ThePasteboardIsTooDamnBig() {
- (BOOL)validateMenuItem:(NSMenuItem*)item {
if ([item action] == @selector(copyToFindPboard:))
return [self selectedRange].length > 0;
+ if ([item action] == @selector(pasteAndGo:)) {
+ // TODO(rohitrao): If the clipboard is empty, should we show a
+ // greyed-out "Paste and Go" or nothing at all?
Peter Kasting 2012/09/11 21:52:59 Nit: Shouldn't this TODO go away?
dominich 2012/09/12 15:23:09 No. I'm not checking the contents of the clipboard
+ AutocompleteTextFieldObserver* observer = [self observer];
+ DCHECK(observer);
+ return observer->CanPasteAndGo();
+ }
+ if ([item action] == @selector(copyURL:)) {
+ AutocompleteTextFieldObserver* observer = [self observer];
+ DCHECK(observer);
+ return observer->ShouldAddCopyURL();
+ }
return [super validateMenuItem:item];
}

Powered by Google App Engine
This is Rietveld 408576698