OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 void OmniboxViewWin::SetUserText(const string16& text) { | 682 void OmniboxViewWin::SetUserText(const string16& text) { |
683 SetUserText(text, text, true); | 683 SetUserText(text, text, true); |
684 } | 684 } |
685 | 685 |
686 void OmniboxViewWin::SetUserText(const string16& text, | 686 void OmniboxViewWin::SetUserText(const string16& text, |
687 const string16& display_text, | 687 const string16& display_text, |
688 bool update_popup) { | 688 bool update_popup) { |
689 ScopedFreeze freeze(this, GetTextObjectModel()); | 689 ScopedFreeze freeze(this, GetTextObjectModel()); |
690 model_->SetUserText(text); | 690 model_->SetUserText(text); |
691 saved_selection_for_focus_change_.cpMin = -1; | 691 saved_selection_for_focus_change_.cpMin = -1; |
692 SetWindowTextAndCaretPos(display_text, display_text.length()); | 692 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
693 if (update_popup) | 693 true); |
694 UpdatePopup(); | |
695 TextChanged(); | |
696 } | 694 } |
697 | 695 |
698 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, | 696 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, |
699 size_t caret_pos) { | 697 size_t caret_pos, |
| 698 bool update_popup, |
| 699 bool notify_text_changed) { |
700 SetWindowText(text.c_str()); | 700 SetWindowText(text.c_str()); |
701 PlaceCaretAt(caret_pos); | 701 PlaceCaretAt(caret_pos); |
| 702 |
| 703 if (update_popup) |
| 704 UpdatePopup(); |
| 705 |
| 706 if (notify_text_changed) |
| 707 TextChanged(); |
702 } | 708 } |
703 | 709 |
704 void OmniboxViewWin::SetForcedQuery() { | 710 void OmniboxViewWin::SetForcedQuery() { |
705 const string16 current_text(GetText()); | 711 const string16 current_text(GetText()); |
706 const size_t start = current_text.find_first_not_of(kWhitespaceWide); | 712 const size_t start = current_text.find_first_not_of(kWhitespaceWide); |
707 if (start == string16::npos || (current_text[start] != '?')) | 713 if (start == string16::npos || (current_text[start] != '?')) |
708 SetUserText(L"?"); | 714 SetUserText(L"?"); |
709 else | 715 else |
710 SetSelection(current_text.length(), start + 1); | 716 SetSelection(current_text.length(), start + 1); |
711 } | 717 } |
(...skipping 19 matching lines...) Expand all Loading... |
731 void OmniboxViewWin::SelectAll(bool reversed) { | 737 void OmniboxViewWin::SelectAll(bool reversed) { |
732 if (reversed) | 738 if (reversed) |
733 SetSelection(GetTextLength(), 0); | 739 SetSelection(GetTextLength(), 0); |
734 else | 740 else |
735 SetSelection(0, GetTextLength()); | 741 SetSelection(0, GetTextLength()); |
736 } | 742 } |
737 | 743 |
738 void OmniboxViewWin::RevertAll() { | 744 void OmniboxViewWin::RevertAll() { |
739 ScopedFreeze freeze(this, GetTextObjectModel()); | 745 ScopedFreeze freeze(this, GetTextObjectModel()); |
740 ClosePopup(); | 746 ClosePopup(); |
| 747 saved_selection_for_focus_change_.cpMin = -1; |
741 model_->Revert(); | 748 model_->Revert(); |
742 saved_selection_for_focus_change_.cpMin = -1; | |
743 TextChanged(); | |
744 } | 749 } |
745 | 750 |
746 void OmniboxViewWin::UpdatePopup() { | 751 void OmniboxViewWin::UpdatePopup() { |
747 ScopedFreeze freeze(this, GetTextObjectModel()); | 752 ScopedFreeze freeze(this, GetTextObjectModel()); |
748 model_->SetInputInProgress(true); | 753 model_->SetInputInProgress(true); |
749 | 754 |
750 // Don't allow the popup to open while the candidate window is open, so | 755 // Don't allow the popup to open while the candidate window is open, so |
751 // they don't overlap. | 756 // they don't overlap. |
752 if (ime_candidate_window_open_) | 757 if (ime_candidate_window_open_) |
753 return; | 758 return; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 GetSelection(original_selection_); | 833 GetSelection(original_selection_); |
829 | 834 |
830 // Set new text and cursor position. Sometimes this does extra work (e.g. | 835 // Set new text and cursor position. Sometimes this does extra work (e.g. |
831 // when the new text and the old text are identical), but it's only called | 836 // when the new text and the old text are identical), but it's only called |
832 // when the user manually changes the selected line in the popup, so that's | 837 // when the user manually changes the selected line in the popup, so that's |
833 // not really a problem. Also, even when the text hasn't changed we'd want to | 838 // not really a problem. Also, even when the text hasn't changed we'd want to |
834 // update the caret, because if the user had the cursor in the middle of the | 839 // update the caret, because if the user had the cursor in the middle of the |
835 // text and then arrowed to another entry with the same text, we'd still want | 840 // text and then arrowed to another entry with the same text, we'd still want |
836 // to move the caret. | 841 // to move the caret. |
837 ScopedFreeze freeze(this, GetTextObjectModel()); | 842 ScopedFreeze freeze(this, GetTextObjectModel()); |
838 SetWindowTextAndCaretPos(display_text, display_text.length()); | 843 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
839 TextChanged(); | |
840 } | 844 } |
841 | 845 |
842 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( | 846 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( |
843 const string16& display_text, | 847 const string16& display_text, |
844 size_t user_text_length) { | 848 size_t user_text_length) { |
845 // Update the text and selection. Because this can be called repeatedly while | 849 // Update the text and selection. Because this can be called repeatedly while |
846 // typing, we've careful not to freeze the edit unless we really need to. | 850 // typing, we've careful not to freeze the edit unless we really need to. |
847 // Also, unlike in the temporary text case above, here we don't want to update | 851 // Also, unlike in the temporary text case above, here we don't want to update |
848 // the caret/selection unless we have to, since this might make the user's | 852 // the caret/selection unless we have to, since this might make the user's |
849 // caret position change without warning during typing. | 853 // caret position change without warning during typing. |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 } | 2085 } |
2082 | 2086 |
2083 // We're showing a keyword and the user pressed backspace at the beginning | 2087 // We're showing a keyword and the user pressed backspace at the beginning |
2084 // of the text. Delete the selected keyword. | 2088 // of the text. Delete the selected keyword. |
2085 ScopedFreeze freeze(this, GetTextObjectModel()); | 2089 ScopedFreeze freeze(this, GetTextObjectModel()); |
2086 model_->ClearKeyword(GetText()); | 2090 model_->ClearKeyword(GetText()); |
2087 return true; | 2091 return true; |
2088 } | 2092 } |
2089 | 2093 |
2090 case VK_TAB: { | 2094 case VK_TAB: { |
2091 if (model_->is_keyword_hint()) { | 2095 const bool shift_pressed = GetKeyState(VK_SHIFT) < 0; |
| 2096 if (model_->is_keyword_hint() && !shift_pressed) { |
2092 // Accept the keyword. | 2097 // Accept the keyword. |
2093 ScopedFreeze freeze(this, GetTextObjectModel()); | 2098 ScopedFreeze freeze(this, GetTextObjectModel()); |
2094 model_->AcceptKeyword(); | 2099 model_->AcceptKeyword(); |
2095 } else if (!IsCaretAtEnd()) { | 2100 } else if (shift_pressed && |
2096 ScopedFreeze freeze(this, GetTextObjectModel()); | 2101 model_->popup_model()->selected_line_state() == |
2097 OnBeforePossibleChange(); | 2102 AutocompletePopupModel::KEYWORD) { |
2098 PlaceCaretAt(GetTextLength()); | 2103 model_->ClearKeyword(GetText()); |
2099 OnAfterPossibleChange(); | |
2100 } else { | 2104 } else { |
2101 model_->CommitSuggestedText(true); | 2105 model_->OnUpOrDownKeyPressed(shift_pressed ? -count : count); |
2102 } | 2106 } |
2103 return true; | 2107 return true; |
2104 } | 2108 } |
2105 | 2109 |
2106 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 2110 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
2107 // We don't use VK_OEM_PLUS in case the macro isn't defined. | 2111 // We don't use VK_OEM_PLUS in case the macro isn't defined. |
2108 // (e.g., we don't have this symbol in embeded environment). | 2112 // (e.g., we don't have this symbol in embeded environment). |
2109 return true; | 2113 return true; |
2110 | 2114 |
2111 default: | 2115 default: |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 return omnibox_view; | 2717 return omnibox_view; |
2714 } | 2718 } |
2715 return new OmniboxViewWin(controller, | 2719 return new OmniboxViewWin(controller, |
2716 toolbar_model, | 2720 toolbar_model, |
2717 location_bar, | 2721 location_bar, |
2718 command_updater, | 2722 command_updater, |
2719 popup_window_mode, | 2723 popup_window_mode, |
2720 location_bar); | 2724 location_bar); |
2721 } | 2725 } |
2722 #endif | 2726 #endif |
OLD | NEW |