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