Chromium Code Reviews| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // If long press happens outside selection, select word and show context | 199 // If long press happens outside selection, select word and show context |
| 200 // menu (If touch selection is enabled, context menu is shown by the | 200 // menu (If touch selection is enabled, context menu is shown by the |
| 201 // |touch_selection_controller_|, hence we mark the event handled. | 201 // |touch_selection_controller_|, hence we mark the event handled. |
| 202 // Otherwise, the regular context menu will be shown by views). | 202 // Otherwise, the regular context menu will be shown by views). |
| 203 // If long press happens in selected text and touch drag drop is enabled, | 203 // If long press happens in selected text and touch drag drop is enabled, |
| 204 // we will turn off touch selection (if one exists) and let views do drag | 204 // we will turn off touch selection (if one exists) and let views do drag |
| 205 // drop. | 205 // drop. |
| 206 if (!GetRenderText()->IsPointInSelection(event->location())) { | 206 if (!GetRenderText()->IsPointInSelection(event->location())) { |
| 207 OnBeforeUserAction(); | 207 OnBeforeUserAction(); |
| 208 model_->SelectWord(); | 208 model_->SelectWord(); |
| 209 touch_selection_controller_.reset( | |
| 210 ui::TouchSelectionController::create(this)); | |
| 211 OnCaretBoundsChanged(); | 209 OnCaretBoundsChanged(); |
| 212 SchedulePaint(); | 210 SchedulePaint(); |
| 213 OnAfterUserAction(); | 211 OnAfterUserAction(); |
| 214 if (touch_selection_controller_.get()) | 212 if (!touch_selection_controller_) |
| 213 CreateTouchSelectionControllerAndNotifyIt(); | |
| 214 if (touch_selection_controller_) | |
| 215 event->SetHandled(); | 215 event->SetHandled(); |
| 216 } else if (switches::IsTouchDragDropEnabled()) { | 216 } else if (switches::IsTouchDragDropEnabled()) { |
| 217 initiating_drag_ = true; | 217 initiating_drag_ = true; |
| 218 touch_selection_controller_.reset(); | 218 touch_selection_controller_.reset(); |
| 219 } else { | 219 } else { |
| 220 if (!touch_selection_controller_.get()) | 220 if (!touch_selection_controller_) |
| 221 CreateTouchSelectionControllerAndNotifyIt(); | 221 CreateTouchSelectionControllerAndNotifyIt(); |
| 222 if (touch_selection_controller_.get()) | 222 if (touch_selection_controller_) |
| 223 event->SetHandled(); | 223 event->SetHandled(); |
| 224 } | 224 } |
| 225 return; | 225 return; |
| 226 case ui::ET_GESTURE_LONG_TAP: | 226 case ui::ET_GESTURE_LONG_TAP: |
| 227 if (!touch_selection_controller_.get()) | 227 if (!touch_selection_controller_) |
| 228 CreateTouchSelectionControllerAndNotifyIt(); | 228 CreateTouchSelectionControllerAndNotifyIt(); |
| 229 | 229 |
| 230 // If touch selection is enabled, the context menu on long tap will be | 230 // If touch selection is enabled, the context menu on long tap will be |
| 231 // shown by the |touch_selection_controller_|, hence we mark the event | 231 // shown by the |touch_selection_controller_|, hence we mark the event |
| 232 // handled so views does not try to show context menu on it. | 232 // handled so views does not try to show context menu on it. |
| 233 if (touch_selection_controller_.get()) | 233 if (touch_selection_controller_) |
| 234 event->SetHandled(); | 234 event->SetHandled(); |
| 235 break; | 235 break; |
| 236 default: | 236 default: |
| 237 View::OnGestureEvent(event); | 237 View::OnGestureEvent(event); |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 PlatformGestureEventHandling(event); | 240 PlatformGestureEventHandling(event); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool NativeTextfieldViews::OnKeyPressed(const ui::KeyEvent& event) { | 243 bool NativeTextfieldViews::OnKeyPressed(const ui::KeyEvent& event) { |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1386 if (textfield_->GetInputMethod()) | 1386 if (textfield_->GetInputMethod()) |
| 1387 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); | 1387 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); |
| 1388 } | 1388 } |
| 1389 | 1389 |
| 1390 void NativeTextfieldViews::OnCaretBoundsChanged() { | 1390 void NativeTextfieldViews::OnCaretBoundsChanged() { |
| 1391 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. | 1391 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. |
| 1392 if (textfield_->GetInputMethod()) | 1392 if (textfield_->GetInputMethod()) |
| 1393 textfield_->GetInputMethod()->OnCaretBoundsChanged(textfield_); | 1393 textfield_->GetInputMethod()->OnCaretBoundsChanged(textfield_); |
| 1394 | 1394 |
| 1395 // Notify selection controller | 1395 // Notify selection controller |
| 1396 if (touch_selection_controller_.get()) | 1396 if (touch_selection_controller_) |
| 1397 touch_selection_controller_->SelectionChanged(); | 1397 touch_selection_controller_->SelectionChanged(); |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 void NativeTextfieldViews::OnBeforeUserAction() { | 1400 void NativeTextfieldViews::OnBeforeUserAction() { |
| 1401 TextfieldController* controller = textfield_->GetController(); | 1401 TextfieldController* controller = textfield_->GetController(); |
| 1402 if (controller) | 1402 if (controller) |
| 1403 controller->OnBeforeUserAction(textfield_); | 1403 controller->OnBeforeUserAction(textfield_); |
| 1404 } | 1404 } |
| 1405 | 1405 |
| 1406 void NativeTextfieldViews::OnAfterUserAction() { | 1406 void NativeTextfieldViews::OnAfterUserAction() { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1512 // Filter out all control characters, including tab and new line characters, | 1512 // Filter out all control characters, including tab and new line characters, |
| 1513 // and all characters with Alt modifier. But we need to allow characters with | 1513 // and all characters with Alt modifier. But we need to allow characters with |
| 1514 // AltGr modifier. | 1514 // AltGr modifier. |
| 1515 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1515 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1516 // flag that we don't care about. | 1516 // flag that we don't care about. |
| 1517 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1517 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1518 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1518 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1519 } | 1519 } |
| 1520 | 1520 |
| 1521 void NativeTextfieldViews::CreateTouchSelectionControllerAndNotifyIt() { | 1521 void NativeTextfieldViews::CreateTouchSelectionControllerAndNotifyIt() { |
| 1522 if (!textfield_->IsFocusable() || !textfield_->HasFocus()) | |
|
sky
2013/12/04 03:56:06
Why do you need to check IsFocusable? Don't you on
mohsen
2013/12/04 05:22:22
The textfield might have focus before getting disa
| |
| 1523 return; | |
| 1524 | |
| 1522 if (!touch_selection_controller_) { | 1525 if (!touch_selection_controller_) { |
| 1523 touch_selection_controller_.reset( | 1526 touch_selection_controller_.reset( |
| 1524 ui::TouchSelectionController::create(this)); | 1527 ui::TouchSelectionController::create(this)); |
| 1525 } | 1528 } |
| 1526 if (touch_selection_controller_) | 1529 if (touch_selection_controller_) |
| 1527 touch_selection_controller_->SelectionChanged(); | 1530 touch_selection_controller_->SelectionChanged(); |
| 1528 } | 1531 } |
| 1529 | 1532 |
| 1530 void NativeTextfieldViews::PlatformGestureEventHandling( | 1533 void NativeTextfieldViews::PlatformGestureEventHandling( |
| 1531 const ui::GestureEvent* event) { | 1534 const ui::GestureEvent* event) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1543 if (index != -1) { | 1546 if (index != -1) { |
| 1544 obscured_reveal_timer_.Start( | 1547 obscured_reveal_timer_.Start( |
| 1545 FROM_HERE, | 1548 FROM_HERE, |
| 1546 duration, | 1549 duration, |
| 1547 base::Bind(&NativeTextfieldViews::RevealObscuredChar, | 1550 base::Bind(&NativeTextfieldViews::RevealObscuredChar, |
| 1548 base::Unretained(this), -1, base::TimeDelta())); | 1551 base::Unretained(this), -1, base::TimeDelta())); |
| 1549 } | 1552 } |
| 1550 } | 1553 } |
| 1551 | 1554 |
| 1552 } // namespace views | 1555 } // namespace views |
| OLD | NEW |