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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { 256 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) {
257 int formats; 257 int formats;
258 std::set<OSExchangeData::CustomFormat> custom_formats; 258 std::set<OSExchangeData::CustomFormat> custom_formats;
259 GetDropFormats(&formats, &custom_formats); 259 GetDropFormats(&formats, &custom_formats);
260 return textfield_->enabled() && !textfield_->read_only() && 260 return textfield_->enabled() && !textfield_->read_only() &&
261 data.HasAnyFormat(formats, custom_formats); 261 data.HasAnyFormat(formats, custom_formats);
262 } 262 }
263 263
264 int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) { 264 int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) {
265 DCHECK(CanDrop(event.data())); 265 DCHECK(CanDrop(event.data()));
266 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); 266
267 const ui::Range& selection = GetRenderText()->selection();
268 drop_cursor_position_ = GetRenderText()->FindCursorPosition(event.location());
269 bool in_selection = !selection.is_empty() &&
270 GetRenderText()->RangeContainsCaret(
271 selection,
272 drop_cursor_position_.caret_pos(),
273 drop_cursor_position_.caret_affinity());
267 is_drop_cursor_visible_ = !in_selection; 274 is_drop_cursor_visible_ = !in_selection;
268 // TODO(msw): Pan over text when the user drags to the visible text edge. 275 // TODO(msw): Pan over text when the user drags to the visible text edge.
269 OnCaretBoundsChanged(); 276 OnCaretBoundsChanged();
270 SchedulePaint(); 277 SchedulePaint();
271 278
272 if (initiating_drag_) { 279 if (initiating_drag_) {
273 if (in_selection) 280 if (in_selection)
274 return ui::DragDropTypes::DRAG_NONE; 281 return ui::DragDropTypes::DRAG_NONE;
275 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : 282 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY :
276 ui::DragDropTypes::DRAG_MOVE; 283 ui::DragDropTypes::DRAG_MOVE;
277 } 284 }
278 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; 285 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE;
279 } 286 }
280 287
288 void NativeTextfieldViews::OnDragExited() {
289 is_drop_cursor_visible_ = false;
290 SchedulePaint();
291 }
292
281 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) { 293 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) {
282 DCHECK(CanDrop(event.data())); 294 DCHECK(CanDrop(event.data()));
283 295
296 is_drop_cursor_visible_ = false;
ckocagil 2013/04/16 19:20:25 Added to fix a condition where OnDragDone isn't ca
297
284 TextfieldController* controller = textfield_->GetController(); 298 TextfieldController* controller = textfield_->GetController();
285 if (controller) { 299 if (controller) {
286 int drag_operation = controller->OnDrop(event.data()); 300 int drag_operation = controller->OnDrop(event.data());
287 if (drag_operation != ui::DragDropTypes::DRAG_NONE) 301 if (drag_operation != ui::DragDropTypes::DRAG_NONE)
288 return drag_operation; 302 return drag_operation;
289 } 303 }
290 304
291 DCHECK(!initiating_drag_ || 305 DCHECK(!initiating_drag_ ||
292 !GetRenderText()->IsPointInSelection(event.location())); 306 !GetRenderText()->IsPointInSelection(event.location()));
293 OnBeforeUserAction(); 307 OnBeforeUserAction();
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1088
1075 void NativeTextfieldViews::RepaintCursor() { 1089 void NativeTextfieldViews::RepaintCursor() {
1076 gfx::Rect r(GetCaretBounds()); 1090 gfx::Rect r(GetCaretBounds());
1077 r.Inset(-1, -1, -1, -1); 1091 r.Inset(-1, -1, -1, -1);
1078 SchedulePaintInRect(r); 1092 SchedulePaintInRect(r);
1079 } 1093 }
1080 1094
1081 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { 1095 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) {
1082 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor"); 1096 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor");
1083 canvas->Save(); 1097 canvas->Save();
1084 GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || 1098 GetRenderText()->set_cursor_visible(!is_drop_cursor_visible_ &&
1085 (is_cursor_visible_ && !model_->HasSelection())); 1099 is_cursor_visible_ && !model_->HasSelection());
1086 // Draw the text, cursor, and selection. 1100 // Draw the text, cursor, and selection.
1087 GetRenderText()->Draw(canvas); 1101 GetRenderText()->Draw(canvas);
1088 1102
1103 // Draw the detached drop cursor that marks where the text will be dropped.
1104 if (is_drop_cursor_visible_)
1105 GetRenderText()->DrawCursor(canvas, drop_cursor_position_);
1106
1089 // Draw placeholder text if needed. 1107 // Draw placeholder text if needed.
1090 if (model_->GetText().empty() && 1108 if (model_->GetText().empty() &&
1091 !textfield_->placeholder_text().empty()) { 1109 !textfield_->placeholder_text().empty()) {
1092 canvas->DrawStringInt( 1110 canvas->DrawStringInt(
1093 textfield_->placeholder_text(), 1111 textfield_->placeholder_text(),
1094 GetRenderText()->GetFont(), 1112 GetRenderText()->GetFont(),
1095 textfield_->placeholder_text_color(), 1113 textfield_->placeholder_text_color(),
1096 GetRenderText()->display_rect()); 1114 GetRenderText()->display_rect());
1097 } 1115 }
1098 canvas->Restore(); 1116 canvas->Restore();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1431
1414 void NativeTextfieldViews::PlatformGestureEventHandling( 1432 void NativeTextfieldViews::PlatformGestureEventHandling(
1415 const ui::GestureEvent* event) { 1433 const ui::GestureEvent* event) {
1416 #if defined(OS_WIN) && defined(USE_AURA) 1434 #if defined(OS_WIN) && defined(USE_AURA)
1417 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only()) 1435 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only())
1418 base::win::DisplayVirtualKeyboard(); 1436 base::win::DisplayVirtualKeyboard();
1419 #endif 1437 #endif
1420 } 1438 }
1421 1439
1422 } // namespace views 1440 } // namespace views
OLDNEW
« 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