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/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 return false; | 502 return false; |
| 503 | 503 |
| 504 if (instant_tab_) | 504 if (instant_tab_) |
| 505 instant_tab_->UpOrDownKeyPressed(count); | 505 instant_tab_->UpOrDownKeyPressed(count); |
| 506 else | 506 else |
| 507 overlay_->UpOrDownKeyPressed(count); | 507 overlay_->UpOrDownKeyPressed(count); |
| 508 | 508 |
| 509 return true; | 509 return true; |
| 510 } | 510 } |
| 511 | 511 |
| 512 void InstantController::OnCancel(const string16& user_text) { | |
| 513 if (!extended_enabled_) | |
| 514 return; | |
| 515 | |
| 516 if (!instant_tab_ && !overlay_) | |
| 517 return; | |
| 518 | |
| 519 // We manually reset the state here since the JS is not expected to do it. | |
| 520 last_match_was_search_ = !user_text.empty(); | |
|
sreeram
2013/02/12 20:52:59
This isn't totally correct. Consider: I type [face
beaudoin
2013/02/12 21:34:41
Added TODO.
Done.
| |
| 521 last_omnibox_text_ = user_text; | |
| 522 last_suggestion_ = InstantSuggestion(); | |
| 523 | |
| 524 if (instant_tab_) | |
| 525 instant_tab_->CancelSelection(user_text); | |
| 526 else | |
| 527 overlay_->CancelSelection(user_text); | |
| 528 } | |
| 529 | |
| 512 content::WebContents* InstantController::GetPreviewContents() const { | 530 content::WebContents* InstantController::GetPreviewContents() const { |
| 513 return overlay_ ? overlay_->contents() : NULL; | 531 return overlay_ ? overlay_->contents() : NULL; |
| 514 } | 532 } |
| 515 | 533 |
| 516 bool InstantController::IsPreviewingSearchResults() const { | 534 bool InstantController::IsPreviewingSearchResults() const { |
| 517 return model_.mode().is_search_suggestions() && IsFullHeight(model_) && | 535 return model_.mode().is_search_suggestions() && IsFullHeight(model_) && |
| 518 (last_match_was_search_ || | 536 (last_match_was_search_ || |
| 519 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); | 537 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); |
| 520 } | 538 } |
| 521 | 539 |
| 522 bool InstantController::CommitIfPossible(InstantCommitType type) { | 540 bool InstantController::CommitIfPossible(InstantCommitType type) { |
| 523 if (!extended_enabled_ && !instant_enabled_) | 541 if (!extended_enabled_ && !instant_enabled_) |
| 524 return false; | 542 return false; |
| 525 | |
| 526 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 543 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 527 "CommitIfPossible: type=%d last_omnibox_text_='%s' " | 544 "CommitIfPossible: type=%d last_omnibox_text_='%s' " |
| 528 "last_match_was_search_=%d instant_tab_=%d", type, | 545 "last_match_was_search_=%d instant_tab_=%d", type, |
| 529 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, | 546 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, |
| 530 instant_tab_ != NULL)); | 547 instant_tab_ != NULL)); |
| 531 | 548 |
| 532 // If we are on an already committed search results page, send a submit event | 549 // If we are on an already committed search results page, send a submit event |
| 533 // to the page, but otherwise, nothing else to do. | 550 // to the page, but otherwise, nothing else to do. |
| 534 if (instant_tab_) { | 551 if (instant_tab_) { |
| 535 if (type == INSTANT_COMMIT_PRESSED_ENTER && | 552 if (type == INSTANT_COMMIT_PRESSED_ENTER && |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 delete overlay_->ReleaseContents().release(); | 1415 delete overlay_->ReleaseContents().release(); |
| 1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); | 1416 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
| 1400 EnsureOverlayIsCurrent(false); | 1417 EnsureOverlayIsCurrent(false); |
| 1401 } | 1418 } |
| 1402 | 1419 |
| 1403 void InstantController::RemoveFromBlacklist(const std::string& url) { | 1420 void InstantController::RemoveFromBlacklist(const std::string& url) { |
| 1404 if (blacklisted_urls_.erase(url)) { | 1421 if (blacklisted_urls_.erase(url)) { |
| 1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); | 1422 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
| 1406 } | 1423 } |
| 1407 } | 1424 } |
| OLD | NEW |