| 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 <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/clipboard/clipboard.h" | 14 #include "app/clipboard/clipboard.h" |
| 15 #include "app/clipboard/scoped_clipboard_writer.h" | 15 #include "app/clipboard/scoped_clipboard_writer.h" |
| 16 #include "app/keyboard_codes.h" | 16 #include "app/keyboard_codes.h" |
| 17 #include "app/l10n_util.h" | 17 #include "app/l10n_util.h" |
| 18 #include "app/l10n_util_win.h" | 18 #include "app/l10n_util_win.h" |
| 19 #include "app/os_exchange_data.h" | 19 #include "app/os_exchange_data.h" |
| 20 #include "app/os_exchange_data_provider_win.h" | 20 #include "app/os_exchange_data_provider_win.h" |
| 21 #include "app/win_util.h" | 21 #include "app/win_util.h" |
| 22 #include "app/win/drag_source.h" |
| 23 #include "app/win/drop_target.h" |
| 22 #include "app/win/iat_patch_function.h" | 24 #include "app/win/iat_patch_function.h" |
| 23 #include "base/auto_reset.h" | 25 #include "base/auto_reset.h" |
| 24 #include "base/base_drag_source.h" | |
| 25 #include "base/base_drop_target.h" | |
| 26 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
| 27 #include "base/i18n/rtl.h" | 27 #include "base/i18n/rtl.h" |
| 28 #include "base/lazy_instance.h" | 28 #include "base/lazy_instance.h" |
| 29 #include "base/ref_counted.h" | 29 #include "base/ref_counted.h" |
| 30 #include "base/string_util.h" | 30 #include "base/string_util.h" |
| 31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
| 32 #include "chrome/app/chrome_dll_resource.h" | 32 #include "chrome/app/chrome_dll_resource.h" |
| 33 #include "chrome/browser/autocomplete/autocomplete_accessibility.h" | 33 #include "chrome/browser/autocomplete/autocomplete_accessibility.h" |
| 34 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 34 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 35 #include "chrome/browser/autocomplete/keyword_provider.h" | 35 #include "chrome/browser/autocomplete/keyword_provider.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 // AutocompleteEditModel | 60 // AutocompleteEditModel |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 // EditDropTarget is the IDropTarget implementation installed on | 64 // EditDropTarget is the IDropTarget implementation installed on |
| 65 // AutocompleteEditViewWin. EditDropTarget prefers URL over plain text. A drop | 65 // AutocompleteEditViewWin. EditDropTarget prefers URL over plain text. A drop |
| 66 // of a URL replaces all the text of the edit and navigates immediately to the | 66 // of a URL replaces all the text of the edit and navigates immediately to the |
| 67 // URL. A drop of plain text from the same edit either copies or moves the | 67 // URL. A drop of plain text from the same edit either copies or moves the |
| 68 // selected text, and a drop of plain text from a source other than the edit | 68 // selected text, and a drop of plain text from a source other than the edit |
| 69 // does a paste and go. | 69 // does a paste and go. |
| 70 class EditDropTarget : public BaseDropTarget { | 70 class EditDropTarget : public app::win::DropTarget { |
| 71 public: | 71 public: |
| 72 explicit EditDropTarget(AutocompleteEditViewWin* edit); | 72 explicit EditDropTarget(AutocompleteEditViewWin* edit); |
| 73 | 73 |
| 74 protected: | 74 protected: |
| 75 virtual DWORD OnDragEnter(IDataObject* data_object, | 75 virtual DWORD OnDragEnter(IDataObject* data_object, |
| 76 DWORD key_state, | 76 DWORD key_state, |
| 77 POINT cursor_position, | 77 POINT cursor_position, |
| 78 DWORD effect); | 78 DWORD effect); |
| 79 virtual DWORD OnDragOver(IDataObject* data_object, | 79 virtual DWORD OnDragOver(IDataObject* data_object, |
| 80 DWORD key_state, | 80 DWORD key_state, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 111 // DROPEFFECTS. We prefer copy over link. | 111 // DROPEFFECTS. We prefer copy over link. |
| 112 DWORD CopyOrLinkDropEffect(DWORD effect) { | 112 DWORD CopyOrLinkDropEffect(DWORD effect) { |
| 113 if (effect & DROPEFFECT_COPY) | 113 if (effect & DROPEFFECT_COPY) |
| 114 return DROPEFFECT_COPY; | 114 return DROPEFFECT_COPY; |
| 115 if (effect & DROPEFFECT_LINK) | 115 if (effect & DROPEFFECT_LINK) |
| 116 return DROPEFFECT_LINK; | 116 return DROPEFFECT_LINK; |
| 117 return DROPEFFECT_NONE; | 117 return DROPEFFECT_NONE; |
| 118 } | 118 } |
| 119 | 119 |
| 120 EditDropTarget::EditDropTarget(AutocompleteEditViewWin* edit) | 120 EditDropTarget::EditDropTarget(AutocompleteEditViewWin* edit) |
| 121 : BaseDropTarget(edit->m_hWnd), | 121 : app::win::DropTarget(edit->m_hWnd), |
| 122 edit_(edit), | 122 edit_(edit), |
| 123 drag_has_url_(false), | 123 drag_has_url_(false), |
| 124 drag_has_string_(false) { | 124 drag_has_string_(false) { |
| 125 } | 125 } |
| 126 | 126 |
| 127 DWORD EditDropTarget::OnDragEnter(IDataObject* data_object, | 127 DWORD EditDropTarget::OnDragEnter(IDataObject* data_object, |
| 128 DWORD key_state, | 128 DWORD key_state, |
| 129 POINT cursor_position, | 129 POINT cursor_position, |
| 130 DWORD effect) { | 130 DWORD effect) { |
| 131 OSExchangeData os_data(new OSExchangeDataProviderWin(data_object)); | 131 OSExchangeData os_data(new OSExchangeDataProviderWin(data_object)); |
| (...skipping 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragURL"), | 2412 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragURL"), |
| 2413 model_->profile()); | 2413 model_->profile()); |
| 2414 } else { | 2414 } else { |
| 2415 supported_modes |= DROPEFFECT_MOVE; | 2415 supported_modes |= DROPEFFECT_MOVE; |
| 2416 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"), | 2416 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"), |
| 2417 model_->profile()); | 2417 model_->profile()); |
| 2418 } | 2418 } |
| 2419 | 2419 |
| 2420 data.SetString(text_to_write); | 2420 data.SetString(text_to_write); |
| 2421 | 2421 |
| 2422 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); | 2422 scoped_refptr<app::win::DragSource> drag_source(new app::win::DragSource); |
| 2423 DWORD dropped_mode; | 2423 DWORD dropped_mode; |
| 2424 AutoReset<bool> auto_reset_in_drag(&in_drag_, true); | 2424 AutoReset<bool> auto_reset_in_drag(&in_drag_, true); |
| 2425 if (DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source, | 2425 if (DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source, |
| 2426 supported_modes, &dropped_mode) == DRAGDROP_S_DROP) { | 2426 supported_modes, &dropped_mode) == DRAGDROP_S_DROP) { |
| 2427 if ((dropped_mode == DROPEFFECT_MOVE) && (start_text == GetText())) { | 2427 if ((dropped_mode == DROPEFFECT_MOVE) && (start_text == GetText())) { |
| 2428 ScopedFreeze freeze(this, GetTextObjectModel()); | 2428 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2429 OnBeforePossibleChange(); | 2429 OnBeforePossibleChange(); |
| 2430 SetSelectionRange(sel); | 2430 SetSelectionRange(sel); |
| 2431 ReplaceSel(L"", true); | 2431 ReplaceSel(L"", true); |
| 2432 OnAfterPossibleChange(); | 2432 OnAfterPossibleChange(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2550 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2551 } | 2551 } |
| 2552 | 2552 |
| 2553 int AutocompleteEditViewWin::WidthNeededToDisplay(const std::wstring& text) { | 2553 int AutocompleteEditViewWin::WidthNeededToDisplay(const std::wstring& text) { |
| 2554 // Use font_.GetStringWidth() instead of | 2554 // Use font_.GetStringWidth() instead of |
| 2555 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2555 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2556 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2556 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
| 2557 // PosFromChar(i) might return 0 when i is greater than 1. | 2557 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2558 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2558 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2559 } | 2559 } |
| OLD | NEW |