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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_views.cc

Issue 6266015: Fix range comparison. Get space to accept keyword work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit_view_views.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_views.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/logging.h" 8 #include "base/logging.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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 views::TextRange new_sel; 478 views::TextRange new_sel;
479 textfield_->GetSelectedRange(&new_sel); 479 textfield_->GetSelectedRange(&new_sel);
480 480
481 size_t length = GetTextLength(); 481 size_t length = GetTextLength();
482 bool at_end_of_edit = (new_sel.start() == length && new_sel.end() == length); 482 bool at_end_of_edit = (new_sel.start() == length && new_sel.end() == length);
483 483
484 // See if the text or selection have changed since OnBeforePossibleChange(). 484 // See if the text or selection have changed since OnBeforePossibleChange().
485 std::wstring new_text = GetText(); 485 std::wstring new_text = GetText();
486 text_changed_ = (new_text != text_before_change_); 486 text_changed_ = (new_text != text_before_change_);
487 bool selection_differs = !sel_before_change_.Equals(new_sel); 487 bool selection_differs =
488 !((sel_before_change_.is_empty() && new_sel.is_empty()) ||
489 sel_before_change_.EqualsIgnoringDirection(new_sel));
488 490
489 // When the user has deleted text, we don't allow inline autocomplete. Make 491 // When the user has deleted text, we don't allow inline autocomplete. Make
490 // sure to not flag cases like selecting part of the text and then pasting 492 // sure to not flag cases like selecting part of the text and then pasting
491 // (or typing) the prefix of that selection. (We detect these by making 493 // (or typing) the prefix of that selection. (We detect these by making
492 // sure the caret, which should be after any insertion, hasn't moved 494 // sure the caret, which should be after any insertion, hasn't moved
493 // forward of the old selection start.) 495 // forward of the old selection start.)
494 bool just_deleted_text = 496 bool just_deleted_text =
495 (text_before_change_.length() > new_text.length()) && 497 (text_before_change_.length() > new_text.length()) &&
496 (new_sel.start() <= sel_before_change_.GetMin()); 498 (new_sel.start() <= sel_before_change_.GetMin());
497 499
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 628
627 string16 AutocompleteEditViewViews::GetSelectedText() const { 629 string16 AutocompleteEditViewViews::GetSelectedText() const {
628 // TODO(oshima): Support instant, IME. 630 // TODO(oshima): Support instant, IME.
629 return textfield_->GetSelectedText(); 631 return textfield_->GetSelectedText();
630 } 632 }
631 633
632 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) { 634 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) {
633 const views::TextRange range(caret, end); 635 const views::TextRange range(caret, end);
634 textfield_->SelectRange(range); 636 textfield_->SelectRange(range);
635 } 637 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc ('k') | views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698