| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autocomplete/autocomplete_edit_view_win.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" |
| 6 | 6 |
| 7 #include <locale> | 7 #include <locale> |
| 8 #include <richedit.h> | 8 #include <richedit.h> |
| 9 #include <textserv.h> | 9 #include <textserv.h> |
| 10 | 10 |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 POINT p; | 1160 POINT p; |
| 1161 GetCaretPos(&p); | 1161 GetCaretPos(&p); |
| 1162 MapWindowPoints(HWND_DESKTOP, &p, 1); | 1162 MapWindowPoints(HWND_DESKTOP, &p, 1); |
| 1163 context_menu_->RunContextMenuAt(gfx::Point(p)); | 1163 context_menu_->RunContextMenuAt(gfx::Point(p)); |
| 1164 } else { | 1164 } else { |
| 1165 context_menu_->RunContextMenuAt(gfx::Point(point)); | 1165 context_menu_->RunContextMenuAt(gfx::Point(point)); |
| 1166 } | 1166 } |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 void AutocompleteEditViewWin::OnCopy() { | 1169 void AutocompleteEditViewWin::OnCopy() { |
| 1170 const std::wstring text(GetSelectedText()); | 1170 std::wstring text(GetSelectedText()); |
| 1171 if (text.empty()) | 1171 if (text.empty()) |
| 1172 return; | 1172 return; |
| 1173 | 1173 |
| 1174 CHARRANGE sel; |
| 1175 GURL url; |
| 1176 bool write_url = false; |
| 1177 GetSel(sel); |
| 1178 model_->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); |
| 1174 ScopedClipboardWriter scw(g_browser_process->clipboard()); | 1179 ScopedClipboardWriter scw(g_browser_process->clipboard()); |
| 1175 // Check if the user is copying the whole address bar. If they are, we | 1180 scw.WriteText(text); |
| 1176 // assume they are trying to copy a URL and write this to the clipboard as a | 1181 if (write_url) { |
| 1177 // hyperlink. | 1182 scw.WriteBookmark(text, url.spec()); |
| 1178 if (static_cast<int>(text.length()) >= GetTextLength()) { | 1183 scw.WriteHyperlink(EscapeForHTML(UTF16ToUTF8(text)), url.spec()); |
| 1179 // The entire control is selected. Let's see what the user typed. We | |
| 1180 // can't use model_->CurrentTextIsURL() or model_->GetDataForURLExport() | |
| 1181 // because right now the user is probably holding down control to cause the | |
| 1182 // copy, which will screw up our calculation of the desired_tld. | |
| 1183 GURL url; | |
| 1184 if (model_->GetURLForText(text, &url)) { | |
| 1185 // If the scheme is http or https and the user isn't editing, | |
| 1186 // we should copy the true URL instead of the (unescaped) display | |
| 1187 // string to avoid encoding and escaping issues when pasting this text | |
| 1188 // elsewhere. | |
| 1189 if ((url.SchemeIs("http") || url.SchemeIs("https")) && | |
| 1190 !model_->user_input_in_progress()) | |
| 1191 scw.WriteText(UTF8ToWide(url.spec())); | |
| 1192 else | |
| 1193 scw.WriteText(text); | |
| 1194 scw.WriteBookmark(text, url.spec()); | |
| 1195 scw.WriteHyperlink(EscapeForHTML(UTF16ToUTF8(text)), url.spec()); | |
| 1196 return; | |
| 1197 } | |
| 1198 } | 1184 } |
| 1199 scw.WriteText(text); | |
| 1200 } | 1185 } |
| 1201 | 1186 |
| 1202 void AutocompleteEditViewWin::OnCut() { | 1187 void AutocompleteEditViewWin::OnCut() { |
| 1203 OnCopy(); | 1188 OnCopy(); |
| 1204 | 1189 |
| 1205 // This replace selection will have no effect (even on the undo stack) if the | 1190 // This replace selection will have no effect (even on the undo stack) if the |
| 1206 // current selection is empty. | 1191 // current selection is empty. |
| 1207 ReplaceSel(L"", true); | 1192 ReplaceSel(L"", true); |
| 1208 } | 1193 } |
| 1209 | 1194 |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 // | 1772 // |
| 1788 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that | 1773 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that |
| 1789 // they go through our clipboard routines. This allows us to be smarter | 1774 // they go through our clipboard routines. This allows us to be smarter |
| 1790 // about how we interact with the clipboard and avoid bugs in the | 1775 // about how we interact with the clipboard and avoid bugs in the |
| 1791 // CRichEditCtrl. If we didn't hijack here, the edit control would handle | 1776 // CRichEditCtrl. If we didn't hijack here, the edit control would handle |
| 1792 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. | 1777 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. |
| 1793 // | 1778 // |
| 1794 // Cut: Shift-Delete and Ctrl-x are treated as cut. Ctrl-Shift-Delete and | 1779 // Cut: Shift-Delete and Ctrl-x are treated as cut. Ctrl-Shift-Delete and |
| 1795 // Ctrl-Shift-x are not treated as cut even though the underlying | 1780 // Ctrl-Shift-x are not treated as cut even though the underlying |
| 1796 // CRichTextEdit would treat them as such. | 1781 // CRichTextEdit would treat them as such. |
| 1797 // Copy: Ctrl-c is treated as copy. Shift-Ctrl-c is not. (This is handled | 1782 // Copy: Ctrl-Insert and Ctrl-c is treated as copy. Shift-Ctrl-c is not. |
| 1798 // in OnKeyDownAllModes().) | 1783 // (This is handled in OnKeyDownAllModes().) |
| 1799 // Paste: Shift-Insert and Ctrl-v are tread as paste. Ctrl-Shift-Insert and | 1784 // Paste: Shift-Insert and Ctrl-v are treated as paste. Ctrl-Shift-Insert |
| 1800 // Ctrl-Shift-v are not. | 1785 // and Ctrl-Shift-v are not. |
| 1801 // | 1786 // |
| 1802 // This behavior matches most, but not all Windows programs, and largely | 1787 // This behavior matches most, but not all Windows programs, and largely |
| 1803 // conforms to what users expect. | 1788 // conforms to what users expect. |
| 1804 | 1789 |
| 1805 case VK_DELETE: | 1790 case VK_DELETE: |
| 1806 if ((flags & KF_ALTDOWN) || GetKeyState(VK_SHIFT) >= 0) | 1791 if ((flags & KF_ALTDOWN) || GetKeyState(VK_SHIFT) >= 0) |
| 1807 return false; | 1792 return false; |
| 1808 if (GetKeyState(VK_CONTROL) >= 0) { | 1793 if (GetKeyState(VK_CONTROL) >= 0) { |
| 1809 // Cut text if possible. | 1794 // Cut text if possible. |
| 1810 CHARRANGE selection; | 1795 CHARRANGE selection; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 return true; | 1875 return true; |
| 1891 | 1876 |
| 1892 default: | 1877 default: |
| 1893 return false; | 1878 return false; |
| 1894 } | 1879 } |
| 1895 } | 1880 } |
| 1896 | 1881 |
| 1897 bool AutocompleteEditViewWin::OnKeyDownAllModes(TCHAR key, | 1882 bool AutocompleteEditViewWin::OnKeyDownAllModes(TCHAR key, |
| 1898 UINT repeat_count, | 1883 UINT repeat_count, |
| 1899 UINT flags) { | 1884 UINT flags) { |
| 1900 // See KF_ALTDOWN comment atop OnKeyDownOnlyWriteable(). | 1885 // See KF_ALTDOWN comment atop OnKeyDownOnlyWritable(). |
| 1901 | 1886 |
| 1902 switch (key) { | 1887 switch (key) { |
| 1903 case VK_CONTROL: | 1888 case VK_CONTROL: |
| 1904 model_->OnControlKeyChanged(true); | 1889 model_->OnControlKeyChanged(true); |
| 1905 return false; | 1890 return false; |
| 1906 | 1891 |
| 1892 case VK_INSERT: |
| 1907 case 'C': | 1893 case 'C': |
| 1908 // See more detailed comments in OnKeyDownOnlyWriteable(). | 1894 // See more detailed comments in OnKeyDownOnlyWritable(). |
| 1909 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) | 1895 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) |
| 1910 return false; | 1896 return false; |
| 1911 if (GetKeyState(VK_SHIFT) >= 0) | 1897 if (GetKeyState(VK_SHIFT) >= 0) |
| 1912 Copy(); | 1898 Copy(); |
| 1913 return true; | 1899 return true; |
| 1914 | 1900 |
| 1915 default: | 1901 default: |
| 1916 return false; | 1902 return false; |
| 1917 } | 1903 } |
| 1918 } | 1904 } |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, | 2406 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, |
| 2421 IDS_PASTE_AND_GO); | 2407 IDS_PASTE_AND_GO); |
| 2422 context_menu_contents_->AddSeparator(); | 2408 context_menu_contents_->AddSeparator(); |
| 2423 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); | 2409 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); |
| 2424 context_menu_contents_->AddSeparator(); | 2410 context_menu_contents_->AddSeparator(); |
| 2425 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, | 2411 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, |
| 2426 IDS_EDIT_SEARCH_ENGINES); | 2412 IDS_EDIT_SEARCH_ENGINES); |
| 2427 } | 2413 } |
| 2428 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 2414 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
| 2429 } | 2415 } |
| OLD | NEW |