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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

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/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index de46181bb1a875f1735245f9c239c11cbf1cfbd6..558244883c722a82cd538c6a633840f74bf8e36b 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -208,6 +208,14 @@ int GetEditFontPixelSize(bool popup_window_mode) {
kAutocompleteEditFontPixelSize;
}
+void DoCopy(const string16& text, const BookmarkNodeData* bookmark_node_data) {
+ ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard();
+ ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD);
+ scw.WriteText(text);
+ if (bookmark_node_data != NULL)
+ bookmark_node_data->WriteToClipboard(NULL);
+}
+
} // namespace
// static
@@ -768,13 +776,9 @@ void OmniboxViewViews::OnAfterCutOrCopy() {
bool write_url;
model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text,
&selected_text, &url, &write_url);
- ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD);
- scw.WriteText(selected_text);
- if (write_url) {
- BookmarkNodeData data;
- data.ReadFromTuple(url, text);
- data.WriteToClipboard(NULL);
- }
+ BookmarkNodeData data;
+ data.ReadFromTuple(url, text);
Peter Kasting 2012/09/11 21:52:59 Nit: If DoCopy() takes 4 args (what used to be her
dominich 2012/09/12 15:23:09 Done.
+ DoCopy(selected_text, write_url ? &data : NULL);
}
void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) {
@@ -798,16 +802,28 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {
menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
IDS_EDIT_SEARCH_ENGINES);
- int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE);
- if (paste_position >= 0)
+ if (chrome::search::IsInstantExtendedAPIEnabled(
+ location_bar_view_->profile())) {
+ int copy_position = menu_contents->GetIndexOfCommandId(IDS_APP_COPY);
+ DCHECK(copy_position >= 0);
menu_contents->InsertItemWithStringIdAt(
- paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
+ copy_position + 1, IDC_COPY_URL, IDS_COPY_URL);
+ }
+
+ int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE);
+ DCHECK(paste_position >= 0);
+ menu_contents->InsertItemWithStringIdAt(
+ paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
}
bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
- return (command_id == IDS_PASTE_AND_GO) ?
- model()->CanPasteAndGo(GetClipboardText()) :
- command_updater()->IsCommandEnabled(command_id);
+ if (command_id == IDS_PASTE_AND_GO) {
+ return model()->CanPasteAndGo(GetClipboardText());
+ } else if (command_id == IDS_COPY_URL) {
Peter Kasting 2012/09/11 21:52:59 Nit: No else after return.
dominich 2012/09/12 15:23:09 Done.
+ return toolbar_model()->WouldReplaceSearchURLWithSearchTerms() &&
+ !model()->user_input_in_progress();
+ }
+ return command_updater()->IsCommandEnabled(command_id);
}
bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {
@@ -825,12 +841,12 @@ string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const {
}
void OmniboxViewViews::ExecuteCommand(int command_id) {
- if (command_id == IDS_PASTE_AND_GO) {
+ if (command_id == IDS_PASTE_AND_GO)
model()->PasteAndGo(GetClipboardText());
- return;
- }
-
- command_updater()->ExecuteCommand(command_id);
+ else if (command_id == IDS_COPY_URL)
+ CopyURL();
+ else
+ command_updater()->ExecuteCommand(command_id);
}
#if defined(OS_CHROMEOS)
@@ -905,3 +921,10 @@ string16 OmniboxViewViews::GetSelectedText() const {
// TODO(oshima): Support instant, IME.
return textfield_->GetSelectedText();
}
+
+void OmniboxViewViews::CopyURL() {
+ BookmarkNodeData data;
+ const string16& text = toolbar_model()->GetText(false);
+ data.ReadFromTuple(toolbar_model()->GetURL(), text);
+ DoCopy(text, &data);
+}

Powered by Google App Engine
This is Rietveld 408576698