summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text.h
diff options
context:
space:
mode:
authorbenrg@chromium.org <benrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 01:27:28 +0000
committerbenrg@chromium.org <benrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 01:27:28 +0000
commitd66009e4f25eab259ce05315ff8b506cb52c24f6 (patch)
treedc854e251b329b0aa8cf95ae2378cd3561af33df /ui/gfx/render_text.h
parentd4ab68006f402ef6e5ccf0fc3b075ab65b638f3e (diff)
downloadchromium_src-d66009e4f25eab259ce05315ff8b506cb52c24f6.zip
chromium_src-d66009e4f25eab259ce05315ff8b506cb52c24f6.tar.gz
chromium_src-d66009e4f25eab259ce05315ff8b506cb52c24f6.tar.bz2
Merge left and right cursor movement code in RenderText, and misc fixes
* Combine method pairs for left/right cursor motion in RenderText{,Linux,Win}, eliminating a lot of duplicate logic. The merged functions use new enums VisualTextDirection {VISUAL_LEFT, VISUAL_RIGHT} and LogicalTextDirection {LOGICAL_PREVIOUS, LOGICAL_NEXT}. * Make CalculateSubstringBounds and GetSelectionBounds return the result instead of taking it as an out pointer argument. * Remove Utf16IndexOfAdjacentGrapheme for clarity (it took a UTF-8 index as its argument) * Delete some unused obsolete methods in RenderText, remove some logging code, and fix some comments. The logic should be unchanged except that in the Backspace handler in NativeTextfieldViews, cursor_changed is now set to true only if the text changed (like Delete). Formerly it was always set to true, which appears to be a bug. BUG=none TEST=existing unit tests Review URL: http://codereview.chromium.org/8958024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text.h')
-rw-r--r--ui/gfx/render_text.h100
1 files changed, 57 insertions, 43 deletions
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 65057ab..e784f1d 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -57,16 +57,6 @@ class SkiaTextRenderer {
} // namespace internal
-// Color settings for text, backgrounds and cursor.
-// These are tentative, and should be derived from theme, system
-// settings and current settings.
-// TODO(oshima): Change this to match the standard chrome
-// before dogfooding textfield views.
-const SkColor kSelectedTextColor = SK_ColorWHITE;
-const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255);
-const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY;
-const SkColor kCursorColor = SK_ColorBLACK;
-
// A visual style applicable to a range of text.
struct UI_EXPORT StyleRange {
StyleRange();
@@ -91,7 +81,22 @@ enum BreakType {
LINE_BREAK,
};
-// TODO(msw): Implement RenderText[Win|Linux] for Uniscribe/Pango BiDi...
+// VisualCursorDirection and LogicalCursorDirection represent directions of
+// motion of the cursor in BiDi text. The combinations that make sense are:
+//
+// base::i18n::TextDirection VisualCursorDirection LogicalCursorDirection
+// LEFT_TO_RIGHT CURSOR_LEFT CURSOR_BACKWARD
+// LEFT_TO_RIGHT CURSOR_RIGHT CURSOR_FORWARD
+// RIGHT_TO_LEFT CURSOR_RIGHT CURSOR_BACKWARD
+// RIGHT_TO_LEFT CURSOR_LEFT CURSOR_FORWARD
+enum VisualCursorDirection {
+ CURSOR_LEFT,
+ CURSOR_RIGHT
+};
+enum LogicalCursorDirection {
+ CURSOR_BACKWARD,
+ CURSOR_FORWARD
+};
// RenderText represents an abstract model of styled text and its corresponding
// visual layout. Support is built in for a cursor, a selection, simple styling,
@@ -144,8 +149,9 @@ class UI_EXPORT RenderText {
// Moves the cursor left or right. Cursor movement is visual, meaning that
// left and right are relative to screen, not the directionality of the text.
// If |select| is false, the selection start is moved to the same position.
- void MoveCursorLeft(BreakType break_type, bool select);
- void MoveCursorRight(BreakType break_type, bool select);
+ void MoveCursor(BreakType break_type,
+ VisualCursorDirection direction,
+ bool select);
// Set the selection_model_ to the value of |selection|.
// The selection model components are modified if invalid.
@@ -197,7 +203,13 @@ class UI_EXPORT RenderText {
// Apply |default_style_| over the entire text range.
void ApplyDefaultStyle();
- virtual base::i18n::TextDirection GetTextDirection();
+ // Returns the dominant direction of the current text.
+ virtual base::i18n::TextDirection GetTextDirection() = 0;
+
+ // Returns the visual movement direction corresponding to the logical end
+ // of the text, considering only the dominant direction returned by
+ // |GetTextDirection()|, not the direction of a particular run.
+ VisualCursorDirection GetVisualDirectionOfLogicalEnd();
// Get the width of the entire string.
virtual int GetStringWidth() = 0;
@@ -220,8 +232,14 @@ 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|.
- size_t GetIndexOfNextGrapheme(size_t position);
+ // Given an |index| in text(), return the next or previous grapheme boundary
+ // in logical order (that is, the nearest index for which
+ // |IsCursorablePosition(index)| returns true). The return value is in the
+ // range 0 to text().length() inclusive (the input is clamped if it is out of
+ // that range). Always moves by at least one character index unless the
+ // supplied index is already at the boundary of the string.
+ virtual size_t IndexOfAdjacentGrapheme(size_t index,
+ LogicalCursorDirection direction) = 0;
// Return a SelectionModel with the cursor at the current selection's start.
// The returned value represents a cursor/caret position without a selection.
@@ -240,28 +258,37 @@ class UI_EXPORT RenderText {
// Get the selection model that visually neighbors |position| by |break_type|.
// The returned value represents a cursor/caret position without a selection.
- virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
- BreakType break_type);
- virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
- BreakType break_type);
+ SelectionModel GetAdjacentSelectionModel(const SelectionModel& current,
+ BreakType break_type,
+ VisualCursorDirection direction);
+
+ // Get the selection model visually left/right of |selection| by one grapheme.
+ // The returned value represents a cursor/caret position without a selection.
+ virtual SelectionModel AdjacentCharSelectionModel(
+ const SelectionModel& selection,
+ VisualCursorDirection direction) = 0;
+
+ // Get the selection model visually left/right of |selection| by one word.
+ // The returned value represents a cursor/caret position without a selection.
+ virtual SelectionModel AdjacentWordSelectionModel(
+ const SelectionModel& selection,
+ VisualCursorDirection direction) = 0;
// Get the SelectionModels corresponding to visual text ends.
// The returned value represents a cursor/caret position without a selection.
- virtual SelectionModel LeftEndSelectionModel();
- virtual SelectionModel RightEndSelectionModel();
+ virtual SelectionModel EdgeSelectionModel(
+ VisualCursorDirection direction) = 0;
// Sets the selection model, the argument is assumed to be valid.
virtual void SetSelectionModel(const SelectionModel& model);
// Get the visual bounds containing the logical substring within |from| to
- // |to| into |bounds|. If |from| equals to |to|, |bounds| is set as empty.
- // These bounds could be visually discontinuous if the substring is split by a
- // LTR/RTL level change. These bounds are in local coordinates, but may be
- // outside the visible region if the text is longer than the textfield.
- // Subsequent text, cursor, or bounds changes may invalidate returned values.
- virtual void GetSubstringBounds(size_t from,
- size_t to,
- std::vector<Rect>* bounds) = 0;
+ // |to|. If |from| equals |to|, the result is empty. These bounds could be
+ // visually discontinuous if the substring is split by a LTR/RTL level change.
+ // These bounds are in local coordinates, but may be outside the visible
+ // region if the text is longer than the textfield. Subsequent text, cursor,
+ // or bounds changes may invalidate returned values.
+ virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to) = 0;
// 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.
@@ -277,12 +304,6 @@ class UI_EXPORT RenderText {
// Draw the text.
virtual void DrawVisualText(Canvas* canvas) = 0;
- // Get the logical index of the grapheme preceding the argument |position|.
- // If |IsCursorablePosition(position)| is true, the result will be the start
- // of the previous grapheme, if any. Otherwise, the result will be the start
- // of the grapheme containing |position|.
- size_t GetIndexOfPreviousGrapheme(size_t position);
-
// Apply composition style (underline) to composition range and selection
// style (foreground) to selection range.
void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges);
@@ -314,13 +335,6 @@ class UI_EXPORT RenderText {
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForSkiaDrawing);
- // Return an index belonging to the |next| or previous logical grapheme.
- // If |next| is false and |IsCursorablePosition(index)| is true, the result
- // will be the start of the previous grapheme, if any. Otherwise, the result
- // will be the start of the grapheme containing |index|.
- // The return value is bounded by 0 and the text length, inclusive.
- virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0;
-
// 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.