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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 keyword_.clear(); 375 keyword_.clear();
376 is_keyword_hint_ = false; 376 is_keyword_hint_ = false;
377 has_temporary_text_ = false; 377 has_temporary_text_ = false;
378 view_->SetWindowTextAndCaretPos(permanent_text_, 378 view_->SetWindowTextAndCaretPos(permanent_text_,
379 has_focus_ ? permanent_text_.length() : 0); 379 has_focus_ ? permanent_text_.length() : 0);
380 } 380 }
381 381
382 void AutocompleteEditModel::StartAutocomplete( 382 void AutocompleteEditModel::StartAutocomplete(
383 bool has_selected_text, 383 bool has_selected_text,
384 bool prevent_inline_autocomplete) const { 384 bool prevent_inline_autocomplete) const {
385 ResetCurrentMatchKeywordMode();
Peter Kasting 2011/04/07 20:19:21 Your CL must be missing some locally modified file
386
385 bool keyword_is_selected = KeywordIsSelected(); 387 bool keyword_is_selected = KeywordIsSelected();
386 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); 388 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
387 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, 389 // We don't explicitly clear AutocompletePopupModel::manually_selected_match,
388 // as Start ends up invoking AutocompletePopupModel::OnResultChanged which 390 // as Start ends up invoking AutocompletePopupModel::OnResultChanged which
389 // clears it. 391 // clears it.
390 autocomplete_controller_->Start( 392 autocomplete_controller_->Start(
391 user_text_, GetDesiredTLD(), 393 user_text_, GetDesiredTLD(),
392 prevent_inline_autocomplete || just_deleted_text_ || 394 prevent_inline_autocomplete || just_deleted_text_ ||
393 (has_selected_text && inline_autocomplete_text_.empty()) || 395 (has_selected_text && inline_autocomplete_text_.empty()) ||
394 (paste_state_ != NONE), keyword_is_selected, 396 (paste_state_ != NONE), keyword_is_selected,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 543
542 InstantController* instant = controller_->GetInstant(); 544 InstantController* instant = controller_->GetInstant();
543 if (instant && !popup_->IsOpen()) 545 if (instant && !popup_->IsOpen())
544 instant->DestroyPreviewContents(); 546 instant->DestroyPreviewContents();
545 update_instant_ = true; 547 update_instant_ = true;
546 } 548 }
547 549
548 bool AutocompleteEditModel::AcceptKeyword() { 550 bool AutocompleteEditModel::AcceptKeyword() {
549 DCHECK(is_keyword_hint_ && !keyword_.empty()); 551 DCHECK(is_keyword_hint_ && !keyword_.empty());
550 552
551 view_->OnBeforePossibleChange(); 553 autocomplete_controller_->Stop(false);
552 view_->SetWindowTextAndCaretPos(string16(), 0);
553 is_keyword_hint_ = false; 554 is_keyword_hint_ = false;
554 view_->OnAfterPossibleChange(); 555
555 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this 556 if (popup_->selected_line() != AutocompletePopupModel::kNoMatch) {
556 // since the edit contents have disappeared. It 557 AutocompleteMatch match = CurrentMatch();
557 // doesn't really matter, but we clear it to be 558
558 // consistent. 559 match.keyword->is_keyword_mode = true;
560 popup_->view()->InvalidateLine(popup_->selected_line());
561 }
562
563 view_->SetUserText(string16(), string16(), false);
564
559 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeywordHint"), profile_); 565 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeywordHint"), profile_);
560 return true; 566 return true;
561 } 567 }
562 568
563 void AutocompleteEditModel::ClearKeyword(const string16& visible_text) { 569 void AutocompleteEditModel::ClearKeyword(const string16& visible_text) {
564 view_->OnBeforePossibleChange(); 570 autocomplete_controller_->Stop(false);
571 ResetCurrentMatchKeywordMode();
572
565 const string16 window_text(keyword_ + visible_text); 573 const string16 window_text(keyword_ + visible_text);
566 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length()); 574
567 keyword_.clear(); 575 // Only reset the result if the edit text has changed since the
568 is_keyword_hint_ = false; 576 // keyword was accepted.
569 view_->OnAfterPossibleChange(); 577 if (just_deleted_text_) {
570 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this 578 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length());
571 // since the edit contents have actually grown 579 keyword_.clear();
572 // longer. 580 is_keyword_hint_ = false;
581 view_->OnAfterPossibleChange();
582 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this
583 // since the edit contents have actually grown
584 // longer.
585 } else {
586 view_->SetUserText(window_text, window_text, false);
587
588 if (visible_text.size() != 0) {
Peter Kasting 2011/04/07 20:19:21 Nit: Shorter: is_keyword_hint_ = visible_text.emp
589 is_keyword_hint_ = false;
590 keyword_.clear();
591 } else {
592 is_keyword_hint_ = true;
593 }
594
595 OnChanged();
596 }
597 }
598
599 void AutocompleteEditModel::ResetCurrentMatchKeywordMode() const {
600 if (popup_->selected_line() != AutocompletePopupModel::kNoMatch) {
601 AutocompleteMatch match;
602 InfoForCurrentSelection(&match, NULL);
603
604 if (match.keyword.get() && match.keyword->is_keyword_hint &&
605 match.keyword->is_keyword_mode) {
606 match.keyword->is_keyword_mode = false;
607 popup_->view()->InvalidateLine(popup_->selected_line());
608 }
609 }
573 } 610 }
574 611
575 const AutocompleteResult& AutocompleteEditModel::result() const { 612 const AutocompleteResult& AutocompleteEditModel::result() const {
576 return autocomplete_controller_->result(); 613 return autocomplete_controller_->result();
577 } 614 }
578 615
579 void AutocompleteEditModel::OnSetFocus(bool control_down) { 616 void AutocompleteEditModel::OnSetFocus(bool control_down) {
580 has_focus_ = true; 617 has_focus_ = true;
581 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 618 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
582 NotificationService::current()->Notify( 619 NotificationService::current()->Notify(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (!user_input_in_progress_) 698 if (!user_input_in_progress_)
662 InternalSetUserText(permanent_text_); 699 InternalSetUserText(permanent_text_);
663 view_->UpdatePopup(); 700 view_->UpdatePopup();
664 } else { 701 } else {
665 // TODO(pkasting): The popup is working on a query but is not open. We 702 // TODO(pkasting): The popup is working on a query but is not open. We
666 // should force it to open immediately. 703 // should force it to open immediately.
667 } 704 }
668 } else { 705 } else {
669 // The popup is open, so the user should be able to interact with it 706 // The popup is open, so the user should be able to interact with it
670 // normally. 707 // normally.
708 if (popup_->selected_line() != AutocompletePopupModel::kNoMatch) {
709 AutocompleteMatch match = CurrentMatch();
710
711 if (match.keyword.get() && match.keyword->is_keyword_hint &&
712 match.keyword->is_keyword_mode)
713 ClearKeyword(string16());
714 }
715
671 popup_->Move(count); 716 popup_->Move(count);
672 } 717 }
673 } 718 }
674 719
675 void AutocompleteEditModel::OnPopupDataChanged( 720 void AutocompleteEditModel::OnPopupDataChanged(
676 const string16& text, 721 const string16& text,
677 GURL* destination_for_temporary_text_change, 722 GURL* destination_for_temporary_text_change,
678 const string16& keyword, 723 const string16& keyword,
679 bool is_keyword_hint) { 724 bool is_keyword_hint) {
680 // Update keyword/hint-related local state. 725 // Update keyword/hint-related local state.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 if (!match->destination_url.SchemeIs(chrome::kExtensionScheme)) { 891 if (!match->destination_url.SchemeIs(chrome::kExtensionScheme)) {
847 // Warm up DNS Prefetch cache, or preconnect to a search service. 892 // Warm up DNS Prefetch cache, or preconnect to a search service.
848 chrome_browser_net::AnticipateOmniboxUrl(match->destination_url, 893 chrome_browser_net::AnticipateOmniboxUrl(match->destination_url,
849 IsPreconnectable(match->type)); 894 IsPreconnectable(match->type));
850 } 895 }
851 896
852 // We could prefetch the alternate nav URL, if any, but because there 897 // We could prefetch the alternate nav URL, if any, but because there
853 // can be many of these as a user types an initial series of characters, 898 // can be many of these as a user types an initial series of characters,
854 // the OS DNS cache could suffer eviction problems for minimal gain. 899 // the OS DNS cache could suffer eviction problems for minimal gain.
855 900
856 is_keyword_hint = popup_->GetKeywordForMatch(*match, &keyword); 901 if (match->keyword.get()) {
902 is_keyword_hint = match->keyword->is_keyword_hint;
903 keyword = match->keyword->text;
904 }
857 } 905 }
906
858 popup_->OnResultChanged(); 907 popup_->OnResultChanged();
859 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, 908 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword,
860 is_keyword_hint); 909 is_keyword_hint);
861 } else { 910 } else {
862 popup_->OnResultChanged(); 911 popup_->OnResultChanged();
863 } 912 }
864 913
865 if (popup_->IsOpen()) { 914 if (popup_->IsOpen()) {
866 PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); 915 PopupBoundsChangedTo(popup_->view()->GetTargetBounds());
867 } else if (was_open) { 916 } else if (was_open) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 old_user_text.length() - caret_position + 1)) { 1040 old_user_text.length() - caret_position + 1)) {
992 return false; 1041 return false;
993 } 1042 }
994 1043
995 // Then check if the text before the inserted space matches a keyword. 1044 // Then check if the text before the inserted space matches a keyword.
996 string16 keyword; 1045 string16 keyword;
997 TrimWhitespace(new_user_text.substr(0, caret_position - 1), 1046 TrimWhitespace(new_user_text.substr(0, caret_position - 1),
998 TRIM_LEADING, &keyword); 1047 TRIM_LEADING, &keyword);
999 1048
1000 // Only allow exact keyword match if |keyword| represents a keyword hint. 1049 // Only allow exact keyword match if |keyword| represents a keyword hint.
1001 return keyword.length() && popup_->GetKeywordForText(keyword, &keyword); 1050 return keyword.length() &&
1051 autocomplete_controller_->GetKeywordForText(keyword, &keyword);
1002 } 1052 }
1003 1053
1004 // static 1054 // static
1005 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { 1055 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
1006 switch (c) { 1056 switch (c) {
1007 case 0x0020: // Space 1057 case 0x0020: // Space
1008 case 0x3000: // Ideographic Space 1058 case 0x3000: // Ideographic Space
1009 return true; 1059 return true;
1010 default: 1060 default:
1011 return false; 1061 return false;
1012 } 1062 }
1013 } 1063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698