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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 10918289: Instant extended API: Make arrow up/down work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Hackiness noted Created 8 years, 3 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) 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 11 matching lines...) Expand all
22 #include "chrome/browser/ui/search/search.h" 22 #include "chrome/browser/ui/search/search.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "content/public/browser/favicon_status.h" 27 #include "content/public/browser/favicon_status.h"
28 #include "content/public/browser/navigation_entry.h" 28 #include "content/public/browser/navigation_entry.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_widget_host_view.h" 30 #include "content/public/browser/render_widget_host_view.h"
31 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
32 #include "ui/gfx/codec/png_codec.h"
33 32
34 #if defined(TOOLKIT_VIEWS) 33 #if defined(TOOLKIT_VIEWS)
35 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
36 #endif 35 #endif
37 36
38 namespace { 37 namespace {
39 38
40 enum PreviewUsageType { 39 enum PreviewUsageType {
41 PREVIEW_CREATED = 0, 40 PREVIEW_CREATED = 0,
42 PREVIEW_DELETED, 41 PREVIEW_DELETED,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 result.contents = match->description; 280 result.contents = match->description;
282 result.destination_url = match->destination_url; 281 result.destination_url = match->destination_url;
283 result.relevance = match->relevance; 282 result.relevance = match->relevance;
284 results.push_back(result); 283 results.push_back(result);
285 } 284 }
286 } 285 }
287 286
288 loader_->SendAutocompleteResults(results); 287 loader_->SendAutocompleteResults(results);
289 } 288 }
290 289
290 bool InstantController::OnUpOrDownKeyPressed(int count) {
291 if (mode_ != EXTENDED || !GetPreviewContents())
292 return false;
293
294 loader_->OnUpOrDownKeyPressed(count);
295 return true;
296 }
297
291 TabContents* InstantController::GetPreviewContents() const { 298 TabContents* InstantController::GetPreviewContents() const {
292 return loader_.get() ? loader_->preview_contents() : NULL; 299 return loader_.get() ? loader_->preview_contents() : NULL;
293 } 300 }
294 301
295 void InstantController::Hide() { 302 void InstantController::Hide() {
296 last_active_tab_ = NULL; 303 last_active_tab_ = NULL;
297 if (is_showing_) { 304 if (is_showing_) {
298 is_showing_ = false; 305 is_showing_ = false;
299 delegate_->HideInstant(); 306 delegate_->HideInstant();
300 } 307 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 DCHECK_EQ(loader_.get(), loader); 482 DCHECK_EQ(loader_.get(), loader);
476 if (loader_ != loader || IsOutOfDate() || mode_ == SILENT || mode_ == HIDDEN) 483 if (loader_ != loader || IsOutOfDate() || mode_ == SILENT || mode_ == HIDDEN)
477 return; 484 return;
478 485
479 loader_processed_last_update_ = true; 486 loader_processed_last_update_ = true;
480 487
481 InstantSuggestion suggestion; 488 InstantSuggestion suggestion;
482 if (!suggestions.empty()) 489 if (!suggestions.empty())
483 suggestion = suggestions[0]; 490 suggestion = suggestions[0];
484 491
485 string16 suggestion_lower = base::i18n::ToLower(suggestion.text); 492 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
486 string16 user_text_lower = base::i18n::ToLower(last_user_text_); 493 // We don't get an Update() when changing the omnibox due to a REPLACE
487 if (user_text_lower.size() >= suggestion_lower.size() || 494 // suggestion (so that we don't inadvertently cause the preview to change
488 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) 495 // what it's showing, as the user arrows up/down through the page-provided
489 suggestion.text.clear(); 496 // suggestions). So, update these state variables here.
490 else 497 last_full_text_ = suggestion.text;
491 suggestion.text.erase(0, last_user_text_.size()); 498 last_user_text_.clear();
499 last_verbatim_ = true;
500 last_suggestion_ = InstantSuggestion();
501 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH;
502 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior);
503 } else {
504 string16 suggestion_lower = base::i18n::ToLower(suggestion.text);
505 string16 user_text_lower = base::i18n::ToLower(last_user_text_);
506 if (user_text_lower.size() >= suggestion_lower.size() ||
507 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower))
508 suggestion.text.clear();
509 else
510 suggestion.text.erase(0, last_user_text_.size());
492 511
493 last_suggestion_ = suggestion; 512 last_suggestion_ = suggestion;
494 if (!last_verbatim_) 513 if (!last_verbatim_)
495 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); 514 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior);
515 }
496 516
497 if (mode_ != SUGGEST) 517 if (mode_ != SUGGEST)
498 Show(); 518 Show();
499 } 519 }
500 520
501 void InstantController::CommitInstantLoader(InstantLoader* loader) { 521 void InstantController::CommitInstantLoader(InstantLoader* loader) {
502 DCHECK_EQ(loader_.get(), loader); 522 DCHECK_EQ(loader_.get(), loader);
503 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; 523 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_;
504 if (loader_ != loader || !is_showing_ || IsOutOfDate()) 524 if (loader_ != loader || !is_showing_ || IsOutOfDate())
505 return; 525 return;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 iter->second > kMaxInstantSupportFailures) 737 iter->second > kMaxInstantSupportFailures)
718 return false; 738 return false;
719 739
720 return true; 740 return true;
721 } 741 }
722 742
723 bool InstantController::IsOutOfDate() const { 743 bool InstantController::IsOutOfDate() const {
724 return !last_active_tab_ || 744 return !last_active_tab_ ||
725 last_active_tab_ != delegate_->GetActiveTabContents(); 745 last_active_tab_ != delegate_->GetActiveTabContents();
726 } 746 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698