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_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <locale> | 8 #include <locale> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
27 #include "chrome/browser/autocomplete/autocomplete_input.h" | 27 #include "chrome/browser/autocomplete/autocomplete_input.h" |
28 #include "chrome/browser/autocomplete/autocomplete_match.h" | 28 #include "chrome/browser/autocomplete/autocomplete_match.h" |
29 #include "chrome/browser/autocomplete/keyword_provider.h" | 29 #include "chrome/browser/autocomplete/keyword_provider.h" |
30 #include "chrome/browser/command_updater.h" | 30 #include "chrome/browser/command_updater.h" |
31 #include "chrome/browser/net/url_fixer_upper.h" | 31 #include "chrome/browser/net/url_fixer_upper.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
34 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 34 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
35 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 35 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 36 #include "chrome/browser/ui/search/search.h" |
36 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 37 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
37 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 38 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
38 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
39 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
41 #include "googleurl/src/url_util.h" | 42 #include "googleurl/src/url_util.h" |
42 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
43 #include "net/base/escape.h" | 44 #include "net/base/escape.h" |
44 #include "skia/ext/skia_utils_win.h" | 45 #include "skia/ext/skia_utils_win.h" |
45 #include "ui/base/accessibility/accessible_view_state.h" | 46 #include "ui/base/accessibility/accessible_view_state.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const OmniboxViewWin::State view_state; | 115 const OmniboxViewWin::State view_state; |
115 }; | 116 }; |
116 | 117 |
117 // Returns true if the current point is far enough from the origin that it | 118 // Returns true if the current point is far enough from the origin that it |
118 // would be considered a drag. | 119 // would be considered a drag. |
119 bool IsDrag(const POINT& origin, const POINT& current) { | 120 bool IsDrag(const POINT& origin, const POINT& current) { |
120 return views::View::ExceededDragThreshold(current.x - origin.x, | 121 return views::View::ExceededDragThreshold(current.x - origin.x, |
121 current.y - origin.y); | 122 current.y - origin.y); |
122 } | 123 } |
123 | 124 |
| 125 // Write |text| and an optional |url| to the clipboard. |
| 126 void DoCopy(const string16& text, const GURL* url) { |
| 127 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), |
| 128 ui::Clipboard::BUFFER_STANDARD); |
| 129 scw.WriteText(text); |
| 130 if (url != NULL) |
| 131 scw.WriteBookmark(text, url->spec()); |
| 132 } |
| 133 |
124 } // namespace | 134 } // namespace |
125 | 135 |
126 // EditDropTarget is the IDropTarget implementation installed on | 136 // EditDropTarget is the IDropTarget implementation installed on |
127 // OmniboxViewWin. EditDropTarget prefers URL over plain text. A drop | 137 // OmniboxViewWin. EditDropTarget prefers URL over plain text. A drop |
128 // of a URL replaces all the text of the edit and navigates immediately to the | 138 // of a URL replaces all the text of the edit and navigates immediately to the |
129 // URL. A drop of plain text from the same edit either copies or moves the | 139 // URL. A drop of plain text from the same edit either copies or moves the |
130 // selected text, and a drop of plain text from a source other than the edit | 140 // selected text, and a drop of plain text from a source other than the edit |
131 // does a paste and go. | 141 // does a paste and go. |
132 class OmniboxViewWin::EditDropTarget : public ui::DropTarget { | 142 class OmniboxViewWin::EditDropTarget : public ui::DropTarget { |
133 public: | 143 public: |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 if (model()->CanPasteAndGo(collapsed_text)) | 1017 if (model()->CanPasteAndGo(collapsed_text)) |
1008 model()->PasteAndGo(collapsed_text); | 1018 model()->PasteAndGo(collapsed_text); |
1009 } | 1019 } |
1010 return CopyOrLinkDragOperation(event.source_operations()); | 1020 return CopyOrLinkDragOperation(event.source_operations()); |
1011 } | 1021 } |
1012 } | 1022 } |
1013 | 1023 |
1014 return ui::DragDropTypes::DRAG_NONE; | 1024 return ui::DragDropTypes::DRAG_NONE; |
1015 } | 1025 } |
1016 | 1026 |
| 1027 void OmniboxViewWin::CopyURL() { |
| 1028 DoCopy(toolbar_model()->GetText(false), &toolbar_model()->GetURL()); |
| 1029 } |
| 1030 |
1017 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1031 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
1018 ui::KeyboardCode key = event.key_code(); | 1032 ui::KeyboardCode key = event.key_code(); |
1019 // We don't process ALT + numpad digit as accelerators, they are used for | 1033 // We don't process ALT + numpad digit as accelerators, they are used for |
1020 // entering special characters. We do translate alt-home. | 1034 // entering special characters. We do translate alt-home. |
1021 if (event.IsAltDown() && (key != ui::VKEY_HOME) && | 1035 if (event.IsAltDown() && (key != ui::VKEY_HOME) && |
1022 views::NativeTextfieldWin::IsNumPadDigit(key, | 1036 views::NativeTextfieldWin::IsNumPadDigit(key, |
1023 (event.flags() & ui::EF_EXTENDED) != 0)) | 1037 (event.flags() & ui::EF_EXTENDED) != 0)) |
1024 return true; | 1038 return true; |
1025 | 1039 |
1026 // Skip accelerators for key combinations omnibox wants to crack. This list | 1040 // Skip accelerators for key combinations omnibox wants to crack. This list |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 ::MapWindowPoints(NULL, m_hWnd, &client_point, 1); | 1087 ::MapWindowPoints(NULL, m_hWnd, &client_point, 1); |
1074 SendMessage(msg, flags, MAKELPARAM(client_point.x, client_point.y)); | 1088 SendMessage(msg, flags, MAKELPARAM(client_point.x, client_point.y)); |
1075 } | 1089 } |
1076 | 1090 |
1077 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { | 1091 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { |
1078 return false; | 1092 return false; |
1079 } | 1093 } |
1080 | 1094 |
1081 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { | 1095 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { |
1082 switch (command_id) { | 1096 switch (command_id) { |
1083 case IDS_UNDO: return !!CanUndo(); | 1097 case IDS_UNDO: |
1084 case IDC_CUT: return !!CanCut(); | 1098 return !!CanUndo(); |
1085 case IDC_COPY: return !!CanCopy(); | 1099 case IDC_CUT: |
1086 case IDC_PASTE: return !!CanPaste(); | 1100 return !!CanCut(); |
1087 case IDS_PASTE_AND_GO: return model()->CanPasteAndGo(GetClipboardText()); | 1101 case IDC_COPY: |
1088 case IDS_SELECT_ALL: return !!CanSelectAll(); | 1102 return !!CanCopy(); |
| 1103 case IDC_COPY_URL: |
| 1104 return !!CanCopy() && |
| 1105 !model()->user_input_in_progress() && |
| 1106 toolbar_model()->WouldReplaceSearchURLWithSearchTerms(); |
| 1107 case IDC_PASTE: |
| 1108 return !!CanPaste(); |
| 1109 case IDS_PASTE_AND_GO: |
| 1110 return model()->CanPasteAndGo(GetClipboardText()); |
| 1111 case IDS_SELECT_ALL: |
| 1112 return !!CanSelectAll(); |
1089 case IDS_EDIT_SEARCH_ENGINES: | 1113 case IDS_EDIT_SEARCH_ENGINES: |
1090 return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); | 1114 return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); |
1091 default: | 1115 default: |
1092 NOTREACHED(); | 1116 NOTREACHED(); |
1093 return false; | 1117 return false; |
1094 } | 1118 } |
1095 } | 1119 } |
1096 | 1120 |
1097 bool OmniboxViewWin::GetAcceleratorForCommandId( | 1121 bool OmniboxViewWin::GetAcceleratorForCommandId( |
1098 int command_id, | 1122 int command_id, |
(...skipping 30 matching lines...) Expand all Loading... |
1129 break; | 1153 break; |
1130 | 1154 |
1131 case IDC_CUT: | 1155 case IDC_CUT: |
1132 Cut(); | 1156 Cut(); |
1133 break; | 1157 break; |
1134 | 1158 |
1135 case IDC_COPY: | 1159 case IDC_COPY: |
1136 Copy(); | 1160 Copy(); |
1137 break; | 1161 break; |
1138 | 1162 |
| 1163 case IDC_COPY_URL: |
| 1164 CopyURL(); |
| 1165 break; |
| 1166 |
1139 case IDC_PASTE: | 1167 case IDC_PASTE: |
1140 Paste(); | 1168 Paste(); |
1141 break; | 1169 break; |
1142 | 1170 |
1143 case IDS_SELECT_ALL: | 1171 case IDS_SELECT_ALL: |
1144 SelectAll(false); | 1172 SelectAll(false); |
1145 break; | 1173 break; |
1146 | 1174 |
1147 case IDS_EDIT_SEARCH_ENGINES: | 1175 case IDS_EDIT_SEARCH_ENGINES: |
1148 command_updater()->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); | 1176 command_updater()->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 if (text.empty()) | 1353 if (text.empty()) |
1326 return; | 1354 return; |
1327 | 1355 |
1328 CHARRANGE sel; | 1356 CHARRANGE sel; |
1329 GURL url; | 1357 GURL url; |
1330 bool write_url = false; | 1358 bool write_url = false; |
1331 GetSel(sel); | 1359 GetSel(sel); |
1332 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be | 1360 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be |
1333 // the smaller value. | 1361 // the smaller value. |
1334 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); | 1362 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); |
1335 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), | 1363 DoCopy(text, write_url ? &url : NULL); |
1336 ui::Clipboard::BUFFER_STANDARD); | |
1337 scw.WriteText(text); | |
1338 if (write_url) | |
1339 scw.WriteBookmark(text, url.spec()); | |
1340 } | 1364 } |
1341 | 1365 |
1342 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { | 1366 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { |
1343 if (base::win::IsTsfAwareRequired()) { | 1367 if (base::win::IsTsfAwareRequired()) { |
1344 // Enable TSF support of RichEdit. | 1368 // Enable TSF support of RichEdit. |
1345 SetEditStyle(SES_USECTF, SES_USECTF); | 1369 SetEditStyle(SES_USECTF, SES_USECTF); |
1346 } | 1370 } |
1347 SetMsgHandled(FALSE); | 1371 SetMsgHandled(FALSE); |
1348 return 0; | 1372 return 0; |
1349 } | 1373 } |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2589 | 2613 |
2590 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 2614 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
2591 // Set up context menu. | 2615 // Set up context menu. |
2592 if (popup_window_mode_) { | 2616 if (popup_window_mode_) { |
2593 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); | 2617 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); |
2594 } else { | 2618 } else { |
2595 context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO); | 2619 context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO); |
2596 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2620 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
2597 context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); | 2621 context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); |
2598 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); | 2622 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); |
| 2623 if (chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile())) |
| 2624 context_menu_contents_->AddItemWithStringId(IDC_COPY_URL, IDS_COPY_URL); |
2599 context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); | 2625 context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); |
2600 // GetContextualLabel() will override this next label with the | 2626 // GetContextualLabel() will override this next label with the |
2601 // IDS_PASTE_AND_SEARCH label as needed. | 2627 // IDS_PASTE_AND_SEARCH label as needed. |
2602 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, | 2628 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, |
2603 IDS_PASTE_AND_GO); | 2629 IDS_PASTE_AND_GO); |
2604 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2630 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
2605 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); | 2631 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); |
2606 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2632 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
2607 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, | 2633 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, |
2608 IDS_EDIT_SEARCH_ENGINES); | 2634 IDS_EDIT_SEARCH_ENGINES); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2666 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2641 } | 2667 } |
2642 | 2668 |
2643 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2669 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2644 // Use font_.GetStringWidth() instead of | 2670 // Use font_.GetStringWidth() instead of |
2645 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2671 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2646 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2672 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2647 // PosFromChar(i) might return 0 when i is greater than 1. | 2673 // PosFromChar(i) might return 0 when i is greater than 1. |
2648 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2674 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2649 } | 2675 } |
OLD | NEW |