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_linux.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_linux.cc')
-rw-r--r-- | ui/gfx/render_text_linux.cc | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc index d5ac9c1..1e5e865 100644 --- a/ui/gfx/render_text_linux.cc +++ b/ui/gfx/render_text_linux.cc @@ -123,19 +123,13 @@ void RenderTextLinux::Draw(Canvas* canvas) { } SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { + // TODO(xji): when points outside of text, return HOME/END position. PangoLayout* layout = EnsureLayout(); if (text().empty()) return SelectionModel(0, 0, SelectionModel::LEADING); Point p(ToTextPoint(point)); - - // When the point is outside of text, return HOME/END position. - if (p.x() < 0) - return LeftEndSelectionModel(); - else if (p.x() > GetStringWidth()) - return RightEndSelectionModel(); - int caret_pos, trailing; pango_layout_xy_to_index(layout, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, &caret_pos, &trailing); @@ -218,7 +212,7 @@ SelectionModel RenderTextLinux::LeftEndSelectionModel() { return SelectionModel(text().length(), caret, SelectionModel::LEADING); } else { // RTL. size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length, - false); + PREVIOUS); return SelectionModel(text().length(), caret, SelectionModel::TRAILING); } } @@ -233,7 +227,7 @@ SelectionModel RenderTextLinux::RightEndSelectionModel() { PangoItem* item = last_visual_run->item; if (item->analysis.level % 2 == 0) { // LTR. size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length, - false); + PREVIOUS); return SelectionModel(text().length(), caret, SelectionModel::TRAILING); } else { // RTL. size_t caret = Utf8IndexToUtf16Index(item->offset); @@ -244,18 +238,16 @@ SelectionModel RenderTextLinux::RightEndSelectionModel() { return SelectionModel(0, 0, SelectionModel::LEADING); } -bool RenderTextLinux::IsCursorablePosition(size_t position) { - if (position == 0 && text().empty()) - return true; - +size_t RenderTextLinux::GetIndexOfPreviousGrapheme(size_t position) { EnsureLayout(); - return (position >= 0 && position < static_cast<size_t>(num_log_attrs_) && - log_attrs_[position].is_cursor_position); + size_t index = Utf16IndexToUtf8Index(position); + return Utf16IndexOfAdjacentGrapheme(index, PREVIOUS); } -size_t RenderTextLinux::IndexOfAdjacentGrapheme(size_t index, bool next) { +size_t RenderTextLinux::GetIndexOfNextGrapheme(size_t position) { EnsureLayout(); - return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next); + size_t index = Utf16IndexToUtf8Index(position); + return Utf16IndexOfAdjacentGrapheme(index, NEXT); } GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { @@ -274,12 +266,12 @@ GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { size_t RenderTextLinux::Utf8IndexOfAdjacentGrapheme( size_t utf8_index_of_current_grapheme, - bool next) const { + RelativeLogicalPosition pos) const { const char* ch = layout_text_ + utf8_index_of_current_grapheme; int char_offset = static_cast<int>(g_utf8_pointer_to_offset(layout_text_, ch)); int start_char_offset = char_offset; - if (!next) { + if (pos == PREVIOUS) { if (char_offset > 0) { do { --char_offset; @@ -300,23 +292,23 @@ size_t RenderTextLinux::Utf8IndexOfAdjacentGrapheme( size_t RenderTextLinux::Utf16IndexOfAdjacentGrapheme( size_t utf8_index_of_current_grapheme, - bool next) const { + RelativeLogicalPosition pos) const { size_t utf8_index = Utf8IndexOfAdjacentGrapheme( - utf8_index_of_current_grapheme, next); + utf8_index_of_current_grapheme, pos); return Utf8IndexToUtf16Index(utf8_index); } SelectionModel RenderTextLinux::FirstSelectionModelInsideRun( const PangoItem* item) const { size_t caret = Utf8IndexToUtf16Index(item->offset); - size_t cursor = Utf16IndexOfAdjacentGrapheme(item->offset, true); + size_t cursor = Utf16IndexOfAdjacentGrapheme(item->offset, NEXT); return SelectionModel(cursor, caret, SelectionModel::TRAILING); } SelectionModel RenderTextLinux::LastSelectionModelInsideRun( const PangoItem* item) const { size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length, - false); + PREVIOUS); return SelectionModel(caret, caret, SelectionModel::LEADING); } |