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

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: add comment about 'next' in ReplaceTextInternal 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
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/selection_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
===================================================================
--- ui/gfx/render_text.cc (revision 103984)
+++ ui/gfx/render_text.cc (working copy)
@@ -220,6 +220,30 @@
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;
+
+ size_t pos = end;
+ SelectionModel::CaretPlacement placement = SelectionModel::LEADING;
+ if (start < end) {
+ pos = GetIndexOfPreviousGrapheme(end);
+ DCHECK_LT(pos, end);
+ placement = SelectionModel::TRAILING;
+ } else if (end == text_length) {
+ SelectionModel boundary = GetTextDirection() == base::i18n::RIGHT_TO_LEFT ?
+ LeftEndSelectionModel() : RightEndSelectionModel();
+ pos = boundary.caret_pos();
+ placement = boundary.caret_placement();
+ }
+ SetSelectionModel(SelectionModel(start, end, pos, placement));
+ return true;
+}
+
bool RenderText::IsPointInSelection(const Point& point) {
if (EmptySelection())
return false;
@@ -450,7 +474,7 @@
SelectionModel RenderText::GetLeftSelectionModel(const SelectionModel& current,
BreakType break_type) {
if (break_type == LINE_BREAK)
- return SelectionModel(0, 0, SelectionModel::LEADING);
+ return LeftEndSelectionModel();
size_t pos = std::max(static_cast<long>(current.selection_end() - 1),
static_cast<long>(0));
if (break_type == CHARACTER_BREAK)
@@ -491,8 +515,7 @@
if (text_.empty())
return SelectionModel(0, 0, SelectionModel::LEADING);
if (break_type == LINE_BREAK)
- return SelectionModel(text().length(),
- GetIndexOfPreviousGrapheme(text().length()), SelectionModel::TRAILING);
+ return RightEndSelectionModel();
size_t pos = std::min(current.selection_end() + 1, text().length());
if (break_type == CHARACTER_BREAK)
return SelectionModel(pos, pos, SelectionModel::LEADING);
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/selection_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698