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 "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // NOTE: Be sure and set keyword-related state BEFORE invoking | 177 // NOTE: Be sure and set keyword-related state BEFORE invoking |
178 // DisplayTextFromUserText(), as its result depends upon this state. | 178 // DisplayTextFromUserText(), as its result depends upon this state. |
179 keyword_ = state.keyword; | 179 keyword_ = state.keyword; |
180 is_keyword_hint_ = state.is_keyword_hint; | 180 is_keyword_hint_ = state.is_keyword_hint; |
181 view_->SetUserText(state.user_text, | 181 view_->SetUserText(state.user_text, |
182 DisplayTextFromUserText(state.user_text), false); | 182 DisplayTextFromUserText(state.user_text), false); |
183 view_->SetInstantSuggestion(state.instant_suggestion); | 183 view_->SetInstantSuggestion(state.instant_suggestion); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 AutocompleteMatch OmniboxEditModel::CurrentMatch() { | 187 AutocompleteMatch OmniboxEditModel::CurrentMatch() const { |
188 // If we have a valid match use it. Otherwise get one for the current text. | |
189 if (omnibox_controller_->current_match().destination_url.is_valid()) | |
Peter Kasting
2013/06/11 22:42:55
I think you can have a valid match without a valid
beaudoin
2013/06/14 21:39:38
Thanks for pointing this out. I don't think it has
| |
190 return omnibox_controller_->current_match(); | |
188 AutocompleteMatch match; | 191 AutocompleteMatch match; |
189 GetInfoForCurrentText(&match, NULL); | 192 GetInfoForCurrentText(&match, NULL); |
190 return match; | 193 return match; |
191 } | 194 } |
192 | 195 |
193 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { | 196 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { |
194 // When there's a new URL, and the user is not editing anything or the edit | 197 // When there's a new URL, and the user is not editing anything or the edit |
195 // doesn't have focus, we want to revert the edit to show the new URL. (The | 198 // doesn't have focus, we want to revert the edit to show the new URL. (The |
196 // common case where the edit doesn't have focus is when the user has started | 199 // common case where the edit doesn't have focus is when the user has started |
197 // an edit and then abandoned it and clicked a link on the page.) | 200 // an edit and then abandoned it and clicked a link on the page.) |
(...skipping 15 matching lines...) Expand all Loading... | |
213 return visibly_changed_permanent_text; | 216 return visibly_changed_permanent_text; |
214 } | 217 } |
215 | 218 |
216 GURL OmniboxEditModel::PermanentURL() { | 219 GURL OmniboxEditModel::PermanentURL() { |
217 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); | 220 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); |
218 } | 221 } |
219 | 222 |
220 void OmniboxEditModel::SetUserText(const string16& text) { | 223 void OmniboxEditModel::SetUserText(const string16& text) { |
221 SetInputInProgress(true); | 224 SetInputInProgress(true); |
222 InternalSetUserText(text); | 225 InternalSetUserText(text); |
226 omnibox_controller_->InvalidateCurrentMatch(); | |
223 paste_state_ = NONE; | 227 paste_state_ = NONE; |
224 has_temporary_text_ = false; | 228 has_temporary_text_ = false; |
225 is_temporary_text_set_by_instant_ = false; | 229 is_temporary_text_set_by_instant_ = false; |
226 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 230 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
227 is_instant_temporary_text_a_search_query_ = false; | 231 is_instant_temporary_text_a_search_query_ = false; |
228 } | 232 } |
229 | 233 |
230 void OmniboxEditModel::FinalizeInstantQuery( | |
231 const string16& input_text, | |
232 const InstantSuggestion& suggestion) { | |
233 if (!popup_model()->result().empty()) { | |
234 // When a IME is active and a candidate window is open, we don't show | |
235 // the omnibox popup, though |result()| may be available. Thus we check | |
236 // whether result().empty() or not instead of whether IsOpen() or not. | |
237 // We need the finalization of instant query when result() is available. | |
238 SearchProvider* search_provider = | |
239 autocomplete_controller()->search_provider(); | |
240 // There may be no providers during testing; guard against that. | |
241 if (search_provider) | |
242 search_provider->FinalizeInstantQuery(input_text, suggestion); | |
243 } | |
244 } | |
245 | |
246 void OmniboxEditModel::SetInstantSuggestion( | 234 void OmniboxEditModel::SetInstantSuggestion( |
247 const InstantSuggestion& suggestion) { | 235 const InstantSuggestion& suggestion) { |
248 switch (suggestion.behavior) { | 236 omnibox_controller_->SetInstantSuggestion(suggestion); |
249 case INSTANT_COMPLETE_NOW: | |
250 view_->SetInstantSuggestion(string16()); | |
251 if (!suggestion.text.empty()) | |
252 FinalizeInstantQuery(view_->GetText(), suggestion); | |
253 break; | |
254 | |
255 case INSTANT_COMPLETE_NEVER: { | |
256 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); | |
257 view_->SetInstantSuggestion(suggestion.text); | |
258 autocomplete_controller()->search_provider()->ClearInstantSuggestion(); | |
259 break; | |
260 } | |
261 | |
262 case INSTANT_COMPLETE_REPLACE: { | |
263 const bool save_original_selection = !has_temporary_text_; | |
264 view_->SetInstantSuggestion(string16()); | |
265 has_temporary_text_ = true; | |
266 is_temporary_text_set_by_instant_ = true; | |
267 selected_instant_autocomplete_match_index_ = | |
268 suggestion.autocomplete_match_index; | |
269 is_instant_temporary_text_a_search_query_ = | |
270 suggestion.type == INSTANT_SUGGESTION_SEARCH; | |
271 // Instant suggestions are never a keyword. | |
272 keyword_ = string16(); | |
273 is_keyword_hint_ = false; | |
274 view_->OnTemporaryTextMaybeChanged(suggestion.text, | |
275 save_original_selection, true); | |
276 break; | |
277 } | |
278 } | |
279 } | 237 } |
280 | 238 |
281 bool OmniboxEditModel::CommitSuggestedText() { | 239 bool OmniboxEditModel::CommitSuggestedText() { |
282 const string16 suggestion = view_->GetInstantSuggestion(); | 240 const string16 suggestion = view_->GetInstantSuggestion(); |
283 if (suggestion.empty()) | 241 if (suggestion.empty()) |
284 return false; | 242 return false; |
285 | 243 |
286 // Assume that the gray text we are committing is a search suggestion. | 244 // Assume that the gray text we are committing is a search suggestion. |
287 const string16 final_text = view_->GetText() + suggestion; | 245 const string16 final_text = view_->GetText() + suggestion; |
288 view_->OnBeforePossibleChange(); | 246 view_->OnBeforePossibleChange(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 user_input_in_progress_, in_escape_handler_, | 290 user_input_in_progress_, in_escape_handler_, |
333 view_->DeleteAtEndPressed() || just_deleted_text_, | 291 view_->DeleteAtEndPressed() || just_deleted_text_, |
334 KeywordIsSelected()); | 292 KeywordIsSelected()); |
335 } | 293 } |
336 | 294 |
337 if (!performed_instant) { | 295 if (!performed_instant) { |
338 // Hide any suggestions we might be showing. | 296 // Hide any suggestions we might be showing. |
339 view_->SetInstantSuggestion(string16()); | 297 view_->SetInstantSuggestion(string16()); |
340 | 298 |
341 // No need to wait any longer for Instant. | 299 // No need to wait any longer for Instant. |
342 FinalizeInstantQuery(string16(), InstantSuggestion()); | 300 omnibox_controller_->FinalizeInstantQuery(string16(), InstantSuggestion()); |
343 } | 301 } |
344 | 302 |
345 switch (recommended_action) { | 303 switch (recommended_action) { |
346 case AutocompleteActionPredictor::ACTION_PRERENDER: | 304 case AutocompleteActionPredictor::ACTION_PRERENDER: |
347 // It's possible that there is no current page, for instance if the tab | 305 // It's possible that there is no current page, for instance if the tab |
348 // has been closed or on return from a sleep state. | 306 // has been closed or on return from a sleep state. |
349 // (http://crbug.com/105689) | 307 // (http://crbug.com/105689) |
350 if (!delegate_->CurrentPageExists()) | 308 if (!delegate_->CurrentPageExists()) |
351 break; | 309 break; |
352 // Ask for prerendering if the destination URL is different than the | 310 // Ask for prerendering if the destination URL is different than the |
353 // current URL. | 311 // current URL. |
354 if (current_match.destination_url != PermanentURL()) | 312 if (current_match.destination_url != PermanentURL()) |
355 delegate_->DoPrerender(current_match); | 313 delegate_->DoPrerender(current_match); |
356 break; | 314 break; |
357 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 315 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
358 omnibox_controller_->DoPreconnect(current_match); | 316 omnibox_controller_->DoPreconnect(current_match); |
359 break; | 317 break; |
360 case AutocompleteActionPredictor::ACTION_NONE: | 318 case AutocompleteActionPredictor::ACTION_NONE: |
361 break; | 319 break; |
362 } | 320 } |
363 | 321 |
364 controller_->OnChanged(); | 322 controller_->OnChanged(); |
365 } | 323 } |
366 | 324 |
367 void OmniboxEditModel::GetDataForURLExport(GURL* url, | 325 void OmniboxEditModel::GetDataForURLExport(GURL* url, |
368 string16* title, | 326 string16* title, |
369 gfx::Image* favicon) { | 327 gfx::Image* favicon) { |
370 AutocompleteMatch match; | 328 AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2013/06/11 22:42:55
Nit: Just inline into the next statement
beaudoin
2013/06/14 21:39:38
Done.
| |
371 GetInfoForCurrentText(&match, NULL); | |
372 *url = match.destination_url; | 329 *url = match.destination_url; |
373 if (*url == URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), | 330 if (*url == URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), |
374 std::string())) { | 331 std::string())) { |
375 *title = controller_->GetTitle(); | 332 *title = controller_->GetTitle(); |
376 *favicon = controller_->GetFavicon(); | 333 *favicon = controller_->GetFavicon(); |
377 } | 334 } |
378 } | 335 } |
379 | 336 |
380 bool OmniboxEditModel::CurrentTextIsURL() const { | 337 bool OmniboxEditModel::CurrentTextIsURL() const { |
381 if (view_->toolbar_model()->GetSearchTermsType() != | 338 if (view_->toolbar_model()->GetSearchTermsType() != |
382 ToolbarModel::NO_SEARCH_TERMS) | 339 ToolbarModel::NO_SEARCH_TERMS) |
383 return false; | 340 return false; |
384 | 341 |
385 // If current text is not composed of replaced search terms and | 342 // If current text is not composed of replaced search terms and |
386 // !user_input_in_progress_, then permanent text is showing and should be a | 343 // !user_input_in_progress_, then permanent text is showing and should be a |
387 // URL, so no further checking is needed. By avoiding checking in this case, | 344 // URL, so no further checking is needed. By avoiding checking in this case, |
388 // we avoid calling into the autocomplete providers, and thus initializing the | 345 // we avoid calling into the autocomplete providers, and thus initializing the |
389 // history system, as long as possible, which speeds startup. | 346 // history system, as long as possible, which speeds startup. |
390 if (!user_input_in_progress_) | 347 if (!user_input_in_progress_) |
391 return true; | 348 return true; |
392 | 349 |
393 AutocompleteMatch match; | 350 AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2013/06/11 22:42:55
Nit: Here too
beaudoin
2013/06/14 21:39:38
Done.
| |
394 GetInfoForCurrentText(&match, NULL); | |
395 return !AutocompleteMatch::IsSearchType(match.type); | 351 return !AutocompleteMatch::IsSearchType(match.type); |
396 } | 352 } |
397 | 353 |
398 AutocompleteMatch::Type OmniboxEditModel::CurrentTextType() const { | 354 AutocompleteMatch::Type OmniboxEditModel::CurrentTextType() const { |
399 AutocompleteMatch match; | 355 return CurrentMatch().type; |
400 GetInfoForCurrentText(&match, NULL); | |
401 return match.type; | |
402 } | 356 } |
403 | 357 |
404 void OmniboxEditModel::AdjustTextForCopy(int sel_min, | 358 void OmniboxEditModel::AdjustTextForCopy(int sel_min, |
405 bool is_all_selected, | 359 bool is_all_selected, |
406 string16* text, | 360 string16* text, |
407 GURL* url, | 361 GURL* url, |
408 bool* write_url) { | 362 bool* write_url) { |
409 *write_url = false; | 363 *write_url = false; |
410 | 364 |
411 // Do not adjust if selection did not start at the beginning of the field, or | 365 // Do not adjust if selection did not start at the beginning of the field, or |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 | 503 |
550 bool OmniboxEditModel::IsPasteAndSearch(const string16& text) const { | 504 bool OmniboxEditModel::IsPasteAndSearch(const string16& text) const { |
551 AutocompleteMatch match; | 505 AutocompleteMatch match; |
552 ClassifyStringForPasteAndGo(text, &match, NULL); | 506 ClassifyStringForPasteAndGo(text, &match, NULL); |
553 return AutocompleteMatch::IsSearchType(match.type); | 507 return AutocompleteMatch::IsSearchType(match.type); |
554 } | 508 } |
555 | 509 |
556 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, | 510 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, |
557 bool for_drop) { | 511 bool for_drop) { |
558 // Get the URL and transition type for the selected entry. | 512 // Get the URL and transition type for the selected entry. |
559 AutocompleteMatch match; | 513 AutocompleteMatch match = omnibox_controller_->current_match(); |
560 GURL alternate_nav_url; | 514 GURL alternate_nav_url; |
561 GetInfoForCurrentText(&match, &alternate_nav_url); | 515 |
516 if (!match.destination_url.is_valid()) { | |
517 GetInfoForCurrentText(&match, &alternate_nav_url); | |
Peter Kasting
2013/06/11 22:42:55
Nit: Maybe CurrentMatch() should take an |alternat
beaudoin
2013/06/14 21:39:38
Done.
| |
518 } else if (AutocompleteMatch::IsSearchType(match.type)) { | |
519 // Compute the |alternate_nav_url| if needed. | |
Peter Kasting
2013/06/11 22:42:55
Why do we need this new block? It worries me beca
beaudoin
2013/06/14 21:39:38
The problem is that |alternate_nav_url| is compute
Peter Kasting
2013/06/15 00:29:21
I see. I think we should factor out the last piec
beaudoin
2013/06/17 17:22:33
For the moment, the autocomplete controller is sta
| |
520 alternate_nav_url = URLFixerUpper::FixupURL( | |
521 UTF16ToUTF8(match.fill_into_edit), std::string()); | |
522 if (alternate_nav_url == match.destination_url) | |
523 alternate_nav_url = GURL(); | |
524 } | |
562 | 525 |
563 // If CTRL is down it means the user wants to append ".com" to the text he | 526 // If CTRL is down it means the user wants to append ".com" to the text he |
564 // typed. If we can successfully generate a URL_WHAT_YOU_TYPED match doing | 527 // typed. If we can successfully generate a URL_WHAT_YOU_TYPED match doing |
565 // that, then we use this. These matches are marked as generated by the | 528 // that, then we use this. These matches are marked as generated by the |
566 // HistoryURLProvider so we only generate them if this provider is present. | 529 // HistoryURLProvider so we only generate them if this provider is present. |
567 if (control_key_state_ == DOWN_WITHOUT_CHANGE && !KeywordIsSelected() && | 530 if (control_key_state_ == DOWN_WITHOUT_CHANGE && !KeywordIsSelected() && |
568 autocomplete_controller()->history_url_provider()) { | 531 autocomplete_controller()->history_url_provider()) { |
569 // Generate a new AutocompleteInput, copying the latest one but using "com" | 532 // Generate a new AutocompleteInput, copying the latest one but using "com" |
570 // as the desired TLD. Then use this autocomplete input to generate a | 533 // as the desired TLD. Then use this autocomplete input to generate a |
571 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent | 534 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 GoogleURLTracker::GoogleURLSearchCommitted(profile_); | 582 GoogleURLTracker::GoogleURLSearchCommitted(profile_); |
620 | 583 |
621 view_->OpenMatch(match, disposition, alternate_nav_url, | 584 view_->OpenMatch(match, disposition, alternate_nav_url, |
622 OmniboxPopupModel::kNoMatch); | 585 OmniboxPopupModel::kNoMatch); |
623 } | 586 } |
624 | 587 |
625 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, | 588 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
626 WindowOpenDisposition disposition, | 589 WindowOpenDisposition disposition, |
627 const GURL& alternate_nav_url, | 590 const GURL& alternate_nav_url, |
628 size_t index) { | 591 size_t index) { |
592 | |
Peter Kasting
2013/06/11 22:42:55
Nit: Extra newline
beaudoin
2013/06/14 21:39:38
Done.
| |
629 // We only care about cases where there is a selection (i.e. the popup is | 593 // We only care about cases where there is a selection (i.e. the popup is |
630 // open). | 594 // open). |
631 if (popup_model()->IsOpen()) { | 595 if (popup_model()->IsOpen()) { |
632 const base::TimeTicks& now(base::TimeTicks::Now()); | 596 const base::TimeTicks& now(base::TimeTicks::Now()); |
633 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( | 597 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( |
634 now - time_user_first_modified_omnibox_); | 598 now - time_user_first_modified_omnibox_); |
635 base::TimeDelta elapsed_time_since_last_change_to_default_match( | 599 base::TimeDelta elapsed_time_since_last_change_to_default_match( |
636 now - autocomplete_controller()->last_time_default_match_changed()); | 600 now - autocomplete_controller()->last_time_default_match_changed()); |
637 // These elapsed times don't really make sense for ZeroSuggest matches | 601 // These elapsed times don't really make sense for ZeroSuggest matches |
638 // (because the user does not modify the omnibox for ZeroSuggest), so for | 602 // (because the user does not modify the omnibox for ZeroSuggest), so for |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 content::Source<Profile>(profile_), | 652 content::Source<Profile>(profile_), |
689 content::Details<OmniboxLog>(&log)); | 653 content::Details<OmniboxLog>(&log)); |
690 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); | 654 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); |
691 } | 655 } |
692 | 656 |
693 TemplateURL* template_url = match.GetTemplateURL(profile_, false); | 657 TemplateURL* template_url = match.GetTemplateURL(profile_, false); |
694 if (template_url) { | 658 if (template_url) { |
695 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { | 659 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { |
696 // The user is using a non-substituting keyword or is explicitly in | 660 // The user is using a non-substituting keyword or is explicitly in |
697 // keyword mode. | 661 // keyword mode. |
698 | |
699 AutocompleteMatch current_match; | |
700 GetInfoForCurrentText(¤t_match, NULL); | |
701 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? | 662 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? |
702 current_match : result().match_at(index); | 663 CurrentMatch() : result().match_at(index); |
703 | 664 |
704 // Don't increment usage count for extension keywords. | 665 // Don't increment usage count for extension keywords. |
705 if (delegate_->ProcessExtensionKeyword(template_url, match, | 666 if (delegate_->ProcessExtensionKeyword(template_url, match, |
706 disposition)) { | 667 disposition)) { |
707 if (disposition != NEW_BACKGROUND_TAB) | 668 if (disposition != NEW_BACKGROUND_TAB) |
708 view_->RevertAll(); | 669 view_->RevertAll(); |
709 return; | 670 return; |
710 } | 671 } |
711 | 672 |
712 content::RecordAction(UserMetricsAction("AcceptedKeyword")); | 673 content::RecordAction(UserMetricsAction("AcceptedKeyword")); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 // TODO(samarth): determine if it is safe to move the call to | 838 // TODO(samarth): determine if it is safe to move the call to |
878 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us | 839 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us |
879 // just call SetFocusState() to handle the state change. | 840 // just call SetFocusState() to handle the state change. |
880 focus_state_ = OMNIBOX_FOCUS_NONE; | 841 focus_state_ = OMNIBOX_FOCUS_NONE; |
881 control_key_state_ = UP; | 842 control_key_state_ = UP; |
882 paste_state_ = NONE; | 843 paste_state_ = NONE; |
883 } | 844 } |
884 | 845 |
885 bool OmniboxEditModel::OnEscapeKeyPressed() { | 846 bool OmniboxEditModel::OnEscapeKeyPressed() { |
886 if (has_temporary_text_) { | 847 if (has_temporary_text_) { |
887 AutocompleteMatch match; | 848 if (CurrentMatch().destination_url != original_url_) { |
888 GetInfoForCurrentText(&match, NULL); | |
889 if (match.destination_url != original_url_) { | |
890 RevertTemporaryText(true); | 849 RevertTemporaryText(true); |
891 return true; | 850 return true; |
892 } | 851 } |
893 } | 852 } |
894 | 853 |
895 // We do not clear the pending entry from the omnibox when a load is first | 854 // We do not clear the pending entry from the omnibox when a load is first |
896 // stopped. If the user presses Escape while stopped, we clear it. | 855 // stopped. If the user presses Escape while stopped, we clear it. |
897 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { | 856 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { |
898 delegate_->GetNavigationController().DiscardNonCommittedEntries(); | 857 delegate_->GetNavigationController().DiscardNonCommittedEntries(); |
899 view_->Update(NULL); | 858 view_->Update(NULL); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 // determine what keyword, if any, is applicable. | 1112 // determine what keyword, if any, is applicable. |
1154 // | 1113 // |
1155 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that | 1114 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that |
1156 // will have updated our state already, so in that case we don't also return | 1115 // will have updated our state already, so in that case we don't also return |
1157 // true from this function. | 1116 // true from this function. |
1158 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1117 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
1159 no_selection && (selection_start == user_text_.length()) && | 1118 no_selection && (selection_start == user_text_.length()) && |
1160 MaybeAcceptKeywordBySpace(user_text_)); | 1119 MaybeAcceptKeywordBySpace(user_text_)); |
1161 } | 1120 } |
1162 | 1121 |
1163 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { | 1122 void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { |
1123 const bool save_original_selection = | |
1124 is_temporary_set_by_instant && !has_temporary_text_; | |
1125 has_temporary_text_ = is_temporary_set_by_instant; | |
1126 is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; | |
1127 | |
1128 const AutocompleteMatch& match = omnibox_controller_->current_match(); | |
1129 match.GetKeywordUIState(profile_, &keyword_, &is_keyword_hint_); | |
1130 | |
1131 view_->SetInstantSuggestion(match.gray_suggestion); | |
1132 string16 inline_autocomplete_text; | |
1133 if ((match.inline_autocomplete_offset != string16::npos) && | |
Peter Kasting
2013/06/11 22:42:55
Nit: This first condition is unnecessary; in cases
beaudoin
2013/06/14 21:39:38
Done.
| |
1134 (match.inline_autocomplete_offset < | |
1135 match.fill_into_edit.length())) { | |
1136 // We have blue text, go through OnPopupDataChanged. | |
1137 // TODO(beaudoin): Merge OnPopupDataChanged with this method once the popup | |
1138 // handling has completely migrated to omnibox_controller. | |
1139 inline_autocomplete_text = | |
1140 match.fill_into_edit.substr(match.inline_autocomplete_offset); | |
1141 popup_model()->OnResultChanged(); | |
1142 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword_, | |
1143 is_keyword_hint_); | |
1144 } else { | |
1145 view_->OnTemporaryTextMaybeChanged( | |
Peter Kasting
2013/06/11 22:42:55
I'm trying to figure out where this used to happen
| |
1146 DisplayTextFromUserText(match.fill_into_edit), save_original_selection, | |
1147 false); | |
1148 } | |
1149 } | |
1150 | |
1151 string16 OmniboxEditModel::GetViewText() const { | |
1152 return view_->GetText(); | |
1164 } | 1153 } |
1165 | 1154 |
1166 InstantController* OmniboxEditModel::GetInstantController() const { | 1155 InstantController* OmniboxEditModel::GetInstantController() const { |
1167 return controller_->GetInstant(); | 1156 return controller_->GetInstant(); |
1168 } | 1157 } |
1169 | 1158 |
1170 bool OmniboxEditModel::query_in_progress() const { | 1159 bool OmniboxEditModel::query_in_progress() const { |
1171 return !autocomplete_controller()->done(); | 1160 return !autocomplete_controller()->done(); |
1172 } | 1161 } |
1173 | 1162 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 instant->OmniboxFocusChanged(state, reason, NULL); | 1397 instant->OmniboxFocusChanged(state, reason, NULL); |
1409 | 1398 |
1410 // Update state and notify view if the omnibox has focus and the caret | 1399 // Update state and notify view if the omnibox has focus and the caret |
1411 // visibility changed. | 1400 // visibility changed. |
1412 const bool was_caret_visible = is_caret_visible(); | 1401 const bool was_caret_visible = is_caret_visible(); |
1413 focus_state_ = state; | 1402 focus_state_ = state; |
1414 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1403 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1415 is_caret_visible() != was_caret_visible) | 1404 is_caret_visible() != was_caret_visible) |
1416 view_->ApplyCaretVisibility(); | 1405 view_->ApplyCaretVisibility(); |
1417 } | 1406 } |
OLD | NEW |