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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } // namespace | 142 } // namespace |
143 | 143 |
144 | 144 |
145 // OmniboxEditModel::State ---------------------------------------------------- | 145 // OmniboxEditModel::State ---------------------------------------------------- |
146 | 146 |
147 OmniboxEditModel::State::State(bool user_input_in_progress, | 147 OmniboxEditModel::State::State(bool user_input_in_progress, |
148 const base::string16& user_text, | 148 const base::string16& user_text, |
149 const base::string16& gray_text, | 149 const base::string16& gray_text, |
150 const base::string16& keyword, | 150 const base::string16& keyword, |
151 bool is_keyword_hint, | 151 bool is_keyword_hint, |
152 EnteredKeywordModeMethod keyword_entered_method, | |
152 bool url_replacement_enabled, | 153 bool url_replacement_enabled, |
153 OmniboxFocusState focus_state, | 154 OmniboxFocusState focus_state, |
154 FocusSource focus_source, | 155 FocusSource focus_source, |
155 const AutocompleteInput& autocomplete_input) | 156 const AutocompleteInput& autocomplete_input) |
156 : user_input_in_progress(user_input_in_progress), | 157 : user_input_in_progress(user_input_in_progress), |
157 user_text(user_text), | 158 user_text(user_text), |
158 gray_text(gray_text), | 159 gray_text(gray_text), |
159 keyword(keyword), | 160 keyword(keyword), |
160 is_keyword_hint(is_keyword_hint), | 161 is_keyword_hint(is_keyword_hint), |
162 keyword_entered_method(keyword_entered_method), | |
161 url_replacement_enabled(url_replacement_enabled), | 163 url_replacement_enabled(url_replacement_enabled), |
162 focus_state(focus_state), | 164 focus_state(focus_state), |
163 focus_source(focus_source), | 165 focus_source(focus_source), |
164 autocomplete_input(autocomplete_input) { | 166 autocomplete_input(autocomplete_input) { |
165 } | 167 } |
166 | 168 |
167 OmniboxEditModel::State::State(const State& other) = default; | 169 OmniboxEditModel::State::State(const State& other) = default; |
168 | 170 |
169 OmniboxEditModel::State::~State() { | 171 OmniboxEditModel::State::~State() { |
170 } | 172 } |
171 | 173 |
172 | 174 |
173 // OmniboxEditModel ----------------------------------------------------------- | 175 // OmniboxEditModel ----------------------------------------------------------- |
174 | 176 |
175 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, | 177 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
176 OmniboxEditController* controller, | 178 OmniboxEditController* controller, |
177 scoped_ptr<OmniboxClient> client) | 179 scoped_ptr<OmniboxClient> client) |
178 : client_(std::move(client)), | 180 : client_(std::move(client)), |
179 view_(view), | 181 view_(view), |
180 controller_(controller), | 182 controller_(controller), |
181 focus_state_(OMNIBOX_FOCUS_NONE), | 183 focus_state_(OMNIBOX_FOCUS_NONE), |
182 focus_source_(INVALID), | 184 focus_source_(INVALID), |
183 user_input_in_progress_(false), | 185 user_input_in_progress_(false), |
184 user_input_since_focus_(true), | 186 user_input_since_focus_(true), |
185 just_deleted_text_(false), | 187 just_deleted_text_(false), |
188 just_cleared_keyword_(false), | |
186 has_temporary_text_(false), | 189 has_temporary_text_(false), |
187 paste_state_(NONE), | 190 paste_state_(NONE), |
188 control_key_state_(UP), | 191 control_key_state_(UP), |
189 is_keyword_hint_(false), | 192 is_keyword_hint_(false), |
190 in_revert_(false), | 193 in_revert_(false), |
191 allow_exact_keyword_match_(false) { | 194 allow_exact_keyword_match_(false) { |
192 omnibox_controller_.reset(new OmniboxController(this, client_.get())); | 195 omnibox_controller_.reset(new OmniboxController(this, client_.get())); |
193 } | 196 } |
194 | 197 |
195 OmniboxEditModel::~OmniboxEditModel() { | 198 OmniboxEditModel::~OmniboxEditModel() { |
(...skipping 14 matching lines...) Expand all Loading... | |
210 view_->SelectAll(true); | 213 view_->SelectAll(true); |
211 } else { | 214 } else { |
212 InternalSetUserText(user_text); | 215 InternalSetUserText(user_text); |
213 } | 216 } |
214 } | 217 } |
215 | 218 |
216 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", | 219 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", |
217 user_input_in_progress_); | 220 user_input_in_progress_); |
218 return State( | 221 return State( |
219 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), | 222 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), |
220 keyword_, is_keyword_hint_, | 223 keyword_, is_keyword_hint_, keyword_entered_method_, |
221 controller_->GetToolbarModel()->url_replacement_enabled(), | 224 controller_->GetToolbarModel()->url_replacement_enabled(), |
222 focus_state_, focus_source_, input_); | 225 focus_state_, focus_source_, input_); |
223 } | 226 } |
224 | 227 |
225 void OmniboxEditModel::RestoreState(const State* state) { | 228 void OmniboxEditModel::RestoreState(const State* state) { |
226 // We need to update the permanent text correctly and revert the view | 229 // We need to update the permanent text correctly and revert the view |
227 // regardless of whether there is saved state. | 230 // regardless of whether there is saved state. |
228 bool url_replacement_enabled = !state || state->url_replacement_enabled; | 231 bool url_replacement_enabled = !state || state->url_replacement_enabled; |
229 controller_->GetToolbarModel()->set_url_replacement_enabled( | 232 controller_->GetToolbarModel()->set_url_replacement_enabled( |
230 url_replacement_enabled); | 233 url_replacement_enabled); |
231 permanent_text_ = controller_->GetToolbarModel()->GetText(); | 234 permanent_text_ = controller_->GetToolbarModel()->GetText(); |
232 // Don't muck with the search term replacement state, as we've just set it | 235 // Don't muck with the search term replacement state, as we've just set it |
233 // correctly. | 236 // correctly. |
234 view_->RevertWithoutResettingSearchTermReplacement(); | 237 view_->RevertWithoutResettingSearchTermReplacement(); |
235 // Restore the autocomplete controller's input, or clear it if this is a new | 238 // Restore the autocomplete controller's input, or clear it if this is a new |
236 // tab. | 239 // tab. |
237 input_ = state ? state->autocomplete_input : AutocompleteInput(); | 240 input_ = state ? state->autocomplete_input : AutocompleteInput(); |
238 if (!state) | 241 if (!state) |
239 return; | 242 return; |
240 | 243 |
241 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); | 244 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); |
242 focus_source_ = state->focus_source; | 245 focus_source_ = state->focus_source; |
243 // Restore any user editing. | 246 // Restore any user editing. |
244 if (state->user_input_in_progress) { | 247 if (state->user_input_in_progress) { |
245 // NOTE: Be sure and set keyword-related state BEFORE invoking | 248 // NOTE: Be sure and set keyword-related state BEFORE invoking |
246 // DisplayTextFromUserText(), as its result depends upon this state. | 249 // DisplayTextFromUserText(), as its result depends upon this state. |
247 keyword_ = state->keyword; | 250 keyword_ = state->keyword; |
248 is_keyword_hint_ = state->is_keyword_hint; | 251 is_keyword_hint_ = state->is_keyword_hint; |
252 keyword_entered_method_ = state->keyword_entered_method; | |
249 view_->SetUserText(state->user_text, | 253 view_->SetUserText(state->user_text, |
250 DisplayTextFromUserText(state->user_text), false); | 254 DisplayTextFromUserText(state->user_text), false); |
251 view_->SetGrayTextAutocompletion(state->gray_text); | 255 view_->SetGrayTextAutocompletion(state->gray_text); |
252 } | 256 } |
253 } | 257 } |
254 | 258 |
255 AutocompleteMatch OmniboxEditModel::CurrentMatch( | 259 AutocompleteMatch OmniboxEditModel::CurrentMatch( |
256 GURL* alternate_nav_url) const { | 260 GURL* alternate_nav_url) const { |
257 // If we have a valid match use it. Otherwise get one for the current text. | 261 // If we have a valid match use it. Otherwise get one for the current text. |
258 AutocompleteMatch match = omnibox_controller_->current_match(); | 262 AutocompleteMatch match = omnibox_controller_->current_match(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 325 |
322 const base::string16 final_text = view_->GetText() + suggestion; | 326 const base::string16 final_text = view_->GetText() + suggestion; |
323 view_->OnBeforePossibleChange(); | 327 view_->OnBeforePossibleChange(); |
324 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, | 328 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, |
325 false); | 329 false); |
326 view_->OnAfterPossibleChange(true); | 330 view_->OnAfterPossibleChange(true); |
327 return true; | 331 return true; |
328 } | 332 } |
329 | 333 |
330 void OmniboxEditModel::OnChanged() { | 334 void OmniboxEditModel::OnChanged() { |
335 // If the user input a "?", put them into keyword mode. | |
336 if (!just_cleared_keyword_ && !just_deleted_text_ && | |
337 user_text_ == base::ASCIIToUTF16("?")) { | |
Peter Kasting
2016/04/13 02:52:16
It doesn't seem like this handles the case of inse
Tom (Use chromium acct)
2016/04/13 23:37:40
It does not. However, it would be a bit complex t
Peter Kasting
2016/04/15 00:58:55
I think so -- if you prefix some existing text wit
| |
338 user_text_ = base::string16(); | |
339 EnterKeywordModeForDefaultSearchProvider( | |
340 ENTERED_KEYWORD_MODE_VIA_QUESTION_MARK); | |
341 } | |
342 | |
331 // Hide any suggestions we might be showing. | 343 // Hide any suggestions we might be showing. |
332 view_->SetGrayTextAutocompletion(base::string16()); | 344 view_->SetGrayTextAutocompletion(base::string16()); |
333 | 345 |
334 // Don't call CurrentMatch() when there's no editing, as in this case we'll | 346 // Don't call CurrentMatch() when there's no editing, as in this case we'll |
335 // never actually use it. This avoids running the autocomplete providers (and | 347 // never actually use it. This avoids running the autocomplete providers (and |
336 // any systems they then spin up) during startup. | 348 // any systems they then spin up) during startup. |
337 const AutocompleteMatch& current_match = user_input_in_progress_ ? | 349 const AutocompleteMatch& current_match = user_input_in_progress_ ? |
338 CurrentMatch(NULL) : AutocompleteMatch(); | 350 CurrentMatch(NULL) : AutocompleteMatch(); |
339 | 351 |
340 client_->OnTextChanged(current_match, user_input_in_progress_, user_text_, | 352 client_->OnTextChanged(current_match, user_input_in_progress_, user_text_, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 match.transition = ui::PAGE_TRANSITION_LINK; | 630 match.transition = ui::PAGE_TRANSITION_LINK; |
619 } | 631 } |
620 | 632 |
621 client_->OnInputAccepted(match); | 633 client_->OnInputAccepted(match); |
622 | 634 |
623 DCHECK(popup_model()); | 635 DCHECK(popup_model()); |
624 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), | 636 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), |
625 popup_model()->selected_line()); | 637 popup_model()->selected_line()); |
626 } | 638 } |
627 | 639 |
640 void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider( | |
641 EnteredKeywordModeMethod keyword_entered_method) { | |
642 autocomplete_controller()->Stop(false); | |
643 | |
644 base::string16 query = DisplayTextFromUserText(user_text_); | |
645 keyword_ = client_->GetTemplateURLService()-> | |
646 GetDefaultSearchProvider()->keyword(); | |
647 is_keyword_hint_ = false; | |
648 keyword_entered_method_ = keyword_entered_method; | |
649 InternalSetUserText(keyword_ + base::ASCIIToUTF16(" ") + query); | |
650 | |
651 view_->OnTemporaryTextMaybeChanged(user_text_, false, true); | |
652 StartAutocomplete(false, false, true); | |
653 | |
654 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, | |
655 keyword_entered_method, | |
656 ENTERED_KEYWORD_MODE_NUM_ITEMS); | |
657 } | |
658 | |
628 void OmniboxEditModel::OpenMatch(AutocompleteMatch match, | 659 void OmniboxEditModel::OpenMatch(AutocompleteMatch match, |
629 WindowOpenDisposition disposition, | 660 WindowOpenDisposition disposition, |
630 const GURL& alternate_nav_url, | 661 const GURL& alternate_nav_url, |
631 const base::string16& pasted_text, | 662 const base::string16& pasted_text, |
632 size_t index) { | 663 size_t index) { |
633 const base::TimeTicks& now(base::TimeTicks::Now()); | 664 const base::TimeTicks& now(base::TimeTicks::Now()); |
634 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( | 665 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( |
635 now - time_user_first_modified_omnibox_); | 666 now - time_user_first_modified_omnibox_); |
636 autocomplete_controller()->UpdateMatchDestinationURLWithQueryFormulationTime( | 667 autocomplete_controller()->UpdateMatchDestinationURLWithQueryFormulationTime( |
637 elapsed_time_since_user_first_modified_omnibox, &match); | 668 elapsed_time_since_user_first_modified_omnibox, &match); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 BookmarkModel* bookmark_model = client_->GetBookmarkModel(); | 812 BookmarkModel* bookmark_model = client_->GetBookmarkModel(); |
782 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url)) | 813 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url)) |
783 client_->OnBookmarkLaunched(); | 814 client_->OnBookmarkLaunched(); |
784 } | 815 } |
785 | 816 |
786 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { | 817 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
787 DCHECK(is_keyword_hint_ && !keyword_.empty()); | 818 DCHECK(is_keyword_hint_ && !keyword_.empty()); |
788 | 819 |
789 autocomplete_controller()->Stop(false); | 820 autocomplete_controller()->Stop(false); |
790 is_keyword_hint_ = false; | 821 is_keyword_hint_ = false; |
822 keyword_entered_method_ = entered_method; | |
791 | 823 |
792 if (popup_model() && popup_model()->IsOpen()) | 824 if (popup_model() && popup_model()->IsOpen()) |
793 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); | 825 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
794 else | 826 else |
795 StartAutocomplete(false, true, true); | 827 StartAutocomplete(false, true, true); |
796 | 828 |
797 // When entering keyword mode via tab, the new text to show is whatever the | 829 // 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, | 830 // 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 | 831 // 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 | 832 // text. This ensures that if the user types "<keyword><space>" and the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { | 869 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { |
838 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 870 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
839 has_temporary_text_ = false; | 871 has_temporary_text_ = false; |
840 | 872 |
841 if (user_input_in_progress_ || !in_revert_) | 873 if (user_input_in_progress_ || !in_revert_) |
842 client_->OnInputStateChanged(); | 874 client_->OnInputStateChanged(); |
843 } | 875 } |
844 | 876 |
845 void OmniboxEditModel::ClearKeyword() { | 877 void OmniboxEditModel::ClearKeyword() { |
846 autocomplete_controller()->Stop(false); | 878 autocomplete_controller()->Stop(false); |
879 just_cleared_keyword_ = true; | |
Peter Kasting
2016/04/13 02:52:16
Nit: Use base::AutoReset here to ensure you set th
Tom (Use chromium acct)
2016/04/13 23:37:41
Not broken. Added base::AutoReset for now.
On a s
| |
847 | 880 |
848 // While we're always in keyword mode upon reaching here, sometimes we've just | 881 // While we're always in keyword mode upon reaching here, sometimes we've just |
849 // toggled in via space or tab, and sometimes we're on a non-toggled line | 882 // toggled in via space or tab, and sometimes we're on a non-toggled line |
850 // (usually because the user has typed a search string). Keep track of the | 883 // (usually because the user has typed a search string). Keep track of the |
851 // difference, as we'll need it below. | 884 // difference, as we'll need it below. |
852 bool was_toggled_into_keyword_mode = | 885 bool was_toggled_into_keyword_mode = |
853 popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD; | 886 popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD; |
854 | 887 |
855 omnibox_controller_->ClearPopupKeywordMode(); | 888 omnibox_controller_->ClearPopupKeywordMode(); |
856 | 889 |
890 // If we entered keyword mode in a special way like using a keyboard shortcut | |
891 // or typing a question mark in a blank omnibox, don't restore the keyword. | |
Peter Kasting
2016/04/13 02:52:16
Nit: "... Instead, restore the question mark iff t
Tom (Use chromium acct)
2016/04/13 23:37:41
Done.
| |
892 if (keyword_entered_method_ == ENTERED_KEYWORD_MODE_VIA_KEYBOARD_SHORTCUT || | |
893 keyword_entered_method_ == ENTERED_KEYWORD_MODE_VIA_QUESTION_MARK) { | |
894 view_->OnBeforePossibleChange(); | |
Peter Kasting
2016/04/13 02:52:16
Nit: This function body is basically identical to
Tom (Use chromium acct)
2016/04/13 23:37:40
Done.
| |
895 if (keyword_entered_method_ == ENTERED_KEYWORD_MODE_VIA_QUESTION_MARK) | |
Peter Kasting
2016/04/13 02:52:16
Nit: Needs {}
Tom (Use chromium acct)
2016/04/13 23:37:41
Done.
| |
896 view_->SetWindowTextAndCaretPos( | |
897 base::ASCIIToUTF16("?") + view_->GetText(), 1, false, false); | |
898 else | |
899 view_->SetWindowTextAndCaretPos(view_->GetText(), 0, false, false); | |
900 keyword_.clear(); | |
901 is_keyword_hint_ = false; | |
902 view_->OnAfterPossibleChange(false); | |
903 just_cleared_keyword_ = false; | |
904 return; | |
905 } | |
906 | |
857 // There are several possible states we could have been in before the user hit | 907 // There are several possible states we could have been in before the user hit |
858 // backspace or shift-tab to enter this function: | 908 // backspace or shift-tab to enter this function: |
859 // (1) was_toggled_into_keyword_mode == false, has_temporary_text_ == false | 909 // (1) was_toggled_into_keyword_mode == false, has_temporary_text_ == false |
860 // The user typed a further key after being in keyword mode already, e.g. | 910 // The user typed a further key after being in keyword mode already, e.g. |
861 // "google.com f". | 911 // "google.com f". |
862 // (2) was_toggled_into_keyword_mode == false, has_temporary_text_ == true | 912 // (2) was_toggled_into_keyword_mode == false, has_temporary_text_ == true |
863 // The user tabbed away from a dropdown entry in keyword mode, then tabbed | 913 // The user tabbed away from a dropdown entry in keyword mode, then tabbed |
864 // back to it, e.g. "google.com f<tab><shift-tab>". | 914 // back to it, e.g. "google.com f<tab><shift-tab>". |
865 // (3) was_toggled_into_keyword_mode == true, has_temporary_text_ == false | 915 // (3) was_toggled_into_keyword_mode == true, has_temporary_text_ == false |
866 // The user had just typed space to enter keyword mode, e.g. | 916 // The user had just typed space to enter keyword mode, e.g. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 // the user wants it, it's more work to add because typing the space will | 964 // the user wants it, it's more work to add because typing the space will |
915 // enter keyword mode, which then the user would have to leave again. | 965 // enter keyword mode, which then the user would have to leave again. |
916 const base::string16 window_text = | 966 const base::string16 window_text = |
917 keyword_ + base::ASCIIToUTF16(" ") + view_->GetText(); | 967 keyword_ + base::ASCIIToUTF16(" ") + view_->GetText(); |
918 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, | 968 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, |
919 false, false); | 969 false, false); |
920 keyword_.clear(); | 970 keyword_.clear(); |
921 is_keyword_hint_ = false; | 971 is_keyword_hint_ = false; |
922 view_->OnAfterPossibleChange(false); | 972 view_->OnAfterPossibleChange(false); |
923 } | 973 } |
974 just_cleared_keyword_ = false; | |
924 } | 975 } |
925 | 976 |
926 void OmniboxEditModel::OnSetFocus(bool control_down) { | 977 void OmniboxEditModel::OnSetFocus(bool control_down) { |
927 last_omnibox_focus_ = base::TimeTicks::Now(); | 978 last_omnibox_focus_ = base::TimeTicks::Now(); |
928 user_input_since_focus_ = false; | 979 user_input_since_focus_ = false; |
929 | 980 |
930 // If the omnibox lost focus while the caret was hidden and then regained | 981 // If the omnibox lost focus while the caret was hidden and then regained |
931 // focus, OnSetFocus() is called and should restore visibility. Note that | 982 // focus, OnSetFocus() is called and should restore visibility. Note that |
932 // focus can be regained without an accompanying call to | 983 // focus can be regained without an accompanying call to |
933 // OmniboxView::SetFocus(), e.g. by tabbing in. | 984 // OmniboxView::SetFocus(), e.g. by tabbing in. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 if (call_controller_onchanged) | 1199 if (call_controller_onchanged) |
1149 OnChanged(); | 1200 OnChanged(); |
1150 } | 1201 } |
1151 | 1202 |
1152 bool OmniboxEditModel::OnAfterPossibleChange(const base::string16& old_text, | 1203 bool OmniboxEditModel::OnAfterPossibleChange(const base::string16& old_text, |
1153 const base::string16& new_text, | 1204 const base::string16& new_text, |
1154 size_t selection_start, | 1205 size_t selection_start, |
1155 size_t selection_end, | 1206 size_t selection_end, |
1156 bool selection_differs, | 1207 bool selection_differs, |
1157 bool text_differs, | 1208 bool text_differs, |
1209 bool keyword_differs, | |
1158 bool just_deleted_text, | 1210 bool just_deleted_text, |
1159 bool allow_keyword_ui_change) { | 1211 bool allow_keyword_ui_change) { |
1160 // Update the paste state as appropriate: if we're just finishing a paste | 1212 // Update the paste state as appropriate: if we're just finishing a paste |
1161 // that replaced all the text, preserve that information; otherwise, if we've | 1213 // that replaced all the text, preserve that information; otherwise, if we've |
1162 // made some other edit, clear paste tracking. | 1214 // made some other edit, clear paste tracking. |
1163 if (paste_state_ == PASTING) | 1215 if (paste_state_ == PASTING) |
1164 paste_state_ = PASTED; | 1216 paste_state_ = PASTED; |
1165 else if (text_differs) | 1217 else if (text_differs) |
1166 paste_state_ = NONE; | 1218 paste_state_ = NONE; |
1167 | 1219 |
(...skipping 19 matching lines...) Expand all Loading... | |
1187 const bool user_text_changed = | 1239 const bool user_text_changed = |
1188 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 1240 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
1189 | 1241 |
1190 // If something has changed while the control key is down, prevent | 1242 // If something has changed while the control key is down, prevent |
1191 // "ctrl-enter" until the control key is released. | 1243 // "ctrl-enter" until the control key is released. |
1192 if ((text_differs || selection_differs) && | 1244 if ((text_differs || selection_differs) && |
1193 (control_key_state_ == DOWN_WITHOUT_CHANGE)) | 1245 (control_key_state_ == DOWN_WITHOUT_CHANGE)) |
1194 control_key_state_ = DOWN_WITH_CHANGE; | 1246 control_key_state_ = DOWN_WITH_CHANGE; |
1195 | 1247 |
1196 if (!user_text_changed) | 1248 if (!user_text_changed) |
1197 return false; | 1249 return keyword_differs; |
1198 | 1250 |
1199 // If the user text has not changed, we do not want to change the model's | 1251 // 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 | 1252 // state associated with the text. Otherwise, we can get surprising behavior |
1201 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1253 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
1202 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1254 InternalSetUserText(UserTextFromDisplayText(new_text)); |
1203 has_temporary_text_ = false; | 1255 has_temporary_text_ = false; |
1204 | 1256 |
1205 // Track when the user has deleted text so we won't allow inline | 1257 // Track when the user has deleted text so we won't allow inline |
1206 // autocomplete. | 1258 // autocomplete. |
1207 just_deleted_text_ = just_deleted_text; | 1259 just_deleted_text_ = just_deleted_text; |
(...skipping 255 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 | 1515 // Update state and notify view if the omnibox has focus and the caret |
1464 // visibility changed. | 1516 // visibility changed. |
1465 const bool was_caret_visible = is_caret_visible(); | 1517 const bool was_caret_visible = is_caret_visible(); |
1466 focus_state_ = state; | 1518 focus_state_ = state; |
1467 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1519 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1468 is_caret_visible() != was_caret_visible) | 1520 is_caret_visible() != was_caret_visible) |
1469 view_->ApplyCaretVisibility(); | 1521 view_->ApplyCaretVisibility(); |
1470 | 1522 |
1471 client_->OnFocusChanged(focus_state_, reason); | 1523 client_->OnFocusChanged(focus_state_, reason); |
1472 } | 1524 } |
OLD | NEW |