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 10 matching lines...) Expand all Loading... |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "base/win/iat_patch_function.h" | 22 #include "base/win/iat_patch_function.h" |
23 #include "base/win/metro.h" | 23 #include "base/win/metro.h" |
24 #include "base/win/scoped_hdc.h" | 24 #include "base/win/scoped_hdc.h" |
25 #include "base/win/scoped_select_object.h" | 25 #include "base/win/scoped_select_object.h" |
26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
27 #include "chrome/app/chrome_command_ids.h" | 27 #include "chrome/app/chrome_command_ids.h" |
28 #include "chrome/browser/autocomplete/autocomplete_input.h" | 28 #include "chrome/browser/autocomplete/autocomplete_input.h" |
29 #include "chrome/browser/autocomplete/autocomplete_match.h" | 29 #include "chrome/browser/autocomplete/autocomplete_match.h" |
30 #include "chrome/browser/autocomplete/keyword_provider.h" | 30 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 31 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
31 #include "chrome/browser/command_updater.h" | 32 #include "chrome/browser/command_updater.h" |
32 #include "chrome/browser/net/url_fixer_upper.h" | 33 #include "chrome/browser/net/url_fixer_upper.h" |
33 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 36 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
36 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 37 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
37 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 38 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
38 #include "chrome/browser/ui/search/search.h" | 39 #include "chrome/browser/ui/search/search.h" |
39 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
40 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 41 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 const OmniboxViewWin::State view_state; | 121 const OmniboxViewWin::State view_state; |
121 }; | 122 }; |
122 | 123 |
123 // Returns true if the current point is far enough from the origin that it | 124 // Returns true if the current point is far enough from the origin that it |
124 // would be considered a drag. | 125 // would be considered a drag. |
125 bool IsDrag(const POINT& origin, const POINT& current) { | 126 bool IsDrag(const POINT& origin, const POINT& current) { |
126 return views::View::ExceededDragThreshold( | 127 return views::View::ExceededDragThreshold( |
127 gfx::Point(current) - gfx::Point(origin)); | 128 gfx::Point(current) - gfx::Point(origin)); |
128 } | 129 } |
129 | 130 |
130 // Write |text| and an optional |url| to the clipboard. | 131 // Copies |selected_text| as text to the primary clipboard. |
131 void DoCopy(const string16& text, const GURL* url) { | 132 void DoCopyText(const string16& selected_text) { |
132 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), | 133 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), |
133 ui::Clipboard::BUFFER_STANDARD); | 134 ui::Clipboard::BUFFER_STANDARD); |
134 scw.WriteText(text); | 135 scw.WriteText(selected_text); |
135 if (url != NULL) | 136 } |
136 scw.WriteBookmark(text, url->spec()); | 137 |
| 138 // Writes |url| and |text| to the clipboard as a well-formed URL. |
| 139 void DoCopyURL(const GURL& url, const string16& text) { |
| 140 BookmarkNodeData data; |
| 141 data.ReadFromTuple(url, text); |
| 142 data.WriteToClipboard(NULL); |
137 } | 143 } |
138 | 144 |
139 } // namespace | 145 } // namespace |
140 | 146 |
141 // EditDropTarget is the IDropTarget implementation installed on | 147 // EditDropTarget is the IDropTarget implementation installed on |
142 // OmniboxViewWin. EditDropTarget prefers URL over plain text. A drop | 148 // OmniboxViewWin. EditDropTarget prefers URL over plain text. A drop |
143 // of a URL replaces all the text of the edit and navigates immediately to the | 149 // of a URL replaces all the text of the edit and navigates immediately to the |
144 // URL. A drop of plain text from the same edit either copies or moves the | 150 // URL. A drop of plain text from the same edit either copies or moves the |
145 // selected text, and a drop of plain text from a source other than the edit | 151 // selected text, and a drop of plain text from a source other than the edit |
146 // does a paste and go. | 152 // does a paste and go. |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 model()->PasteAndGo(collapsed_text); | 1092 model()->PasteAndGo(collapsed_text); |
1087 } | 1093 } |
1088 return CopyOrLinkDragOperation(event.source_operations()); | 1094 return CopyOrLinkDragOperation(event.source_operations()); |
1089 } | 1095 } |
1090 } | 1096 } |
1091 | 1097 |
1092 return ui::DragDropTypes::DRAG_NONE; | 1098 return ui::DragDropTypes::DRAG_NONE; |
1093 } | 1099 } |
1094 | 1100 |
1095 void OmniboxViewWin::CopyURL() { | 1101 void OmniboxViewWin::CopyURL() { |
1096 DoCopy(toolbar_model()->GetText(false), &toolbar_model()->GetURL()); | 1102 DoCopyURL(toolbar_model()->GetURL(), toolbar_model()->GetText(false)); |
1097 } | 1103 } |
1098 | 1104 |
1099 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1105 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
1100 ui::KeyboardCode key = event.key_code(); | 1106 ui::KeyboardCode key = event.key_code(); |
1101 // We don't process ALT + numpad digit as accelerators, they are used for | 1107 // We don't process ALT + numpad digit as accelerators, they are used for |
1102 // entering special characters. We do translate alt-home. | 1108 // entering special characters. We do translate alt-home. |
1103 if (event.IsAltDown() && (key != ui::VKEY_HOME) && | 1109 if (event.IsAltDown() && (key != ui::VKEY_HOME) && |
1104 views::NativeTextfieldWin::IsNumPadDigit(key, | 1110 views::NativeTextfieldWin::IsNumPadDigit(key, |
1105 (event.flags() & ui::EF_EXTENDED) != 0)) | 1111 (event.flags() & ui::EF_EXTENDED) != 0)) |
1106 return true; | 1112 return true; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 if (text.empty()) | 1427 if (text.empty()) |
1422 return; | 1428 return; |
1423 | 1429 |
1424 CHARRANGE sel; | 1430 CHARRANGE sel; |
1425 GURL url; | 1431 GURL url; |
1426 bool write_url = false; | 1432 bool write_url = false; |
1427 GetSel(sel); | 1433 GetSel(sel); |
1428 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be | 1434 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be |
1429 // the smaller value. | 1435 // the smaller value. |
1430 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); | 1436 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); |
1431 DoCopy(text, write_url ? &url : NULL); | 1437 if (write_url) |
| 1438 DoCopyURL(url, text); |
| 1439 else |
| 1440 DoCopyText(text); |
1432 } | 1441 } |
1433 | 1442 |
1434 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { | 1443 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { |
1435 if (base::win::IsTSFAwareRequired()) { | 1444 if (base::win::IsTSFAwareRequired()) { |
1436 // Enable TSF support of RichEdit. | 1445 // Enable TSF support of RichEdit. |
1437 SetEditStyle(SES_USECTF, SES_USECTF); | 1446 SetEditStyle(SES_USECTF, SES_USECTF); |
1438 } | 1447 } |
1439 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 1448 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
1440 BOOL touch_mode = RegisterTouchWindow(m_hWnd, TWF_WANTPALM); | 1449 BOOL touch_mode = RegisterTouchWindow(m_hWnd, TWF_WANTPALM); |
1441 DCHECK(touch_mode); | 1450 DCHECK(touch_mode); |
(...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2816 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2808 } | 2817 } |
2809 | 2818 |
2810 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2819 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2811 // Use font_.GetStringWidth() instead of | 2820 // Use font_.GetStringWidth() instead of |
2812 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2821 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2813 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2822 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2814 // PosFromChar(i) might return 0 when i is greater than 1. | 2823 // PosFromChar(i) might return 0 when i is greater than 1. |
2815 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2824 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2816 } | 2825 } |
OLD | NEW |