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

Side by Side Diff: views/controls/textfield/textfield_views_model.cc

Issue 7008005: base/i18n: Pass |str| as const reference in BreakIterator::Init(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const reference Created 9 years, 7 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 | « ui/base/text/text_elider.cc ('k') | views/view_text_utils.cc » ('j') | 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) 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 "views/controls/textfield/textfield_views_model.h" 5 #include "views/controls/textfield/textfield_views_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 424 }
425 } 425 }
426 426
427 void TextfieldViewsModel::MoveCursorToPreviousWord(bool select) { 427 void TextfieldViewsModel::MoveCursorToPreviousWord(bool select) {
428 if (HasCompositionText()) 428 if (HasCompositionText())
429 ConfirmCompositionText(); 429 ConfirmCompositionText();
430 // Notes: We always iterate words from the begining. 430 // Notes: We always iterate words from the begining.
431 // This is probably fast enough for our usage, but we may 431 // This is probably fast enough for our usage, but we may
432 // want to modify WordIterator so that it can start from the 432 // want to modify WordIterator so that it can start from the
433 // middle of string and advance backwards. 433 // middle of string and advance backwards.
434 base::i18n::BreakIterator iter(&text_, base::i18n::BreakIterator::BREAK_WORD); 434 base::i18n::BreakIterator iter(text_, base::i18n::BreakIterator::BREAK_WORD);
435 bool success = iter.Init(); 435 bool success = iter.Init();
436 DCHECK(success); 436 DCHECK(success);
437 if (!success) 437 if (!success)
438 return; 438 return;
439 int last = 0; 439 int last = 0;
440 while (iter.Advance()) { 440 while (iter.Advance()) {
441 if (iter.IsWord()) { 441 if (iter.IsWord()) {
442 size_t begin = iter.pos() - iter.GetString().length(); 442 size_t begin = iter.pos() - iter.GetString().length();
443 if (begin == cursor_pos_) { 443 if (begin == cursor_pos_) {
444 // The cursor is at the beginning of a word. 444 // The cursor is at the beginning of a word.
(...skipping 11 matching lines...) Expand all
456 } 456 }
457 457
458 cursor_pos_ = last; 458 cursor_pos_ = last;
459 if (!select) 459 if (!select)
460 ClearSelection(); 460 ClearSelection();
461 } 461 }
462 462
463 void TextfieldViewsModel::MoveCursorToNextWord(bool select) { 463 void TextfieldViewsModel::MoveCursorToNextWord(bool select) {
464 if (HasCompositionText()) 464 if (HasCompositionText())
465 ConfirmCompositionText(); 465 ConfirmCompositionText();
466 base::i18n::BreakIterator iter(&text_, base::i18n::BreakIterator::BREAK_WORD); 466 base::i18n::BreakIterator iter(text_, base::i18n::BreakIterator::BREAK_WORD);
467 bool success = iter.Init(); 467 bool success = iter.Init();
468 DCHECK(success); 468 DCHECK(success);
469 if (!success) 469 if (!success)
470 return; 470 return;
471 size_t pos = 0; 471 size_t pos = 0;
472 while (iter.Advance()) { 472 while (iter.Advance()) {
473 pos = iter.pos(); 473 pos = iter.pos();
474 if (iter.IsWord() && pos > cursor_pos_) { 474 if (iter.IsWord() && pos > cursor_pos_) {
475 break; 475 break;
476 } 476 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 text_.erase(delete_from, delete_to - delete_from); 891 text_.erase(delete_from, delete_to - delete_from);
892 if (!new_text.empty()) 892 if (!new_text.empty())
893 text_.insert(new_text_insert_at, new_text); 893 text_.insert(new_text_insert_at, new_text);
894 cursor_pos_ = new_cursor_pos; 894 cursor_pos_ = new_cursor_pos;
895 ClearSelection(); 895 ClearSelection();
896 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). 896 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't).
897 // This looks fine feature and we may want to do the same. 897 // This looks fine feature and we may want to do the same.
898 } 898 }
899 899
900 } // namespace views 900 } // namespace views
OLDNEW
« no previous file with comments | « ui/base/text/text_elider.cc ('k') | views/view_text_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698