From 685aa79c35e7e9de565ebb4d159b17db9d3e6900 Mon Sep 17 00:00:00 2001 From: "tkent@chromium.org" Date: Thu, 11 Mar 2010 06:31:57 +0000 Subject: Merge 34145 - Reverts my r4300 and refixes Issue 3156 and 13500. My r4300, which is a fix Issue 3156, has been causing regressions (Issue 9596, Issue 13500, Issue 29290, etc.) Every time when this change caused regressions, we added more code to Chromium and made Chromium code more complicated. So, I think it is better to revert this change once and find another solution for Issue 3156 rather than to add another workaround for Issue 29290. To look into Issue 3156 more deeply, it is caused by a recursive messagehandler call. When SetWindowText() is called while an IME is composing text, the IME calls SendMessage() to send a WM_IME_COMPOSITION message. When we receive this WM_IME_COMPOSITION message, it updates the omnibox and calls SetWindowText()... This recursive call caused not only Issue 3156 but also caused some other IME issues, such as Issue 13500. BUG=3156,13500,29290 TEST=On XP, open a new tab, set the IME to Hiragana, type 'c', and then click an entry in the popup. The browser should navigate and show the popup URL without a crash. TEST=Open Gmail, compose a new email (without using a tearoff window), set the IME to Hiragana, type 'c' in its message body, and wait for the draft autosaving. The browser should show the 'c' character. Review URL: http://codereview.chromium.org/467015 TBR=hbono@chromium.org BUG=3156,13500,29290 Review URL: http://codereview.chromium.org/865001 git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@41254 0039d316-1c4b-4281-b951-d872f2087c98 --- .../autocomplete/autocomplete_edit_view_win.cc | 37 ++++++++-------------- .../autocomplete/autocomplete_edit_view_win.h | 2 ++ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index aea2a86..50ca9a0 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -616,26 +616,6 @@ void AutocompleteEditViewWin::SetUserText(const std::wstring& text, void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) { - HIMC imm_context = ImmGetContext(m_hWnd); - if (imm_context) { - // In Windows Vista, SetWindowText() automatically cancels any ongoing - // IME composition, and updates the text of the underlying edit control. - // In Windows XP, however, SetWindowText() gets applied to the IME - // composition string if it exists, and doesn't update the underlying edit - // control. To avoid this, we force the IME to cancel any outstanding - // compositions here. This is harmless in Vista and in cases where the IME - // isn't composing. - - // NOTE: We MUST ignore messages like WM_IME_COMPOSITION that may be sent as - // a result of doing this. Until the SetWindowText() call below, the - // underlying edit (on XP) has out-of-date text in it; for problems this can - // cause, see OnImeComposition(). - ignore_ime_messages_ = true; - ImmNotifyIME(imm_context, NI_COMPOSITIONSTR, CPS_CANCEL, 0); - ImmReleaseContext(m_hWnd, imm_context); - ignore_ime_messages_ = false; - } - SetWindowText(text.c_str()); PlaceCaretAt(caret_pos); } @@ -802,9 +782,6 @@ bool AutocompleteEditViewWin::OnInlineAutocompleteTextMaybeChanged( return false; ScopedFreeze freeze(this, GetTextObjectModel()); - // NOTE: We don't need the IME composition hack in SetWindowTextAndCaretPos() - // here, because UpdatePopup() disables inline autocomplete when a - // composition is in progress, thus preventing us from reaching this code. SetWindowText(display_text.c_str()); // Set a reversed selection to keep the caret in the same position, which // avoids scrolling the user's text. @@ -1717,6 +1694,20 @@ void AutocompleteEditViewWin::OnSetFocus(HWND focus_wnd) { SetMsgHandled(false); } +LRESULT AutocompleteEditViewWin::OnSetText(const wchar_t* text) { + // Ignore all IME messages while we process this WM_SETTEXT message. + // When SetWindowText() is called while an IME is composing text, the IME + // calls SendMessage() to send a WM_IME_COMPOSITION message. When we receive + // this WM_IME_COMPOSITION message, we update the omnibox and may call + // SetWindowText() again. To stop this recursive message-handler call, we + // stop updating the omnibox while we process a WM_SETTEXT message. + // We wouldn't need to do this update anyway, because either we're in the + // middle of updating the omnibox already or the caller of SetWindowText() + // is going to update the omnibox next. + AutoReset auto_reset_ignore_ime_messages(&ignore_ime_messages_, true); + return DefWindowProc(WM_SETTEXT, 0, reinterpret_cast(text)); +} + void AutocompleteEditViewWin::OnSysChar(TCHAR ch, UINT repeat_count, UINT flags) { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index 0d20df0..8242ce2 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -176,6 +176,7 @@ class AutocompleteEditViewWin MSG_WM_RBUTTONDOWN(OnNonLButtonDown) MSG_WM_RBUTTONUP(OnNonLButtonUp) MSG_WM_SETFOCUS(OnSetFocus) + MSG_WM_SETTEXT(OnSetText) MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down MSG_WM_SYSKEYDOWN(OnKeyDown) MSG_WM_SYSKEYUP(OnKeyUp) @@ -259,6 +260,7 @@ class AutocompleteEditViewWin void OnPaint(HDC bogus_hdc); void OnPaste(); void OnSetFocus(HWND focus_wnd); + LRESULT OnSetText(const wchar_t* text); void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags); void OnWindowPosChanging(WINDOWPOS* window_pos); -- cgit v1.1