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

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