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

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

Issue 10949016: Fix case handling in Instant suggestions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebaseline Created 8 years, 2 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
« no previous file with comments | « chrome/browser/instant/instant_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time.h" 10 #include "base/time.h"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // suggestion (so that we don't inadvertently cause the preview to change 502 // suggestion (so that we don't inadvertently cause the preview to change
503 // what it's showing, as the user arrows up/down through the page-provided 503 // what it's showing, as the user arrows up/down through the page-provided
504 // suggestions). So, update these state variables here. 504 // suggestions). So, update these state variables here.
505 last_full_text_ = suggestion.text; 505 last_full_text_ = suggestion.text;
506 last_user_text_.clear(); 506 last_user_text_.clear();
507 last_verbatim_ = true; 507 last_verbatim_ = true;
508 last_suggestion_ = InstantSuggestion(); 508 last_suggestion_ = InstantSuggestion();
509 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; 509 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH;
510 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); 510 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior);
511 } else { 511 } else {
512 string16 suggestion_lower = base::i18n::ToLower(suggestion.text); 512 // Match case-sensitively first, to preserve suggestion case if possible.
513 string16 user_text_lower = base::i18n::ToLower(last_user_text_); 513 // If that fails, match case-insensitively. http://crbug.com/150728
514 if (user_text_lower.size() >= suggestion_lower.size() || 514 if (last_user_text_.size() < suggestion.text.size() &&
515 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) 515 !suggestion.text.compare(0, last_user_text_.size(), last_user_text_)) {
516 suggestion.text.clear();
517 else
518 suggestion.text.erase(0, last_user_text_.size()); 516 suggestion.text.erase(0, last_user_text_.size());
517 } else {
518 string16 suggestion_lower = base::i18n::ToLower(suggestion.text);
519 string16 user_text_lower = base::i18n::ToLower(last_user_text_);
520 if (user_text_lower.size() < suggestion_lower.size() &&
521 !suggestion_lower.compare(0, user_text_lower.size(),
522 user_text_lower)) {
523 suggestion.text.assign(suggestion_lower, user_text_lower.size(),
524 suggestion_lower.size() - user_text_lower.size());
525 } else {
526 suggestion.text.clear();
527 }
528 }
519 529
520 last_suggestion_ = suggestion; 530 last_suggestion_ = suggestion;
521 if (!last_verbatim_) 531 if (!last_verbatim_)
522 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); 532 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior);
523 } 533 }
524 534
525 if (mode_ != SUGGEST) 535 if (mode_ != SUGGEST)
526 Show(100, INSTANT_SIZE_PERCENT); 536 Show(100, INSTANT_SIZE_PERCENT);
527 } 537 }
528 538
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 DCHECK(url_obj.is_valid()); 798 DCHECK(url_obj.is_valid());
789 *instant_url = url_obj.spec(); 799 *instant_url = url_obj.spec();
790 } 800 }
791 } 801 }
792 } 802 }
793 803
794 bool InstantController::IsOutOfDate() const { 804 bool InstantController::IsOutOfDate() const {
795 return !last_active_tab_ || 805 return !last_active_tab_ ||
796 last_active_tab_ != delegate_->GetActiveTabContents(); 806 last_active_tab_ != delegate_->GetActiveTabContents();
797 } 807 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698