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

Unified Diff: ui/views/controls/textfield/native_textfield_views.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
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fc69c0d5076993e0da69fbb269c870f90182efb0 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -263,8 +263,12 @@ 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();
+ bool in_selection = GetRenderText()->IsPointInSelection(location);
is_drop_cursor_visible_ = !in_selection;
+ if (is_drop_cursor_visible_)
+ drop_cursor_position_ = GetRenderText()->FindCursorPosition(location);
msw 2013/04/15 17:14:04 You can optionally avoid calling both FindCursorPo
ckocagil 2013/04/15 20:41:15 Done.
// TODO(msw): Pan over text when the user drags to the visible text edge.
OnCaretBoundsChanged();
SchedulePaint();
@@ -278,6 +282,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 +1090,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()) {
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698