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

Unified Diff: ui/gfx/render_text.cc

Issue 8044004: Clean up of SelectionModel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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.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;

Powered by Google App Engine
This is Rietveld 408576698