Index: ui/gfx/render_text.cc |
=================================================================== |
--- ui/gfx/render_text.cc (revision 103758) |
+++ ui/gfx/render_text.cc (working copy) |
@@ -220,6 +220,32 @@ |
return MoveCursorTo(selection); |
} |
+bool RenderText::SelectRange(const ui::Range& range) { |
+ size_t text_length = text().length(); |
+ size_t start = std::min(range.start(), text_length); |
+ size_t end = std::min(range.end(), text_length); |
+ |
+ if (!IsCursorablePosition(start) || !IsCursorablePosition(end)) |
+ return false; |
+ |
+ int pos; |
+ SelectionModel::CaretPlacement placement; |
+ if (start < end) { |
+ pos = GetIndexOfPreviousGrapheme(end); |
+ placement = SelectionModel::TRAILING; |
msw
2011/10/04 07:25:41
Please DCHECK_LT(pos, end);
xji
2011/10/05 01:23:42
Done.
|
+ } else if (end == text_length) { |
+ SelectionModel boundary = GetTextDirection() == base::i18n::RIGHT_TO_LEFT ? |
+ LeftEndSelectionModel() : RightEndSelectionModel(); |
+ pos = boundary.caret_pos(); |
+ placement = boundary.caret_placement(); |
+ } else { |
+ pos = end; |
msw
2011/10/04 07:25:41
Initialize |pos| and |placement| with these 'defau
xji
2011/10/05 01:23:42
Done.
|
+ placement = SelectionModel::LEADING; |
+ } |
+ SetSelectionModel(SelectionModel(start, end, pos, placement)); |
+ return true; |
+} |
+ |
bool RenderText::IsPointInSelection(const Point& point) { |
if (EmptySelection()) |
return false; |