Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index fc9353f682f79ae48a19638650539c8275a629cd..4388b6d1db817dcbeb03acc6d64f65de1f38505d 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -611,7 +611,8 @@ void RenderText::Draw(Canvas* canvas) { |
if (!text().empty()) |
DrawSelection(canvas); |
- DrawCursor(canvas); |
+ if (cursor_enabled() && cursor_visible() && focused()) |
+ DrawCursor(canvas, selection_model_); |
if (!text().empty()) |
DrawVisualText(canvas); |
@@ -620,6 +621,12 @@ void RenderText::Draw(Canvas* canvas) { |
canvas->Restore(); |
} |
+void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
+ // Paint cursor. Replace cursor is drawn as rectangle for now. |
+ // TODO(msw): Draw a better cursor with a better indication of association. |
+ canvas->FillRect(GetCursorBounds(position, true), cursor_color_); |
+} |
+ |
void RenderText::DrawSelectedText(Canvas* canvas) { |
EnsureLayout(); |
const std::vector<Rect> sel = GetSubstringBounds(selection()); |
@@ -636,6 +643,7 @@ Rect RenderText::GetCursorBounds(const SelectionModel& caret, |
EnsureLayout(); |
size_t caret_pos = caret.caret_pos(); |
+ DCHECK(IsCursorablePosition(caret_pos)); |
// In overtype mode, ignore the affinity and always indicate that we will |
// overtype the next character. |
LogicalCursorDirection caret_affinity = |
@@ -963,13 +971,4 @@ void RenderText::DrawSelection(Canvas* canvas) { |
canvas->FillRect(*i, color); |
} |
-void RenderText::DrawCursor(Canvas* canvas) { |
- // Paint cursor. Replace cursor is drawn as rectangle for now. |
- // TODO(msw): Draw a better cursor with a better indication of association. |
- if (cursor_enabled() && cursor_visible() && focused()) { |
- canvas->FillRect(GetUpdatedCursorBounds(), |
- insert_mode_ ? cursor_color_ : selection_background_unfocused_color_); |
- } |
-} |
- |
} // namespace gfx |