Chromium Code Reviews| 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/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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 InstantController::InstantController(chrome::BrowserInstantController* browser, | 146 InstantController::InstantController(chrome::BrowserInstantController* browser, |
| 147 bool extended_enabled) | 147 bool extended_enabled) |
| 148 : browser_(browser), | 148 : browser_(browser), |
| 149 extended_enabled_(extended_enabled), | 149 extended_enabled_(extended_enabled), |
| 150 instant_enabled_(false), | 150 instant_enabled_(false), |
| 151 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 151 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 152 last_verbatim_(false), | 152 last_verbatim_(false), |
| 153 last_transition_type_(content::PAGE_TRANSITION_LINK), | 153 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 154 last_match_was_search_(false), | 154 last_match_was_search_(false), |
| 155 is_omnibox_focused_(false) { | 155 is_omnibox_focused_(false), |
| 156 is_omnibox_invisibly_focused_(false) { | |
| 156 } | 157 } |
| 157 | 158 |
| 158 InstantController::~InstantController() { | 159 InstantController::~InstantController() { |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool InstantController::Update(const AutocompleteMatch& match, | 162 bool InstantController::Update(const AutocompleteMatch& match, |
| 162 const string16& user_text, | 163 const string16& user_text, |
| 163 const string16& full_text, | 164 const string16& full_text, |
| 164 const bool verbatim, | 165 const bool verbatim, |
| 165 const bool user_input_in_progress, | 166 const bool user_input_in_progress, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 // Try to create another loader immediately so that it is ready for the next | 471 // Try to create another loader immediately so that it is ready for the next |
| 471 // user interaction. | 472 // user interaction. |
| 472 CreateDefaultLoader(); | 473 CreateDefaultLoader(); |
| 473 | 474 |
| 474 return true; | 475 return true; |
| 475 } | 476 } |
| 476 | 477 |
| 477 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { | 478 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
| 478 DVLOG(1) << "OmniboxLostFocus"; | 479 DVLOG(1) << "OmniboxLostFocus"; |
| 479 is_omnibox_focused_ = false; | 480 is_omnibox_focused_ = false; |
| 481 is_omnibox_invisibly_focused_ = false; | |
| 480 | 482 |
| 481 if (!extended_enabled_ && !instant_enabled_) | 483 if (!extended_enabled_ && !instant_enabled_) |
| 482 return; | 484 return; |
| 483 | 485 |
| 484 // If the preview isn't showing search suggestions, nothing to do. The check | 486 // If the preview isn't showing search suggestions, nothing to do. The check |
| 485 // for GetPreviewContents() (which normally is redundant, given IsCurrent()) | 487 // for GetPreviewContents() (which normally is redundant, given IsCurrent()) |
| 486 // is to handle the case when we get here during a commit. | 488 // is to handle the case when we get here during a commit. |
| 487 if (!IsCurrent() || !GetPreviewContents()) { | 489 if (!IsCurrent() || !GetPreviewContents()) { |
| 488 OnStaleLoader(); | 490 OnStaleLoader(); |
| 489 return; | 491 return; |
| 490 } | 492 } |
| 491 | 493 |
| 494 loader_->OnStoppedCapturingKeyStrokes(); | |
|
Jered
2012/11/28 17:50:16
OnStopKeyCapture
samarth
2012/11/28 19:33:09
Now just OnKeyCaptureChange.
| |
| 495 | |
| 492 #if defined(OS_MACOSX) | 496 #if defined(OS_MACOSX) |
| 493 if (!loader_->IsPointerDownFromActivate()) | 497 if (!loader_->IsPointerDownFromActivate()) |
| 494 Hide(true); | 498 Hide(true); |
| 495 #else | 499 #else |
| 496 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), | 500 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
| 497 GetPreviewContents()->web_contents())) | 501 GetPreviewContents()->web_contents())) |
| 498 CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST); | 502 CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST); |
| 499 else | 503 else |
| 500 Hide(true); | 504 Hide(true); |
| 501 #endif | 505 #endif |
| 502 } | 506 } |
| 503 | 507 |
| 504 void InstantController::OmniboxGotFocus() { | 508 void InstantController::OmniboxGotFocus(bool focus_is_visible) { |
| 505 DVLOG(1) << "OmniboxGotFocus"; | 509 DVLOG(1) << "OmniboxGotFocus"; |
| 506 is_omnibox_focused_ = true; | 510 is_omnibox_focused_ = true; |
| 511 is_omnibox_invisibly_focused_ = !focus_is_visible; | |
| 507 | 512 |
| 508 if (!extended_enabled_ && !instant_enabled_) | 513 if (!extended_enabled_ && !instant_enabled_) |
| 509 return; | 514 return; |
| 510 | 515 |
| 516 if (is_omnibox_invisibly_focused_) | |
| 517 loader_->OnStartedCapturingKeyStrokes(); | |
|
Jered
2012/11/28 17:50:16
OnStartKeyCapture
samarth
2012/11/28 19:33:09
Now just OnKeyCaptureChange.
samarth
2012/11/28 19:33:09
Now just OnKeyCaptureChange.
| |
| 518 else | |
| 519 loader_->OnStoppedCapturingKeyStrokes(); | |
| 520 | |
| 511 if (!GetPreviewContents()) | 521 if (!GetPreviewContents()) |
| 512 CreateDefaultLoader(); | 522 CreateDefaultLoader(); |
| 513 } | 523 } |
| 514 | 524 |
| 515 void InstantController::SearchModeChanged( | 525 void InstantController::SearchModeChanged( |
| 516 const chrome::search::Mode& old_mode, | 526 const chrome::search::Mode& old_mode, |
| 517 const chrome::search::Mode& new_mode) { | 527 const chrome::search::Mode& new_mode) { |
| 518 if (!extended_enabled_) | 528 if (!extended_enabled_) |
| 519 return; | 529 return; |
| 520 | 530 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 DeleteLoader(); | 714 DeleteLoader(); |
| 705 | 715 |
| 706 if (!GetPreviewContents()) { | 716 if (!GetPreviewContents()) { |
| 707 loader_.reset(new InstantLoader(this, instant_url, active_tab)); | 717 loader_.reset(new InstantLoader(this, instant_url, active_tab)); |
| 708 loader_->Init(); | 718 loader_->Init(); |
| 709 | 719 |
| 710 // Ensure the searchbox API has the correct theme-related info and context. | 720 // Ensure the searchbox API has the correct theme-related info and context. |
| 711 if (extended_enabled_) { | 721 if (extended_enabled_) { |
| 712 browser_->UpdateThemeInfoForPreview(); | 722 browser_->UpdateThemeInfoForPreview(); |
| 713 loader_->SearchModeChanged(search_mode_); | 723 loader_->SearchModeChanged(search_mode_); |
| 724 if (is_omnibox_invisibly_focused_) | |
| 725 loader_->OnStartedCapturingKeyStrokes(); | |
| 726 else | |
| 727 loader_->OnStoppedCapturingKeyStrokes(); | |
| 714 } | 728 } |
| 715 | 729 |
| 716 // Reset the loader timer. | 730 // Reset the loader timer. |
| 717 stale_loader_timer_.Start( | 731 stale_loader_timer_.Start( |
| 718 FROM_HERE, | 732 FROM_HERE, |
| 719 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, | 733 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, |
| 720 &InstantController::OnStaleLoader); | 734 &InstantController::OnStaleLoader); |
| 721 } | 735 } |
| 722 | 736 |
| 723 return true; | 737 return true; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 } | 908 } |
| 895 | 909 |
| 896 std::map<std::string, int>::const_iterator iter = | 910 std::map<std::string, int>::const_iterator iter = |
| 897 blacklisted_urls_.find(*instant_url); | 911 blacklisted_urls_.find(*instant_url); |
| 898 if (iter != blacklisted_urls_.end() && | 912 if (iter != blacklisted_urls_.end() && |
| 899 iter->second > kMaxInstantSupportFailures) | 913 iter->second > kMaxInstantSupportFailures) |
| 900 return false; | 914 return false; |
| 901 | 915 |
| 902 return true; | 916 return true; |
| 903 } | 917 } |
| OLD | NEW |