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 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2080 } | 2084 } |
2081 | 2085 |
2082 // We're showing a keyword and the user pressed backspace at the beginning | 2086 // We're showing a keyword and the user pressed backspace at the beginning |
2083 // of the text. Delete the selected keyword. | 2087 // of the text. Delete the selected keyword. |
2084 ScopedFreeze freeze(this, GetTextObjectModel()); | 2088 ScopedFreeze freeze(this, GetTextObjectModel()); |
2085 model_->ClearKeyword(GetText()); | 2089 model_->ClearKeyword(GetText()); |
2086 return true; | 2090 return true; |
2087 } | 2091 } |
2088 | 2092 |
2089 case VK_TAB: { | 2093 case VK_TAB: { |
2090 if (model_->is_keyword_hint()) { | 2094 const bool shift_pressed = GetKeyState(VK_SHIFT) < 0; |
| 2095 if (model_->is_keyword_hint() && !shift_pressed) { |
2091 // Accept the keyword. | 2096 // Accept the keyword. |
2092 ScopedFreeze freeze(this, GetTextObjectModel()); | 2097 ScopedFreeze freeze(this, GetTextObjectModel()); |
2093 model_->AcceptKeyword(); | 2098 model_->AcceptKeyword(); |
2094 } else if (!IsCaretAtEnd()) { | 2099 } else if (shift_pressed && |
2095 ScopedFreeze freeze(this, GetTextObjectModel()); | 2100 model_->popup_model()->selected_line_state() == |
2096 OnBeforePossibleChange(); | 2101 AutocompletePopupModel::KEYWORD) { |
2097 PlaceCaretAt(GetTextLength()); | 2102 model_->ClearKeyword(GetText()); |
2098 OnAfterPossibleChange(); | |
2099 } else { | 2103 } else { |
2100 model_->CommitSuggestedText(true); | 2104 model_->OnUpOrDownKeyPressed(shift_pressed ? -count : count); |
2101 } | 2105 } |
2102 return true; | 2106 return true; |
2103 } | 2107 } |
2104 | 2108 |
2105 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 2109 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
2106 // We don't use VK_OEM_PLUS in case the macro isn't defined. | 2110 // We don't use VK_OEM_PLUS in case the macro isn't defined. |
2107 // (e.g., we don't have this symbol in embeded environment). | 2111 // (e.g., we don't have this symbol in embeded environment). |
2108 return true; | 2112 return true; |
2109 | 2113 |
2110 default: | 2114 default: |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 return omnibox_view; | 2716 return omnibox_view; |
2713 } | 2717 } |
2714 return new OmniboxViewWin(controller, | 2718 return new OmniboxViewWin(controller, |
2715 toolbar_model, | 2719 toolbar_model, |
2716 location_bar, | 2720 location_bar, |
2717 command_updater, | 2721 command_updater, |
2718 popup_window_mode, | 2722 popup_window_mode, |
2719 location_bar); | 2723 location_bar); |
2720 } | 2724 } |
2721 #endif | 2725 #endif |
OLD | NEW |