| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 last_suggestion_.behavior); | 215 last_suggestion_.behavior); |
| 216 | 216 |
| 217 // We need to call Show() here because of this: | 217 // We need to call Show() here because of this: |
| 218 // 1. User has typed a query (say Q). Instant overlay is showing results. | 218 // 1. User has typed a query (say Q). Instant overlay is showing results. |
| 219 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of | 219 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of |
| 220 // these cause the overlay to Hide(). | 220 // these cause the overlay to Hide(). |
| 221 // 3. User arrows-up to Q or types Q again. The last text we processed is | 221 // 3. User arrows-up to Q or types Q again. The last text we processed is |
| 222 // still Q, so we don't Update() the loader, but we do need to Show(). | 222 // still Q, so we don't Update() the loader, but we do need to Show(). |
| 223 if (loader_processed_last_update_ && | 223 if (loader_processed_last_update_ && |
| 224 (mode_ == INSTANT || mode_ == EXTENDED)) | 224 (mode_ == INSTANT || mode_ == EXTENDED)) |
| 225 Show(); | 225 Show(100, INSTANT_SIZE_PERCENT); |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 last_verbatim_ = verbatim; | 229 last_verbatim_ = verbatim; |
| 230 loader_processed_last_update_ = false; | 230 loader_processed_last_update_ = false; |
| 231 last_suggestion_ = InstantSuggestion(); | 231 last_suggestion_ = InstantSuggestion(); |
| 232 | 232 |
| 233 if (mode_ != SILENT) { | 233 if (mode_ != SILENT) { |
| 234 loader_->Update(query_text, verbatim); | 234 loader_->Update(query_text, verbatim); |
| 235 | 235 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) | 488 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) |
| 489 suggestion.text.clear(); | 489 suggestion.text.clear(); |
| 490 else | 490 else |
| 491 suggestion.text.erase(0, last_user_text_.size()); | 491 suggestion.text.erase(0, last_user_text_.size()); |
| 492 | 492 |
| 493 last_suggestion_ = suggestion; | 493 last_suggestion_ = suggestion; |
| 494 if (!last_verbatim_) | 494 if (!last_verbatim_) |
| 495 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); | 495 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); |
| 496 | 496 |
| 497 if (mode_ != SUGGEST) | 497 if (mode_ != SUGGEST) |
| 498 Show(); | 498 Show(100, INSTANT_SIZE_PERCENT); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void InstantController::CommitInstantLoader(InstantLoader* loader) { | 501 void InstantController::CommitInstantLoader(InstantLoader* loader) { |
| 502 DCHECK_EQ(loader_.get(), loader); | 502 DCHECK_EQ(loader_.get(), loader); |
| 503 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 503 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 504 if (loader_ != loader || !is_showing_ || IsOutOfDate()) | 504 if (loader_ != loader || !is_showing_ || IsOutOfDate()) |
| 505 return; | 505 return; |
| 506 | 506 |
| 507 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 507 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void InstantController::SetInstantPreviewHeight(InstantLoader* loader, |
| 511 int height, |
| 512 InstantSizeUnits units) { |
| 513 DCHECK_EQ(loader_.get(), loader); |
| 514 if (loader_ != loader || mode_ != EXTENDED) |
| 515 return; |
| 516 |
| 517 Show(height, units); |
| 518 } |
| 519 |
| 510 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { | 520 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { |
| 511 DCHECK_EQ(loader_.get(), loader); | 521 DCHECK_EQ(loader_.get(), loader); |
| 512 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); | 522 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); |
| 513 } | 523 } |
| 514 | 524 |
| 515 void InstantController::InstantSupportDetermined(InstantLoader* loader, | 525 void InstantController::InstantSupportDetermined(InstantLoader* loader, |
| 516 bool supports_instant) { | 526 bool supports_instant) { |
| 517 DCHECK_EQ(loader_.get(), loader); | 527 DCHECK_EQ(loader_.get(), loader); |
| 518 if (supports_instant) { | 528 if (supports_instant) { |
| 519 blacklisted_urls_.erase(loader->instant_url()); | 529 blacklisted_urls_.erase(loader->instant_url()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 532 content::Details<const bool> details(&supports_instant); | 542 content::Details<const bool> details(&supports_instant); |
| 533 content::NotificationService::current()->Notify( | 543 content::NotificationService::current()->Notify( |
| 534 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 544 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 535 content::NotificationService::AllSources(), | 545 content::NotificationService::AllSources(), |
| 536 details); | 546 details); |
| 537 } | 547 } |
| 538 | 548 |
| 539 void InstantController::SwappedTabContents(InstantLoader* loader) { | 549 void InstantController::SwappedTabContents(InstantLoader* loader) { |
| 540 DCHECK_EQ(loader_.get(), loader); | 550 DCHECK_EQ(loader_.get(), loader); |
| 541 if (loader_ == loader && is_showing_) | 551 if (loader_ == loader && is_showing_) |
| 542 delegate_->ShowInstant(); | 552 delegate_->ShowInstant(100, INSTANT_SIZE_PERCENT); |
| 543 } | 553 } |
| 544 | 554 |
| 545 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { | 555 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { |
| 546 DCHECK_EQ(loader_.get(), loader); | 556 DCHECK_EQ(loader_.get(), loader); |
| 547 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 557 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 548 #if defined(USE_AURA) | 558 #if defined(USE_AURA) |
| 549 // On aura the omnibox only receives a focus lost if we initiate the focus | 559 // On aura the omnibox only receives a focus lost if we initiate the focus |
| 550 // change. This does that. | 560 // change. This does that. |
| 551 if (is_showing_ && !IsOutOfDate()) | 561 if (is_showing_ && !IsOutOfDate()) |
| 552 delegate_->InstantPreviewFocused(); | 562 delegate_->InstantPreviewFocused(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 last_transition_type_ = content::PAGE_TRANSITION_LINK; | 636 last_transition_type_ = content::PAGE_TRANSITION_LINK; |
| 627 last_match_was_search_ = false; | 637 last_match_was_search_ = false; |
| 628 last_omnibox_bounds_ = gfx::Rect(); | 638 last_omnibox_bounds_ = gfx::Rect(); |
| 629 url_for_history_ = GURL(); | 639 url_for_history_ = GURL(); |
| 630 Hide(); | 640 Hide(); |
| 631 if (GetPreviewContents()) | 641 if (GetPreviewContents()) |
| 632 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); | 642 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| 633 loader_.reset(); | 643 loader_.reset(); |
| 634 } | 644 } |
| 635 | 645 |
| 636 void InstantController::Show() { | 646 void InstantController::Show(int height, InstantSizeUnits units) { |
| 647 // Call even if showing in case height changed. |
| 648 delegate_->ShowInstant(height, units); |
| 637 if (!is_showing_) { | 649 if (!is_showing_) { |
| 638 is_showing_ = true; | 650 is_showing_ = true; |
| 639 delegate_->ShowInstant(); | |
| 640 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); | 651 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); |
| 652 |
| 653 content::NotificationService::current()->Notify( |
| 654 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 655 content::Source<InstantController>(this), |
| 656 content::NotificationService::NoDetails()); |
| 641 } | 657 } |
| 642 } | 658 } |
| 643 | 659 |
| 644 void InstantController::SendBoundsToPage() { | 660 void InstantController::SendBoundsToPage() { |
| 645 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || | 661 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || |
| 646 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) | 662 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) |
| 647 return; | 663 return; |
| 648 | 664 |
| 649 last_omnibox_bounds_ = omnibox_bounds_; | 665 last_omnibox_bounds_ = omnibox_bounds_; |
| 650 gfx::Rect preview_bounds = delegate_->GetInstantBounds(); | 666 gfx::Rect preview_bounds = delegate_->GetInstantBounds(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 iter->second > kMaxInstantSupportFailures) | 733 iter->second > kMaxInstantSupportFailures) |
| 718 return false; | 734 return false; |
| 719 | 735 |
| 720 return true; | 736 return true; |
| 721 } | 737 } |
| 722 | 738 |
| 723 bool InstantController::IsOutOfDate() const { | 739 bool InstantController::IsOutOfDate() const { |
| 724 return !last_active_tab_ || | 740 return !last_active_tab_ || |
| 725 last_active_tab_ != delegate_->GetActiveTabContents(); | 741 last_active_tab_ != delegate_->GetActiveTabContents(); |
| 726 } | 742 } |
| OLD | NEW |