diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 00:37:09 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 00:37:09 +0000 |
commit | 0a12d5fdc9b861f48e0d431fa9f1887bf84246b1 (patch) | |
tree | 68aa74232007f5a106512de8a797d97a07e3a867 /ui/gfx/render_text_win.cc | |
parent | 51dbd1c879a48c7a28deb9f6e83e1a2d7ee78cee (diff) | |
download | chromium_src-0a12d5fdc9b861f48e0d431fa9f1887bf84246b1.zip chromium_src-0a12d5fdc9b861f48e0d431fa9f1887bf84246b1.tar.gz chromium_src-0a12d5fdc9b861f48e0d431fa9f1887bf84246b1.tar.bz2 |
Rewrite RenderText::IndexOfAdjacentGrapheme() in terms of IsCursorablePosition().
This moves the implementation of IndexOfAdjacentGrapheme() entirely into the base class, removing the need for platform-specific implementations.
This rewrite exposed a couple of problems in RenderTextLinux::IsCursorablePosition() that caused some tests to fail. The fixes are also included.
Also includes additional test coverage for UTF16 surrogate pairs, which was only caught by a Linux-specific password censorship test.
BUG=125664
TEST=Existing unit tests.
Review URL: https://chromiumcodereview.appspot.com/10389148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_win.cc')
-rw-r--r-- | ui/gfx/render_text_win.cc | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index b5cfec3..6705cb6 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -251,57 +251,6 @@ SelectionModel RenderTextWin::FindCursorPosition(const Point& point) { return SelectionModel(cursor, trailing ? CURSOR_BACKWARD : CURSOR_FORWARD); } -size_t RenderTextWin::IndexOfAdjacentGrapheme( - size_t index, - LogicalCursorDirection direction) { - EnsureLayout(); - - if (text().empty()) - return 0; - - if (index >= text().length()) { - if (direction == CURSOR_FORWARD || index > text().length()) { - return text().length(); - } else { - // The requested |index| is at the end of the text. Use the index of the - // last character to find the grapheme. - index = text().length() - 1; - if (IsCursorablePosition(index)) - return index; - } - } - - size_t run_index = - GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); - DCHECK(run_index < runs_.size()); - internal::TextRun* run = runs_[run_index]; - size_t start = run->range.start(); - size_t ch = index - start; - - if (direction == CURSOR_BACKWARD) { - // If |ch| is the start of the run, use the preceding run, if any. - if (ch == 0) { - if (run_index == 0) - return 0; - run = runs_[run_index - 1]; - start = run->range.start(); - ch = run->range.length(); - } - - // Loop to find the start of the grapheme. - WORD cluster = run->logical_clusters[ch - 1]; - do { - ch--; - } while (ch > 0 && run->logical_clusters[ch - 1] == cluster); - } else { // direction == CURSOR_FORWARD - WORD cluster = run->logical_clusters[ch]; - while (ch < run->range.length() && run->logical_clusters[ch] == cluster) - ch++; - } - - return start + ch; -} - std::vector<RenderText::FontSpan> RenderTextWin::GetFontSpansForTesting() { EnsureLayout(); |