OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
6 | 6 |
7 #include <locale> | 7 #include <locale> |
8 | 8 |
9 #include "base/base_drag_source.h" | 9 #include "base/base_drag_source.h" |
10 #include "base/clipboard.h" | 10 #include "base/clipboard.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 UserMetrics::RecordAction(L"AcceptedKeyword", profile_); | 298 UserMetrics::RecordAction(L"AcceptedKeyword", profile_); |
299 template_url_model->IncrementUsageCount(template_url); | 299 template_url_model->IncrementUsageCount(template_url); |
300 } | 300 } |
301 | 301 |
302 // NOTE: We purposefully don't increment the usage count of the default search | 302 // NOTE: We purposefully don't increment the usage count of the default search |
303 // engine, if applicable; see comments in template_url.h. | 303 // engine, if applicable; see comments in template_url.h. |
304 } | 304 } |
305 | 305 |
306 void AutocompleteEditModel::AcceptKeyword() { | 306 void AutocompleteEditModel::AcceptKeyword() { |
307 view_->OnBeforePossibleChange(); | 307 view_->OnBeforePossibleChange(); |
| 308 // NOTE: We don't need the IME composition hack in SetWindowTextAndCaretPos() |
| 309 // here, because any active IME composition will eat <tab> characters, |
| 310 // preventing the user from using tab-to-search until the composition is |
| 311 // ended. |
308 view_->SetWindowText(L""); | 312 view_->SetWindowText(L""); |
309 is_keyword_hint_ = false; | 313 is_keyword_hint_ = false; |
310 keyword_ui_state_ = KEYWORD; | 314 keyword_ui_state_ = KEYWORD; |
311 view_->OnAfterPossibleChange(); | 315 view_->OnAfterPossibleChange(); |
312 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this | 316 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this |
313 // since the edit contents have disappeared. It | 317 // since the edit contents have disappeared. It |
314 // doesn't really matter, but we clear it to be | 318 // doesn't really matter, but we clear it to be |
315 // consistent. | 319 // consistent. |
316 UserMetrics::RecordAction(L"AcceptedKeywordHint", profile_); | 320 UserMetrics::RecordAction(L"AcceptedKeywordHint", profile_); |
317 } | 321 } |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 model_->SetUserText(text); | 894 model_->SetUserText(text); |
891 saved_selection_for_focus_change_.cpMin = -1; | 895 saved_selection_for_focus_change_.cpMin = -1; |
892 SetWindowTextAndCaretPos(display_text, display_text.length()); | 896 SetWindowTextAndCaretPos(display_text, display_text.length()); |
893 if (update_popup) | 897 if (update_popup) |
894 UpdatePopup(); | 898 UpdatePopup(); |
895 TextChanged(); | 899 TextChanged(); |
896 } | 900 } |
897 | 901 |
898 void AutocompleteEditView::SetWindowTextAndCaretPos(const std::wstring& text, | 902 void AutocompleteEditView::SetWindowTextAndCaretPos(const std::wstring& text, |
899 size_t caret_pos) { | 903 size_t caret_pos) { |
| 904 HIMC imm_context = ImmGetContext(m_hWnd); |
| 905 if (imm_context) { |
| 906 // In Windows Vista, SetWindowText() automatically completes any ongoing |
| 907 // IME composition, and updates the text of the underlying edit control. |
| 908 // In Windows XP, however, SetWindowText() gets applied to the IME |
| 909 // composition string if it exists, and doesn't update the underlying edit |
| 910 // control. To avoid this, we force the IME to complete any outstanding |
| 911 // compositions here. This is harmless in Vista and in cases where the IME |
| 912 // isn't composing. |
| 913 ImmNotifyIME(imm_context, NI_COMPOSITIONSTR, CPS_COMPLETE, 0); |
| 914 ImmReleaseContext(m_hWnd, imm_context); |
| 915 } |
| 916 |
900 SetWindowText(text.c_str()); | 917 SetWindowText(text.c_str()); |
901 PlaceCaretAt(caret_pos); | 918 PlaceCaretAt(caret_pos); |
902 } | 919 } |
903 | 920 |
904 void AutocompleteEditView::SelectAll(bool reversed) { | 921 void AutocompleteEditView::SelectAll(bool reversed) { |
905 if (reversed) | 922 if (reversed) |
906 SetSelection(GetTextLength(), 0); | 923 SetSelection(GetTextLength(), 0); |
907 else | 924 else |
908 SetSelection(0, GetTextLength()); | 925 SetSelection(0, GetTextLength()); |
909 } | 926 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 size_t user_text_length) { | 1054 size_t user_text_length) { |
1038 // Update the text and selection. Because this can be called repeatedly while | 1055 // Update the text and selection. Because this can be called repeatedly while |
1039 // typing, we've careful not to freeze the edit unless we really need to. | 1056 // typing, we've careful not to freeze the edit unless we really need to. |
1040 // Also, unlike in the temporary text case above, here we don't want to update | 1057 // Also, unlike in the temporary text case above, here we don't want to update |
1041 // the caret/selection unless we have to, since this might make the user's | 1058 // the caret/selection unless we have to, since this might make the user's |
1042 // caret position change without warning during typing. | 1059 // caret position change without warning during typing. |
1043 if (display_text == GetText()) | 1060 if (display_text == GetText()) |
1044 return false; | 1061 return false; |
1045 | 1062 |
1046 ScopedFreeze freeze(this, GetTextObjectModel()); | 1063 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1064 // NOTE: We don't need the IME composition hack in SetWindowTextAndCaretPos() |
| 1065 // here, because UpdatePopup() disables inline autocomplete when a |
| 1066 // composition is in progress, thus preventing us from reaching this code. |
1047 SetWindowText(display_text.c_str()); | 1067 SetWindowText(display_text.c_str()); |
1048 // Set a reversed selection to keep the caret in the same position, which | 1068 // Set a reversed selection to keep the caret in the same position, which |
1049 // avoids scrolling the user's text. | 1069 // avoids scrolling the user's text. |
1050 SetSelection(static_cast<LONG>(display_text.length()), | 1070 SetSelection(static_cast<LONG>(display_text.length()), |
1051 static_cast<LONG>(user_text_length)); | 1071 static_cast<LONG>(user_text_length)); |
1052 TextChanged(); | 1072 TextChanged(); |
1053 return true; | 1073 return true; |
1054 } | 1074 } |
1055 | 1075 |
1056 void AutocompleteEditView::OnRevertTemporaryText() { | 1076 void AutocompleteEditView::OnRevertTemporaryText() { |
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2412 } | 2432 } |
2413 | 2433 |
2414 void AutocompleteEditView::RepaintDropHighlight(int position) { | 2434 void AutocompleteEditView::RepaintDropHighlight(int position) { |
2415 if ((position != -1) && (position <= GetTextLength())) { | 2435 if ((position != -1) && (position <= GetTextLength())) { |
2416 const POINT min_loc(PosFromChar(position)); | 2436 const POINT min_loc(PosFromChar(position)); |
2417 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, | 2437 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, |
2418 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; | 2438 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; |
2419 InvalidateRect(&highlight_bounds, false); | 2439 InvalidateRect(&highlight_bounds, false); |
2420 } | 2440 } |
2421 } | 2441 } |
OLD | NEW |