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

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: 3 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 gfx::Point& location = event.location();
268 const ui::Range& selection = GetRenderText()->selection();
269 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.
270 bool in_selection = !selection.is_empty() &&
271 GetRenderText()->RangeContainsCaret(
272 selection,
273 drop_cursor_position_.caret_pos(),
274 drop_cursor_position_.caret_affinity());
267 is_drop_cursor_visible_ = !in_selection; 275 is_drop_cursor_visible_ = !in_selection;
268 // TODO(msw): Pan over text when the user drags to the visible text edge. 276 // TODO(msw): Pan over text when the user drags to the visible text edge.
269 OnCaretBoundsChanged(); 277 OnCaretBoundsChanged();
270 SchedulePaint(); 278 SchedulePaint();
271 279
272 if (initiating_drag_) { 280 if (initiating_drag_) {
273 if (in_selection) 281 if (in_selection)
274 return ui::DragDropTypes::DRAG_NONE; 282 return ui::DragDropTypes::DRAG_NONE;
275 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : 283 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY :
276 ui::DragDropTypes::DRAG_MOVE; 284 ui::DragDropTypes::DRAG_MOVE;
277 } 285 }
278 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; 286 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE;
279 } 287 }
280 288
289 void NativeTextfieldViews::OnDragExited() {
290 is_drop_cursor_visible_ = false;
291 SchedulePaint();
292 }
293
281 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) { 294 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) {
282 DCHECK(CanDrop(event.data())); 295 DCHECK(CanDrop(event.data()));
283 296
284 TextfieldController* controller = textfield_->GetController(); 297 TextfieldController* controller = textfield_->GetController();
285 if (controller) { 298 if (controller) {
286 int drag_operation = controller->OnDrop(event.data()); 299 int drag_operation = controller->OnDrop(event.data());
287 if (drag_operation != ui::DragDropTypes::DRAG_NONE) 300 if (drag_operation != ui::DragDropTypes::DRAG_NONE)
288 return drag_operation; 301 return drag_operation;
289 } 302 }
290 303
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1087
1075 void NativeTextfieldViews::RepaintCursor() { 1088 void NativeTextfieldViews::RepaintCursor() {
1076 gfx::Rect r(GetCaretBounds()); 1089 gfx::Rect r(GetCaretBounds());
1077 r.Inset(-1, -1, -1, -1); 1090 r.Inset(-1, -1, -1, -1);
1078 SchedulePaintInRect(r); 1091 SchedulePaintInRect(r);
1079 } 1092 }
1080 1093
1081 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { 1094 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) {
1082 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor"); 1095 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor");
1083 canvas->Save(); 1096 canvas->Save();
1084 GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || 1097 GetRenderText()->set_cursor_visible(!is_drop_cursor_visible_ &&
1085 (is_cursor_visible_ && !model_->HasSelection())); 1098 is_cursor_visible_ && !model_->HasSelection());
1086 // Draw the text, cursor, and selection. 1099 // Draw the text, cursor, and selection.
1087 GetRenderText()->Draw(canvas); 1100 GetRenderText()->Draw(canvas);
1088 1101
1102 // Draw the detached drop cursor that marks where the text will be dropped.
1103 if (is_drop_cursor_visible_)
1104 GetRenderText()->DrawCursor(canvas, drop_cursor_position_);
1105
1089 // Draw placeholder text if needed. 1106 // Draw placeholder text if needed.
1090 if (model_->GetText().empty() && 1107 if (model_->GetText().empty() &&
1091 !textfield_->placeholder_text().empty()) { 1108 !textfield_->placeholder_text().empty()) {
1092 canvas->DrawStringInt( 1109 canvas->DrawStringInt(
1093 textfield_->placeholder_text(), 1110 textfield_->placeholder_text(),
1094 GetRenderText()->GetFont(), 1111 GetRenderText()->GetFont(),
1095 textfield_->placeholder_text_color(), 1112 textfield_->placeholder_text_color(),
1096 GetRenderText()->display_rect()); 1113 GetRenderText()->display_rect());
1097 } 1114 }
1098 canvas->Restore(); 1115 canvas->Restore();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1430
1414 void NativeTextfieldViews::PlatformGestureEventHandling( 1431 void NativeTextfieldViews::PlatformGestureEventHandling(
1415 const ui::GestureEvent* event) { 1432 const ui::GestureEvent* event) {
1416 #if defined(OS_WIN) && defined(USE_AURA) 1433 #if defined(OS_WIN) && defined(USE_AURA)
1417 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only()) 1434 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only())
1418 base::win::DisplayVirtualKeyboard(); 1435 base::win::DisplayVirtualKeyboard();
1419 #endif 1436 #endif
1420 } 1437 }
1421 1438
1422 } // namespace views 1439 } // 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