| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_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 |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 void OmniboxViewWin::SetUserText(const string16& text) { | 668 void OmniboxViewWin::SetUserText(const string16& text) { |
| 669 SetUserText(text, text, true); | 669 SetUserText(text, text, true); |
| 670 } | 670 } |
| 671 | 671 |
| 672 void OmniboxViewWin::SetUserText(const string16& text, | 672 void OmniboxViewWin::SetUserText(const string16& text, |
| 673 const string16& display_text, | 673 const string16& display_text, |
| 674 bool update_popup) { | 674 bool update_popup) { |
| 675 ScopedFreeze freeze(this, GetTextObjectModel()); | 675 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 676 model_->SetUserText(text); | 676 model_->SetUserText(text); |
| 677 saved_selection_for_focus_change_.cpMin = -1; | 677 saved_selection_for_focus_change_.cpMin = -1; |
| 678 SetWindowTextAndCaretPos(display_text, display_text.length()); | 678 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
| 679 if (update_popup) | 679 true); |
| 680 UpdatePopup(); | |
| 681 TextChanged(); | |
| 682 } | 680 } |
| 683 | 681 |
| 684 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, | 682 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, |
| 685 size_t caret_pos) { | 683 size_t caret_pos, |
| 684 bool update_popup, |
| 685 bool notify_text_changed) { |
| 686 SetWindowText(text.c_str()); | 686 SetWindowText(text.c_str()); |
| 687 PlaceCaretAt(caret_pos); | 687 PlaceCaretAt(caret_pos); |
| 688 |
| 689 if (update_popup) |
| 690 UpdatePopup(); |
| 691 |
| 692 if (notify_text_changed) |
| 693 TextChanged(); |
| 688 } | 694 } |
| 689 | 695 |
| 690 void OmniboxViewWin::SetForcedQuery() { | 696 void OmniboxViewWin::SetForcedQuery() { |
| 691 const string16 current_text(GetText()); | 697 const string16 current_text(GetText()); |
| 692 const size_t start = current_text.find_first_not_of(kWhitespaceWide); | 698 const size_t start = current_text.find_first_not_of(kWhitespaceWide); |
| 693 if (start == string16::npos || (current_text[start] != '?')) | 699 if (start == string16::npos || (current_text[start] != '?')) |
| 694 SetUserText(L"?"); | 700 SetUserText(L"?"); |
| 695 else | 701 else |
| 696 SetSelection(current_text.length(), start + 1); | 702 SetSelection(current_text.length(), start + 1); |
| 697 } | 703 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 717 void OmniboxViewWin::SelectAll(bool reversed) { | 723 void OmniboxViewWin::SelectAll(bool reversed) { |
| 718 if (reversed) | 724 if (reversed) |
| 719 SetSelection(GetTextLength(), 0); | 725 SetSelection(GetTextLength(), 0); |
| 720 else | 726 else |
| 721 SetSelection(0, GetTextLength()); | 727 SetSelection(0, GetTextLength()); |
| 722 } | 728 } |
| 723 | 729 |
| 724 void OmniboxViewWin::RevertAll() { | 730 void OmniboxViewWin::RevertAll() { |
| 725 ScopedFreeze freeze(this, GetTextObjectModel()); | 731 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 726 ClosePopup(); | 732 ClosePopup(); |
| 733 saved_selection_for_focus_change_.cpMin = -1; |
| 727 model_->Revert(); | 734 model_->Revert(); |
| 728 saved_selection_for_focus_change_.cpMin = -1; | |
| 729 TextChanged(); | |
| 730 } | 735 } |
| 731 | 736 |
| 732 void OmniboxViewWin::UpdatePopup() { | 737 void OmniboxViewWin::UpdatePopup() { |
| 733 ScopedFreeze freeze(this, GetTextObjectModel()); | 738 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 734 model_->SetInputInProgress(true); | 739 model_->SetInputInProgress(true); |
| 735 | 740 |
| 736 // Don't allow the popup to open while the candidate window is open, so | 741 // Don't allow the popup to open while the candidate window is open, so |
| 737 // they don't overlap. | 742 // they don't overlap. |
| 738 if (ime_candidate_window_open_) | 743 if (ime_candidate_window_open_) |
| 739 return; | 744 return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 GetSelection(original_selection_); | 819 GetSelection(original_selection_); |
| 815 | 820 |
| 816 // Set new text and cursor position. Sometimes this does extra work (e.g. | 821 // Set new text and cursor position. Sometimes this does extra work (e.g. |
| 817 // when the new text and the old text are identical), but it's only called | 822 // when the new text and the old text are identical), but it's only called |
| 818 // when the user manually changes the selected line in the popup, so that's | 823 // when the user manually changes the selected line in the popup, so that's |
| 819 // not really a problem. Also, even when the text hasn't changed we'd want to | 824 // not really a problem. Also, even when the text hasn't changed we'd want to |
| 820 // update the caret, because if the user had the cursor in the middle of the | 825 // update the caret, because if the user had the cursor in the middle of the |
| 821 // text and then arrowed to another entry with the same text, we'd still want | 826 // text and then arrowed to another entry with the same text, we'd still want |
| 822 // to move the caret. | 827 // to move the caret. |
| 823 ScopedFreeze freeze(this, GetTextObjectModel()); | 828 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 824 SetWindowTextAndCaretPos(display_text, display_text.length()); | 829 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
| 825 TextChanged(); | |
| 826 } | 830 } |
| 827 | 831 |
| 828 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( | 832 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( |
| 829 const string16& display_text, | 833 const string16& display_text, |
| 830 size_t user_text_length) { | 834 size_t user_text_length) { |
| 831 // Update the text and selection. Because this can be called repeatedly while | 835 // Update the text and selection. Because this can be called repeatedly while |
| 832 // typing, we've careful not to freeze the edit unless we really need to. | 836 // typing, we've careful not to freeze the edit unless we really need to. |
| 833 // Also, unlike in the temporary text case above, here we don't want to update | 837 // Also, unlike in the temporary text case above, here we don't want to update |
| 834 // the caret/selection unless we have to, since this might make the user's | 838 // the caret/selection unless we have to, since this might make the user's |
| 835 // caret position change without warning during typing. | 839 // caret position change without warning during typing. |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 } | 2060 } |
| 2057 | 2061 |
| 2058 // We're showing a keyword and the user pressed backspace at the beginning | 2062 // We're showing a keyword and the user pressed backspace at the beginning |
| 2059 // of the text. Delete the selected keyword. | 2063 // of the text. Delete the selected keyword. |
| 2060 ScopedFreeze freeze(this, GetTextObjectModel()); | 2064 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2061 model_->ClearKeyword(GetText()); | 2065 model_->ClearKeyword(GetText()); |
| 2062 return true; | 2066 return true; |
| 2063 } | 2067 } |
| 2064 | 2068 |
| 2065 case VK_TAB: { | 2069 case VK_TAB: { |
| 2066 if (model_->is_keyword_hint()) { | 2070 const bool shift_pressed = GetKeyState(VK_SHIFT) < 0; |
| 2071 if (model_->is_keyword_hint() && !shift_pressed) { |
| 2067 // Accept the keyword. | 2072 // Accept the keyword. |
| 2068 ScopedFreeze freeze(this, GetTextObjectModel()); | 2073 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2069 model_->AcceptKeyword(); | 2074 model_->AcceptKeyword(); |
| 2070 } else if (!IsCaretAtEnd()) { | 2075 } else if (shift_pressed && |
| 2071 ScopedFreeze freeze(this, GetTextObjectModel()); | 2076 model_->popup_model()->selected_line_state() == |
| 2072 OnBeforePossibleChange(); | 2077 AutocompletePopupModel::KEYWORD) { |
| 2073 PlaceCaretAt(GetTextLength()); | 2078 model_->ClearKeyword(GetText()); |
| 2074 OnAfterPossibleChange(); | |
| 2075 } else { | 2079 } else { |
| 2076 model_->CommitSuggestedText(true); | 2080 model_->OnUpOrDownKeyPressed(shift_pressed ? -count : count); |
| 2077 } | 2081 } |
| 2078 return true; | 2082 return true; |
| 2079 } | 2083 } |
| 2080 | 2084 |
| 2081 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 2085 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
| 2082 // We don't use VK_OEM_PLUS in case the macro isn't defined. | 2086 // We don't use VK_OEM_PLUS in case the macro isn't defined. |
| 2083 // (e.g., we don't have this symbol in embeded environment). | 2087 // (e.g., we don't have this symbol in embeded environment). |
| 2084 return true; | 2088 return true; |
| 2085 | 2089 |
| 2086 default: | 2090 default: |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 return omnibox_view; | 2692 return omnibox_view; |
| 2689 } | 2693 } |
| 2690 return new OmniboxViewWin(controller, | 2694 return new OmniboxViewWin(controller, |
| 2691 toolbar_model, | 2695 toolbar_model, |
| 2692 location_bar, | 2696 location_bar, |
| 2693 command_updater, | 2697 command_updater, |
| 2694 popup_window_mode, | 2698 popup_window_mode, |
| 2695 location_bar); | 2699 location_bar); |
| 2696 } | 2700 } |
| 2697 #endif | 2701 #endif |
| OLD | NEW |