Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: ui/gfx/render_text.h

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make set_selection_start private, fix accidental inclusion of local hacks Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.h
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index db98b846057abbc7a8a0b63e0b1f7ce81953b3a6..7706ccf7c622c3b43ad68a61b6924e1969cec7ff 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -90,23 +90,6 @@ enum HorizontalAlignment {
ALIGN_RIGHT,
};
-// 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,
// complex scripts, and bi-directional text. Implementations provide mechanisms
@@ -160,11 +143,7 @@ class UI_EXPORT RenderText {
void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; }
bool fade_tail() const { return fade_tail_; }
- // This cursor position corresponds to SelectionModel::selection_end. In
- // addition to representing the selection end, it's also where logical text
- // edits take place, and doesn't necessarily correspond to
- // SelectionModel::caret_pos.
- size_t GetCursorPosition() const;
+ size_t cursor_position() const { return selection_model_.caret_pos(); }
void SetCursorPosition(size_t position);
// Moves the cursor left or right. Cursor movement is visual, meaning that
@@ -175,11 +154,10 @@ class UI_EXPORT RenderText {
bool select);
// Set the selection_model_ to the value of |selection|.
- // The selection model components are modified if invalid.
+ // The selection range is clamped to text().length() if out of range.
// Returns true if the cursor position or selection range changed.
- // 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.
+ // If any index in |selection_model| is not a cursorable position (not on a
+ // 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.
@@ -194,18 +172,7 @@ class UI_EXPORT RenderText {
// boundary), it is a NO-OP and returns false. Otherwise, returns true.
bool SelectRange(const ui::Range& range);
- size_t GetSelectionStart() const {
- return selection_model_.selection_start();
- }
- size_t MinOfSelection() const {
- return std::min(GetSelectionStart(), GetCursorPosition());
- }
- size_t MaxOfSelection() const {
- return std::max(GetSelectionStart(), GetCursorPosition());
- }
- bool EmptySelection() const {
- return GetSelectionStart() == GetCursorPosition();
- }
+ const ui::Range& selection() const { return selection_model_.selection(); }
msw 2012/02/28 22:51:32 nit: move this up with cursor_position()
benrg 2012/03/07 01:04:44 Done. I also moved selection_model().
// Returns true if the local point is over selected text.
bool IsPointInSelection(const Point& point);
@@ -232,8 +199,8 @@ class UI_EXPORT RenderText {
// |GetTextDirection()|, not the direction of a particular run.
VisualCursorDirection GetVisualDirectionOfLogicalEnd();
- // Get the width of the entire string.
- virtual int GetStringWidth() = 0;
+ // Get the size in pixels of the entire string.
+ virtual Size GetStringSize() = 0;
void Draw(Canvas* canvas);
@@ -245,8 +212,7 @@ class UI_EXPORT RenderText {
// bounds of the associated glyph. 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 Rect GetCursorBounds(const SelectionModel& selection,
- bool insert_mode) = 0;
+ Rect GetCursorBounds(const SelectionModel& selection, bool insert_mode);
// Compute the current cursor bounds, panning the text to show the cursor in
// the display rect if necessary. These bounds are in local coordinates.
@@ -297,19 +263,24 @@ class UI_EXPORT RenderText {
// Get the SelectionModels corresponding to visual text ends.
// The returned value represents a cursor/caret position without a selection.
- virtual SelectionModel EdgeSelectionModel(
- VisualCursorDirection direction) = 0;
+ SelectionModel EdgeSelectionModel(VisualCursorDirection direction);
// 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|. 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.
+ // Get the height and horizontal bounds (relative to the left of the text, not
+ // the view) of the glyph starting at |index|. If the glyph is RTL then
+ // xspan->is_reversed(). This does not return a Rect because a Rect can't have
+ // a negative width.
+ virtual void GetGlyphBounds(size_t index, ui::Range* xspan, int* height) = 0;
+
+ // Get the visual bounds containing the logical substring within the |range|.
+ // If |range| is empty, 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;
+ virtual std::vector<Rect> GetSubstringBounds(ui::Range range) = 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.
@@ -350,6 +321,12 @@ class UI_EXPORT RenderText {
// Applies fade effects to |renderer|.
void ApplyFadeEffects(internal::SkiaTextRenderer* renderer);
+ // A convenience function to check whether the glyph attached to the caret
+ // is within the given range.
+ static bool RangeContainsCaret(const ui::Range& range,
+ size_t caret_pos,
+ LogicalCursorDirection caret_affinity);
+
private:
friend class RenderTextTest;
@@ -358,7 +335,7 @@ class UI_EXPORT RenderText {
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
- FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels);
+ FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForSkiaDrawing);
// Set the cursor to |position|, with the caret trailing the previous
« no previous file with comments | « ui/gfx/canvas_skia_skia.cc ('k') | ui/gfx/render_text.cc » ('j') | ui/gfx/render_text.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698