diff options
author | xji@google.com <xji@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-16 21:18:57 +0000 |
---|---|---|
committer | xji@google.com <xji@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-16 21:18:57 +0000 |
commit | cb5827d8256021c98d051f391877ba9faffa6e7e (patch) | |
tree | 6ac30d46a87ec66f209bae3f302a1648e9e2cafa /ui/gfx | |
parent | cc0333740b0c8653ebe71c42afc0eb526a0bdebc (diff) | |
download | chromium_src-cb5827d8256021c98d051f391877ba9faffa6e7e.zip chromium_src-cb5827d8256021c98d051f391877ba9faffa6e7e.tar.gz chromium_src-cb5827d8256021c98d051f391877ba9faffa6e7e.tar.bz2 |
Remove PREVIOUS_GRAPHEME_TRAILING.
Remove const from GetIndexOfPreviousGrapheme() so the override function could
update local data.
Construct SelectionModel correctly in unittest.
BUG=90426
TEST=--use-pure-view.
Review URL: http://codereview.chromium.org/7607018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/render_text.cc | 15 | ||||
-rw-r--r-- | ui/gfx/render_text.h | 6 |
2 files changed, 13 insertions, 8 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 2855a07..498bb3b 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -87,11 +87,15 @@ StyleRange::StyleRange() } SelectionModel::SelectionModel() { - Init(0, 0, 0, PREVIOUS_GRAPHEME_TRAILING); + Init(0, 0, 0, LEADING); } SelectionModel::SelectionModel(size_t pos) { - Init(pos, pos, pos, PREVIOUS_GRAPHEME_TRAILING); + Init(pos, pos, pos, LEADING); +} + +SelectionModel::SelectionModel(size_t start, size_t end) { + Init(start, end, end, LEADING); } SelectionModel::SelectionModel(size_t end, @@ -266,6 +270,8 @@ void RenderText::SelectAll() { SetSelectionModel(sel); } +// TODO(xji): it does not work for languages do not use space as word breaker, +// such as Chinese. Should use BreakIterator. void RenderText::SelectWord() { size_t selection_start = GetSelectionStart(); size_t cursor_position = GetCursorPosition(); @@ -305,7 +311,8 @@ void RenderText::SelectWord() { SelectionModel sel(selection_model()); sel.set_selection_start(selection_start); sel.set_selection_end(cursor_position); - sel.set_caret_placement(SelectionModel::PREVIOUS_GRAPHEME_TRAILING); + sel.set_caret_pos(GetIndexOfPreviousGrapheme(cursor_position)); + sel.set_caret_placement(SelectionModel::TRAILING); SetSelectionModel(sel); } @@ -542,7 +549,7 @@ SelectionModel RenderText::GetRightSelectionModel(const SelectionModel& current, return SelectionModel(pos, pos, SelectionModel::LEADING); } -size_t RenderText::GetIndexOfPreviousGrapheme(size_t position) const { +size_t RenderText::GetIndexOfPreviousGrapheme(size_t position) { // TODO(msw): Handle complex script. return std::max(static_cast<int>(position - 1), static_cast<int>(0)); } diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index c3f9104..cc4f4e5 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -90,15 +90,13 @@ enum BreakType { class UI_EXPORT SelectionModel { public: enum CaretPlacement { - // PREVIOUS_GRAPHEME_TRAILING means cursor is visually attached to the - // trailing edge of previous grapheme. - PREVIOUS_GRAPHEME_TRAILING, LEADING, TRAILING, }; SelectionModel(); explicit SelectionModel(size_t pos); + SelectionModel(size_t start, size_t end); SelectionModel(size_t end, size_t pos, CaretPlacement status); SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); @@ -277,7 +275,7 @@ class UI_EXPORT RenderText { BreakType break_type); // Get the logical index of the grapheme preceeding the argument |position|. - virtual size_t GetIndexOfPreviousGrapheme(size_t position) const; + virtual size_t GetIndexOfPreviousGrapheme(size_t position); // Apply composition style (underline) to composition range and selection // style (foreground) to selection range. |