Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: components/omnibox/browser/omnibox_edit_model.cc

Issue 2048693003: Misc. omnibox cleanup: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // to make any change to the edit. While auto-commits modify the underlying 283 // to make any change to the edit. While auto-commits modify the underlying
284 // permanent URL, they're intended to have no effect on the user's editing 284 // permanent URL, they're intended to have no effect on the user's editing
285 // process -- before and after the auto-commit, the omnibox should show the 285 // process -- before and after the auto-commit, the omnibox should show the
286 // same user text and the same instant suggestion, even if the auto-commit 286 // same user text and the same instant suggestion, even if the auto-commit
287 // happens while the edit doesn't have focus. 287 // happens while the edit doesn't have focus.
288 base::string16 new_permanent_text = controller_->GetToolbarModel()->GetText(); 288 base::string16 new_permanent_text = controller_->GetToolbarModel()->GetText();
289 base::string16 gray_text = view_->GetGrayTextAutocompletion(); 289 base::string16 gray_text = view_->GetGrayTextAutocompletion();
290 const bool visibly_changed_permanent_text = 290 const bool visibly_changed_permanent_text =
291 (permanent_text_ != new_permanent_text) && 291 (permanent_text_ != new_permanent_text) &&
292 (!has_focus() || 292 (!has_focus() ||
293 (!user_input_in_progress_ && 293 (!user_input_in_progress_ && !PopupIsOpen() &&
294 !(popup_model() && popup_model()->IsOpen()) &&
295 controller_->GetToolbarModel()->url_replacement_enabled())) && 294 controller_->GetToolbarModel()->url_replacement_enabled())) &&
296 (gray_text.empty() || 295 (gray_text.empty() ||
297 new_permanent_text != user_text_ + gray_text); 296 new_permanent_text != user_text_ + gray_text);
298 297
299 permanent_text_ = new_permanent_text; 298 permanent_text_ = new_permanent_text;
300 return visibly_changed_permanent_text; 299 return visibly_changed_permanent_text;
301 } 300 }
302 301
303 GURL OmniboxEditModel::PermanentURL() { 302 GURL OmniboxEditModel::PermanentURL() {
304 return url_formatter::FixupURL(base::UTF16ToUTF8(permanent_text_), 303 return url_formatter::FixupURL(base::UTF16ToUTF8(permanent_text_),
(...skipping 24 matching lines...) Expand all
329 } 328 }
330 329
331 void OmniboxEditModel::OnChanged() { 330 void OmniboxEditModel::OnChanged() {
332 // Hide any suggestions we might be showing. 331 // Hide any suggestions we might be showing.
333 view_->SetGrayTextAutocompletion(base::string16()); 332 view_->SetGrayTextAutocompletion(base::string16());
334 333
335 // Don't call CurrentMatch() when there's no editing, as in this case we'll 334 // Don't call CurrentMatch() when there's no editing, as in this case we'll
336 // never actually use it. This avoids running the autocomplete providers (and 335 // never actually use it. This avoids running the autocomplete providers (and
337 // any systems they then spin up) during startup. 336 // any systems they then spin up) during startup.
338 const AutocompleteMatch& current_match = user_input_in_progress_ ? 337 const AutocompleteMatch& current_match = user_input_in_progress_ ?
339 CurrentMatch(NULL) : AutocompleteMatch(); 338 CurrentMatch(nullptr) : AutocompleteMatch();
340 339
341 client_->OnTextChanged(current_match, user_input_in_progress_, user_text_, 340 client_->OnTextChanged(current_match, user_input_in_progress_, user_text_,
342 result(), popup_model() && popup_model()->IsOpen(), 341 result(), PopupIsOpen(), has_focus());
343 has_focus());
344 controller_->OnChanged(); 342 controller_->OnChanged();
345 } 343 }
346 344
347 void OmniboxEditModel::GetDataForURLExport(GURL* url, 345 void OmniboxEditModel::GetDataForURLExport(GURL* url,
348 base::string16* title, 346 base::string16* title,
349 gfx::Image* favicon) { 347 gfx::Image* favicon) {
350 *url = CurrentMatch(NULL).destination_url; 348 *url = CurrentMatch(nullptr).destination_url;
351 if (*url == client_->GetURL()) { 349 if (*url == client_->GetURL()) {
352 *title = client_->GetTitle(); 350 *title = client_->GetTitle();
353 *favicon = client_->GetFavicon(); 351 *favicon = client_->GetFavicon();
354 } 352 }
355 } 353 }
356 354
357 bool OmniboxEditModel::CurrentTextIsURL() const { 355 bool OmniboxEditModel::CurrentTextIsURL() const {
358 if (controller_->GetToolbarModel()->WouldReplaceURL()) 356 if (controller_->GetToolbarModel()->WouldReplaceURL())
359 return false; 357 return false;
360 358
361 // If current text is not composed of replaced search terms and 359 // If current text is not composed of replaced search terms and
362 // !user_input_in_progress_, then permanent text is showing and should be a 360 // !user_input_in_progress_, then permanent text is showing and should be a
363 // URL, so no further checking is needed. By avoiding checking in this case, 361 // URL, so no further checking is needed. By avoiding checking in this case,
364 // we avoid calling into the autocomplete providers, and thus initializing the 362 // we avoid calling into the autocomplete providers, and thus initializing the
365 // history system, as long as possible, which speeds startup. 363 // history system, as long as possible, which speeds startup.
366 if (!user_input_in_progress_) 364 if (!user_input_in_progress_)
367 return true; 365 return true;
368 366
369 return !AutocompleteMatch::IsSearchType(CurrentMatch(NULL).type); 367 return !AutocompleteMatch::IsSearchType(CurrentMatch(nullptr).type);
370 } 368 }
371 369
372 AutocompleteMatch::Type OmniboxEditModel::CurrentTextType() const { 370 AutocompleteMatch::Type OmniboxEditModel::CurrentTextType() const {
373 return CurrentMatch(NULL).type; 371 return CurrentMatch(nullptr).type;
374 } 372 }
375 373
376 void OmniboxEditModel::AdjustTextForCopy(int sel_min, 374 void OmniboxEditModel::AdjustTextForCopy(int sel_min,
377 bool is_all_selected, 375 bool is_all_selected,
378 base::string16* text, 376 base::string16* text,
379 GURL* url, 377 GURL* url,
380 bool* write_url) { 378 bool* write_url) {
381 *write_url = false; 379 *write_url = false;
382 380
383 // Do not adjust if selection did not start at the beginning of the field, or 381 // Do not adjust if selection did not start at the beginning of the field, or
384 // if the URL was omitted. 382 // if the URL was omitted.
385 if ((sel_min != 0) || controller_->GetToolbarModel()->WouldReplaceURL()) 383 if ((sel_min != 0) || controller_->GetToolbarModel()->WouldReplaceURL())
386 return; 384 return;
387 385
388 // Check whether the user is trying to copy the current page's URL by 386 // Check whether the user is trying to copy the current page's URL by
389 // selecting the whole thing without editing it. 387 // selecting the whole thing without editing it.
390 // 388 //
391 // This is complicated by ZeroSuggest. When ZeroSuggest is active, the user 389 // This is complicated by ZeroSuggest. When ZeroSuggest is active, the user
392 // may be selecting different items and thus changing the address bar text, 390 // may be selecting different items and thus changing the address bar text,
393 // even though !user_input_in_progress_; and the permanent URL may change 391 // even though !user_input_in_progress_; and the permanent URL may change
394 // without updating the visible text, just like when user input is in 392 // without updating the visible text, just like when user input is in
395 // progress. In these cases, we don't want to copy the underlying URL, we 393 // progress. In these cases, we don't want to copy the underlying URL, we
396 // want to copy what the user actually sees. However, if we simply never do 394 // want to copy what the user actually sees. However, if we simply never do
397 // this block when !popup_model()->IsOpen(), then just clicking into the 395 // this block when !PopupIsOpen(), then just clicking into the address bar and
398 // address bar and trying to copy will always bypass this block on pages that 396 // trying to copy will always bypass this block on pages that trigger
399 // trigger ZeroSuggest, which is too conservative. Instead, in the 397 // ZeroSuggest, which is too conservative. Instead, in the ZeroSuggest case,
400 // ZeroSuggest case, we check that (a) the user hasn't selected one of the 398 // we check that (a) the user hasn't selected one of the other suggestions,
401 // other suggestions, and (b) the selected text is still the same as the 399 // and (b) the selected text is still the same as the permanent text. ((b)
402 // permanent text. ((b) probably implies (a), but it doesn't hurt to be 400 // probably implies (a), but it doesn't hurt to be sure.) If these hold, then
403 // sure.) If these hold, then it's safe to copy the underlying URL. 401 // it's safe to copy the underlying URL.
404 if (!user_input_in_progress_ && is_all_selected && 402 if (!user_input_in_progress_ && is_all_selected &&
405 (!popup_model() || !popup_model()->IsOpen() || 403 (!PopupIsOpen() ||
406 ((popup_model()->selected_line() == 0) && (*text == permanent_text_)))) { 404 ((popup_model()->selected_line() == 0) && (*text == permanent_text_)))) {
407 // It's safe to copy the underlying URL. These lines ensure that if the 405 // It's safe to copy the underlying URL. These lines ensure that if the
408 // scheme was stripped it's added back, and the URL is unescaped (we escape 406 // scheme was stripped it's added back, and the URL is unescaped (we escape
409 // parts of it for display). 407 // parts of it for display).
410 *url = PermanentURL(); 408 *url = PermanentURL();
411 *text = base::UTF8ToUTF16(url->spec()); 409 *text = base::UTF8ToUTF16(url->spec());
412 *write_url = true; 410 *write_url = true;
413 return; 411 return;
414 } 412 }
415 413
416 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now 414 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now
417 // the user is probably holding down control to cause the copy, which will 415 // the user is probably holding down control to cause the copy, which will
418 // screw up our calculation of the desired_tld. 416 // screw up our calculation of the desired_tld.
419 AutocompleteMatch match; 417 AutocompleteMatch match;
420 client_->GetAutocompleteClassifier()->Classify( 418 client_->GetAutocompleteClassifier()->Classify(
421 *text, is_keyword_selected(), true, ClassifyPage(), &match, NULL); 419 *text, is_keyword_selected(), true, ClassifyPage(), &match, nullptr);
422 if (AutocompleteMatch::IsSearchType(match.type)) 420 if (AutocompleteMatch::IsSearchType(match.type))
423 return; 421 return;
424 *url = match.destination_url; 422 *url = match.destination_url;
425 423
426 // Prefix the text with 'http://' if the text doesn't start with 'http://', 424 // Prefix the text with 'http://' if the text doesn't start with 'http://',
427 // the text parses as a url with a scheme of http, the user selected the 425 // the text parses as a url with a scheme of http, the user selected the
428 // entire host, and the user hasn't edited the host or manually removed the 426 // entire host, and the user hasn't edited the host or manually removed the
429 // scheme. 427 // scheme.
430 GURL perm_url(PermanentURL()); 428 GURL perm_url(PermanentURL());
431 if (perm_url.SchemeIs(url::kHttpScheme) && 429 if (perm_url.SchemeIs(url::kHttpScheme) &&
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 525
528 void OmniboxEditModel::StopAutocomplete() { 526 void OmniboxEditModel::StopAutocomplete() {
529 autocomplete_controller()->Stop(true); 527 autocomplete_controller()->Stop(true);
530 } 528 }
531 529
532 bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const { 530 bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const {
533 if (!client_->IsPasteAndGoEnabled()) 531 if (!client_->IsPasteAndGoEnabled())
534 return false; 532 return false;
535 533
536 AutocompleteMatch match; 534 AutocompleteMatch match;
537 ClassifyStringForPasteAndGo(text, &match, NULL); 535 ClassifyStringForPasteAndGo(text, &match, nullptr);
538 return match.destination_url.is_valid(); 536 return match.destination_url.is_valid();
539 } 537 }
540 538
541 void OmniboxEditModel::PasteAndGo(const base::string16& text) { 539 void OmniboxEditModel::PasteAndGo(const base::string16& text) {
542 DCHECK(CanPasteAndGo(text)); 540 DCHECK(CanPasteAndGo(text));
543 UMA_HISTOGRAM_COUNTS("Omnibox.PasteAndGo", 1); 541 UMA_HISTOGRAM_COUNTS("Omnibox.PasteAndGo", 1);
544 542
545 view_->RevertAll(); 543 view_->RevertAll();
546 AutocompleteMatch match; 544 AutocompleteMatch match;
547 GURL alternate_nav_url; 545 GURL alternate_nav_url;
548 ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url); 546 ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url);
549 view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, text, 547 view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, text,
550 OmniboxPopupModel::kNoMatch); 548 OmniboxPopupModel::kNoMatch);
551 } 549 }
552 550
553 bool OmniboxEditModel::IsPasteAndSearch(const base::string16& text) const { 551 bool OmniboxEditModel::IsPasteAndSearch(const base::string16& text) const {
554 AutocompleteMatch match; 552 AutocompleteMatch match;
555 ClassifyStringForPasteAndGo(text, &match, NULL); 553 ClassifyStringForPasteAndGo(text, &match, nullptr);
556 return AutocompleteMatch::IsSearchType(match.type); 554 return AutocompleteMatch::IsSearchType(match.type);
557 } 555 }
558 556
559 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, 557 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition,
560 bool for_drop) { 558 bool for_drop) {
561 // Get the URL and transition type for the selected entry. 559 // Get the URL and transition type for the selected entry.
562 GURL alternate_nav_url; 560 GURL alternate_nav_url;
563 AutocompleteMatch match = CurrentMatch(&alternate_nav_url); 561 AutocompleteMatch match = CurrentMatch(&alternate_nav_url);
564 562
565 // If CTRL is down it means the user wants to append ".com" to the text he 563 // If CTRL is down it means the user wants to append ".com" to the text he
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 654
657 base::TimeDelta elapsed_time_since_last_change_to_default_match( 655 base::TimeDelta elapsed_time_since_last_change_to_default_match(
658 now - autocomplete_controller()->last_time_default_match_changed()); 656 now - autocomplete_controller()->last_time_default_match_changed());
659 DCHECK(match.provider); 657 DCHECK(match.provider);
660 // These elapsed times don't really make sense for ZeroSuggest matches 658 // These elapsed times don't really make sense for ZeroSuggest matches
661 // (because the user does not modify the omnibox for ZeroSuggest), so for 659 // (because the user does not modify the omnibox for ZeroSuggest), so for
662 // those we set the elapsed times to something that will be ignored by 660 // those we set the elapsed times to something that will be ignored by
663 // metrics_log.cc. They also don't necessarily make sense if the omnibox 661 // metrics_log.cc. They also don't necessarily make sense if the omnibox
664 // dropdown is closed or the user used a paste-and-go action. (In most 662 // dropdown is closed or the user used a paste-and-go action. (In most
665 // cases when this happens, the user never modified the omnibox.) 663 // cases when this happens, the user never modified the omnibox.)
664 const bool popup_open = PopupIsOpen();
666 if ((match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) || 665 if ((match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) ||
667 !popup_model()->IsOpen() || !pasted_text.empty()) { 666 !popup_open || !pasted_text.empty()) {
668 const base::TimeDelta default_time_delta = 667 const base::TimeDelta default_time_delta =
669 base::TimeDelta::FromMilliseconds(-1); 668 base::TimeDelta::FromMilliseconds(-1);
670 elapsed_time_since_user_first_modified_omnibox = default_time_delta; 669 elapsed_time_since_user_first_modified_omnibox = default_time_delta;
671 elapsed_time_since_last_change_to_default_match = default_time_delta; 670 elapsed_time_since_last_change_to_default_match = default_time_delta;
672 } 671 }
673 // If the popup is closed or this is a paste-and-go action (meaning the 672 // If the popup is closed or this is a paste-and-go action (meaning the
674 // contents of the dropdown are ignored regardless), we record for logging 673 // contents of the dropdown are ignored regardless), we record for logging
675 // purposes a selected_index of 0 and a suggestion list as having a single 674 // purposes a selected_index of 0 and a suggestion list as having a single
676 // entry of the match used. 675 // entry of the match used.
676 const bool dropdown_ignored = !popup_open || !pasted_text.empty();
677 ACMatches fake_single_entry_matches; 677 ACMatches fake_single_entry_matches;
678 fake_single_entry_matches.push_back(match); 678 fake_single_entry_matches.push_back(match);
679 AutocompleteResult fake_single_entry_result; 679 AutocompleteResult fake_single_entry_result;
680 fake_single_entry_result.AppendMatches(input_, fake_single_entry_matches); 680 fake_single_entry_result.AppendMatches(input_, fake_single_entry_matches);
681 OmniboxLog log( 681 OmniboxLog log(
682 input_.from_omnibox_focus() ? base::string16() : input_text, 682 input_.from_omnibox_focus() ? base::string16() : input_text,
683 just_deleted_text_, 683 just_deleted_text_,
684 input_.type(), 684 input_.type(),
685 popup_model()->IsOpen(), 685 popup_open,
686 (!popup_model()->IsOpen() || !pasted_text.empty()) ? 0 : index, 686 dropdown_ignored ? 0 : index,
687 !pasted_text.empty(), 687 !pasted_text.empty(),
688 -1, // don't yet know tab ID; set later if appropriate 688 -1, // don't yet know tab ID; set later if appropriate
689 ClassifyPage(), 689 ClassifyPage(),
690 elapsed_time_since_user_first_modified_omnibox, 690 elapsed_time_since_user_first_modified_omnibox,
691 match.allowed_to_be_default_match ? match.inline_autocompletion.length() : 691 match.allowed_to_be_default_match ? match.inline_autocompletion.length() :
692 base::string16::npos, 692 base::string16::npos,
693 elapsed_time_since_last_change_to_default_match, 693 elapsed_time_since_last_change_to_default_match,
694 (!popup_model()->IsOpen() || !pasted_text.empty()) ? 694 dropdown_ignored ? fake_single_entry_result : result());
695 fake_single_entry_result : result()); 695 DCHECK(dropdown_ignored ||
696 DCHECK(!popup_model()->IsOpen() || !pasted_text.empty() ||
697 (log.elapsed_time_since_user_first_modified_omnibox >= 696 (log.elapsed_time_since_user_first_modified_omnibox >=
698 log.elapsed_time_since_last_change_to_default_match)) 697 log.elapsed_time_since_last_change_to_default_match))
699 << "We should've got the notification that the user modified the " 698 << "We should've got the notification that the user modified the "
700 << "omnibox text at same time or before the most recent time the " 699 << "omnibox text at same time or before the most recent time the "
701 << "default match changed."; 700 << "default match changed.";
702 701
703 if ((disposition == CURRENT_TAB) && client_->CurrentPageExists()) { 702 if ((disposition == CURRENT_TAB) && client_->CurrentPageExists()) {
704 // If we know the destination is being opened in the current tab, 703 // If we know the destination is being opened in the current tab,
705 // we can easily get the tab ID. (If it's being opened in a new 704 // we can easily get the tab ID. (If it's being opened in a new
706 // tab, we don't know the tab ID yet.) 705 // tab, we don't know the tab ID yet.)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 783 }
785 784
786 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { 785 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) {
787 DCHECK(is_keyword_hint_ && !keyword_.empty()); 786 DCHECK(is_keyword_hint_ && !keyword_.empty());
788 787
789 autocomplete_controller()->Stop(false); 788 autocomplete_controller()->Stop(false);
790 is_keyword_hint_ = false; 789 is_keyword_hint_ = false;
791 790
792 user_text_ = MaybeStripKeyword(user_text_); 791 user_text_ = MaybeStripKeyword(user_text_);
793 792
794 if (popup_model() && popup_model()->IsOpen()) 793 if (PopupIsOpen())
795 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); 794 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD);
796 else 795 else
797 StartAutocomplete(false, true, true); 796 StartAutocomplete(false, true, true);
798 797
799 // When entering keyword mode via tab, the new text to show is whatever the 798 // When entering keyword mode via tab, the new text to show is whatever the
800 // newly-selected match in the dropdown is. When entering via space, however, 799 // newly-selected match in the dropdown is. When entering via space, however,
801 // we should make sure to use the actual |user_text_| as the basis for the new 800 // we should make sure to use the actual |user_text_| as the basis for the new
802 // text. This ensures that if the user types "<keyword><space>" and the 801 // text. This ensures that if the user types "<keyword><space>" and the
803 // default match would have inline autocompleted a further string (e.g. 802 // default match would have inline autocompleted a further string (e.g.
804 // because there's a past multi-word search beginning with this keyword), the 803 // because there's a past multi-word search beginning with this keyword), the
805 // inline autocompletion doesn't get filled in as the keyword search query 804 // inline autocompletion doesn't get filled in as the keyword search query
806 // text. 805 // text.
807 // 806 //
808 // We also treat tabbing into keyword mode like tabbing through the popup in 807 // We also treat tabbing into keyword mode like tabbing through the popup in
809 // that we set |has_temporary_text_|, whereas pressing space is treated like 808 // that we set |has_temporary_text_|, whereas pressing space is treated like
810 // a new keystroke that changes the current match instead of overlaying it 809 // a new keystroke that changes the current match instead of overlaying it
811 // with a temporary one. This is important because rerunning autocomplete 810 // with a temporary one. This is important because rerunning autocomplete
812 // after the user pressed space, which will have happened just before reaching 811 // after the user pressed space, which will have happened just before reaching
813 // here, may have generated a new match, which the user won't actually see and 812 // here, may have generated a new match, which the user won't actually see and
814 // which we don't want to switch back to when existing keyword mode; see 813 // which we don't want to switch back to when existing keyword mode; see
815 // comments in ClearKeyword(). 814 // comments in ClearKeyword().
816 if (entered_method == ENTERED_KEYWORD_MODE_VIA_TAB) { 815 if (entered_method == ENTERED_KEYWORD_MODE_VIA_TAB) {
817 // Ensure the current selection is saved before showing keyword mode 816 // Ensure the current selection is saved before showing keyword mode
818 // so that moving to another line and then reverting the text will restore 817 // so that moving to another line and then reverting the text will restore
819 // the current state properly. 818 // the current state properly.
820 bool save_original_selection = !has_temporary_text_; 819 bool save_original_selection = !has_temporary_text_;
821 has_temporary_text_ = true; 820 has_temporary_text_ = true;
822 const AutocompleteMatch& match = CurrentMatch(NULL); 821 const AutocompleteMatch& match = CurrentMatch(nullptr);
823 original_url_ = match.destination_url; 822 original_url_ = match.destination_url;
824 view_->OnTemporaryTextMaybeChanged( 823 view_->OnTemporaryTextMaybeChanged(
825 MaybeStripKeyword(match.fill_into_edit), save_original_selection, 824 MaybeStripKeyword(match.fill_into_edit), save_original_selection,
826 true); 825 true);
827 } else { 826 } else {
828 view_->OnTemporaryTextMaybeChanged(user_text_, false, true); 827 view_->OnTemporaryTextMaybeChanged(user_text_, false, true);
829 } 828 }
830 829
831 base::RecordAction(base::UserMetricsAction("AcceptedKeywordHint")); 830 base::RecordAction(base::UserMetricsAction("AcceptedKeywordHint"));
832 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, 831 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 void OmniboxEditModel::OnKillFocus() { 972 void OmniboxEditModel::OnKillFocus() {
974 SetFocusState(OMNIBOX_FOCUS_NONE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); 973 SetFocusState(OMNIBOX_FOCUS_NONE, OMNIBOX_FOCUS_CHANGE_EXPLICIT);
975 focus_source_ = INVALID; 974 focus_source_ = INVALID;
976 control_key_state_ = UP; 975 control_key_state_ = UP;
977 paste_state_ = NONE; 976 paste_state_ = NONE;
978 } 977 }
979 978
980 bool OmniboxEditModel::WillHandleEscapeKey() const { 979 bool OmniboxEditModel::WillHandleEscapeKey() const {
981 return user_input_in_progress_ || 980 return user_input_in_progress_ ||
982 (has_temporary_text_ && 981 (has_temporary_text_ &&
983 (CurrentMatch(NULL).destination_url != original_url_)); 982 (CurrentMatch(nullptr).destination_url != original_url_));
984 } 983 }
985 984
986 bool OmniboxEditModel::OnEscapeKeyPressed() { 985 bool OmniboxEditModel::OnEscapeKeyPressed() {
987 if (has_temporary_text_ && 986 if (has_temporary_text_ &&
988 (CurrentMatch(NULL).destination_url != original_url_)) { 987 (CurrentMatch(nullptr).destination_url != original_url_)) {
989 RevertTemporaryText(true); 988 RevertTemporaryText(true);
990 return true; 989 return true;
991 } 990 }
992 991
993 // We do not clear the pending entry from the omnibox when a load is first 992 // We do not clear the pending entry from the omnibox when a load is first
994 // stopped. If the user presses Escape while stopped, whether editing or not, 993 // stopped. If the user presses Escape while stopped, whether editing or not,
995 // we clear it. 994 // we clear it.
996 if (client_->CurrentPageExists() && !client_->IsLoading()) { 995 if (client_->CurrentPageExists() && !client_->IsLoading()) {
997 client_->DiscardNonCommittedNavigations(); 996 client_->DiscardNonCommittedNavigations();
998 view_->Update(); 997 view_->Update();
(...skipping 27 matching lines...) Expand all
1026 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; 1025 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP;
1027 } 1026 }
1028 1027
1029 void OmniboxEditModel::OnPaste() { 1028 void OmniboxEditModel::OnPaste() {
1030 UMA_HISTOGRAM_COUNTS("Omnibox.Paste", 1); 1029 UMA_HISTOGRAM_COUNTS("Omnibox.Paste", 1);
1031 paste_state_ = PASTING; 1030 paste_state_ = PASTING;
1032 } 1031 }
1033 1032
1034 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { 1033 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) {
1035 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. 1034 // NOTE: This purposefully doesn't trigger any code that resets paste_state_.
1036 if (popup_model() && popup_model()->IsOpen()) { 1035 if (PopupIsOpen()) {
1037 // The popup is open, so the user should be able to interact with it 1036 // The popup is open, so the user should be able to interact with it
1038 // normally. 1037 // normally.
1039 popup_model()->Move(count); 1038 popup_model()->Move(count);
1040 return; 1039 return;
1041 } 1040 }
1042 1041
1043 if (!query_in_progress()) { 1042 if (!query_in_progress()) {
1044 // The popup is neither open nor working on a query already. So, start an 1043 // The popup is neither open nor working on a query already. So, start an
1045 // autocomplete query for the current text. This also sets 1044 // autocomplete query for the current text. This also sets
1046 // user_input_in_progress_ to true, which we want: if the user has started 1045 // user_input_in_progress_ to true, which we want: if the user has started
(...skipping 30 matching lines...) Expand all
1077 if (!keyword_was_selected && is_keyword_selected()) { 1076 if (!keyword_was_selected && is_keyword_selected()) {
1078 // We just entered keyword mode, so remove the keyword from the input. 1077 // We just entered keyword mode, so remove the keyword from the input.
1079 user_text_ = MaybeStripKeyword(user_text_); 1078 user_text_ = MaybeStripKeyword(user_text_);
1080 } 1079 }
1081 1080
1082 // |is_keyword_hint_| should always be false if |keyword_| is empty. 1081 // |is_keyword_hint_| should always be false if |keyword_| is empty.
1083 DCHECK(!keyword_.empty() || !is_keyword_hint_); 1082 DCHECK(!keyword_.empty() || !is_keyword_hint_);
1084 } 1083 }
1085 1084
1086 // Handle changes to temporary text. 1085 // Handle changes to temporary text.
1087 if (destination_for_temporary_text_change != NULL) { 1086 if (destination_for_temporary_text_change) {
1088 const bool save_original_selection = !has_temporary_text_; 1087 const bool save_original_selection = !has_temporary_text_;
1089 if (save_original_selection) { 1088 if (save_original_selection) {
1090 // Save the original selection and URL so it can be reverted later. 1089 // Save the original selection and URL so it can be reverted later.
1091 has_temporary_text_ = true; 1090 has_temporary_text_ = true;
1092 original_url_ = *destination_for_temporary_text_change; 1091 original_url_ = *destination_for_temporary_text_change;
1093 inline_autocomplete_text_.clear(); 1092 inline_autocomplete_text_.clear();
1094 view_->OnInlineAutocompleteTextCleared(); 1093 view_->OnInlineAutocompleteTextCleared();
1095 } 1094 }
1096 if (control_key_state_ == DOWN_WITHOUT_CHANGE) { 1095 if (control_key_state_ == DOWN_WITHOUT_CHANGE) {
1097 // Arrowing around the popup cancels control-enter. 1096 // Arrowing around the popup cancels control-enter.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 // that case the RevertTemporaryText() call below will reset the caret or 1131 // that case the RevertTemporaryText() call below will reset the caret or
1133 // selection correctly so the caret positioning we do here won't matter. 1132 // selection correctly so the caret positioning we do here won't matter.
1134 view_->SetWindowTextAndCaretPos(user_text, 0, false, false); 1133 view_->SetWindowTextAndCaretPos(user_text, 0, false, false);
1135 } else if (view_->OnInlineAutocompleteTextMaybeChanged( 1134 } else if (view_->OnInlineAutocompleteTextMaybeChanged(
1136 user_text + inline_autocomplete_text_, user_text.length())) { 1135 user_text + inline_autocomplete_text_, user_text.length())) {
1137 call_controller_onchanged = false; 1136 call_controller_onchanged = false;
1138 } 1137 }
1139 1138
1140 // If |has_temporary_text_| is true, then we previously had a manual selection 1139 // If |has_temporary_text_| is true, then we previously had a manual selection
1141 // but now don't (or |destination_for_temporary_text_change| would have been 1140 // but now don't (or |destination_for_temporary_text_change| would have been
1142 // non-NULL). This can happen when deleting the selected item in the popup. 1141 // non-null). This can happen when deleting the selected item in the popup.
1143 // In this case, we've already reverted the popup to the default match, so we 1142 // In this case, we've already reverted the popup to the default match, so we
1144 // need to revert ourselves as well. 1143 // need to revert ourselves as well.
1145 if (has_temporary_text_) { 1144 if (has_temporary_text_) {
1146 RevertTemporaryText(false); 1145 RevertTemporaryText(false);
1147 call_controller_onchanged = false; 1146 call_controller_onchanged = false;
1148 } 1147 }
1149 1148
1150 // We need to invoke OnChanged in case the destination url changed (as could 1149 // We need to invoke OnChanged in case the destination url changed (as could
1151 // happen when control is toggled). 1150 // happen when control is toggled).
1152 if (call_controller_onchanged) 1151 if (call_controller_onchanged)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 base::string16 keyword; 1268 base::string16 keyword;
1270 bool is_keyword_hint; 1269 bool is_keyword_hint;
1271 TemplateURLService* service = client_->GetTemplateURLService(); 1270 TemplateURLService* service = client_->GetTemplateURLService();
1272 match.GetKeywordUIState(service, &keyword, &is_keyword_hint); 1271 match.GetKeywordUIState(service, &keyword, &is_keyword_hint);
1273 if (popup_model()) 1272 if (popup_model())
1274 popup_model()->OnResultChanged(); 1273 popup_model()->OnResultChanged();
1275 // OnPopupDataChanged() resets OmniboxController's |current_match_| early 1274 // OnPopupDataChanged() resets OmniboxController's |current_match_| early
1276 // on. Therefore, copy match.inline_autocompletion to a temp to preserve 1275 // on. Therefore, copy match.inline_autocompletion to a temp to preserve
1277 // its value across the entire call. 1276 // its value across the entire call.
1278 const base::string16 inline_autocompletion(match.inline_autocompletion); 1277 const base::string16 inline_autocompletion(match.inline_autocompletion);
1279 OnPopupDataChanged(inline_autocompletion, NULL, keyword, is_keyword_hint); 1278 OnPopupDataChanged(inline_autocompletion, nullptr, keyword, is_keyword_hint);
1280 } 1279 }
1281 1280
1282 // static 1281 // static
1283 const char OmniboxEditModel::kCutOrCopyAllTextHistogram[] = 1282 const char OmniboxEditModel::kCutOrCopyAllTextHistogram[] =
1284 "Omnibox.CutOrCopyAllText"; 1283 "Omnibox.CutOrCopyAllText";
1285 1284
1286 bool OmniboxEditModel::query_in_progress() const { 1285 bool OmniboxEditModel::PopupIsOpen() const {
1287 return !autocomplete_controller()->done(); 1286 return popup_model() && popup_model()->IsOpen();
1288 } 1287 }
1289 1288
1290 void OmniboxEditModel::InternalSetUserText(const base::string16& text) { 1289 void OmniboxEditModel::InternalSetUserText(const base::string16& text) {
1291 user_text_ = text; 1290 user_text_ = text;
1292 just_deleted_text_ = false; 1291 just_deleted_text_ = false;
1293 inline_autocomplete_text_.clear(); 1292 inline_autocomplete_text_.clear();
1294 view_->OnInlineAutocompleteTextCleared(); 1293 view_->OnInlineAutocompleteTextCleared();
1295 } 1294 }
1296 1295
1297 void OmniboxEditModel::ClearPopupKeywordMode() const { 1296 void OmniboxEditModel::ClearPopupKeywordMode() const {
1298 omnibox_controller_->ClearPopupKeywordMode(); 1297 omnibox_controller_->ClearPopupKeywordMode();
1299 } 1298 }
1300 1299
1301 base::string16 OmniboxEditModel::MaybeStripKeyword( 1300 base::string16 OmniboxEditModel::MaybeStripKeyword(
1302 const base::string16& text) const { 1301 const base::string16& text) const {
1303 return is_keyword_selected() ? 1302 return is_keyword_selected() ?
1304 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; 1303 KeywordProvider::SplitReplacementStringFromInput(text, false) : text;
1305 } 1304 }
1306 1305
1307 base::string16 OmniboxEditModel::MaybePrependKeyword( 1306 base::string16 OmniboxEditModel::MaybePrependKeyword(
1308 const base::string16& text) const { 1307 const base::string16& text) const {
1309 return is_keyword_selected() ? (keyword_ + base::char16(' ') + text) : text; 1308 return is_keyword_selected() ? (keyword_ + base::char16(' ') + text) : text;
1310 } 1309 }
1311 1310
1312 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, 1311 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match,
1313 GURL* alternate_nav_url) const { 1312 GURL* alternate_nav_url) const {
1314 DCHECK(match != NULL); 1313 DCHECK(match);
1315 1314
1316 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement( 1315 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(
1317 false)) { 1316 false)) {
1318 // Any time the user hits enter on the unchanged omnibox, we should reload. 1317 // Any time the user hits enter on the unchanged omnibox, we should reload.
1319 // When we're not extracting search terms, AcceptInput() will take care of 1318 // When we're not extracting search terms, AcceptInput() will take care of
1320 // this (see code referring to PAGE_TRANSITION_RELOAD there), but when we're 1319 // this (see code referring to PAGE_TRANSITION_RELOAD there), but when we're
1321 // extracting search terms, the conditionals there won't fire, so we 1320 // extracting search terms, the conditionals there won't fire, so we
1322 // explicitly set up a match that will reload here. 1321 // explicitly set up a match that will reload here.
1323 1322
1324 // It's important that we fetch the current visible URL to reload instead of 1323 // It's important that we fetch the current visible URL to reload instead of
1325 // just getting a "search what you typed" URL from 1324 // just getting a "search what you typed" URL from
1326 // SearchProvider::CreateSearchSuggestion(), since the user may be in a 1325 // SearchProvider::CreateSearchSuggestion(), since the user may be in a
1327 // non-default search mode such as image search. 1326 // non-default search mode such as image search.
1328 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; 1327 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED;
1329 match->provider = autocomplete_controller()->search_provider(); 1328 match->provider = autocomplete_controller()->search_provider();
1330 match->destination_url = client_->GetURL(); 1329 match->destination_url = client_->GetURL();
1331 match->transition = ui::PAGE_TRANSITION_RELOAD; 1330 match->transition = ui::PAGE_TRANSITION_RELOAD;
1332 } else if (query_in_progress() || 1331 } else if (query_in_progress() || PopupIsOpen()) {
1333 (popup_model() && popup_model()->IsOpen())) {
1334 if (query_in_progress()) { 1332 if (query_in_progress()) {
1335 // It's technically possible for |result| to be empty if no provider 1333 // It's technically possible for |result| to be empty if no provider
1336 // returns a synchronous result but the query has not completed 1334 // returns a synchronous result but the query has not completed
1337 // synchronously; pratically, however, that should never actually happen. 1335 // synchronously; pratically, however, that should never actually happen.
1338 if (result().empty()) 1336 if (result().empty())
1339 return; 1337 return;
1340 // The user cannot have manually selected a match, or the query would have 1338 // The user cannot have manually selected a match, or the query would have
1341 // stopped. So the default match must be the desired selection. 1339 // stopped. So the default match must be the desired selection.
1342 *match = *result().default_match(); 1340 *match = *result().default_match();
1343 } else { 1341 } else {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 // Update state and notify view if the omnibox has focus and the caret 1465 // Update state and notify view if the omnibox has focus and the caret
1468 // visibility changed. 1466 // visibility changed.
1469 const bool was_caret_visible = is_caret_visible(); 1467 const bool was_caret_visible = is_caret_visible();
1470 focus_state_ = state; 1468 focus_state_ = state;
1471 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1469 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1472 is_caret_visible() != was_caret_visible) 1470 is_caret_visible() != was_caret_visible)
1473 view_->ApplyCaretVisibility(); 1471 view_->ApplyCaretVisibility();
1474 1472
1475 client_->OnFocusChanged(focus_state_, reason); 1473 client_->OnFocusChanged(focus_state_, reason);
1476 } 1474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698