diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 21:21:14 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 21:21:14 +0000 |
commit | aa351ca8d4ec607d94b1559bb78b46d8301daf1b (patch) | |
tree | fad1e2da20e07f483ff3a45ddc4c79a9fc8cccdb /ui/gfx/render_text_win.cc | |
parent | 9edeb71c75df9eed63d4e27e90c2ddfc287049b8 (diff) | |
download | chromium_src-aa351ca8d4ec607d94b1559bb78b46d8301daf1b.zip chromium_src-aa351ca8d4ec607d94b1559bb78b46d8301daf1b.tar.gz chromium_src-aa351ca8d4ec607d94b1559bb78b46d8301daf1b.tar.bz2 |
Revert 102006 - fix know issues in RenderText
1. add tests.
2. change SelectWord() to use BreakIterator, so it works for Chinese and Complex script.
3. DELETE/ReplaceChar delete/replace a whole grapheme. ReplaceTextInternal should only replace one grapheme when there is no selection.
4. pointing to position outside of text returns HOME/END position.
5. based on Chrome Linux omnibox and gedit, given
"abc| def", double click should select " " instead of "abc". Change test expectation.
BUG=90426
TEST=compile with touchui=1 test omnibox. run views_unittests.NativeTextfieldViewsTest/TextfieldViewsModelTest
Review URL: http://codereview.chromium.org/7841056
TBR=xji@google.com
Review URL: http://codereview.chromium.org/7982013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_win.cc')
-rw-r--r-- | ui/gfx/render_text_win.cc | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index f6b983d..c2c9acf 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -237,6 +237,10 @@ SelectionModel RenderTextWin::RightEndSelectionModel() { return SelectionModel(cursor, caret, placement); } +size_t RenderTextWin::GetIndexOfPreviousGrapheme(size_t position) { + return IndexOfAdjacentGrapheme(position, false); +} + std::vector<Rect> RenderTextWin::GetSubstringBounds(size_t from, size_t to) { ui::Range range(from, to); DCHECK(ui::Range(0, text().length()).Contains(range)); @@ -291,41 +295,6 @@ std::vector<Rect> RenderTextWin::GetSubstringBounds(size_t from, size_t to) { return bounds; } -bool RenderTextWin::IsCursorablePosition(size_t position) { - if (position == 0 || position == text().length()) - return true; - - size_t run_index = GetRunContainingPosition(position); - if (run_index >= runs_.size()) - return false; - - internal::TextRun* run = runs_[run_index]; - size_t start = run->range.start(); - if (position == start) - return true; - return run->logical_clusters[position - start] != - run->logical_clusters[position - start - 1]; -} - -size_t RenderTextWin::IndexOfAdjacentGrapheme(size_t index, bool next) { - size_t run_index = GetRunContainingPosition(index); - internal::TextRun* run = run_index < runs_.size() ? runs_[run_index] : NULL; - long start = run ? run->range.start() : 0; - long length = run ? run->range.length() : text().length(); - long ch = index - start; - WORD cluster = run ? run->logical_clusters[ch] : 0; - - if (!next) { - do { - ch--; - } while (ch >= 0 && run && run->logical_clusters[ch] == cluster); - } else { - while (ch < length && run && run->logical_clusters[ch] == cluster) - ch++; - } - return std::max(static_cast<long>(std::min(ch, length) + start), 0L); -} - void RenderTextWin::ItemizeLogicalText() { text_is_dirty_ = false; STLDeleteContainerPointers(runs_.begin(), runs_.end()); @@ -492,16 +461,34 @@ size_t RenderTextWin::GetRunContainingPoint(const Point& point) const { return run; } +size_t RenderTextWin::IndexOfAdjacentGrapheme(size_t index, bool next) const { + size_t run_index = GetRunContainingPosition(index); + internal::TextRun* run = run_index < runs_.size() ? runs_[run_index] : NULL; + long start = run ? run->range.start() : 0; + long length = run ? run->range.length() : text().length(); + long ch = index - start; + WORD cluster = run ? run->logical_clusters[ch] : 0; + + if (!next) { + do { + ch--; + } while (ch >= 0 && run && run->logical_clusters[ch] == cluster); + } else { + while (ch < length && run && run->logical_clusters[ch] == cluster) + ch++; + } + return std::max(static_cast<long>(std::min(ch, length) + start), 0L); +} SelectionModel RenderTextWin::FirstSelectionModelInsideRun( - internal::TextRun* run) { + internal::TextRun* run) const { size_t caret = run->range.start(); size_t cursor = IndexOfAdjacentGrapheme(caret, true); return SelectionModel(cursor, caret, SelectionModel::TRAILING); } SelectionModel RenderTextWin::LastSelectionModelInsideRun( - internal::TextRun* run) { + internal::TextRun* run) const { size_t caret = IndexOfAdjacentGrapheme(run->range.end(), false); return SelectionModel(caret, caret, SelectionModel::LEADING); } |