| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <locale> | 7 #include <locale> |
| 8 | 8 |
| 9 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 10 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
| (...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 // modifying the result set that we're in the midst of using. For example, | 1245 // modifying the result set that we're in the midst of using. For example, |
| 1246 // if SetWindowTextAndCaretPos() was called due to the user clicking an | 1246 // if SetWindowTextAndCaretPos() was called due to the user clicking an |
| 1247 // entry in the popup, we're in the middle of executing SetSelectedLine(), | 1247 // entry in the popup, we're in the middle of executing SetSelectedLine(), |
| 1248 // and changing the results can cause checkfailures. | 1248 // and changing the results can cause checkfailures. |
| 1249 return DefWindowProc(message, wparam, lparam); | 1249 return DefWindowProc(message, wparam, lparam); |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 ScopedFreeze freeze(this, GetTextObjectModel()); | 1252 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1253 OnBeforePossibleChange(); | 1253 OnBeforePossibleChange(); |
| 1254 LRESULT result = DefWindowProc(message, wparam, lparam); | 1254 LRESULT result = DefWindowProc(message, wparam, lparam); |
| 1255 |
| 1256 // Some IMEs insert whitespace characters instead of input characters while |
| 1257 // they are composing text, and trimming these whitespace characters at the |
| 1258 // beginning of this control (in OnAfterPossibleChange()) prevents users from |
| 1259 // inputting text on these IMEs. |
| 1260 // To prevent this problem, we should not start auto-complete if the |
| 1261 // composition string starts with whitespace characters. |
| 1262 // (When we type a space key to insert a whitespace character, IMEs don't |
| 1263 // insert the whitespace character to their composition string but their |
| 1264 // result string. So, this code doesn't prevent us from updating autocomplete |
| 1265 // when we insert a whitespace character.) |
| 1266 if (lparam & GCS_COMPSTR) { |
| 1267 std::wstring text; |
| 1268 HIMC context = ImmGetContext(m_hWnd); |
| 1269 if (context) { |
| 1270 int size = ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); |
| 1271 if (size > 0) { |
| 1272 wchar_t* text_data = WriteInto(&text, size / sizeof(wchar_t) + 1); |
| 1273 if (text_data) |
| 1274 ImmGetCompositionString(context, GCS_COMPSTR, text_data, size); |
| 1275 } |
| 1276 ImmReleaseContext(m_hWnd, context); |
| 1277 } |
| 1278 if (!text.empty() && IsWhitespace(text[0])) |
| 1279 return result; |
| 1280 } |
| 1281 |
| 1255 if (!OnAfterPossibleChange() && (lparam & GCS_RESULTSTR)) { | 1282 if (!OnAfterPossibleChange() && (lparam & GCS_RESULTSTR)) { |
| 1256 // The result string changed, but the text in the popup didn't actually | 1283 // The result string changed, but the text in the popup didn't actually |
| 1257 // change. This means the user finalized the composition. Rerun | 1284 // change. This means the user finalized the composition. Rerun |
| 1258 // autocomplete so that we can now trigger inline autocomplete if | 1285 // autocomplete so that we can now trigger inline autocomplete if |
| 1259 // applicable. | 1286 // applicable. |
| 1260 // | 1287 // |
| 1261 // Note that if we're in the midst of losing focus, UpdatePopup() won't | 1288 // Note that if we're in the midst of losing focus, UpdatePopup() won't |
| 1262 // actually rerun autocomplete, but will just set local state correctly. | 1289 // actually rerun autocomplete, but will just set local state correctly. |
| 1263 UpdatePopup(); | 1290 UpdatePopup(); |
| 1264 } | 1291 } |
| (...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2404 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, | 2431 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, |
| 2405 IDS_PASTE_AND_GO); | 2432 IDS_PASTE_AND_GO); |
| 2406 context_menu_contents_->AddSeparator(); | 2433 context_menu_contents_->AddSeparator(); |
| 2407 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); | 2434 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); |
| 2408 context_menu_contents_->AddSeparator(); | 2435 context_menu_contents_->AddSeparator(); |
| 2409 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, | 2436 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, |
| 2410 IDS_EDIT_SEARCH_ENGINES); | 2437 IDS_EDIT_SEARCH_ENGINES); |
| 2411 } | 2438 } |
| 2412 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 2439 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
| 2413 } | 2440 } |
| OLD | NEW |