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

Unified Diff: ui/gfx/render_text.cc

Issue 14264004: Re-land: NativeTextfieldViews: Show the drop cursor when dragging text (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 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
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

Powered by Google App Engine
This is Rietveld 408576698