| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 data->SetURL(url, selected_text); | 791 data->SetURL(url, selected_text); |
| 792 } | 792 } |
| 793 | 793 |
| 794 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { | 794 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { |
| 795 // Minor note: We use IDC_ for command id here while the underlying textfield | 795 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 796 // is using IDS_ for all its command ids. This is because views cannot depend | 796 // is using IDS_ for all its command ids. This is because views cannot depend |
| 797 // on IDC_ for now. | 797 // on IDC_ for now. |
| 798 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 798 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 799 IDS_EDIT_SEARCH_ENGINES); | 799 IDS_EDIT_SEARCH_ENGINES); |
| 800 | 800 |
| 801 if (toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && |
| 802 !model()->user_input_in_progress()) { |
| 803 int copy_position = menu_contents->GetIndexOfCommandId(IDS_APP_COPY); |
| 804 if (copy_position >= 0) |
| 805 menu_contents->InsertItemWithStringIdAt( |
| 806 copy_position + 1, IDC_COPY_URL, IDS_COPY_URL); |
| 807 } |
| 808 |
| 801 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); | 809 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); |
| 802 if (paste_position >= 0) | 810 if (paste_position >= 0) |
| 803 menu_contents->InsertItemWithStringIdAt( | 811 menu_contents->InsertItemWithStringIdAt( |
| 804 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 812 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 805 } | 813 } |
| 806 | 814 |
| 807 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 815 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
| 808 return (command_id == IDS_PASTE_AND_GO) ? | 816 return (command_id == IDS_PASTE_AND_GO) ? |
| 809 model()->CanPasteAndGo(GetClipboardText()) : | 817 model()->CanPasteAndGo(GetClipboardText()) : |
| 810 command_updater()->IsCommandEnabled(command_id); | 818 command_updater()->IsCommandEnabled(command_id); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 823 | 831 |
| 824 return string16(); | 832 return string16(); |
| 825 } | 833 } |
| 826 | 834 |
| 827 void OmniboxViewViews::ExecuteCommand(int command_id) { | 835 void OmniboxViewViews::ExecuteCommand(int command_id) { |
| 828 if (command_id == IDS_PASTE_AND_GO) { | 836 if (command_id == IDS_PASTE_AND_GO) { |
| 829 model()->PasteAndGo(GetClipboardText()); | 837 model()->PasteAndGo(GetClipboardText()); |
| 830 return; | 838 return; |
| 831 } | 839 } |
| 832 | 840 |
| 841 if (command_id == IDS_COPY_URL) { |
| 842 CopyURL(); |
| 843 return; |
| 844 } |
| 845 |
| 833 command_updater()->ExecuteCommand(command_id); | 846 command_updater()->ExecuteCommand(command_id); |
| 834 } | 847 } |
| 835 | 848 |
| 836 #if defined(OS_CHROMEOS) | 849 #if defined(OS_CHROMEOS) |
| 837 void OmniboxViewViews::CandidateWindowOpened( | 850 void OmniboxViewViews::CandidateWindowOpened( |
| 838 chromeos::input_method::InputMethodManager* manager) { | 851 chromeos::input_method::InputMethodManager* manager) { |
| 839 ime_candidate_window_open_ = true; | 852 ime_candidate_window_open_ = true; |
| 840 CloseOmniboxPopup(); | 853 CloseOmniboxPopup(); |
| 841 } | 854 } |
| 842 | 855 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 const ui::Range& range) { | 911 const ui::Range& range) { |
| 899 if (text != GetText()) | 912 if (text != GetText()) |
| 900 textfield_->SetText(text); | 913 textfield_->SetText(text); |
| 901 textfield_->SelectRange(range); | 914 textfield_->SelectRange(range); |
| 902 } | 915 } |
| 903 | 916 |
| 904 string16 OmniboxViewViews::GetSelectedText() const { | 917 string16 OmniboxViewViews::GetSelectedText() const { |
| 905 // TODO(oshima): Support instant, IME. | 918 // TODO(oshima): Support instant, IME. |
| 906 return textfield_->GetSelectedText(); | 919 return textfield_->GetSelectedText(); |
| 907 } | 920 } |
| 921 |
| 922 void OmniboxViewViews::CopyURL() { |
| 923 const string16& text = toolbar_model()->GetText(false); |
| 924 const GURL& url = toolbar_model()->GetURL(); |
| 925 ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard(); |
| 926 ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); |
| 927 scw.WriteText(text); |
| 928 scw.WriteBookmark(text, url.spec()); |
| 929 scw.WriteHyperlink(net::EscapeForHTML(text), url.spec()); |
| 930 } |
| OLD | NEW |