diff options
author | xji@google.com <xji@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-21 20:32:29 +0000 |
---|---|---|
committer | xji@google.com <xji@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-21 20:32:29 +0000 |
commit | 53c0b1ba80612d92849dc02e2e7a1aa97df0e6a1 (patch) | |
tree | 28201e71c8163fc73b4b849925bdf87d51bf1636 /ui/gfx/render_text.h | |
parent | df09e1b4e119de37af4226a20cd745c209b75f70 (diff) | |
download | chromium_src-53c0b1ba80612d92849dc02e2e7a1aa97df0e6a1.zip chromium_src-53c0b1ba80612d92849dc02e2e7a1aa97df0e6a1.tar.gz chromium_src-53c0b1ba80612d92849dc02e2e7a1aa97df0e6a1.tar.bz2 |
This is a reapply of
http://src.chromium.org/viewvc/chrome?view=rev&revision=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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text.h')
-rw-r--r-- | ui/gfx/render_text.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index 82eab91..4a1f9a9 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -193,7 +193,9 @@ class UI_EXPORT RenderText { // Set the selection_model_ to the value of |selection|. // The selection model components are modified if invalid. // Returns true if the cursor position or selection range changed. - // TODO(xji): need to check the cursor is set at grapheme boundary. + // If |selectin_start_| or |selection_end_| or |caret_pos_| in + // |selection_model| is not a cursorable position (not on grapheme boundary), + // it is a NO-OP and returns false. bool MoveCursorTo(const SelectionModel& selection_model); // Move the cursor to the position associated with the clicked point. @@ -254,6 +256,9 @@ class UI_EXPORT RenderText { // Subsequent text, cursor, or bounds changes may invalidate returned values. const Rect& GetUpdatedCursorBounds(); + // Get the logical index of the grapheme following the argument |position|. + virtual size_t GetIndexOfNextGrapheme(size_t position); + protected: RenderText(); @@ -288,6 +293,10 @@ class UI_EXPORT RenderText { // TODO(msw) Re-evaluate this function's necessity and signature. virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to); + // Return true if cursor can appear in front of the character at |position|, + // which means it is a grapheme boundary or the first character in the text. + virtual bool IsCursorablePosition(size_t position) = 0; + // Apply composition style (underline) to composition range and selection // style (foreground) to selection range. void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; @@ -305,16 +314,20 @@ class UI_EXPORT RenderText { FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); + // Return an index belonging to the |next| or previous logical grapheme. + // The return value is bounded by 0 and the text length, inclusive. + virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; + // Sets the selection model, the argument is assumed to be valid. void SetSelectionModel(const SelectionModel& selection_model); // Set the cursor to |position|, with the caret trailing the previous // grapheme, or if there is no previous grapheme, leading the cursor position. // If |select| is false, the selection start is moved to the same position. + // If the |position| is not a cursorable position (not on grapheme boundary), + // it is a NO-OP. void MoveCursorTo(size_t position, bool select); - bool IsPositionAtWordSelectionBoundary(size_t pos); - // Update the cached bounds and display offset to ensure that the current // cursor is within the visible display area. void UpdateCachedBoundsAndOffset(); |