Index: ui/views/controls/textfield/native_textfield_views.cc |
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc |
index bb29f06ab1257eff9d1167625c2b041d14a2b634..c569b9e8787557e5cd1a63a0b7a3afddcc659982 100644 |
--- a/ui/views/controls/textfield/native_textfield_views.cc |
+++ b/ui/views/controls/textfield/native_textfield_views.cc |
@@ -263,7 +263,15 @@ bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { |
int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) { |
DCHECK(CanDrop(event.data())); |
- bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
+ |
+ const gfx::Point& location = event.location(); |
+ const ui::Range& selection = GetRenderText()->selection(); |
+ drop_cursor_position_ = GetRenderText()->FindCursorPosition(location); |
msw
2013/04/15 21:05:43
nit: Inline event.location() and it's still a one-
ckocagil
2013/04/16 19:20:24
Done.
|
+ bool in_selection = !selection.is_empty() && |
+ GetRenderText()->RangeContainsCaret( |
+ selection, |
+ drop_cursor_position_.caret_pos(), |
+ drop_cursor_position_.caret_affinity()); |
is_drop_cursor_visible_ = !in_selection; |
// TODO(msw): Pan over text when the user drags to the visible text edge. |
OnCaretBoundsChanged(); |
@@ -278,6 +286,11 @@ int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) { |
return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; |
} |
+void NativeTextfieldViews::OnDragExited() { |
+ is_drop_cursor_visible_ = false; |
+ SchedulePaint(); |
+} |
+ |
int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) { |
DCHECK(CanDrop(event.data())); |
@@ -1081,11 +1094,15 @@ void NativeTextfieldViews::RepaintCursor() { |
void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { |
TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor"); |
canvas->Save(); |
- GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || |
- (is_cursor_visible_ && !model_->HasSelection())); |
+ GetRenderText()->set_cursor_visible(!is_drop_cursor_visible_ && |
+ is_cursor_visible_ && !model_->HasSelection()); |
// Draw the text, cursor, and selection. |
GetRenderText()->Draw(canvas); |
+ // Draw the detached drop cursor that marks where the text will be dropped. |
+ if (is_drop_cursor_visible_) |
+ GetRenderText()->DrawCursor(canvas, drop_cursor_position_); |
+ |
// Draw placeholder text if needed. |
if (model_->GetText().empty() && |
!textfield_->placeholder_text().empty()) { |