Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 void Textfield::OnPaint(gfx::Canvas* canvas) { | 329 void Textfield::OnPaint(gfx::Canvas* canvas) { |
| 330 OnPaintBackground(canvas); | 330 OnPaintBackground(canvas); |
| 331 PaintTextAndCursor(canvas); | 331 PaintTextAndCursor(canvas); |
| 332 OnPaintBorder(canvas); | 332 OnPaintBorder(canvas); |
| 333 if (NativeViewHost::kRenderNativeControlFocus) | 333 if (NativeViewHost::kRenderNativeControlFocus) |
| 334 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 334 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 337 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
| 338 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 338 bool handled = controller_ && controller_->HandleKeyEvent(this, event); |
| 339 touch_selection_controller_.reset(); | 339 SetTouchSelectionController(NULL); |
| 340 if (handled) | 340 if (handled) |
| 341 return true; | 341 return true; |
| 342 | 342 |
| 343 // TODO(oshima): Refactor and consolidate with ExecuteCommand. | 343 // TODO(oshima): Refactor and consolidate with ExecuteCommand. |
| 344 if (event.type() == ui::ET_KEY_PRESSED) { | 344 if (event.type() == ui::ET_KEY_PRESSED) { |
| 345 ui::KeyboardCode key_code = event.key_code(); | 345 ui::KeyboardCode key_code = event.key_code(); |
| 346 if (key_code == ui::VKEY_TAB || event.IsUnicodeKeyCode()) | 346 if (key_code == ui::VKEY_TAB || event.IsUnicodeKeyCode()) |
| 347 return false; | 347 return false; |
| 348 | 348 |
| 349 gfx::RenderText* render_text = GetRenderText(); | 349 gfx::RenderText* render_text = GetRenderText(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 OnCaretBoundsChanged(); | 491 OnCaretBoundsChanged(); |
| 492 break; | 492 break; |
| 493 default: | 493 default: |
| 494 NOTREACHED(); | 494 NOTREACHED(); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 SchedulePaint(); | 497 SchedulePaint(); |
| 498 } | 498 } |
| 499 | 499 |
| 500 OnAfterUserAction(); | 500 OnAfterUserAction(); |
| 501 touch_selection_controller_.reset(); | 501 SetTouchSelectionController(NULL); |
| 502 return true; | 502 return true; |
| 503 } | 503 } |
| 504 | 504 |
| 505 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { | 505 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { |
| 506 // Don't adjust the cursor on a potential drag and drop, or if the mouse | 506 // Don't adjust the cursor on a potential drag and drop, or if the mouse |
| 507 // movement from the last mouse click does not exceed the drag threshold. | 507 // movement from the last mouse click does not exceed the drag threshold. |
| 508 if (initiating_drag_ || !event.IsOnlyLeftMouseButton() || | 508 if (initiating_drag_ || !event.IsOnlyLeftMouseButton() || |
| 509 !ExceededDragThreshold(event.location() - last_click_location_)) { | 509 !ExceededDragThreshold(event.location() - last_click_location_)) { |
| 510 return true; | 510 return true; |
| 511 } | 511 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 561 |
| 562 void Textfield::OnBlur() { | 562 void Textfield::OnBlur() { |
| 563 GetRenderText()->set_focused(false); | 563 GetRenderText()->set_focused(false); |
| 564 GetInputMethod()->OnBlur(); | 564 GetInputMethod()->OnBlur(); |
| 565 cursor_repaint_timer_.Stop(); | 565 cursor_repaint_timer_.Stop(); |
| 566 if (cursor_visible_) { | 566 if (cursor_visible_) { |
| 567 cursor_visible_ = false; | 567 cursor_visible_ = false; |
| 568 RepaintCursor(); | 568 RepaintCursor(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 touch_selection_controller_.reset(); | 571 SetTouchSelectionController(NULL); |
| 572 | 572 |
| 573 // Border typically draws focus indicator. | 573 // Border typically draws focus indicator. |
| 574 SchedulePaint(); | 574 SchedulePaint(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { | 577 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { |
| 578 state->role = ui::AccessibilityTypes::ROLE_TEXT; | 578 state->role = ui::AccessibilityTypes::ROLE_TEXT; |
| 579 state->name = accessible_name_; | 579 state->name = accessible_name_; |
| 580 if (read_only()) | 580 if (read_only()) |
| 581 state->state |= ui::AccessibilityTypes::STATE_READONLY; | 581 state->state |= ui::AccessibilityTypes::STATE_READONLY; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 // If long press happens outside selection, select word and show context | 673 // If long press happens outside selection, select word and show context |
| 674 // menu (If touch selection is enabled, context menu is shown by the | 674 // menu (If touch selection is enabled, context menu is shown by the |
| 675 // |touch_selection_controller_|, hence we mark the event handled. | 675 // |touch_selection_controller_|, hence we mark the event handled. |
| 676 // Otherwise, the regular context menu will be shown by views). | 676 // Otherwise, the regular context menu will be shown by views). |
| 677 // If long press happens in selected text and touch drag drop is enabled, | 677 // If long press happens in selected text and touch drag drop is enabled, |
| 678 // we will turn off touch selection (if one exists) and let views do drag | 678 // we will turn off touch selection (if one exists) and let views do drag |
| 679 // drop. | 679 // drop. |
| 680 if (!GetRenderText()->IsPointInSelection(event->location())) { | 680 if (!GetRenderText()->IsPointInSelection(event->location())) { |
| 681 OnBeforeUserAction(); | 681 OnBeforeUserAction(); |
| 682 model_->SelectWord(); | 682 model_->SelectWord(); |
| 683 touch_selection_controller_.reset( | 683 SetTouchSelectionController(ui::TouchSelectionController::create(this)); |
| 684 ui::TouchSelectionController::create(this)); | |
| 685 OnCaretBoundsChanged(); | 684 OnCaretBoundsChanged(); |
| 686 SchedulePaint(); | 685 SchedulePaint(); |
| 687 OnAfterUserAction(); | 686 OnAfterUserAction(); |
| 688 if (touch_selection_controller_) | 687 if (touch_selection_controller_) |
| 689 event->SetHandled(); | 688 event->SetHandled(); |
| 690 } else if (switches::IsTouchDragDropEnabled()) { | 689 } else if (switches::IsTouchDragDropEnabled()) { |
| 691 initiating_drag_ = true; | 690 initiating_drag_ = true; |
| 692 touch_selection_controller_.reset(); | 691 SetTouchSelectionController(NULL); |
| 693 } else { | 692 } else { |
| 694 if (!touch_selection_controller_) | 693 if (!touch_selection_controller_) |
| 695 CreateTouchSelectionControllerAndNotifyIt(); | 694 CreateTouchSelectionControllerAndNotifyIt(); |
| 696 if (touch_selection_controller_) | 695 if (touch_selection_controller_) |
| 697 event->SetHandled(); | 696 event->SetHandled(); |
| 698 } | 697 } |
| 699 return; | 698 return; |
| 700 case ui::ET_GESTURE_LONG_TAP: | 699 case ui::ET_GESTURE_LONG_TAP: |
| 701 if (!touch_selection_controller_) | 700 if (!touch_selection_controller_) |
| 702 CreateTouchSelectionControllerAndNotifyIt(); | 701 CreateTouchSelectionControllerAndNotifyIt(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 | 924 |
| 926 void Textfield::ConvertPointFromScreen(gfx::Point* point) { | 925 void Textfield::ConvertPointFromScreen(gfx::Point* point) { |
| 927 View::ConvertPointFromScreen(this, point); | 926 View::ConvertPointFromScreen(this, point); |
| 928 } | 927 } |
| 929 | 928 |
| 930 bool Textfield::DrawsHandles() { | 929 bool Textfield::DrawsHandles() { |
| 931 return false; | 930 return false; |
| 932 } | 931 } |
| 933 | 932 |
| 934 void Textfield::OpenContextMenu(const gfx::Point& anchor) { | 933 void Textfield::OpenContextMenu(const gfx::Point& anchor) { |
| 935 touch_selection_controller_.reset(); | 934 SetTouchSelectionController(NULL); |
| 936 ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU); | 935 ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU); |
| 937 } | 936 } |
| 938 | 937 |
| 939 //////////////////////////////////////////////////////////////////////////////// | 938 //////////////////////////////////////////////////////////////////////////////// |
| 940 // Textfield, ui::SimpleMenuModel::Delegate overrides: | 939 // Textfield, ui::SimpleMenuModel::Delegate overrides: |
| 941 | 940 |
| 942 bool Textfield::IsCommandIdChecked(int command_id) const { | 941 bool Textfield::IsCommandIdChecked(int command_id) const { |
| 943 return true; | 942 return true; |
| 944 } | 943 } |
| 945 | 944 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 966 return false; | 965 return false; |
| 967 } | 966 } |
| 968 } | 967 } |
| 969 | 968 |
| 970 bool Textfield::GetAcceleratorForCommandId(int command_id, | 969 bool Textfield::GetAcceleratorForCommandId(int command_id, |
| 971 ui::Accelerator* accelerator) { | 970 ui::Accelerator* accelerator) { |
| 972 return false; | 971 return false; |
| 973 } | 972 } |
| 974 | 973 |
| 975 void Textfield::ExecuteCommand(int command_id, int event_flags) { | 974 void Textfield::ExecuteCommand(int command_id, int event_flags) { |
| 976 touch_selection_controller_.reset(); | 975 SetTouchSelectionController(NULL); |
| 977 if (!IsCommandIdEnabled(command_id)) | 976 if (!IsCommandIdEnabled(command_id)) |
| 978 return; | 977 return; |
| 979 | 978 |
| 980 bool text_changed = false; | 979 bool text_changed = false; |
| 981 switch (command_id) { | 980 switch (command_id) { |
| 982 case IDS_APP_UNDO: | 981 case IDS_APP_UNDO: |
| 983 OnBeforeUserAction(); | 982 OnBeforeUserAction(); |
| 984 text_changed = model_->Undo(); | 983 text_changed = model_->Undo(); |
| 985 UpdateAfterChange(text_changed, text_changed); | 984 UpdateAfterChange(text_changed, text_changed); |
| 986 OnAfterUserAction(); | 985 OnAfterUserAction(); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1455 SchedulePaint(); | 1454 SchedulePaint(); |
| 1456 | 1455 |
| 1457 if (index != -1) { | 1456 if (index != -1) { |
| 1458 password_reveal_timer_.Start(FROM_HERE, password_reveal_duration_, | 1457 password_reveal_timer_.Start(FROM_HERE, password_reveal_duration_, |
| 1459 base::Bind(&Textfield::RevealPasswordChar, | 1458 base::Bind(&Textfield::RevealPasswordChar, |
| 1460 weak_ptr_factory_.GetWeakPtr(), -1)); | 1459 weak_ptr_factory_.GetWeakPtr(), -1)); |
| 1461 } | 1460 } |
| 1462 } | 1461 } |
| 1463 | 1462 |
| 1464 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { | 1463 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { |
| 1465 if (!touch_selection_controller_) { | 1464 if (!touch_selection_controller_) |
| 1466 touch_selection_controller_.reset( | 1465 SetTouchSelectionController(ui::TouchSelectionController::create(this)); |
| 1467 ui::TouchSelectionController::create(this)); | |
| 1468 } | |
| 1469 if (touch_selection_controller_) | 1466 if (touch_selection_controller_) |
| 1470 touch_selection_controller_->SelectionChanged(); | 1467 touch_selection_controller_->SelectionChanged(); |
| 1471 } | 1468 } |
| 1472 | 1469 |
| 1470 void Textfield::SetTouchSelectionController(ui::TouchSelectionController* tsc) { | |
| 1471 if (touch_selection_controller_) | |
| 1472 touch_selection_controller_->HideHandles(false); | |
| 1473 touch_selection_controller_.reset(tsc); | |
|
sky
2014/01/16 23:15:02
Can the destructor imply HideHandles(false) so tha
mohsen
2014/01/17 02:09:41
Yep! Done.
Now, handles fade out in their destruct
| |
| 1474 } | |
| 1475 | |
| 1473 } // namespace views | 1476 } // namespace views |
| OLD | NEW |