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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1008 if (model()->CanPasteAndGo(collapsed_text)) | 1008 if (model()->CanPasteAndGo(collapsed_text)) |
1009 model()->PasteAndGo(collapsed_text); | 1009 model()->PasteAndGo(collapsed_text); |
1010 } | 1010 } |
1011 return CopyOrLinkDragOperation(event.source_operations()); | 1011 return CopyOrLinkDragOperation(event.source_operations()); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 return ui::DragDropTypes::DRAG_NONE; | 1015 return ui::DragDropTypes::DRAG_NONE; |
1016 } | 1016 } |
1017 | 1017 |
1018 bool OmniboxViewWin::ShouldAddCopyURL() const { | |
Peter Kasting
2012/09/05 22:32:58
Nit: I'm fine with inlining this into IsCommandIdE
dominich
2012/09/05 23:35:34
Done.
| |
1019 return !!CanCopy() && | |
1020 !model()->user_input_in_progress() && | |
1021 toolbar_model()->WouldReplaceSearchURLWithSearchTerms(); | |
1022 } | |
1023 | |
1024 void OmniboxViewWin::CopyURL() { | |
1025 const string16& text = toolbar_model()->GetText(false); | |
1026 const GURL& url = toolbar_model()->GetURL(); | |
1027 | |
1028 ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), | |
1029 ui::Clipboard::BUFFER_STANDARD); | |
1030 scw.WriteText(text); | |
1031 scw.WriteBookmark(text, url.spec()); | |
1032 scw.WriteHyperlink(net::EscapeForHTML(text), url.spec()); | |
Peter Kasting
2012/09/05 22:32:58
Don't call WriteHyperlink (see https://chromiumcod
dominich
2012/09/05 23:35:34
Done.
| |
1033 } | |
1034 | |
1018 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1035 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
1019 ui::KeyboardCode key = event.key_code(); | 1036 ui::KeyboardCode key = event.key_code(); |
1020 // We don't process ALT + numpad digit as accelerators, they are used for | 1037 // We don't process ALT + numpad digit as accelerators, they are used for |
1021 // entering special characters. We do translate alt-home. | 1038 // entering special characters. We do translate alt-home. |
1022 if (event.IsAltDown() && (key != ui::VKEY_HOME) && | 1039 if (event.IsAltDown() && (key != ui::VKEY_HOME) && |
1023 views::NativeTextfieldWin::IsNumPadDigit(key, | 1040 views::NativeTextfieldWin::IsNumPadDigit(key, |
1024 (event.flags() & ui::EF_EXTENDED) != 0)) | 1041 (event.flags() & ui::EF_EXTENDED) != 0)) |
1025 return true; | 1042 return true; |
1026 | 1043 |
1027 // Skip accelerators for key combinations omnibox wants to crack. This list | 1044 // Skip accelerators for key combinations omnibox wants to crack. This list |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 | 1094 |
1078 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { | 1095 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { |
1079 return false; | 1096 return false; |
1080 } | 1097 } |
1081 | 1098 |
1082 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { | 1099 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { |
1083 switch (command_id) { | 1100 switch (command_id) { |
1084 case IDS_UNDO: return !!CanUndo(); | 1101 case IDS_UNDO: return !!CanUndo(); |
1085 case IDC_CUT: return !!CanCut(); | 1102 case IDC_CUT: return !!CanCut(); |
1086 case IDC_COPY: return !!CanCopy(); | 1103 case IDC_COPY: return !!CanCopy(); |
1104 case IDC_COPY_URL: return ShouldAddCopyURL(); | |
1087 case IDC_PASTE: return !!CanPaste(); | 1105 case IDC_PASTE: return !!CanPaste(); |
1088 case IDS_PASTE_AND_GO: return model()->CanPasteAndGo(GetClipboardText()); | 1106 case IDS_PASTE_AND_GO: return model()->CanPasteAndGo(GetClipboardText()); |
1089 case IDS_SELECT_ALL: return !!CanSelectAll(); | 1107 case IDS_SELECT_ALL: return !!CanSelectAll(); |
1090 case IDS_EDIT_SEARCH_ENGINES: | 1108 case IDS_EDIT_SEARCH_ENGINES: |
1091 return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); | 1109 return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); |
1092 default: | 1110 default: |
1093 NOTREACHED(); | 1111 NOTREACHED(); |
1094 return false; | 1112 return false; |
1095 } | 1113 } |
1096 } | 1114 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 break; | 1148 break; |
1131 | 1149 |
1132 case IDC_CUT: | 1150 case IDC_CUT: |
1133 Cut(); | 1151 Cut(); |
1134 break; | 1152 break; |
1135 | 1153 |
1136 case IDC_COPY: | 1154 case IDC_COPY: |
1137 Copy(); | 1155 Copy(); |
1138 break; | 1156 break; |
1139 | 1157 |
1158 case IDC_COPY_URL: | |
1159 CopyURL(); | |
1160 break; | |
1161 | |
1140 case IDC_PASTE: | 1162 case IDC_PASTE: |
1141 Paste(); | 1163 Paste(); |
1142 break; | 1164 break; |
1143 | 1165 |
1144 case IDS_SELECT_ALL: | 1166 case IDS_SELECT_ALL: |
1145 SelectAll(false); | 1167 SelectAll(false); |
1146 break; | 1168 break; |
1147 | 1169 |
1148 case IDS_EDIT_SEARCH_ENGINES: | 1170 case IDS_EDIT_SEARCH_ENGINES: |
1149 command_updater()->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); | 1171 command_updater()->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); |
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2641 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2663 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2642 } | 2664 } |
2643 | 2665 |
2644 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2666 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2645 // Use font_.GetStringWidth() instead of | 2667 // Use font_.GetStringWidth() instead of |
2646 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2668 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2647 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2669 // 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. | 2670 // PosFromChar(i) might return 0 when i is greater than 1. |
2649 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2671 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2650 } | 2672 } |
OLD | NEW |