OLD | NEW |
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/instant/instant_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 522 |
523 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( | 523 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( |
524 int32 page_id, | 524 int32 page_id, |
525 const std::vector<std::string>& suggestions, | 525 const std::vector<std::string>& suggestions, |
526 InstantCompleteBehavior behavior) { | 526 InstantCompleteBehavior behavior) { |
527 TabContentsWrapper* source = loader_->preview_contents(); | 527 TabContentsWrapper* source = loader_->preview_contents(); |
528 if (!source->controller().GetActiveEntry() || | 528 if (!source->controller().GetActiveEntry() || |
529 page_id != source->controller().GetActiveEntry()->page_id()) | 529 page_id != source->controller().GetActiveEntry()->page_id()) |
530 return; | 530 return; |
531 | 531 |
532 // TODO: pass in behavior to SetCompleteSuggestedText. | |
533 if (suggestions.empty()) | 532 if (suggestions.empty()) |
534 loader_->SetCompleteSuggestedText(string16()); | 533 loader_->SetCompleteSuggestedText(string16(), behavior); |
535 else | 534 else |
536 loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0])); | 535 loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0]), behavior); |
537 } | 536 } |
538 | 537 |
539 void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined( | 538 void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined( |
540 int32 page_id, | 539 int32 page_id, |
541 bool result) { | 540 bool result) { |
542 TabContents* source = loader_->preview_contents()->tab_contents(); | 541 TabContents* source = loader_->preview_contents()->tab_contents(); |
543 if (!source->controller().GetActiveEntry() || | 542 if (!source->controller().GetActiveEntry() || |
544 page_id != source->controller().GetActiveEntry()->page_id()) | 543 page_id != source->controller().GetActiveEntry()->page_id()) |
545 return; | 544 return; |
546 | 545 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 770 |
772 bool InstantLoader::ShouldCommitInstantOnMouseUp() { | 771 bool InstantLoader::ShouldCommitInstantOnMouseUp() { |
773 return delegate_->ShouldCommitInstantOnMouseUp(); | 772 return delegate_->ShouldCommitInstantOnMouseUp(); |
774 } | 773 } |
775 | 774 |
776 void InstantLoader::CommitInstantLoader() { | 775 void InstantLoader::CommitInstantLoader() { |
777 delegate_->CommitInstantLoader(this); | 776 delegate_->CommitInstantLoader(this); |
778 } | 777 } |
779 | 778 |
780 void InstantLoader::SetCompleteSuggestedText( | 779 void InstantLoader::SetCompleteSuggestedText( |
781 const string16& complete_suggested_text) { | 780 const string16& complete_suggested_text, |
| 781 InstantCompleteBehavior behavior) { |
782 if (!is_showing_instant()) { | 782 if (!is_showing_instant()) { |
783 // We're not trying to use the instant API with this page. Ignore it. | 783 // We're not trying to use the instant API with this page. Ignore it. |
784 return; | 784 return; |
785 } | 785 } |
786 | 786 |
787 ShowPreview(); | 787 ShowPreview(); |
788 | 788 |
789 if (complete_suggested_text == complete_suggested_text_) | 789 if (complete_suggested_text == complete_suggested_text_) |
790 return; | 790 return; |
791 | 791 |
792 if (verbatim_) { | 792 if (verbatim_) { |
793 // Don't show suggest results for verbatim queries. | 793 // Don't show suggest results for verbatim queries. |
794 return; | 794 return; |
795 } | 795 } |
796 | 796 |
797 string16 user_text_lower = l10n_util::ToLower(user_text_); | 797 string16 user_text_lower = l10n_util::ToLower(user_text_); |
798 string16 complete_suggested_text_lower = l10n_util::ToLower( | 798 string16 complete_suggested_text_lower = l10n_util::ToLower( |
799 complete_suggested_text); | 799 complete_suggested_text); |
800 last_suggestion_.clear(); | 800 last_suggestion_.clear(); |
801 if (user_text_lower.compare(0, user_text_lower.size(), | 801 if (user_text_lower.compare(0, user_text_lower.size(), |
802 complete_suggested_text_lower, | 802 complete_suggested_text_lower, |
803 0, user_text_lower.size())) { | 803 0, user_text_lower.size())) { |
804 // The user text no longer contains the suggested text, ignore it. | 804 // The user text no longer contains the suggested text, ignore it. |
805 complete_suggested_text_.clear(); | 805 complete_suggested_text_.clear(); |
806 delegate_->SetSuggestedTextFor(this, string16()); | 806 delegate_->SetSuggestedTextFor(this, string16(), behavior); |
807 return; | 807 return; |
808 } | 808 } |
809 | 809 |
810 complete_suggested_text_ = complete_suggested_text; | 810 complete_suggested_text_ = complete_suggested_text; |
811 // We are effectively showing complete_suggested_text_ now. Update user_text_ | 811 if (behavior == INSTANT_COMPLETE_NOW) { |
812 // so we don't notify the page again if Update happens to be invoked (which is | 812 // We are effectively showing complete_suggested_text_ now. Update |
813 // more than likely if this callback completes before the omnibox is done). | 813 // user_text_ so we don't notify the page again if Update happens to be |
814 string16 suggestion = complete_suggested_text_.substr(user_text_.size()); | 814 // invoked (which is more than likely if this callback completes before the |
815 user_text_ = complete_suggested_text_; | 815 // omnibox is done). |
816 last_suggestion_.clear(); | 816 string16 suggestion = complete_suggested_text_.substr(user_text_.size()); |
817 delegate_->SetSuggestedTextFor(this, suggestion); | 817 user_text_ = complete_suggested_text_; |
| 818 delegate_->SetSuggestedTextFor(this, suggestion, behavior); |
| 819 } else { |
| 820 DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || |
| 821 (behavior == INSTANT_COMPLETE_NEVER)); |
| 822 last_suggestion_ = complete_suggested_text_.substr(user_text_.size()); |
| 823 delegate_->SetSuggestedTextFor(this, last_suggestion_, behavior); |
| 824 } |
818 } | 825 } |
819 | 826 |
820 void InstantLoader::PreviewPainted() { | 827 void InstantLoader::PreviewPainted() { |
821 // If instant is supported then we wait for the first suggest result before | 828 // If instant is supported then we wait for the first suggest result before |
822 // showing the page. | 829 // showing the page. |
823 if (!template_url_id_) | 830 if (!template_url_id_) |
824 ShowPreview(); | 831 ShowPreview(); |
825 } | 832 } |
826 | 833 |
827 void InstantLoader::ShowPreview() { | 834 void InstantLoader::ShowPreview() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 Source<NavigationController>(&preview_contents_->controller())); | 951 Source<NavigationController>(&preview_contents_->controller())); |
945 #endif | 952 #endif |
946 | 953 |
947 registrar_.Add( | 954 registrar_.Add( |
948 this, | 955 this, |
949 NotificationType::NAV_ENTRY_COMMITTED, | 956 NotificationType::NAV_ENTRY_COMMITTED, |
950 Source<NavigationController>(&preview_contents_->controller())); | 957 Source<NavigationController>(&preview_contents_->controller())); |
951 | 958 |
952 preview_contents_->tab_contents()->ShowContents(); | 959 preview_contents_->tab_contents()->ShowContents(); |
953 } | 960 } |
OLD | NEW |