Chromium Code Reviews| Index: chrome/browser/ui/views/omnibox/omnibox_view_win.cc |
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc |
| index d620d9ee9b3a1e038b8a06b9d8433b7e712a5fa3..e233e04174b9080fdfcc2fd81ae973ee774e7135 100644 |
| --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc |
| +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc |
| @@ -34,6 +34,7 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
| #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| +#include "chrome/browser/ui/search/search.h" |
| #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -122,6 +123,15 @@ bool IsDrag(const POINT& origin, const POINT& current) { |
| current.y - origin.y); |
| } |
| +// Write |text| and an optional |url| to the clipboard. |
| +void DoCopy(const string16& text, const GURL* url) { |
| + ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), |
| + ui::Clipboard::BUFFER_STANDARD); |
| + scw.WriteText(text); |
| + if (url != NULL) |
| + scw.WriteBookmark(text, url->spec()); |
| +} |
| + |
| } // namespace |
| // EditDropTarget is the IDropTarget implementation installed on |
| @@ -1015,6 +1025,10 @@ int OmniboxViewWin::OnPerformDropImpl(const ui::DropTargetEvent& event, |
| return ui::DragDropTypes::DRAG_NONE; |
| } |
| +void OmniboxViewWin::CopyURL() { |
| + DoCopy(toolbar_model()->GetText(false), &toolbar_model()->GetURL()); |
| +} |
| + |
| bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
| ui::KeyboardCode key = event.key_code(); |
| // We don't process ALT + numpad digit as accelerators, they are used for |
| @@ -1081,12 +1095,22 @@ bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { |
| bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { |
| switch (command_id) { |
| - case IDS_UNDO: return !!CanUndo(); |
| - case IDC_CUT: return !!CanCut(); |
| - case IDC_COPY: return !!CanCopy(); |
| - case IDC_PASTE: return !!CanPaste(); |
| - case IDS_PASTE_AND_GO: return model()->CanPasteAndGo(GetClipboardText()); |
| - case IDS_SELECT_ALL: return !!CanSelectAll(); |
| + case IDS_UNDO: |
| + return !!CanUndo(); |
| + case IDC_CUT: |
| + return !!CanCut(); |
| + case IDC_COPY: |
| + return !!CanCopy(); |
| + case IDC_COPY_URL: |
| + return !!CanCopy() && |
| + !model()->user_input_in_progress() && |
| + toolbar_model()->WouldReplaceSearchURLWithSearchTerms(); |
| + case IDC_PASTE: |
| + return !!CanPaste(); |
| + case IDS_PASTE_AND_GO: |
| + return model()->CanPasteAndGo(GetClipboardText()); |
| + case IDS_SELECT_ALL: |
| + return !!CanSelectAll(); |
| case IDS_EDIT_SEARCH_ENGINES: |
| return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); |
| default: |
| @@ -1137,6 +1161,10 @@ void OmniboxViewWin::ExecuteCommand(int command_id) { |
| Copy(); |
| break; |
| + case IDC_COPY_URL: |
| + CopyURL(); |
| + break; |
| + |
| case IDC_PASTE: |
| Paste(); |
| break; |
| @@ -1333,11 +1361,8 @@ void OmniboxViewWin::OnCopy() { |
| // GetSel() doesn't preserve selection direction, so sel.cpMin will always be |
| // the smaller value. |
| model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); |
| - ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), |
| - ui::Clipboard::BUFFER_STANDARD); |
| - scw.WriteText(text); |
| - if (write_url) |
| - scw.WriteBookmark(text, url.spec()); |
| + |
|
Peter Kasting
2012/09/11 21:52:59
Nit: Blank line unnecessary
dominich
2012/09/12 15:23:09
Done.
|
| + DoCopy(text, write_url ? &url : NULL); |
| } |
| LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { |
| @@ -2597,6 +2622,8 @@ void OmniboxViewWin::BuildContextMenu() { |
| context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
| context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); |
| context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); |
| + if (chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile())) |
| + context_menu_contents_->AddItemWithStringId(IDC_COPY_URL, IDS_COPY_URL); |
| context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); |
| // GetContextualLabel() will override this next label with the |
| // IDS_PASTE_AND_SEARCH label as needed. |