Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 467015: Reverts my r4300.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 model_->SetUserText(text); 610 model_->SetUserText(text);
611 saved_selection_for_focus_change_.cpMin = -1; 611 saved_selection_for_focus_change_.cpMin = -1;
612 SetWindowTextAndCaretPos(display_text, display_text.length()); 612 SetWindowTextAndCaretPos(display_text, display_text.length());
613 if (update_popup) 613 if (update_popup)
614 UpdatePopup(); 614 UpdatePopup();
615 TextChanged(); 615 TextChanged();
616 } 616 }
617 617
618 void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text, 618 void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text,
619 size_t caret_pos) { 619 size_t caret_pos) {
620 HIMC imm_context = ImmGetContext(m_hWnd);
621 if (imm_context) {
622 // In Windows Vista, SetWindowText() automatically cancels any ongoing
623 // IME composition, and updates the text of the underlying edit control.
624 // In Windows XP, however, SetWindowText() gets applied to the IME
625 // composition string if it exists, and doesn't update the underlying edit
626 // control. To avoid this, we force the IME to cancel any outstanding
627 // compositions here. This is harmless in Vista and in cases where the IME
628 // isn't composing.
629
630 // NOTE: We MUST ignore messages like WM_IME_COMPOSITION that may be sent as
631 // a result of doing this. Until the SetWindowText() call below, the
632 // underlying edit (on XP) has out-of-date text in it; for problems this can
633 // cause, see OnImeComposition().
634 ignore_ime_messages_ = true;
635 ImmNotifyIME(imm_context, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
636 ImmReleaseContext(m_hWnd, imm_context);
637 ignore_ime_messages_ = false;
638 }
639
640 SetWindowText(text.c_str()); 620 SetWindowText(text.c_str());
641 PlaceCaretAt(caret_pos); 621 PlaceCaretAt(caret_pos);
642 } 622 }
643 623
644 void AutocompleteEditViewWin::SetForcedQuery() { 624 void AutocompleteEditViewWin::SetForcedQuery() {
645 const std::wstring current_text(GetText()); 625 const std::wstring current_text(GetText());
646 if (current_text.empty() || (current_text[0] != '?')) 626 if (current_text.empty() || (current_text[0] != '?'))
647 SetUserText(L"?"); 627 SetUserText(L"?");
648 else 628 else
649 SetSelection(current_text.length(), 1); 629 SetSelection(current_text.length(), 1);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 size_t user_text_length) { 776 size_t user_text_length) {
797 // Update the text and selection. Because this can be called repeatedly while 777 // Update the text and selection. Because this can be called repeatedly while
798 // typing, we've careful not to freeze the edit unless we really need to. 778 // typing, we've careful not to freeze the edit unless we really need to.
799 // Also, unlike in the temporary text case above, here we don't want to update 779 // Also, unlike in the temporary text case above, here we don't want to update
800 // the caret/selection unless we have to, since this might make the user's 780 // the caret/selection unless we have to, since this might make the user's
801 // caret position change without warning during typing. 781 // caret position change without warning during typing.
802 if (display_text == GetText()) 782 if (display_text == GetText())
803 return false; 783 return false;
804 784
805 ScopedFreeze freeze(this, GetTextObjectModel()); 785 ScopedFreeze freeze(this, GetTextObjectModel());
806 // NOTE: We don't need the IME composition hack in SetWindowTextAndCaretPos()
807 // here, because UpdatePopup() disables inline autocomplete when a
808 // composition is in progress, thus preventing us from reaching this code.
809 SetWindowText(display_text.c_str()); 786 SetWindowText(display_text.c_str());
810 // Set a reversed selection to keep the caret in the same position, which 787 // Set a reversed selection to keep the caret in the same position, which
811 // avoids scrolling the user's text. 788 // avoids scrolling the user's text.
812 SetSelection(static_cast<LONG>(display_text.length()), 789 SetSelection(static_cast<LONG>(display_text.length()),
813 static_cast<LONG>(user_text_length)); 790 static_cast<LONG>(user_text_length));
814 TextChanged(); 791 TextChanged();
815 return true; 792 return true;
816 } 793 }
817 794
818 void AutocompleteEditViewWin::OnRevertTemporaryText() { 795 void AutocompleteEditViewWin::OnRevertTemporaryText() {
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 1688
1712 // Restore saved selection if available. 1689 // Restore saved selection if available.
1713 if (saved_selection_for_focus_change_.cpMin != -1) { 1690 if (saved_selection_for_focus_change_.cpMin != -1) {
1714 SetSelectionRange(saved_selection_for_focus_change_); 1691 SetSelectionRange(saved_selection_for_focus_change_);
1715 saved_selection_for_focus_change_.cpMin = -1; 1692 saved_selection_for_focus_change_.cpMin = -1;
1716 } 1693 }
1717 1694
1718 SetMsgHandled(false); 1695 SetMsgHandled(false);
1719 } 1696 }
1720 1697
1698 LRESULT AutocompleteEditViewWin::OnSetText(const wchar_t* text) {
1699 // Ignore all IME messages while we process this WM_SETTEXT message.
1700 // When SetWindowText() is called while an IME is composing text, the IME
1701 // calls SendMessage() to send a WM_IME_COMPOSITION message. When we receive
1702 // this WM_IME_COMPOSITION message, we update the omnibox and may call
1703 // SetWindowText() again. To stop this recursive message-handler call, we
1704 // stop updating the omnibox while we process a WM_SETTEXT message.
1705 // We wouldn't need to do this update anyway, because either we're in the
1706 // middle of updating the omnibox already or the caller of SetWindowText()
1707 // is going to update the omnibox next.
1708 AutoReset auto_reset_ignore_ime_messages(&ignore_ime_messages_, true);
1709 return DefWindowProc(WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
1710 }
1711
1721 void AutocompleteEditViewWin::OnSysChar(TCHAR ch, 1712 void AutocompleteEditViewWin::OnSysChar(TCHAR ch,
1722 UINT repeat_count, 1713 UINT repeat_count,
1723 UINT flags) { 1714 UINT flags) {
1724 // Nearly all alt-<xxx> combos result in beeping rather than doing something 1715 // Nearly all alt-<xxx> combos result in beeping rather than doing something
1725 // useful, so we discard most. Exceptions: 1716 // useful, so we discard most. Exceptions:
1726 // * ctrl-alt-<xxx>, which is sometimes important, generates WM_CHAR instead 1717 // * ctrl-alt-<xxx>, which is sometimes important, generates WM_CHAR instead
1727 // of WM_SYSCHAR, so it doesn't need to be handled here. 1718 // of WM_SYSCHAR, so it doesn't need to be handled here.
1728 // * alt-space gets translated by the default WM_SYSCHAR handler to a 1719 // * alt-space gets translated by the default WM_SYSCHAR handler to a
1729 // WM_SYSCOMMAND to open the application context menu, so we need to allow 1720 // WM_SYSCOMMAND to open the application context menu, so we need to allow
1730 // it through. 1721 // it through.
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, 2423 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO,
2433 IDS_PASTE_AND_GO); 2424 IDS_PASTE_AND_GO);
2434 context_menu_contents_->AddSeparator(); 2425 context_menu_contents_->AddSeparator();
2435 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); 2426 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL);
2436 context_menu_contents_->AddSeparator(); 2427 context_menu_contents_->AddSeparator();
2437 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, 2428 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES,
2438 IDS_EDIT_SEARCH_ENGINES); 2429 IDS_EDIT_SEARCH_ENGINES);
2439 } 2430 }
2440 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); 2431 context_menu_.reset(new views::Menu2(context_menu_contents_.get()));
2441 } 2432 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698