OLD | NEW |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( | 116 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( |
117 const ui::MouseEvent& event) { | 117 const ui::MouseEvent& event) { |
118 return ExceededDragThreshold(event.location() - last_click_location_); | 118 return ExceededDragThreshold(event.location() - last_click_location_); |
119 } | 119 } |
120 | 120 |
121 bool NativeTextfieldViews::OnMouseDragged(const ui::MouseEvent& event) { | 121 bool NativeTextfieldViews::OnMouseDragged(const ui::MouseEvent& event) { |
122 // Don't adjust the cursor on a potential drag and drop, or if the mouse | 122 // Don't adjust the cursor on a potential drag and drop, or if the mouse |
123 // movement from the last mouse click does not exceed the drag threshold. | 123 // movement from the last mouse click does not exceed the drag threshold. |
124 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) | 124 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event) || |
| 125 !event.IsOnlyLeftMouseButton()) { |
125 return true; | 126 return true; |
| 127 } |
126 | 128 |
127 OnBeforeUserAction(); | 129 OnBeforeUserAction(); |
128 // TODO: Remove once NativeTextfield implementations are consolidated to | 130 // TODO: Remove once NativeTextfield implementations are consolidated to |
129 // Textfield. | 131 // Textfield. |
130 if (!textfield_->OnMouseDragged(event)) { | 132 if (!textfield_->OnMouseDragged(event)) { |
131 if (MoveCursorTo(event.location(), true)) | 133 if (MoveCursorTo(event.location(), true)) |
132 SchedulePaint(); | 134 SchedulePaint(); |
133 } | 135 } |
134 OnAfterUserAction(); | 136 OnAfterUserAction(); |
135 return true; | 137 return true; |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; | 1344 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; |
1343 } else { | 1345 } else { |
1344 aggregated_clicks_ = 0; | 1346 aggregated_clicks_ = 0; |
1345 } | 1347 } |
1346 last_click_time_ = event.time_stamp(); | 1348 last_click_time_ = event.time_stamp(); |
1347 last_click_location_ = event.location(); | 1349 last_click_location_ = event.location(); |
1348 } | 1350 } |
1349 } | 1351 } |
1350 | 1352 |
1351 void NativeTextfieldViews::HandleMousePressEvent(const ui::MouseEvent& event) { | 1353 void NativeTextfieldViews::HandleMousePressEvent(const ui::MouseEvent& event) { |
1352 if (event.IsOnlyLeftMouseButton()) { | 1354 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) |
1353 textfield_->RequestFocus(); | 1355 textfield_->RequestFocus(); |
1354 | 1356 |
1355 initiating_drag_ = false; | 1357 if (!event.IsOnlyLeftMouseButton()) |
1356 bool can_drag = true; | 1358 return; |
1357 | 1359 |
1358 switch (aggregated_clicks_) { | 1360 initiating_drag_ = false; |
1359 case 0: | 1361 bool can_drag = true; |
1360 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) | 1362 |
1361 initiating_drag_ = true; | 1363 switch (aggregated_clicks_) { |
1362 else | 1364 case 0: |
1363 MoveCursorTo(event.location(), event.IsShiftDown()); | 1365 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
1364 break; | 1366 initiating_drag_ = true; |
1365 case 1: | 1367 else |
1366 MoveCursorTo(event.location(), false); | 1368 MoveCursorTo(event.location(), event.IsShiftDown()); |
1367 model_->SelectWord(); | 1369 break; |
1368 OnCaretBoundsChanged(); | 1370 case 1: |
1369 break; | 1371 MoveCursorTo(event.location(), false); |
1370 case 2: | 1372 model_->SelectWord(); |
1371 model_->SelectAll(false); | 1373 OnCaretBoundsChanged(); |
1372 OnCaretBoundsChanged(); | 1374 break; |
1373 break; | 1375 case 2: |
1374 default: | 1376 model_->SelectAll(false); |
1375 NOTREACHED(); | 1377 OnCaretBoundsChanged(); |
1376 } | 1378 break; |
1377 SchedulePaint(); | 1379 default: |
| 1380 NOTREACHED(); |
1378 } | 1381 } |
| 1382 SchedulePaint(); |
1379 } | 1383 } |
1380 | 1384 |
1381 bool NativeTextfieldViews::ImeEditingAllowed() const { | 1385 bool NativeTextfieldViews::ImeEditingAllowed() const { |
1382 // We don't allow the input method to retrieve or delete content from a | 1386 // We don't allow the input method to retrieve or delete content from a |
1383 // password field. | 1387 // password field. |
1384 ui::TextInputType t = GetTextInputType(); | 1388 ui::TextInputType t = GetTextInputType(); |
1385 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); | 1389 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
1386 } | 1390 } |
1387 | 1391 |
1388 // static | 1392 // static |
(...skipping 16 matching lines...) Expand all Loading... |
1405 | 1409 |
1406 void NativeTextfieldViews::PlatformGestureEventHandling( | 1410 void NativeTextfieldViews::PlatformGestureEventHandling( |
1407 const ui::GestureEvent* event) { | 1411 const ui::GestureEvent* event) { |
1408 #if defined(OS_WIN) && defined(USE_AURA) | 1412 #if defined(OS_WIN) && defined(USE_AURA) |
1409 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only()) | 1413 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !textfield_->read_only()) |
1410 base::win::DisplayVirtualKeyboard(); | 1414 base::win::DisplayVirtualKeyboard(); |
1411 #endif | 1415 #endif |
1412 } | 1416 } |
1413 | 1417 |
1414 } // namespace views | 1418 } // namespace views |
OLD | NEW |