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/property_bag.h" | 7 #include "base/property_bag.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 12 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 15 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
16 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
17 #include "chrome/browser/ui/view_ids.h" | 17 #include "chrome/browser/ui/view_ids.h" |
18 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" | 18 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" |
19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "grit/app_locale_settings.h" | 22 #include "grit/app_locale_settings.h" |
23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/ui_strings.h" |
24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
25 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
26 #include "ui/base/accessibility/accessible_view_state.h" | 27 #include "ui/base/accessibility/accessible_view_state.h" |
27 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 28 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
28 #include "ui/base/dragdrop/drag_drop_types.h" | 29 #include "ui/base/dragdrop/drag_drop_types.h" |
29 #include "ui/base/dragdrop/os_exchange_data.h" | 30 #include "ui/base/dragdrop/os_exchange_data.h" |
30 #include "ui/base/ime/text_input_client.h" | 31 #include "ui/base/ime/text_input_client.h" |
31 #include "ui/base/ime/text_input_type.h" | 32 #include "ui/base/ime/text_input_type.h" |
32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/models/simple_menu_model.h" | 34 #include "ui/base/models/simple_menu_model.h" |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 if (write_url) | 752 if (write_url) |
752 data->SetURL(url, selected_text); | 753 data->SetURL(url, selected_text); |
753 } | 754 } |
754 | 755 |
755 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { | 756 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { |
756 // Minor note: We use IDC_ for command id here while the underlying textfield | 757 // Minor note: We use IDC_ for command id here while the underlying textfield |
757 // is using IDS_ for all its command ids. This is because views cannot depend | 758 // is using IDS_ for all its command ids. This is because views cannot depend |
758 // on IDC_ for now. | 759 // on IDC_ for now. |
759 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 760 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
760 IDS_EDIT_SEARCH_ENGINES); | 761 IDS_EDIT_SEARCH_ENGINES); |
| 762 |
| 763 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); |
| 764 if (paste_position >= 0) |
| 765 menu_contents->InsertItemWithStringIdAt( |
| 766 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
761 } | 767 } |
762 | 768 |
763 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 769 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
| 770 if (command_id == IDS_PASTE_AND_GO) |
| 771 return !popup_window_mode_ && model_->CanPasteAndGo(GetClipboardText()); |
| 772 |
764 return command_updater_->IsCommandEnabled(command_id); | 773 return command_updater_->IsCommandEnabled(command_id); |
765 } | 774 } |
766 | 775 |
767 void OmniboxViewViews::ExecuteCommand(int command_id) { | 776 void OmniboxViewViews::ExecuteCommand(int command_id) { |
| 777 if (command_id == IDS_PASTE_AND_GO) { |
| 778 model_->PasteAndGo(); |
| 779 return; |
| 780 } |
| 781 |
768 command_updater_->ExecuteCommand(command_id); | 782 command_updater_->ExecuteCommand(command_id); |
769 } | 783 } |
770 | 784 |
771 #if defined(OS_CHROMEOS) | 785 #if defined(OS_CHROMEOS) |
772 void OmniboxViewViews::CandidateWindowOpened( | 786 void OmniboxViewViews::CandidateWindowOpened( |
773 chromeos::input_method::InputMethodManager* manager) { | 787 chromeos::input_method::InputMethodManager* manager) { |
774 ime_candidate_window_open_ = true; | 788 ime_candidate_window_open_ = true; |
775 ClosePopup(); | 789 ClosePopup(); |
776 } | 790 } |
777 | 791 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 868 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
855 toolbar_model, | 869 toolbar_model, |
856 profile, | 870 profile, |
857 command_updater, | 871 command_updater, |
858 popup_window_mode, | 872 popup_window_mode, |
859 location_bar); | 873 location_bar); |
860 omnibox_view->Init(); | 874 omnibox_view->Init(); |
861 return omnibox_view; | 875 return omnibox_view; |
862 } | 876 } |
863 #endif | 877 #endif |
OLD | NEW |