OLD | NEW |
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 "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 468 |
469 size_t cursor_pos = cursor_position(); | 469 size_t cursor_pos = cursor_position(); |
470 | 470 |
471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
472 bool success = iter.Init(); | 472 bool success = iter.Init(); |
473 DCHECK(success); | 473 DCHECK(success); |
474 if (!success) | 474 if (!success) |
475 return; | 475 return; |
476 | 476 |
477 size_t selection_start = cursor_pos; | 477 size_t selection_start = cursor_pos; |
| 478 if (selection_start == text().length() && selection_start != 0) |
| 479 --selection_start; |
| 480 |
478 for (; selection_start != 0; --selection_start) { | 481 for (; selection_start != 0; --selection_start) { |
479 if (iter.IsStartOfWord(selection_start) || | 482 if (iter.IsStartOfWord(selection_start) || |
480 iter.IsEndOfWord(selection_start)) | 483 iter.IsEndOfWord(selection_start)) |
481 break; | 484 break; |
482 } | 485 } |
483 | 486 |
484 if (selection_start == cursor_pos) | 487 if (selection_start == cursor_pos) |
485 ++cursor_pos; | 488 ++cursor_pos; |
486 | 489 |
487 for (; cursor_pos < text().length(); ++cursor_pos) | 490 for (; cursor_pos < text().length(); ++cursor_pos) |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 void RenderText::DrawCursor(Canvas* canvas) { | 969 void RenderText::DrawCursor(Canvas* canvas) { |
967 // Paint cursor. Replace cursor is drawn as rectangle for now. | 970 // Paint cursor. Replace cursor is drawn as rectangle for now. |
968 // TODO(msw): Draw a better cursor with a better indication of association. | 971 // TODO(msw): Draw a better cursor with a better indication of association. |
969 if (cursor_enabled() && cursor_visible() && focused()) { | 972 if (cursor_enabled() && cursor_visible() && focused()) { |
970 canvas->FillRect(GetUpdatedCursorBounds(), | 973 canvas->FillRect(GetUpdatedCursorBounds(), |
971 insert_mode_ ? cursor_color_ : selection_background_unfocused_color_); | 974 insert_mode_ ? cursor_color_ : selection_background_unfocused_color_); |
972 } | 975 } |
973 } | 976 } |
974 | 977 |
975 } // namespace gfx | 978 } // namespace gfx |
OLD | NEW |