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

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

Powered by Google App Engine
This is Rietveld 408576698