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

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: 4 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..4d19a3bfa5b1e0fa500863cb23d4bc5a567a819d 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 =
@@ -706,6 +714,16 @@ void RenderText::SetTextShadows(const ShadowValues& shadows) {
text_shadows_ = shadows;
}
+// static
+bool RenderText::RangeContainsCaret(const ui::Range& range,
+ size_t caret_pos,
+ LogicalCursorDirection caret_affinity) {
+ // NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9).
+ size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ?
+ caret_pos - 1 : caret_pos + 1;
+ return range.Contains(ui::Range(caret_pos, adjacent));
+}
+
RenderText::RenderText()
: horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
directionality_mode_(DIRECTIONALITY_FROM_TEXT),
@@ -880,16 +898,6 @@ void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) {
renderer->SetDrawLooper(looper.get());
}
-// static
-bool RenderText::RangeContainsCaret(const ui::Range& range,
- size_t caret_pos,
- LogicalCursorDirection caret_affinity) {
- // NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9).
- size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ?
- caret_pos - 1 : caret_pos + 1;
- return range.Contains(ui::Range(caret_pos, adjacent));
-}
-
void RenderText::MoveCursorTo(size_t position, bool select) {
size_t cursor = std::min(position, text().length());
if (IsCursorablePosition(cursor))
@@ -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