Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/omnibox/browser/omnibox_edit_model.h" | 5 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } | 196 } |
| 197 | 197 |
| 198 const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() { | 198 const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() { |
| 199 // Like typing, switching tabs "accepts" the temporary text as the user | 199 // Like typing, switching tabs "accepts" the temporary text as the user |
| 200 // text, because it makes little sense to have temporary text when the | 200 // text, because it makes little sense to have temporary text when the |
| 201 // popup is closed. | 201 // popup is closed. |
| 202 if (user_input_in_progress_) { | 202 if (user_input_in_progress_) { |
| 203 // Weird edge case to match other browsers: if the edit is empty, revert to | 203 // Weird edge case to match other browsers: if the edit is empty, revert to |
| 204 // the permanent text (so the user can get it back easily) but select it (so | 204 // the permanent text (so the user can get it back easily) but select it (so |
| 205 // on switching back, typing will "just work"). | 205 // on switching back, typing will "just work"). |
| 206 const base::string16 user_text(UserTextFromDisplayText(view_->GetText())); | 206 const base::string16 user_text(user_text_); |
|
Peter Kasting
2016/05/09 23:15:53
I think this change means we'll now take the first
Tom (Use chromium acct)
2016/05/10 04:54:50
Good catch. Done.
| |
| 207 if (user_text.empty()) { | 207 if (user_text.empty()) { |
| 208 base::AutoReset<bool> tmp(&in_revert_, true); | 208 base::AutoReset<bool> tmp(&in_revert_, true); |
| 209 view_->RevertAll(); | 209 view_->RevertAll(); |
| 210 view_->SelectAll(true); | 210 view_->SelectAll(true); |
| 211 } else { | 211 } else { |
| 212 InternalSetUserText(user_text); | 212 InternalSetUserText(user_text); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", | 216 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 235 // Restore the autocomplete controller's input, or clear it if this is a new | 235 // Restore the autocomplete controller's input, or clear it if this is a new |
| 236 // tab. | 236 // tab. |
| 237 input_ = state ? state->autocomplete_input : AutocompleteInput(); | 237 input_ = state ? state->autocomplete_input : AutocompleteInput(); |
| 238 if (!state) | 238 if (!state) |
| 239 return; | 239 return; |
| 240 | 240 |
| 241 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); | 241 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); |
| 242 focus_source_ = state->focus_source; | 242 focus_source_ = state->focus_source; |
| 243 // Restore any user editing. | 243 // Restore any user editing. |
| 244 if (state->user_input_in_progress) { | 244 if (state->user_input_in_progress) { |
| 245 // NOTE: Be sure and set keyword-related state BEFORE invoking | |
| 246 // DisplayTextFromUserText(), as its result depends upon this state. | |
| 247 keyword_ = state->keyword; | 245 keyword_ = state->keyword; |
| 248 is_keyword_hint_ = state->is_keyword_hint; | 246 is_keyword_hint_ = state->is_keyword_hint; |
| 249 view_->SetUserText(state->user_text, | 247 view_->SetUserText(state->user_text, state->user_text, false); |
|
Peter Kasting
2016/05/09 23:15:53
I think this was the only place that passed differ
Tom (Use chromium acct)
2016/05/10 04:54:50
Done.
| |
| 250 DisplayTextFromUserText(state->user_text), false); | |
| 251 view_->SetGrayTextAutocompletion(state->gray_text); | 248 view_->SetGrayTextAutocompletion(state->gray_text); |
| 252 } | 249 } |
| 253 } | 250 } |
| 254 | 251 |
| 255 AutocompleteMatch OmniboxEditModel::CurrentMatch( | 252 AutocompleteMatch OmniboxEditModel::CurrentMatch( |
| 256 GURL* alternate_nav_url) const { | 253 GURL* alternate_nav_url) const { |
| 257 // If we have a valid match use it. Otherwise get one for the current text. | 254 // If we have a valid match use it. Otherwise get one for the current text. |
| 258 AutocompleteMatch match = omnibox_controller_->current_match(); | 255 AutocompleteMatch match = omnibox_controller_->current_match(); |
| 259 | 256 |
| 260 if (!match.destination_url.is_valid()) { | 257 if (!match.destination_url.is_valid()) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 | 474 |
| 478 void OmniboxEditModel::StartAutocomplete( | 475 void OmniboxEditModel::StartAutocomplete( |
| 479 bool has_selected_text, | 476 bool has_selected_text, |
| 480 bool prevent_inline_autocomplete, | 477 bool prevent_inline_autocomplete, |
| 481 bool entering_keyword_mode) { | 478 bool entering_keyword_mode) { |
| 482 size_t cursor_position; | 479 size_t cursor_position; |
| 483 if (inline_autocomplete_text_.empty()) { | 480 if (inline_autocomplete_text_.empty()) { |
| 484 // Cursor position is equivalent to the current selection's end. | 481 // Cursor position is equivalent to the current selection's end. |
| 485 size_t start; | 482 size_t start; |
| 486 view_->GetSelectionBounds(&start, &cursor_position); | 483 view_->GetSelectionBounds(&start, &cursor_position); |
| 487 // If we're in keyword mode, we're not displaying the full |user_text_|, so | 484 // If we're in keyword mode, we're not displaying the full |user_text_|, so |
|
Peter Kasting
2016/05/09 23:15:53
This comment is no longer correct, as we no longer
Tom (Use chromium acct)
2016/05/10 04:54:50
Done.
| |
| 488 // the cursor position we got from the view has to be adjusted later by the | 485 // the cursor position we got from the view has to be adjusted later by the |
| 489 // length of the undisplayed text. If we're just entering keyword mode, | 486 // length of the undisplayed text. If we're just entering keyword mode, |
| 490 // though, we have to avoid making this adjustment, because we haven't | 487 // though, we have to avoid making this adjustment, because we haven't |
| 491 // actually hidden any text yet, but the caller has already cleared | 488 // actually hidden any text yet, but the caller has already cleared |
| 492 // |is_keyword_hint_|, so DisplayTextFromUserText() will believe we are | 489 // |is_keyword_hint_|, so MaybeStripKeyword() will believe we are |
| 493 // already in keyword mode, and will thus mis-adjust the cursor position. | 490 // already in keyword mode, and will thus mis-adjust the cursor position. |
| 494 if (!entering_keyword_mode) { | 491 if (!entering_keyword_mode) |
| 495 cursor_position += | 492 cursor_position += user_text_.length() - user_text_.length(); |
|
Peter Kasting
2016/05/09 23:15:53
This statement now does nothing. In general, you
Tom (Use chromium acct)
2016/05/10 04:54:50
Done.
| |
| 496 user_text_.length() - DisplayTextFromUserText(user_text_).length(); | |
| 497 } | |
| 498 } else { | 493 } else { |
| 499 // There are some cases where StartAutocomplete() may be called | 494 // There are some cases where StartAutocomplete() may be called |
| 500 // with non-empty |inline_autocomplete_text_|. In such cases, we cannot | 495 // with non-empty |inline_autocomplete_text_|. In such cases, we cannot |
| 501 // use the current selection, because it could result with the cursor | 496 // use the current selection, because it could result with the cursor |
| 502 // position past the last character from the user text. Instead, | 497 // position past the last character from the user text. Instead, |
| 503 // we assume that the cursor is simply at the end of input. | 498 // we assume that the cursor is simply at the end of input. |
| 504 // One example is when user presses Ctrl key while having a highlighted | 499 // One example is when user presses Ctrl key while having a highlighted |
| 505 // inline autocomplete text. | 500 // inline autocomplete text. |
| 506 // TODO: Rethink how we are going to handle this case to avoid | 501 // TODO: Rethink how we are going to handle this case to avoid |
| 507 // inconsistent behavior when user presses Ctrl key. | 502 // inconsistent behavior when user presses Ctrl key. |
| 508 // See http://crbug.com/165961 and http://crbug.com/165968 for more details. | 503 // See http://crbug.com/165961 and http://crbug.com/165968 for more details. |
| 509 cursor_position = user_text_.length(); | 504 cursor_position = MaybePrependKeyword(user_text_).length(); |
| 510 } | 505 } |
| 511 | 506 |
| 512 GURL current_url; | 507 GURL current_url; |
| 513 if (client_->CurrentPageExists()) | 508 if (client_->CurrentPageExists()) |
| 514 current_url = client_->GetURL(); | 509 current_url = client_->GetURL(); |
| 515 input_ = AutocompleteInput( | 510 input_ = AutocompleteInput( |
| 516 user_text_, cursor_position, std::string(), current_url, ClassifyPage(), | 511 MaybePrependKeyword(user_text_), cursor_position, std::string(), |
| 512 current_url, ClassifyPage(), | |
| 517 prevent_inline_autocomplete || just_deleted_text_ || | 513 prevent_inline_autocomplete || just_deleted_text_ || |
| 518 (has_selected_text && inline_autocomplete_text_.empty()) || | 514 (has_selected_text && inline_autocomplete_text_.empty()) || |
| 519 (paste_state_ != NONE), | 515 (paste_state_ != NONE), |
| 520 is_keyword_selected(), | 516 is_keyword_selected(), |
| 521 is_keyword_selected() || allow_exact_keyword_match_, true, false, | 517 is_keyword_selected() || allow_exact_keyword_match_, true, false, |
| 522 client_->GetSchemeClassifier()); | 518 client_->GetSchemeClassifier()); |
| 523 | 519 |
| 524 omnibox_controller_->StartAutocomplete(input_); | 520 omnibox_controller_->StartAutocomplete(input_); |
| 525 } | 521 } |
| 526 | 522 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 autocomplete_controller()->history_url_provider()) { | 565 autocomplete_controller()->history_url_provider()) { |
| 570 // Generate a new AutocompleteInput, copying the latest one but using "com" | 566 // Generate a new AutocompleteInput, copying the latest one but using "com" |
| 571 // as the desired TLD. Then use this autocomplete input to generate a | 567 // as the desired TLD. Then use this autocomplete input to generate a |
| 572 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent | 568 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent |
| 573 // input instead of the currently visible text means we'll ignore any | 569 // input instead of the currently visible text means we'll ignore any |
| 574 // visible inline autocompletion: if a user types "foo" and is autocompleted | 570 // visible inline autocompletion: if a user types "foo" and is autocompleted |
| 575 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not | 571 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not |
| 576 // "foodnetwork.com". At the time of writing, this behavior matches | 572 // "foodnetwork.com". At the time of writing, this behavior matches |
| 577 // Internet Explorer, but not Firefox. | 573 // Internet Explorer, but not Firefox. |
| 578 input_ = AutocompleteInput( | 574 input_ = AutocompleteInput( |
| 579 has_temporary_text_ ? UserTextFromDisplayText(view_->GetText()) | 575 has_temporary_text_ ? MaybePrependKeyword(user_text_) : input_.text(), |
|
Peter Kasting
2016/05/09 23:15:53
We know is_keyword_selected() is false, so MaybePr
Tom (Use chromium acct)
2016/05/10 04:54:50
Done.
| |
| 580 : input_.text(), | |
| 581 input_.cursor_position(), "com", GURL(), | 576 input_.cursor_position(), "com", GURL(), |
| 582 input_.current_page_classification(), | 577 input_.current_page_classification(), |
| 583 input_.prevent_inline_autocomplete(), input_.prefer_keyword(), | 578 input_.prevent_inline_autocomplete(), input_.prefer_keyword(), |
| 584 input_.allow_exact_keyword_match(), input_.want_asynchronous_matches(), | 579 input_.allow_exact_keyword_match(), input_.want_asynchronous_matches(), |
| 585 input_.from_omnibox_focus(), client_->GetSchemeClassifier()); | 580 input_.from_omnibox_focus(), client_->GetSchemeClassifier()); |
| 586 AutocompleteMatch url_match( | 581 AutocompleteMatch url_match( |
| 587 autocomplete_controller()->history_url_provider()->SuggestExactInput( | 582 autocomplete_controller()->history_url_provider()->SuggestExactInput( |
| 588 input_, input_.canonicalized_url(), false)); | 583 input_, input_.canonicalized_url(), false)); |
| 589 | 584 |
| 590 if (url_match.destination_url.is_valid()) { | 585 if (url_match.destination_url.is_valid()) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url)) | 777 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url)) |
| 783 client_->OnBookmarkLaunched(); | 778 client_->OnBookmarkLaunched(); |
| 784 } | 779 } |
| 785 | 780 |
| 786 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { | 781 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
| 787 DCHECK(is_keyword_hint_ && !keyword_.empty()); | 782 DCHECK(is_keyword_hint_ && !keyword_.empty()); |
| 788 | 783 |
| 789 autocomplete_controller()->Stop(false); | 784 autocomplete_controller()->Stop(false); |
| 790 is_keyword_hint_ = false; | 785 is_keyword_hint_ = false; |
| 791 | 786 |
| 787 user_text_ = MaybeStripKeyword(user_text_); | |
| 788 | |
| 792 if (popup_model() && popup_model()->IsOpen()) | 789 if (popup_model() && popup_model()->IsOpen()) |
| 793 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); | 790 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
| 794 else | 791 else |
| 795 StartAutocomplete(false, true, true); | 792 StartAutocomplete(false, true, true); |
| 796 | 793 |
| 797 // When entering keyword mode via tab, the new text to show is whatever the | 794 // When entering keyword mode via tab, the new text to show is whatever the |
| 798 // newly-selected match in the dropdown is. When entering via space, however, | 795 // newly-selected match in the dropdown is. When entering via space, however, |
| 799 // we should make sure to use the actual |user_text_| as the basis for the new | 796 // we should make sure to use the actual |user_text_| as the basis for the new |
| 800 // text. This ensures that if the user types "<keyword><space>" and the | 797 // text. This ensures that if the user types "<keyword><space>" and the |
| 801 // default match would have inline autocompleted a further string (e.g. | 798 // default match would have inline autocompleted a further string (e.g. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 813 // comments in ClearKeyword(). | 810 // comments in ClearKeyword(). |
| 814 if (entered_method == ENTERED_KEYWORD_MODE_VIA_TAB) { | 811 if (entered_method == ENTERED_KEYWORD_MODE_VIA_TAB) { |
| 815 // Ensure the current selection is saved before showing keyword mode | 812 // Ensure the current selection is saved before showing keyword mode |
| 816 // so that moving to another line and then reverting the text will restore | 813 // so that moving to another line and then reverting the text will restore |
| 817 // the current state properly. | 814 // the current state properly. |
| 818 bool save_original_selection = !has_temporary_text_; | 815 bool save_original_selection = !has_temporary_text_; |
| 819 has_temporary_text_ = true; | 816 has_temporary_text_ = true; |
| 820 const AutocompleteMatch& match = CurrentMatch(NULL); | 817 const AutocompleteMatch& match = CurrentMatch(NULL); |
| 821 original_url_ = match.destination_url; | 818 original_url_ = match.destination_url; |
| 822 view_->OnTemporaryTextMaybeChanged( | 819 view_->OnTemporaryTextMaybeChanged( |
| 823 DisplayTextFromUserText(match.fill_into_edit), | 820 MaybeStripKeyword(match.fill_into_edit), save_original_selection, |
| 824 save_original_selection, true); | 821 true); |
| 825 } else { | 822 } else { |
| 826 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(user_text_), | 823 view_->OnTemporaryTextMaybeChanged(user_text_, false, true); |
| 827 false, true); | |
| 828 } | 824 } |
| 829 | 825 |
| 830 base::RecordAction(base::UserMetricsAction("AcceptedKeywordHint")); | 826 base::RecordAction(base::UserMetricsAction("AcceptedKeywordHint")); |
| 831 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, | 827 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, |
| 832 ENTERED_KEYWORD_MODE_NUM_ITEMS); | 828 ENTERED_KEYWORD_MODE_NUM_ITEMS); |
| 833 | 829 |
| 834 return true; | 830 return true; |
| 835 } | 831 } |
| 836 | 832 |
| 837 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { | 833 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { |
| 838 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 834 InternalSetUserText(view_->GetText()); |
| 839 has_temporary_text_ = false; | 835 has_temporary_text_ = false; |
| 840 | 836 |
| 841 if (user_input_in_progress_ || !in_revert_) | 837 if (user_input_in_progress_ || !in_revert_) |
| 842 client_->OnInputStateChanged(); | 838 client_->OnInputStateChanged(); |
| 843 } | 839 } |
| 844 | 840 |
| 845 void OmniboxEditModel::ClearKeyword() { | 841 void OmniboxEditModel::ClearKeyword() { |
| 846 autocomplete_controller()->Stop(false); | 842 autocomplete_controller()->Stop(false); |
| 847 | 843 |
| 848 // While we're always in keyword mode upon reaching here, sometimes we've just | 844 // While we're always in keyword mode upon reaching here, sometimes we've just |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 if (control_key_state_ == DOWN_WITHOUT_CHANGE) { | 1086 if (control_key_state_ == DOWN_WITHOUT_CHANGE) { |
| 1091 // Arrowing around the popup cancels control-enter. | 1087 // Arrowing around the popup cancels control-enter. |
| 1092 control_key_state_ = DOWN_WITH_CHANGE; | 1088 control_key_state_ = DOWN_WITH_CHANGE; |
| 1093 // Now things are a bit screwy: the desired_tld has changed, but if we | 1089 // Now things are a bit screwy: the desired_tld has changed, but if we |
| 1094 // update the popup, the new order of entries won't match the old, so the | 1090 // update the popup, the new order of entries won't match the old, so the |
| 1095 // user's selection gets screwy; and if we don't update the popup, and the | 1091 // user's selection gets screwy; and if we don't update the popup, and the |
| 1096 // user reverts, then the selected item will be as if control is still | 1092 // user reverts, then the selected item will be as if control is still |
| 1097 // pressed, even though maybe it isn't any more. There is no obvious | 1093 // pressed, even though maybe it isn't any more. There is no obvious |
| 1098 // right answer here :( | 1094 // right answer here :( |
| 1099 } | 1095 } |
| 1100 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text), | 1096 view_->OnTemporaryTextMaybeChanged(MaybeStripKeyword(text), |
| 1101 save_original_selection, true); | 1097 save_original_selection, true); |
| 1102 return; | 1098 return; |
| 1103 } | 1099 } |
| 1104 | 1100 |
| 1105 bool call_controller_onchanged = true; | 1101 bool call_controller_onchanged = true; |
| 1106 inline_autocomplete_text_ = text; | 1102 inline_autocomplete_text_ = text; |
| 1107 if (inline_autocomplete_text_.empty()) | 1103 if (inline_autocomplete_text_.empty()) |
| 1108 view_->OnInlineAutocompleteTextCleared(); | 1104 view_->OnInlineAutocompleteTextCleared(); |
| 1109 | 1105 |
| 1110 const base::string16& user_text = | 1106 const base::string16& user_text = |
| 1111 user_input_in_progress_ ? user_text_ : permanent_text_; | 1107 user_input_in_progress_ ? user_text_ : permanent_text_; |
| 1112 if (keyword_state_changed && is_keyword_selected()) { | 1108 if (keyword_state_changed && is_keyword_selected()) { |
| 1113 // If we reach here, the user most likely entered keyword mode by inserting | 1109 // If we reach here, the user most likely entered keyword mode by inserting |
| 1114 // a space between a keyword name and a search string (as pressing space or | 1110 // a space between a keyword name and a search string (as pressing space or |
| 1115 // tab after the keyword name alone would have been be handled in | 1111 // tab after the keyword name alone would have been be handled in |
| 1116 // MaybeAcceptKeywordBySpace() by calling AcceptKeyword(), which won't reach | 1112 // MaybeAcceptKeywordBySpace() by calling AcceptKeyword(), which won't reach |
| 1117 // here). In this case, we don't want to call | 1113 // here). In this case, we don't want to call |
| 1118 // OnInlineAutocompleteTextMaybeChanged() as normal, because that will | 1114 // OnInlineAutocompleteTextMaybeChanged() as normal, because that will |
| 1119 // correctly change the text (to the search string alone) but move the caret | 1115 // correctly change the text (to the search string alone) but move the caret |
| 1120 // to the end of the string; instead we want the caret at the start of the | 1116 // to the end of the string; instead we want the caret at the start of the |
| 1121 // search string since that's where it was in the original input. So we set | 1117 // search string since that's where it was in the original input. So we set |
| 1122 // the text and caret position directly. | 1118 // the text and caret position directly. |
| 1123 // | 1119 // |
| 1124 // It may also be possible to reach here if we're reverting from having | 1120 // It may also be possible to reach here if we're reverting from having |
| 1125 // temporary text back to a default match that's a keyword search, but in | 1121 // temporary text back to a default match that's a keyword search, but in |
| 1126 // that case the RevertTemporaryText() call below will reset the caret or | 1122 // that case the RevertTemporaryText() call below will reset the caret or |
| 1127 // selection correctly so the caret positioning we do here won't matter. | 1123 // selection correctly so the caret positioning we do here won't matter. |
| 1128 view_->SetWindowTextAndCaretPos(DisplayTextFromUserText(user_text), 0, | 1124 view_->SetWindowTextAndCaretPos(user_text, 0, false, false); |
| 1129 false, false); | |
| 1130 } else if (view_->OnInlineAutocompleteTextMaybeChanged( | 1125 } else if (view_->OnInlineAutocompleteTextMaybeChanged( |
| 1131 DisplayTextFromUserText(user_text + inline_autocomplete_text_), | 1126 user_text + inline_autocomplete_text_, user_text.length())) { |
| 1132 DisplayTextFromUserText(user_text).length())) { | |
| 1133 call_controller_onchanged = false; | 1127 call_controller_onchanged = false; |
| 1134 } | 1128 } |
| 1135 | 1129 |
| 1136 // If |has_temporary_text_| is true, then we previously had a manual selection | 1130 // If |has_temporary_text_| is true, then we previously had a manual selection |
| 1137 // but now don't (or |destination_for_temporary_text_change| would have been | 1131 // but now don't (or |destination_for_temporary_text_change| would have been |
| 1138 // non-NULL). This can happen when deleting the selected item in the popup. | 1132 // non-NULL). This can happen when deleting the selected item in the popup. |
| 1139 // In this case, we've already reverted the popup to the default match, so we | 1133 // In this case, we've already reverted the popup to the default match, so we |
| 1140 // need to revert ourselves as well. | 1134 // need to revert ourselves as well. |
| 1141 if (has_temporary_text_) { | 1135 if (has_temporary_text_) { |
| 1142 RevertTemporaryText(false); | 1136 RevertTemporaryText(false); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 if ((text_differs || selection_differs) && | 1186 if ((text_differs || selection_differs) && |
| 1193 (control_key_state_ == DOWN_WITHOUT_CHANGE)) | 1187 (control_key_state_ == DOWN_WITHOUT_CHANGE)) |
| 1194 control_key_state_ = DOWN_WITH_CHANGE; | 1188 control_key_state_ = DOWN_WITH_CHANGE; |
| 1195 | 1189 |
| 1196 if (!user_text_changed) | 1190 if (!user_text_changed) |
| 1197 return false; | 1191 return false; |
| 1198 | 1192 |
| 1199 // If the user text has not changed, we do not want to change the model's | 1193 // If the user text has not changed, we do not want to change the model's |
| 1200 // state associated with the text. Otherwise, we can get surprising behavior | 1194 // state associated with the text. Otherwise, we can get surprising behavior |
| 1201 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1195 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
| 1202 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1196 InternalSetUserText(new_text); |
| 1203 has_temporary_text_ = false; | 1197 has_temporary_text_ = false; |
| 1204 | 1198 |
| 1205 // Track when the user has deleted text so we won't allow inline | 1199 // Track when the user has deleted text so we won't allow inline |
| 1206 // autocomplete. | 1200 // autocomplete. |
| 1207 just_deleted_text_ = just_deleted_text; | 1201 just_deleted_text_ = just_deleted_text; |
| 1208 | 1202 |
| 1209 if (user_input_in_progress_ && user_text_.empty()) { | 1203 if (user_input_in_progress_ && user_text_.empty()) { |
| 1210 // Log cases where the user started editing and then subsequently cleared | 1204 // Log cases where the user started editing and then subsequently cleared |
| 1211 // all the text. Note that this explicitly doesn't catch cases like | 1205 // all the text. Note that this explicitly doesn't catch cases like |
| 1212 // "hit ctrl-l to select whole edit contents, then hit backspace", because | 1206 // "hit ctrl-l to select whole edit contents, then hit backspace", because |
| 1213 // in such cases, |user_input_in_progress| won't be true here. | 1207 // in such cases, |user_input_in_progress| won't be true here. |
| 1214 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, | 1208 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, |
| 1215 OMNIBOX_USER_TEXT_CLEARED_BY_EDITING, | 1209 OMNIBOX_USER_TEXT_CLEARED_BY_EDITING, |
| 1216 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); | 1210 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); |
| 1217 } | 1211 } |
| 1218 | 1212 |
| 1219 const bool no_selection = selection_start == selection_end; | 1213 const bool no_selection = selection_start == selection_end; |
| 1220 | 1214 |
| 1221 // Update the popup for the change, in the process changing to keyword mode | 1215 // Update the popup for the change, in the process changing to keyword mode |
| 1222 // if the user hit space in mid-string after a keyword. | 1216 // if the user hit space in mid-string after a keyword. |
| 1223 // |allow_exact_keyword_match_| will be used by StartAutocomplete() method, | 1217 // |allow_exact_keyword_match_| will be used by StartAutocomplete() method, |
| 1224 // which will be called by |view_->UpdatePopup()|; so after that returns we | 1218 // which will be called by |view_->UpdatePopup()|; so after that returns we |
| 1225 // can safely reset this flag. | 1219 // can safely reset this flag. |
| 1226 allow_exact_keyword_match_ = text_differs && allow_keyword_ui_change && | 1220 allow_exact_keyword_match_ = text_differs && allow_keyword_ui_change && |
| 1227 !just_deleted_text && no_selection && | 1221 !just_deleted_text && no_selection && |
| 1228 CreatedKeywordSearchByInsertingSpaceInMiddle(old_text, user_text_, | 1222 CreatedKeywordSearchByInsertingSpaceInMiddle(old_text, user_text_, |
| 1229 selection_start); | 1223 selection_start); |
| 1224 | |
| 1225 if (allow_exact_keyword_match_) { | |
| 1226 base::TrimWhitespace(user_text_.substr(0, selection_start - 1), | |
| 1227 base::TRIM_LEADING, &keyword_); | |
| 1228 is_keyword_hint_ = false; | |
| 1229 user_text_ = MaybeStripKeyword(user_text_); | |
| 1230 view_->SetWindowTextAndCaretPos(user_text_, 0, false, false); | |
| 1231 } | |
|
Peter Kasting
2016/05/09 23:15:53
This seems really questionable. Before your patch
Tom (Use chromium acct)
2016/05/10 04:54:50
Here's the stack trace I get from setting a watchp
| |
| 1232 | |
| 1230 view_->UpdatePopup(); | 1233 view_->UpdatePopup(); |
| 1231 if (allow_exact_keyword_match_) { | 1234 if (allow_exact_keyword_match_) { |
| 1232 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, | 1235 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, |
| 1233 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE, | 1236 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE, |
| 1234 ENTERED_KEYWORD_MODE_NUM_ITEMS); | 1237 ENTERED_KEYWORD_MODE_NUM_ITEMS); |
| 1235 allow_exact_keyword_match_ = false; | 1238 allow_exact_keyword_match_ = false; |
| 1236 } | 1239 } |
| 1237 | 1240 |
| 1238 // Change to keyword mode if the user is now pressing space after a keyword | 1241 // Change to keyword mode if the user is now pressing space after a keyword |
| 1239 // name. Note that if this is the case, then even if there was no keyword | 1242 // name. Note that if this is the case, then even if there was no keyword |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1287 user_text_ = text; | 1290 user_text_ = text; |
| 1288 just_deleted_text_ = false; | 1291 just_deleted_text_ = false; |
| 1289 inline_autocomplete_text_.clear(); | 1292 inline_autocomplete_text_.clear(); |
| 1290 view_->OnInlineAutocompleteTextCleared(); | 1293 view_->OnInlineAutocompleteTextCleared(); |
| 1291 } | 1294 } |
| 1292 | 1295 |
| 1293 void OmniboxEditModel::ClearPopupKeywordMode() const { | 1296 void OmniboxEditModel::ClearPopupKeywordMode() const { |
| 1294 omnibox_controller_->ClearPopupKeywordMode(); | 1297 omnibox_controller_->ClearPopupKeywordMode(); |
| 1295 } | 1298 } |
| 1296 | 1299 |
| 1297 base::string16 OmniboxEditModel::DisplayTextFromUserText( | 1300 base::string16 OmniboxEditModel::MaybeStripKeyword( |
| 1298 const base::string16& text) const { | 1301 const base::string16& text) const { |
| 1299 return is_keyword_selected() ? | 1302 return is_keyword_selected() ? |
| 1300 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; | 1303 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; |
| 1301 } | 1304 } |
| 1302 | 1305 |
| 1303 base::string16 OmniboxEditModel::UserTextFromDisplayText( | 1306 base::string16 OmniboxEditModel::MaybePrependKeyword( |
| 1304 const base::string16& text) const { | 1307 const base::string16& text) const { |
| 1305 return is_keyword_selected() ? (keyword_ + base::char16(' ') + text) : text; | 1308 return is_keyword_selected() ? (keyword_ + base::char16(' ') + text) : text; |
| 1306 } | 1309 } |
| 1307 | 1310 |
| 1308 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, | 1311 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, |
| 1309 GURL* alternate_nav_url) const { | 1312 GURL* alternate_nav_url) const { |
| 1310 DCHECK(match != NULL); | 1313 DCHECK(match != NULL); |
| 1311 | 1314 |
| 1312 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement( | 1315 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement( |
| 1313 false)) { | 1316 false)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1345 result().match_at(popup_model()->selected_line()); | 1348 result().match_at(popup_model()->selected_line()); |
| 1346 *match = | 1349 *match = |
| 1347 (popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD) ? | 1350 (popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD) ? |
| 1348 *selected_match.associated_keyword : selected_match; | 1351 *selected_match.associated_keyword : selected_match; |
| 1349 } | 1352 } |
| 1350 if (alternate_nav_url && | 1353 if (alternate_nav_url && |
| 1351 (!popup_model() || popup_model()->manually_selected_match().empty())) | 1354 (!popup_model() || popup_model()->manually_selected_match().empty())) |
| 1352 *alternate_nav_url = result().alternate_nav_url(); | 1355 *alternate_nav_url = result().alternate_nav_url(); |
| 1353 } else { | 1356 } else { |
| 1354 client_->GetAutocompleteClassifier()->Classify( | 1357 client_->GetAutocompleteClassifier()->Classify( |
| 1355 UserTextFromDisplayText(view_->GetText()), is_keyword_selected(), true, | 1358 MaybePrependKeyword(user_text_), is_keyword_selected(), true, |
| 1356 ClassifyPage(), match, alternate_nav_url); | 1359 ClassifyPage(), match, alternate_nav_url); |
| 1357 } | 1360 } |
| 1358 } | 1361 } |
| 1359 | 1362 |
| 1360 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { | 1363 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
| 1361 // The user typed something, then selected a different item. Restore the | 1364 // The user typed something, then selected a different item. Restore the |
| 1362 // text they typed and change back to the default item. | 1365 // text they typed and change back to the default item. |
| 1363 // NOTE: This purposefully does not reset paste_state_. | 1366 // NOTE: This purposefully does not reset paste_state_. |
| 1364 just_deleted_text_ = false; | 1367 just_deleted_text_ = false; |
| 1365 has_temporary_text_ = false; | 1368 has_temporary_text_ = false; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1463 // Update state and notify view if the omnibox has focus and the caret | 1466 // Update state and notify view if the omnibox has focus and the caret |
| 1464 // visibility changed. | 1467 // visibility changed. |
| 1465 const bool was_caret_visible = is_caret_visible(); | 1468 const bool was_caret_visible = is_caret_visible(); |
| 1466 focus_state_ = state; | 1469 focus_state_ = state; |
| 1467 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1470 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1468 is_caret_visible() != was_caret_visible) | 1471 is_caret_visible() != was_caret_visible) |
| 1469 view_->ApplyCaretVisibility(); | 1472 view_->ApplyCaretVisibility(); |
| 1470 | 1473 |
| 1471 client_->OnFocusChanged(focus_state_, reason); | 1474 client_->OnFocusChanged(focus_state_, reason); |
| 1472 } | 1475 } |
| OLD | NEW |