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

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: 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
« 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..65a2e6e7ae34cf256eda010270d7ef24c9060efd 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -263,7 +263,14 @@ 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 ui::Range& selection = GetRenderText()->selection();
+ drop_cursor_position_ = GetRenderText()->FindCursorPosition(event.location());
+ 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,9 +285,16 @@ 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()));
+ is_drop_cursor_visible_ = false;
ckocagil 2013/04/16 19:20:25 Added to fix a condition where OnDragDone isn't ca
+
TextfieldController* controller = textfield_->GetController();
if (controller) {
int drag_operation = controller->OnDrop(event.data());
@@ -1081,11 +1095,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