OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <locale> | 8 #include <locale> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "chrome/browser/search_engines/template_url_model.h" | 33 #include "chrome/browser/search_engines/template_url_model.h" |
34 #include "chrome/browser/tab_contents/tab_contents.h" | 34 #include "chrome/browser/tab_contents/tab_contents.h" |
35 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 35 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
36 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
37 #include "googleurl/src/url_util.h" | 37 #include "googleurl/src/url_util.h" |
38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
39 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
40 #include "skia/ext/skia_utils_win.h" | 40 #include "skia/ext/skia_utils_win.h" |
41 #include "ui/base/clipboard/clipboard.h" | 41 #include "ui/base/clipboard/clipboard.h" |
42 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 42 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
43 #include "ui/base/dragdrop/drag_drop_types.h" | |
43 #include "ui/base/dragdrop/drag_source.h" | 44 #include "ui/base/dragdrop/drag_source.h" |
44 #include "ui/base/dragdrop/drop_target.h" | 45 #include "ui/base/dragdrop/drop_target.h" |
45 #include "ui/base/dragdrop/os_exchange_data.h" | 46 #include "ui/base/dragdrop/os_exchange_data.h" |
46 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 47 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
47 #include "ui/base/keycodes/keyboard_codes.h" | 48 #include "ui/base/keycodes/keyboard_codes.h" |
48 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
49 #include "ui/base/l10n/l10n_util_win.h" | 50 #include "ui/base/l10n/l10n_util_win.h" |
50 #include "ui/gfx/canvas.h" | 51 #include "ui/gfx/canvas.h" |
51 #include "ui/gfx/canvas_skia.h" | 52 #include "ui/gfx/canvas_skia.h" |
52 #include "views/controls/textfield/native_textfield_win.h" | 53 #include "views/controls/textfield/native_textfield_win.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 } | 173 } |
173 | 174 |
174 void EditDropTarget::OnDragLeave(IDataObject* data_object) { | 175 void EditDropTarget::OnDragLeave(IDataObject* data_object) { |
175 ResetDropHighlights(); | 176 ResetDropHighlights(); |
176 } | 177 } |
177 | 178 |
178 DWORD EditDropTarget::OnDrop(IDataObject* data_object, | 179 DWORD EditDropTarget::OnDrop(IDataObject* data_object, |
179 DWORD key_state, | 180 DWORD key_state, |
180 POINT cursor_position, | 181 POINT cursor_position, |
181 DWORD effect) { | 182 DWORD effect) { |
183 effect = OnDragOver(data_object, key_state, cursor_position, effect); | |
184 | |
182 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object)); | 185 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object)); |
186 views::DropTargetEvent event(os_data, cursor_position.x, cursor_position.y, | |
187 ui::DragDropTypes::DropEffectToDragOperation(effect)); | |
183 | 188 |
184 if (drag_has_url_) { | 189 int drag_operation = edit_->OnPerformDrop(event); |
185 GURL url; | |
186 string16 title; | |
187 if (os_data.GetURLAndTitle(&url, &title)) { | |
188 edit_->SetUserText(UTF8ToWide(url.spec())); | |
189 edit_->model()->AcceptInput(CURRENT_TAB, true); | |
190 return CopyOrLinkDropEffect(effect); | |
191 } | |
192 } else if (drag_has_string_) { | |
193 int string_drop_position = edit_->drop_highlight_position(); | |
194 string16 text; | |
195 if ((string_drop_position != -1 || !edit_->in_drag()) && | |
196 os_data.GetString(&text)) { | |
197 DCHECK(string_drop_position == -1 || | |
198 ((string_drop_position >= 0) && | |
199 (string_drop_position <= edit_->GetTextLength()))); | |
200 const DWORD drop_operation = | |
201 OnDragOver(data_object, key_state, cursor_position, effect); | |
202 if (edit_->in_drag()) { | |
203 if (drop_operation == DROPEFFECT_MOVE) | |
204 edit_->MoveSelectedText(string_drop_position); | |
205 else | |
206 edit_->InsertText(string_drop_position, text); | |
207 } else { | |
208 edit_->PasteAndGo(CollapseWhitespace(text, true)); | |
209 } | |
210 ResetDropHighlights(); | |
211 return drop_operation; | |
212 } | |
213 } | |
214 | 190 |
215 ResetDropHighlights(); | 191 if (!drag_has_url_) |
192 ResetDropHighlights(); | |
216 | 193 |
217 return DROPEFFECT_NONE; | 194 return ui::DragDropTypes::DragOperationToDropEffect(drag_operation); |
218 } | 195 } |
219 | 196 |
220 void EditDropTarget::UpdateDropHighlightPosition( | 197 void EditDropTarget::UpdateDropHighlightPosition( |
221 const POINT& cursor_screen_position) { | 198 const POINT& cursor_screen_position) { |
222 if (drag_has_string_) { | 199 if (drag_has_string_) { |
223 POINT client_position = cursor_screen_position; | 200 POINT client_position = cursor_screen_position; |
224 ScreenToClient(edit_->m_hWnd, &client_position); | 201 ScreenToClient(edit_->m_hWnd, &client_position); |
225 int drop_position = edit_->CharFromPos(client_position); | 202 int drop_position = edit_->CharFromPos(client_position); |
226 if (edit_->in_drag()) { | 203 if (edit_->in_drag()) { |
227 // Our edit originated the drag, don't allow a drop if over the selected | 204 // Our edit originated the drag, don't allow a drop if over the selected |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 } | 932 } |
956 | 933 |
957 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { | 934 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { |
958 views::NativeViewHost* host = new views::NativeViewHost; | 935 views::NativeViewHost* host = new views::NativeViewHost; |
959 parent->AddChildView(host); | 936 parent->AddChildView(host); |
960 host->set_focus_view(parent); | 937 host->set_focus_view(parent); |
961 host->Attach(GetNativeView()); | 938 host->Attach(GetNativeView()); |
962 return host; | 939 return host; |
963 } | 940 } |
964 | 941 |
942 int AutocompleteEditViewWin::OnPerformDrop( | |
943 const views::DropTargetEvent& event) { | |
944 const ui::OSExchangeData& data = event.data(); | |
945 | |
946 if (data.HasURL()) { | |
947 GURL url; | |
948 string16 title; | |
949 if (data.GetURLAndTitle(&url, &title)) { | |
950 SetUserText(UTF8ToWide(url.spec())); | |
951 model()->AcceptInput(CURRENT_TAB, true); | |
952 return event.source_operations(); | |
sky
2011/02/11 01:06:07
I believe you need to return one type here, not al
Roger Tawa OOO till Jul 10th
2011/02/11 15:20:17
At line 183, effect is guaranteed to have only one
sky
2011/02/11 17:14:53
But isn't OnPerformDrop also forwarded from the to
Roger Tawa OOO till Jul 10th
2011/02/11 21:35:26
You are correct, I missed that. Fixed.
| |
953 } | |
954 } else if (data.HasString()) { | |
955 int string_drop_position = drop_highlight_position(); | |
956 string16 text; | |
957 if ((string_drop_position != -1 || !in_drag()) && data.GetString(&text)) { | |
958 DCHECK(string_drop_position == -1 || | |
959 ((string_drop_position >= 0) && | |
960 (string_drop_position <= GetTextLength()))); | |
961 if (in_drag()) { | |
962 if (event.source_operations()== ui::DragDropTypes::DRAG_MOVE) | |
963 MoveSelectedText(string_drop_position); | |
964 else | |
965 InsertText(string_drop_position, text); | |
966 } else { | |
967 PasteAndGo(CollapseWhitespace(text, true)); | |
968 } | |
969 return event.source_operations(); | |
970 } | |
971 } | |
972 | |
973 return ui::DragDropTypes::DRAG_NONE; | |
974 } | |
975 | |
965 void AutocompleteEditViewWin::PasteAndGo(const string16& text) { | 976 void AutocompleteEditViewWin::PasteAndGo(const string16& text) { |
966 if (CanPasteAndGo(text)) | 977 if (CanPasteAndGo(text)) |
967 model_->PasteAndGo(); | 978 model_->PasteAndGo(); |
968 } | 979 } |
969 | 980 |
970 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( | 981 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( |
971 const views::KeyEvent& e) { | 982 const views::KeyEvent& e) { |
972 ui::KeyboardCode key = e.key_code(); | 983 ui::KeyboardCode key = e.key_code(); |
973 // We don't process ALT + numpad digit as accelerators, they are used for | 984 // We don't process ALT + numpad digit as accelerators, they are used for |
974 // entering special characters. We do translate alt-home. | 985 // entering special characters. We do translate alt-home. |
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2582 // PosFromChar(i) might return 0 when i is greater than 1. | 2593 // PosFromChar(i) might return 0 when i is greater than 1. |
2583 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2594 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2584 } | 2595 } |
2585 | 2596 |
2586 bool AutocompleteEditViewWin::IsCaretAtEnd() const { | 2597 bool AutocompleteEditViewWin::IsCaretAtEnd() const { |
2587 long length = GetTextLength(); | 2598 long length = GetTextLength(); |
2588 CHARRANGE sel; | 2599 CHARRANGE sel; |
2589 GetSelection(sel); | 2600 GetSelection(sel); |
2590 return sel.cpMin == sel.cpMax && sel.cpMin == length; | 2601 return sel.cpMin == sel.cpMax && sel.cpMin == length; |
2591 } | 2602 } |
OLD | NEW |