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 27 matching lines...) Expand all Loading... | |
38 #include "components/search_engines/template_url_service.h" | 38 #include "components/search_engines/template_url_service.h" |
39 #include "components/toolbar/toolbar_model.h" | 39 #include "components/toolbar/toolbar_model.h" |
40 #include "components/url_formatter/url_fixer.h" | 40 #include "components/url_formatter/url_fixer.h" |
41 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
42 #include "url/url_util.h" | 42 #include "url/url_util.h" |
43 | 43 |
44 using bookmarks::BookmarkModel; | 44 using bookmarks::BookmarkModel; |
45 using metrics::OmniboxEventProto; | 45 using metrics::OmniboxEventProto; |
46 | 46 |
47 | 47 |
48 | |
Peter Kasting
2016/04/08 00:39:56
Nit: Don't add this
Tom (Use chromium acct)
2016/04/12 20:03:05
Done.
| |
48 // Helpers -------------------------------------------------------------------- | 49 // Helpers -------------------------------------------------------------------- |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 // Histogram name which counts the number of times that the user text is | 53 // Histogram name which counts the number of times that the user text is |
53 // cleared. IME users are sometimes in the situation that IME was | 54 // cleared. IME users are sometimes in the situation that IME was |
54 // unintentionally turned on and failed to input latin alphabets (ASCII | 55 // unintentionally turned on and failed to input latin alphabets (ASCII |
55 // characters) or the opposite case. In that case, users may delete all | 56 // characters) or the opposite case. In that case, users may delete all |
56 // the text and the user text gets cleared. We'd like to measure how often | 57 // the text and the user text gets cleared. We'd like to measure how often |
57 // this scenario happens. | 58 // this scenario happens. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } // namespace | 143 } // namespace |
143 | 144 |
144 | 145 |
145 // OmniboxEditModel::State ---------------------------------------------------- | 146 // OmniboxEditModel::State ---------------------------------------------------- |
146 | 147 |
147 OmniboxEditModel::State::State(bool user_input_in_progress, | 148 OmniboxEditModel::State::State(bool user_input_in_progress, |
148 const base::string16& user_text, | 149 const base::string16& user_text, |
149 const base::string16& gray_text, | 150 const base::string16& gray_text, |
150 const base::string16& keyword, | 151 const base::string16& keyword, |
151 bool is_keyword_hint, | 152 bool is_keyword_hint, |
153 EnteredKeywordModeMethod keyword_entered_method, | |
152 bool url_replacement_enabled, | 154 bool url_replacement_enabled, |
153 OmniboxFocusState focus_state, | 155 OmniboxFocusState focus_state, |
154 FocusSource focus_source, | 156 FocusSource focus_source, |
155 const AutocompleteInput& autocomplete_input) | 157 const AutocompleteInput& autocomplete_input) |
156 : user_input_in_progress(user_input_in_progress), | 158 : user_input_in_progress(user_input_in_progress), |
157 user_text(user_text), | 159 user_text(user_text), |
158 gray_text(gray_text), | 160 gray_text(gray_text), |
159 keyword(keyword), | 161 keyword(keyword), |
160 is_keyword_hint(is_keyword_hint), | 162 is_keyword_hint(is_keyword_hint), |
163 keyword_entered_method(keyword_entered_method), | |
161 url_replacement_enabled(url_replacement_enabled), | 164 url_replacement_enabled(url_replacement_enabled), |
162 focus_state(focus_state), | 165 focus_state(focus_state), |
163 focus_source(focus_source), | 166 focus_source(focus_source), |
164 autocomplete_input(autocomplete_input) { | 167 autocomplete_input(autocomplete_input) { |
165 } | 168 } |
166 | 169 |
167 OmniboxEditModel::State::State(const State& other) = default; | 170 OmniboxEditModel::State::State(const State& other) = default; |
168 | 171 |
169 OmniboxEditModel::State::~State() { | 172 OmniboxEditModel::State::~State() { |
170 } | 173 } |
171 | 174 |
172 | 175 |
173 // OmniboxEditModel ----------------------------------------------------------- | 176 // OmniboxEditModel ----------------------------------------------------------- |
174 | 177 |
175 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, | 178 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
176 OmniboxEditController* controller, | 179 OmniboxEditController* controller, |
177 scoped_ptr<OmniboxClient> client) | 180 scoped_ptr<OmniboxClient> client) |
178 : client_(std::move(client)), | 181 : client_(std::move(client)), |
179 view_(view), | 182 view_(view), |
180 controller_(controller), | 183 controller_(controller), |
181 focus_state_(OMNIBOX_FOCUS_NONE), | 184 focus_state_(OMNIBOX_FOCUS_NONE), |
182 focus_source_(INVALID), | 185 focus_source_(INVALID), |
183 user_input_in_progress_(false), | 186 user_input_in_progress_(false), |
184 user_input_since_focus_(true), | 187 user_input_since_focus_(true), |
185 just_deleted_text_(false), | 188 just_deleted_text_(false), |
189 just_cleared_keyword_(false), | |
186 has_temporary_text_(false), | 190 has_temporary_text_(false), |
187 paste_state_(NONE), | 191 paste_state_(NONE), |
188 control_key_state_(UP), | 192 control_key_state_(UP), |
189 is_keyword_hint_(false), | 193 is_keyword_hint_(false), |
190 in_revert_(false), | 194 in_revert_(false), |
191 allow_exact_keyword_match_(false) { | 195 allow_exact_keyword_match_(false) { |
192 omnibox_controller_.reset(new OmniboxController(this, client_.get())); | 196 omnibox_controller_.reset(new OmniboxController(this, client_.get())); |
193 } | 197 } |
194 | 198 |
195 OmniboxEditModel::~OmniboxEditModel() { | 199 OmniboxEditModel::~OmniboxEditModel() { |
(...skipping 14 matching lines...) Expand all Loading... | |
210 view_->SelectAll(true); | 214 view_->SelectAll(true); |
211 } else { | 215 } else { |
212 InternalSetUserText(user_text); | 216 InternalSetUserText(user_text); |
213 } | 217 } |
214 } | 218 } |
215 | 219 |
216 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", | 220 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", |
217 user_input_in_progress_); | 221 user_input_in_progress_); |
218 return State( | 222 return State( |
219 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), | 223 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), |
220 keyword_, is_keyword_hint_, | 224 keyword_, is_keyword_hint_, keyword_entered_method_, |
221 controller_->GetToolbarModel()->url_replacement_enabled(), | 225 controller_->GetToolbarModel()->url_replacement_enabled(), |
222 focus_state_, focus_source_, input_); | 226 focus_state_, focus_source_, input_); |
223 } | 227 } |
224 | 228 |
225 void OmniboxEditModel::RestoreState(const State* state) { | 229 void OmniboxEditModel::RestoreState(const State* state) { |
226 // We need to update the permanent text correctly and revert the view | 230 // We need to update the permanent text correctly and revert the view |
227 // regardless of whether there is saved state. | 231 // regardless of whether there is saved state. |
228 bool url_replacement_enabled = !state || state->url_replacement_enabled; | 232 bool url_replacement_enabled = !state || state->url_replacement_enabled; |
229 controller_->GetToolbarModel()->set_url_replacement_enabled( | 233 controller_->GetToolbarModel()->set_url_replacement_enabled( |
230 url_replacement_enabled); | 234 url_replacement_enabled); |
231 permanent_text_ = controller_->GetToolbarModel()->GetText(); | 235 permanent_text_ = controller_->GetToolbarModel()->GetText(); |
232 // Don't muck with the search term replacement state, as we've just set it | 236 // Don't muck with the search term replacement state, as we've just set it |
233 // correctly. | 237 // correctly. |
234 view_->RevertWithoutResettingSearchTermReplacement(); | 238 view_->RevertWithoutResettingSearchTermReplacement(); |
235 // Restore the autocomplete controller's input, or clear it if this is a new | 239 // Restore the autocomplete controller's input, or clear it if this is a new |
236 // tab. | 240 // tab. |
237 input_ = state ? state->autocomplete_input : AutocompleteInput(); | 241 input_ = state ? state->autocomplete_input : AutocompleteInput(); |
238 if (!state) | 242 if (!state) |
239 return; | 243 return; |
240 | 244 |
241 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); | 245 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); |
242 focus_source_ = state->focus_source; | 246 focus_source_ = state->focus_source; |
243 // Restore any user editing. | 247 // Restore any user editing. |
244 if (state->user_input_in_progress) { | 248 if (state->user_input_in_progress) { |
245 // NOTE: Be sure and set keyword-related state BEFORE invoking | 249 // NOTE: Be sure and set keyword-related state BEFORE invoking |
246 // DisplayTextFromUserText(), as its result depends upon this state. | 250 // DisplayTextFromUserText(), as its result depends upon this state. |
247 keyword_ = state->keyword; | 251 keyword_ = state->keyword; |
248 is_keyword_hint_ = state->is_keyword_hint; | 252 is_keyword_hint_ = state->is_keyword_hint; |
253 keyword_entered_method_ = state->keyword_entered_method; | |
249 view_->SetUserText(state->user_text, | 254 view_->SetUserText(state->user_text, |
250 DisplayTextFromUserText(state->user_text), false); | 255 DisplayTextFromUserText(state->user_text), false); |
251 view_->SetGrayTextAutocompletion(state->gray_text); | 256 view_->SetGrayTextAutocompletion(state->gray_text); |
252 } | 257 } |
253 } | 258 } |
254 | 259 |
255 AutocompleteMatch OmniboxEditModel::CurrentMatch( | 260 AutocompleteMatch OmniboxEditModel::CurrentMatch( |
256 GURL* alternate_nav_url) const { | 261 GURL* alternate_nav_url) const { |
257 // If we have a valid match use it. Otherwise get one for the current text. | 262 // If we have a valid match use it. Otherwise get one for the current text. |
258 AutocompleteMatch match = omnibox_controller_->current_match(); | 263 AutocompleteMatch match = omnibox_controller_->current_match(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 326 |
322 const base::string16 final_text = view_->GetText() + suggestion; | 327 const base::string16 final_text = view_->GetText() + suggestion; |
323 view_->OnBeforePossibleChange(); | 328 view_->OnBeforePossibleChange(); |
324 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, | 329 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, |
325 false); | 330 false); |
326 view_->OnAfterPossibleChange(true); | 331 view_->OnAfterPossibleChange(true); |
327 return true; | 332 return true; |
328 } | 333 } |
329 | 334 |
330 void OmniboxEditModel::OnChanged() { | 335 void OmniboxEditModel::OnChanged() { |
336 // If the user input a "?", put them into keyword mode. | |
337 if (!just_cleared_keyword_ && !just_deleted_text_) { | |
338 if (user_text_ == base::ASCIIToUTF16("?")) { | |
Peter Kasting
2016/04/08 00:39:56
Nit: Combine these ifs
Tom (Use chromium acct)
2016/04/12 20:03:05
Done.
| |
339 user_text_ = base::string16(); | |
340 SetKeywordWithDefaultSearchProvider( | |
341 ENTERED_KEYWORD_MODE_VIA_QUESTION_MARK); | |
342 } | |
343 } | |
344 | |
331 // Hide any suggestions we might be showing. | 345 // Hide any suggestions we might be showing. |
332 view_->SetGrayTextAutocompletion(base::string16()); | 346 view_->SetGrayTextAutocompletion(base::string16()); |
333 | 347 |
334 // Don't call CurrentMatch() when there's no editing, as in this case we'll | 348 // 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 | 349 // never actually use it. This avoids running the autocomplete providers (and |
336 // any systems they then spin up) during startup. | 350 // any systems they then spin up) during startup. |
337 const AutocompleteMatch& current_match = user_input_in_progress_ ? | 351 const AutocompleteMatch& current_match = user_input_in_progress_ ? |
338 CurrentMatch(NULL) : AutocompleteMatch(); | 352 CurrentMatch(NULL) : AutocompleteMatch(); |
339 | 353 |
340 client_->OnTextChanged(current_match, user_input_in_progress_, user_text_, | 354 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; | 632 match.transition = ui::PAGE_TRANSITION_LINK; |
619 } | 633 } |
620 | 634 |
621 client_->OnInputAccepted(match); | 635 client_->OnInputAccepted(match); |
622 | 636 |
623 DCHECK(popup_model()); | 637 DCHECK(popup_model()); |
624 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), | 638 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), |
625 popup_model()->selected_line()); | 639 popup_model()->selected_line()); |
626 } | 640 } |
627 | 641 |
642 void OmniboxEditModel::SetKeywordWithDefaultSearchProvider( | |
643 EnteredKeywordModeMethod keyword_entered_method) { | |
644 autocomplete_controller()->Stop(false); | |
645 | |
646 keyword_ = client_->GetTemplateURLService()-> | |
647 GetDefaultSearchProvider()->keyword(); | |
648 | |
Peter Kasting
2016/04/08 00:39:56
Nit: I'd remove this blank line
Tom (Use chromium acct)
2016/04/12 20:03:05
Done.
| |
649 is_keyword_hint_ = false; | |
650 keyword_entered_method_ = keyword_entered_method; | |
651 | |
652 view_->OnTemporaryTextMaybeChanged(user_text_, 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 view_->OnBeforePossibleChange(); | |
Peter Kasting
2016/04/08 00:39:56
This will result in calling this in the "state 4"
Tom (Use chromium acct)
2016/04/12 20:03:05
Done.
I also moved view_->OnAfterPossibleChange(fa
| |
880 just_cleared_keyword_ = true; | |
847 | 881 |
848 // While we're always in keyword mode upon reaching here, sometimes we've just | 882 // 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 | 883 // 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 | 884 // (usually because the user has typed a search string). Keep track of the |
851 // difference, as we'll need it below. | 885 // difference, as we'll need it below. |
852 bool was_toggled_into_keyword_mode = | 886 bool was_toggled_into_keyword_mode = |
853 popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD; | 887 popup_model()->selected_line_state() == OmniboxPopupModel::KEYWORD; |
854 | 888 |
855 omnibox_controller_->ClearPopupKeywordMode(); | 889 omnibox_controller_->ClearPopupKeywordMode(); |
856 | 890 |
891 // If we entered keyword mode in a special way like using a keyboard shortcut | |
892 // or typing a question mark in a blank omnibox, don't restore the keyword. | |
893 const char* clear_text = nullptr; | |
Peter Kasting
2016/04/08 00:39:56
Use a std::string in preference to char*.
Or bett
Tom (Use chromium acct)
2016/04/12 20:03:05
Done.
| |
894 switch (keyword_entered_method_) { | |
895 case ENTERED_KEYWORD_MODE_VIA_KEYBOARD_SHORTCUT: | |
896 clear_text = ""; | |
897 break; | |
898 case ENTERED_KEYWORD_MODE_VIA_QUESTION_MARK: | |
899 clear_text = "?"; | |
900 break; | |
901 default: | |
902 break; | |
903 } | |
904 if (clear_text) { | |
905 view_->SetWindowTextAndCaretPos( | |
906 base::ASCIIToUTF16(clear_text) + view_->GetText(), strlen(clear_text), | |
907 false, false); | |
908 keyword_.clear(); | |
909 is_keyword_hint_ = false; | |
910 view_->OnAfterPossibleChange(false); | |
911 just_cleared_keyword_ = false; | |
912 return; | |
913 } | |
914 | |
857 // There are several possible states we could have been in before the user hit | 915 // There are several possible states we could have been in before the user hit |
858 // backspace or shift-tab to enter this function: | 916 // backspace or shift-tab to enter this function: |
859 // (1) was_toggled_into_keyword_mode == false, has_temporary_text_ == false | 917 // (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. | 918 // The user typed a further key after being in keyword mode already, e.g. |
861 // "google.com f". | 919 // "google.com f". |
862 // (2) was_toggled_into_keyword_mode == false, has_temporary_text_ == true | 920 // (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 | 921 // 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>". | 922 // back to it, e.g. "google.com f<tab><shift-tab>". |
865 // (3) was_toggled_into_keyword_mode == true, has_temporary_text_ == false | 923 // (3) was_toggled_into_keyword_mode == true, has_temporary_text_ == false |
866 // The user had just typed space to enter keyword mode, e.g. | 924 // The user had just typed space to enter keyword mode, e.g. |
(...skipping 27 matching lines...) Expand all Loading... | |
894 // then hitting backspace could wind up with the default match as the "x y" | 952 // then hitting backspace could wind up with the default match as the "x y" |
895 // search, which feels bizarre. | 953 // search, which feels bizarre. |
896 if (was_toggled_into_keyword_mode && has_temporary_text_) { | 954 if (was_toggled_into_keyword_mode && has_temporary_text_) { |
897 // State 4 above. | 955 // State 4 above. |
898 is_keyword_hint_ = true; | 956 is_keyword_hint_ = true; |
899 const base::string16 window_text = keyword_ + view_->GetText(); | 957 const base::string16 window_text = keyword_ + view_->GetText(); |
900 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 958 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
901 false, true); | 959 false, true); |
902 } else { | 960 } else { |
903 // States 1-3 above. | 961 // States 1-3 above. |
904 view_->OnBeforePossibleChange(); | 962 view_->OnBeforePossibleChange(); |
Peter Kasting
2016/04/08 00:39:56
This will result in calling this twice, which is b
Tom (Use chromium acct)
2016/04/13 23:37:40
Done.
| |
905 // Add a space after the keyword to allow the user to continue typing | 963 // Add a space after the keyword to allow the user to continue typing |
906 // without re-enabling keyword mode. The common case is state 3, where | 964 // without re-enabling keyword mode. The common case is state 3, where |
907 // the user entered keyword mode unintentionally, so backspacing | 965 // the user entered keyword mode unintentionally, so backspacing |
908 // immediately out of keyword mode should keep the space. In states 1 and | 966 // immediately out of keyword mode should keep the space. In states 1 and |
909 // 2, having the space is "safer" behavior. For instance, if the user types | 967 // 2, having the space is "safer" behavior. For instance, if the user types |
910 // "google.com f" or "google.com<tab>f" in the omnibox, moves the cursor to | 968 // "google.com f" or "google.com<tab>f" in the omnibox, moves the cursor to |
911 // the left, and presses backspace to leave keyword mode (state 1), it's | 969 // the left, and presses backspace to leave keyword mode (state 1), it's |
912 // better to have the space because it may be what the user wanted. The | 970 // better to have the space because it may be what the user wanted. The |
913 // user can easily delete it. On the other hand, if there is no space and | 971 // user can easily delete it. On the other hand, if there is no space and |
914 // the user wants it, it's more work to add because typing the space will | 972 // 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. | 973 // enter keyword mode, which then the user would have to leave again. |
916 const base::string16 window_text = | 974 const base::string16 window_text = |
917 keyword_ + base::ASCIIToUTF16(" ") + view_->GetText(); | 975 keyword_ + base::ASCIIToUTF16(" ") + view_->GetText(); |
918 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, | 976 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, |
919 false, false); | 977 false, false); |
920 keyword_.clear(); | 978 keyword_.clear(); |
921 is_keyword_hint_ = false; | 979 is_keyword_hint_ = false; |
922 view_->OnAfterPossibleChange(false); | |
923 } | 980 } |
981 view_->OnAfterPossibleChange(false); | |
982 just_cleared_keyword_ = false; | |
924 } | 983 } |
925 | 984 |
926 void OmniboxEditModel::OnSetFocus(bool control_down) { | 985 void OmniboxEditModel::OnSetFocus(bool control_down) { |
927 last_omnibox_focus_ = base::TimeTicks::Now(); | 986 last_omnibox_focus_ = base::TimeTicks::Now(); |
928 user_input_since_focus_ = false; | 987 user_input_since_focus_ = false; |
929 | 988 |
930 // If the omnibox lost focus while the caret was hidden and then regained | 989 // If the omnibox lost focus while the caret was hidden and then regained |
931 // focus, OnSetFocus() is called and should restore visibility. Note that | 990 // focus, OnSetFocus() is called and should restore visibility. Note that |
932 // focus can be regained without an accompanying call to | 991 // focus can be regained without an accompanying call to |
933 // OmniboxView::SetFocus(), e.g. by tabbing in. | 992 // 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) | 1207 if (call_controller_onchanged) |
1149 OnChanged(); | 1208 OnChanged(); |
1150 } | 1209 } |
1151 | 1210 |
1152 bool OmniboxEditModel::OnAfterPossibleChange(const base::string16& old_text, | 1211 bool OmniboxEditModel::OnAfterPossibleChange(const base::string16& old_text, |
1153 const base::string16& new_text, | 1212 const base::string16& new_text, |
1154 size_t selection_start, | 1213 size_t selection_start, |
1155 size_t selection_end, | 1214 size_t selection_end, |
1156 bool selection_differs, | 1215 bool selection_differs, |
1157 bool text_differs, | 1216 bool text_differs, |
1217 bool keyword_differs, | |
1158 bool just_deleted_text, | 1218 bool just_deleted_text, |
1159 bool allow_keyword_ui_change) { | 1219 bool allow_keyword_ui_change) { |
1160 // Update the paste state as appropriate: if we're just finishing a paste | 1220 // 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 | 1221 // that replaced all the text, preserve that information; otherwise, if we've |
1162 // made some other edit, clear paste tracking. | 1222 // made some other edit, clear paste tracking. |
1163 if (paste_state_ == PASTING) | 1223 if (paste_state_ == PASTING) |
1164 paste_state_ = PASTED; | 1224 paste_state_ = PASTED; |
1165 else if (text_differs) | 1225 else if (text_differs) |
1166 paste_state_ = NONE; | 1226 paste_state_ = NONE; |
1167 | 1227 |
(...skipping 19 matching lines...) Expand all Loading... | |
1187 const bool user_text_changed = | 1247 const bool user_text_changed = |
1188 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 1248 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
1189 | 1249 |
1190 // If something has changed while the control key is down, prevent | 1250 // If something has changed while the control key is down, prevent |
1191 // "ctrl-enter" until the control key is released. | 1251 // "ctrl-enter" until the control key is released. |
1192 if ((text_differs || selection_differs) && | 1252 if ((text_differs || selection_differs) && |
1193 (control_key_state_ == DOWN_WITHOUT_CHANGE)) | 1253 (control_key_state_ == DOWN_WITHOUT_CHANGE)) |
1194 control_key_state_ = DOWN_WITH_CHANGE; | 1254 control_key_state_ = DOWN_WITH_CHANGE; |
1195 | 1255 |
1196 if (!user_text_changed) | 1256 if (!user_text_changed) |
1197 return false; | 1257 return keyword_differs; |
1198 | 1258 |
1199 // If the user text has not changed, we do not want to change the model's | 1259 // 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 | 1260 // state associated with the text. Otherwise, we can get surprising behavior |
1201 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1261 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
1202 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1262 InternalSetUserText(UserTextFromDisplayText(new_text)); |
1203 has_temporary_text_ = false; | 1263 has_temporary_text_ = false; |
1204 | 1264 |
1205 // Track when the user has deleted text so we won't allow inline | 1265 // Track when the user has deleted text so we won't allow inline |
1206 // autocomplete. | 1266 // autocomplete. |
1207 just_deleted_text_ = just_deleted_text; | 1267 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 | 1523 // Update state and notify view if the omnibox has focus and the caret |
1464 // visibility changed. | 1524 // visibility changed. |
1465 const bool was_caret_visible = is_caret_visible(); | 1525 const bool was_caret_visible = is_caret_visible(); |
1466 focus_state_ = state; | 1526 focus_state_ = state; |
1467 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1527 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1468 is_caret_visible() != was_caret_visible) | 1528 is_caret_visible() != was_caret_visible) |
1469 view_->ApplyCaretVisibility(); | 1529 view_->ApplyCaretVisibility(); |
1470 | 1530 |
1471 client_->OnFocusChanged(focus_state_, reason); | 1531 client_->OnFocusChanged(focus_state_, reason); |
1472 } | 1532 } |
OLD | NEW |