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 |
11 #include <richedit.h> | 11 #include <richedit.h> |
12 #include <textserv.h> | 12 #include <textserv.h> |
13 | 13 |
14 #include "app/keyboard_codes.h" | 14 #include "app/keyboard_codes.h" |
15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
16 #include "app/l10n_util_win.h" | 16 #include "app/l10n_util_win.h" |
17 #include "app/os_exchange_data.h" | |
18 #include "app/os_exchange_data_provider_win.h" | |
19 #include "app/win/drag_source.h" | 17 #include "app/win/drag_source.h" |
20 #include "app/win/drop_target.h" | 18 #include "app/win/drop_target.h" |
21 #include "app/win/iat_patch_function.h" | 19 #include "app/win/iat_patch_function.h" |
22 #include "app/win/win_util.h" | 20 #include "app/win/win_util.h" |
23 #include "base/auto_reset.h" | 21 #include "base/auto_reset.h" |
24 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
25 #include "base/i18n/rtl.h" | 23 #include "base/i18n/rtl.h" |
26 #include "base/lazy_instance.h" | 24 #include "base/lazy_instance.h" |
27 #include "base/ref_counted.h" | 25 #include "base/ref_counted.h" |
28 #include "base/string_util.h" | 26 #include "base/string_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
43 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 41 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
44 #include "chrome/common/notification_service.h" | 42 #include "chrome/common/notification_service.h" |
45 #include "googleurl/src/url_util.h" | 43 #include "googleurl/src/url_util.h" |
46 #include "gfx/canvas.h" | 44 #include "gfx/canvas.h" |
47 #include "gfx/canvas_skia.h" | 45 #include "gfx/canvas_skia.h" |
48 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
49 #include "net/base/escape.h" | 47 #include "net/base/escape.h" |
50 #include "skia/ext/skia_utils_win.h" | 48 #include "skia/ext/skia_utils_win.h" |
51 #include "ui/base/clipboard/clipboard.h" | 49 #include "ui/base/clipboard/clipboard.h" |
52 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 50 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 51 #include "ui/base/dragdrop/os_exchange_data.h" |
| 52 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
53 #include "views/drag_utils.h" | 53 #include "views/drag_utils.h" |
54 #include "views/focus/focus_util_win.h" | 54 #include "views/focus/focus_util_win.h" |
55 #include "views/widget/widget.h" | 55 #include "views/widget/widget.h" |
56 | 56 |
57 #pragma comment(lib, "oleacc.lib") // Needed for accessibility support. | 57 #pragma comment(lib, "oleacc.lib") // Needed for accessibility support. |
58 #pragma comment(lib, "riched20.lib") // Needed for the richedit control. | 58 #pragma comment(lib, "riched20.lib") // Needed for the richedit control. |
59 | 59 |
60 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
61 // AutocompleteEditModel | 61 // AutocompleteEditModel |
62 | 62 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 : app::win::DropTarget(edit->m_hWnd), | 122 : app::win::DropTarget(edit->m_hWnd), |
123 edit_(edit), | 123 edit_(edit), |
124 drag_has_url_(false), | 124 drag_has_url_(false), |
125 drag_has_string_(false) { | 125 drag_has_string_(false) { |
126 } | 126 } |
127 | 127 |
128 DWORD EditDropTarget::OnDragEnter(IDataObject* data_object, | 128 DWORD EditDropTarget::OnDragEnter(IDataObject* data_object, |
129 DWORD key_state, | 129 DWORD key_state, |
130 POINT cursor_position, | 130 POINT cursor_position, |
131 DWORD effect) { | 131 DWORD effect) { |
132 OSExchangeData os_data(new OSExchangeDataProviderWin(data_object)); | 132 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object)); |
133 drag_has_url_ = os_data.HasURL(); | 133 drag_has_url_ = os_data.HasURL(); |
134 drag_has_string_ = !drag_has_url_ && os_data.HasString(); | 134 drag_has_string_ = !drag_has_url_ && os_data.HasString(); |
135 if (drag_has_url_) { | 135 if (drag_has_url_) { |
136 if (edit_->in_drag()) { | 136 if (edit_->in_drag()) { |
137 // The edit we're associated with originated the drag. No point in | 137 // The edit we're associated with originated the drag. No point in |
138 // allowing the user to drop back on us. | 138 // allowing the user to drop back on us. |
139 drag_has_url_ = false; | 139 drag_has_url_ = false; |
140 } | 140 } |
141 // NOTE: it would be nice to visually show all the text is going to | 141 // NOTE: it would be nice to visually show all the text is going to |
142 // be replaced by selecting all, but this caused painting problems. In | 142 // be replaced by selecting all, but this caused painting problems. In |
(...skipping 29 matching lines...) Expand all Loading... |
172 } | 172 } |
173 | 173 |
174 void EditDropTarget::OnDragLeave(IDataObject* data_object) { | 174 void EditDropTarget::OnDragLeave(IDataObject* data_object) { |
175 ResetDropHighlights(); | 175 ResetDropHighlights(); |
176 } | 176 } |
177 | 177 |
178 DWORD EditDropTarget::OnDrop(IDataObject* data_object, | 178 DWORD EditDropTarget::OnDrop(IDataObject* data_object, |
179 DWORD key_state, | 179 DWORD key_state, |
180 POINT cursor_position, | 180 POINT cursor_position, |
181 DWORD effect) { | 181 DWORD effect) { |
182 OSExchangeData os_data(new OSExchangeDataProviderWin(data_object)); | 182 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object)); |
183 | 183 |
184 if (drag_has_url_) { | 184 if (drag_has_url_) { |
185 GURL url; | 185 GURL url; |
186 std::wstring title; | 186 std::wstring title; |
187 if (os_data.GetURLAndTitle(&url, &title)) { | 187 if (os_data.GetURLAndTitle(&url, &title)) { |
188 edit_->SetUserText(UTF8ToWide(url.spec())); | 188 edit_->SetUserText(UTF8ToWide(url.spec())); |
189 edit_->model()->AcceptInput(CURRENT_TAB, true); | 189 edit_->model()->AcceptInput(CURRENT_TAB, true); |
190 return CopyOrLinkDropEffect(effect); | 190 return CopyOrLinkDropEffect(effect); |
191 } | 191 } |
192 } else if (drag_has_string_) { | 192 } else if (drag_has_string_) { |
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2411 reinterpret_cast<void**>(&text_object_model_)); | 2411 reinterpret_cast<void**>(&text_object_model_)); |
2412 } | 2412 } |
2413 } | 2413 } |
2414 return text_object_model_; | 2414 return text_object_model_; |
2415 } | 2415 } |
2416 | 2416 |
2417 void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { | 2417 void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { |
2418 if (initiated_drag_ || !app::win::IsDrag(click_point_[kLeft], point)) | 2418 if (initiated_drag_ || !app::win::IsDrag(click_point_[kLeft], point)) |
2419 return; | 2419 return; |
2420 | 2420 |
2421 OSExchangeData data; | 2421 ui::OSExchangeData data; |
2422 | 2422 |
2423 DWORD supported_modes = DROPEFFECT_COPY; | 2423 DWORD supported_modes = DROPEFFECT_COPY; |
2424 | 2424 |
2425 CHARRANGE sel; | 2425 CHARRANGE sel; |
2426 GetSelection(sel); | 2426 GetSelection(sel); |
2427 | 2427 |
2428 // We're about to start a drag session, but the edit is expecting a mouse up | 2428 // We're about to start a drag session, but the edit is expecting a mouse up |
2429 // that it uses to reset internal state. If we don't send a mouse up now, | 2429 // that it uses to reset internal state. If we don't send a mouse up now, |
2430 // when the mouse moves back into the edit the edit will reset the selection. | 2430 // when the mouse moves back into the edit the edit will reset the selection. |
2431 // So, we send the event now which resets the selection. We then restore the | 2431 // So, we send the event now which resets the selection. We then restore the |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2463 supported_modes |= DROPEFFECT_MOVE; | 2463 supported_modes |= DROPEFFECT_MOVE; |
2464 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"), | 2464 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"), |
2465 model_->profile()); | 2465 model_->profile()); |
2466 } | 2466 } |
2467 | 2467 |
2468 data.SetString(text_to_write); | 2468 data.SetString(text_to_write); |
2469 | 2469 |
2470 scoped_refptr<app::win::DragSource> drag_source(new app::win::DragSource); | 2470 scoped_refptr<app::win::DragSource> drag_source(new app::win::DragSource); |
2471 DWORD dropped_mode; | 2471 DWORD dropped_mode; |
2472 AutoReset<bool> auto_reset_in_drag(&in_drag_, true); | 2472 AutoReset<bool> auto_reset_in_drag(&in_drag_, true); |
2473 if (DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source, | 2473 if (DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), |
2474 supported_modes, &dropped_mode) == DRAGDROP_S_DROP) { | 2474 drag_source, supported_modes, &dropped_mode) == |
| 2475 DRAGDROP_S_DROP) { |
2475 if ((dropped_mode == DROPEFFECT_MOVE) && (start_text == GetText())) { | 2476 if ((dropped_mode == DROPEFFECT_MOVE) && (start_text == GetText())) { |
2476 ScopedFreeze freeze(this, GetTextObjectModel()); | 2477 ScopedFreeze freeze(this, GetTextObjectModel()); |
2477 OnBeforePossibleChange(); | 2478 OnBeforePossibleChange(); |
2478 SetSelectionRange(sel); | 2479 SetSelectionRange(sel); |
2479 ReplaceSel(L"", true); | 2480 ReplaceSel(L"", true); |
2480 OnAfterPossibleChange(); | 2481 OnAfterPossibleChange(); |
2481 } | 2482 } |
2482 // else case, not a move or it was a move and the drop was on us. | 2483 // else case, not a move or it was a move and the drop was on us. |
2483 // If the drop was on us, EditDropTarget took care of the move so that | 2484 // If the drop was on us, EditDropTarget took care of the move so that |
2484 // we don't have to delete the text. | 2485 // we don't have to delete the text. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 | 2610 |
2610 bool AutocompleteEditViewWin::IsImeComposing() const { | 2611 bool AutocompleteEditViewWin::IsImeComposing() const { |
2611 bool ime_composing = false; | 2612 bool ime_composing = false; |
2612 HIMC context = ImmGetContext(m_hWnd); | 2613 HIMC context = ImmGetContext(m_hWnd); |
2613 if (context) { | 2614 if (context) { |
2614 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); | 2615 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); |
2615 ImmReleaseContext(m_hWnd, context); | 2616 ImmReleaseContext(m_hWnd, context); |
2616 } | 2617 } |
2617 return ime_composing; | 2618 return ime_composing; |
2618 } | 2619 } |
OLD | NEW |