| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } | 615 } |
| 616 | 616 |
| 617 gfx::Rect GetDisplayRect() { | 617 gfx::Rect GetDisplayRect() { |
| 618 return test_api_->GetRenderText()->display_rect(); | 618 return test_api_->GetRenderText()->display_rect(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and | 621 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and |
| 622 // y-axis is in the middle of |bound|'s vertical range. | 622 // y-axis is in the middle of |bound|'s vertical range. |
| 623 void MouseClick(const gfx::Rect bound, int x_offset) { | 623 void MouseClick(const gfx::Rect bound, int x_offset) { |
| 624 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); | 624 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); |
| 625 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 625 ui::MouseEvent click( |
| 626 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 626 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
| 627 ui::EF_LEFT_MOUSE_BUTTON); | 627 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 628 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 628 textfield_->OnMousePressed(click); | 629 textfield_->OnMousePressed(click); |
| 629 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, | 630 ui::MouseEvent release( |
| 630 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 631 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), |
| 631 ui::EF_LEFT_MOUSE_BUTTON); | 632 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 633 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 632 textfield_->OnMouseReleased(release); | 634 textfield_->OnMouseReleased(release); |
| 633 } | 635 } |
| 634 | 636 |
| 635 // This is to avoid double/triple click. | 637 // This is to avoid double/triple click. |
| 636 void NonClientMouseClick() { | 638 void NonClientMouseClick() { |
| 637 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 639 ui::MouseEvent click( |
| 638 ui::EventTimeForNow(), | 640 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 639 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 641 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 640 ui::EF_LEFT_MOUSE_BUTTON); | 642 ui::EF_LEFT_MOUSE_BUTTON, |
| 643 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 641 textfield_->OnMousePressed(click); | 644 textfield_->OnMousePressed(click); |
| 642 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 645 ui::MouseEvent release( |
| 643 ui::EventTimeForNow(), | 646 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 644 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 647 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 645 ui::EF_LEFT_MOUSE_BUTTON); | 648 ui::EF_LEFT_MOUSE_BUTTON, |
| 649 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 646 textfield_->OnMouseReleased(release); | 650 textfield_->OnMouseReleased(release); |
| 647 } | 651 } |
| 648 | 652 |
| 649 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 653 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
| 650 bool can_undo, | 654 bool can_undo, |
| 651 ui::MenuModel* menu) { | 655 ui::MenuModel* menu) { |
| 652 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 656 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
| 653 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 657 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
| 654 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 658 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
| 655 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 659 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
| 656 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), | 660 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
| 657 menu->IsEnabledAt(4 /* PASTE */)); | 661 menu->IsEnabledAt(4 /* PASTE */)); |
| 658 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 662 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| 659 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 663 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| 660 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 664 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| 661 } | 665 } |
| 662 | 666 |
| 663 void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) { | 667 void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) { |
| 664 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, | 668 ui::MouseEvent press( |
| 665 ui::EventTimeForNow(), mouse_button_flags, | 669 ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, |
| 666 mouse_button_flags | extra_flags); | 670 ui::EventTimeForNow(), mouse_button_flags, |
| 671 mouse_button_flags | extra_flags, |
| 672 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 667 textfield_->OnMousePressed(press); | 673 textfield_->OnMousePressed(press); |
| 668 } | 674 } |
| 669 | 675 |
| 670 void ReleaseMouseButton(ui::EventFlags mouse_button_flags) { | 676 void ReleaseMouseButton(ui::EventFlags mouse_button_flags) { |
| 671 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, mouse_position_, | 677 ui::MouseEvent release( |
| 672 mouse_position_, ui::EventTimeForNow(), | 678 ui::ET_MOUSE_RELEASED, mouse_position_, mouse_position_, |
| 673 mouse_button_flags, mouse_button_flags); | 679 ui::EventTimeForNow(), mouse_button_flags, mouse_button_flags, |
| 680 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 674 textfield_->OnMouseReleased(release); | 681 textfield_->OnMouseReleased(release); |
| 675 } | 682 } |
| 676 | 683 |
| 677 void PressLeftMouseButton(int extra_flags = 0) { | 684 void PressLeftMouseButton(int extra_flags = 0) { |
| 678 PressMouseButton(ui::EF_LEFT_MOUSE_BUTTON, extra_flags); | 685 PressMouseButton(ui::EF_LEFT_MOUSE_BUTTON, extra_flags); |
| 679 } | 686 } |
| 680 | 687 |
| 681 void ReleaseLeftMouseButton() { | 688 void ReleaseLeftMouseButton() { |
| 682 ReleaseMouseButton(ui::EF_LEFT_MOUSE_BUTTON); | 689 ReleaseMouseButton(ui::EF_LEFT_MOUSE_BUTTON); |
| 683 } | 690 } |
| 684 | 691 |
| 685 void ClickLeftMouseButton(int extra_flags = 0) { | 692 void ClickLeftMouseButton(int extra_flags = 0) { |
| 686 PressLeftMouseButton(extra_flags); | 693 PressLeftMouseButton(extra_flags); |
| 687 ReleaseLeftMouseButton(); | 694 ReleaseLeftMouseButton(); |
| 688 } | 695 } |
| 689 | 696 |
| 690 void ClickRightMouseButton() { | 697 void ClickRightMouseButton() { |
| 691 PressMouseButton(ui::EF_RIGHT_MOUSE_BUTTON, 0); | 698 PressMouseButton(ui::EF_RIGHT_MOUSE_BUTTON, 0); |
| 692 ReleaseMouseButton(ui::EF_RIGHT_MOUSE_BUTTON); | 699 ReleaseMouseButton(ui::EF_RIGHT_MOUSE_BUTTON); |
| 693 } | 700 } |
| 694 | 701 |
| 695 void DragMouseTo(const gfx::Point& where) { | 702 void DragMouseTo(const gfx::Point& where) { |
| 696 mouse_position_ = where; | 703 mouse_position_ = where; |
| 697 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, where, where, | 704 ui::MouseEvent drag( |
| 698 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 705 ui::ET_MOUSE_DRAGGED, where, where, ui::EventTimeForNow(), |
| 706 ui::EF_LEFT_MOUSE_BUTTON, 0, |
| 707 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 699 textfield_->OnMouseDragged(drag); | 708 textfield_->OnMouseDragged(drag); |
| 700 } | 709 } |
| 701 | 710 |
| 702 // Textfield does not listen to OnMouseMoved, so this function does not send | 711 // Textfield does not listen to OnMouseMoved, so this function does not send |
| 703 // an event when it updates the cursor position. | 712 // an event when it updates the cursor position. |
| 704 void MoveMouseTo(const gfx::Point& where) { mouse_position_ = where; } | 713 void MoveMouseTo(const gfx::Point& where) { mouse_position_ = where; } |
| 705 | 714 |
| 706 // We need widget to populate wrapper class. | 715 // We need widget to populate wrapper class. |
| 707 Widget* widget_; | 716 Widget* widget_; |
| 708 | 717 |
| (...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2705 TEST_F(TextfieldTest, SelectionClipboard) { | 2714 TEST_F(TextfieldTest, SelectionClipboard) { |
| 2706 InitTextfield(); | 2715 InitTextfield(); |
| 2707 textfield_->SetText(ASCIIToUTF16("0123")); | 2716 textfield_->SetText(ASCIIToUTF16("0123")); |
| 2708 const int cursor_y = GetCursorYForTesting(); | 2717 const int cursor_y = GetCursorYForTesting(); |
| 2709 gfx::Point point_1(GetCursorPositionX(1), cursor_y); | 2718 gfx::Point point_1(GetCursorPositionX(1), cursor_y); |
| 2710 gfx::Point point_2(GetCursorPositionX(2), cursor_y); | 2719 gfx::Point point_2(GetCursorPositionX(2), cursor_y); |
| 2711 gfx::Point point_3(GetCursorPositionX(3), cursor_y); | 2720 gfx::Point point_3(GetCursorPositionX(3), cursor_y); |
| 2712 gfx::Point point_4(GetCursorPositionX(4), cursor_y); | 2721 gfx::Point point_4(GetCursorPositionX(4), cursor_y); |
| 2713 | 2722 |
| 2714 // Text selected by the mouse should be placed on the selection clipboard. | 2723 // Text selected by the mouse should be placed on the selection clipboard. |
| 2715 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, | 2724 ui::MouseEvent press( |
| 2716 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2725 ui::ET_MOUSE_PRESSED, point_1, point_1, ui::EventTimeForNow(), |
| 2717 ui::EF_LEFT_MOUSE_BUTTON); | 2726 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2727 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2718 textfield_->OnMousePressed(press); | 2728 textfield_->OnMousePressed(press); |
| 2719 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, | 2729 ui::MouseEvent drag( |
| 2720 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2730 ui::ET_MOUSE_DRAGGED, point_3, point_3, ui::EventTimeForNow(), |
| 2721 ui::EF_LEFT_MOUSE_BUTTON); | 2731 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2732 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2722 textfield_->OnMouseDragged(drag); | 2733 textfield_->OnMouseDragged(drag); |
| 2723 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point_3, point_3, | 2734 ui::MouseEvent release( |
| 2724 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2735 ui::ET_MOUSE_RELEASED, point_3, point_3, ui::EventTimeForNow(), |
| 2725 ui::EF_LEFT_MOUSE_BUTTON); | 2736 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2737 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2726 textfield_->OnMouseReleased(release); | 2738 textfield_->OnMouseReleased(release); |
| 2727 EXPECT_EQ(gfx::Range(1, 3), textfield_->GetSelectedRange()); | 2739 EXPECT_EQ(gfx::Range(1, 3), textfield_->GetSelectedRange()); |
| 2728 EXPECT_STR_EQ("12", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2740 EXPECT_STR_EQ("12", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2729 | 2741 |
| 2730 // Select-all should update the selection clipboard. | 2742 // Select-all should update the selection clipboard. |
| 2731 SendKeyEvent(ui::VKEY_A, false, true); | 2743 SendKeyEvent(ui::VKEY_A, false, true); |
| 2732 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); | 2744 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); |
| 2733 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2745 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2734 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2746 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2735 | 2747 |
| 2736 // Shift-click selection modifications should update the clipboard. | 2748 // Shift-click selection modifications should update the clipboard. |
| 2737 NonClientMouseClick(); | 2749 NonClientMouseClick(); |
| 2738 ui::MouseEvent press_2(ui::ET_MOUSE_PRESSED, point_2, point_2, | 2750 ui::MouseEvent press_2( |
| 2739 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2751 ui::ET_MOUSE_PRESSED, point_2, point_2, ui::EventTimeForNow(), |
| 2740 ui::EF_LEFT_MOUSE_BUTTON); | 2752 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2753 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2741 press_2.set_flags(press_2.flags() | ui::EF_SHIFT_DOWN); | 2754 press_2.set_flags(press_2.flags() | ui::EF_SHIFT_DOWN); |
| 2742 #if defined(USE_X11) | 2755 #if defined(USE_X11) |
| 2743 ui::UpdateX11EventForFlags(&press_2); | 2756 ui::UpdateX11EventForFlags(&press_2); |
| 2744 #endif | 2757 #endif |
| 2745 textfield_->OnMousePressed(press_2); | 2758 textfield_->OnMousePressed(press_2); |
| 2746 ui::MouseEvent release_2(ui::ET_MOUSE_RELEASED, point_2, point_2, | 2759 ui::MouseEvent release_2( |
| 2747 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2760 ui::ET_MOUSE_RELEASED, point_2, point_2, ui::EventTimeForNow(), |
| 2748 ui::EF_LEFT_MOUSE_BUTTON); | 2761 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2762 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2749 textfield_->OnMouseReleased(release_2); | 2763 textfield_->OnMouseReleased(release_2); |
| 2750 EXPECT_EQ(gfx::Range(0, 2), textfield_->GetSelectedRange()); | 2764 EXPECT_EQ(gfx::Range(0, 2), textfield_->GetSelectedRange()); |
| 2751 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2765 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2752 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2766 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2753 | 2767 |
| 2754 // Shift-Left/Right should update the selection clipboard. | 2768 // Shift-Left/Right should update the selection clipboard. |
| 2755 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 2769 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 2756 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2770 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2757 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2771 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2758 SendKeyEvent(ui::VKEY_LEFT, true, false); | 2772 SendKeyEvent(ui::VKEY_LEFT, true, false); |
| 2759 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2773 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2760 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2774 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2761 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 2775 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
| 2762 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2776 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2763 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2777 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2764 | 2778 |
| 2765 // Moving the cursor without a selection should not change the clipboard. | 2779 // Moving the cursor without a selection should not change the clipboard. |
| 2766 SendKeyEvent(ui::VKEY_LEFT, false, false); | 2780 SendKeyEvent(ui::VKEY_LEFT, false, false); |
| 2767 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); | 2781 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); |
| 2768 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2782 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2769 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 2783 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2770 | 2784 |
| 2771 // Middle clicking should paste at the mouse (not cursor) location. | 2785 // Middle clicking should paste at the mouse (not cursor) location. |
| 2772 // The cursor should be placed at the end of the pasted text. | 2786 // The cursor should be placed at the end of the pasted text. |
| 2773 ui::MouseEvent middle(ui::ET_MOUSE_PRESSED, point_4, point_4, | 2787 ui::MouseEvent middle( |
| 2774 ui::EventTimeForNow(), ui::EF_MIDDLE_MOUSE_BUTTON, | 2788 ui::ET_MOUSE_PRESSED, point_4, point_4, ui::EventTimeForNow(), |
| 2775 ui::EF_MIDDLE_MOUSE_BUTTON); | 2789 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON, |
| 2790 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2776 textfield_->OnMousePressed(middle); | 2791 textfield_->OnMousePressed(middle); |
| 2777 EXPECT_STR_EQ("01230123", textfield_->text()); | 2792 EXPECT_STR_EQ("01230123", textfield_->text()); |
| 2778 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange()); | 2793 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange()); |
| 2779 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2794 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2780 | 2795 |
| 2781 // Middle clicking on an unfocused textfield should focus it and paste. | 2796 // Middle clicking on an unfocused textfield should focus it and paste. |
| 2782 textfield_->GetFocusManager()->ClearFocus(); | 2797 textfield_->GetFocusManager()->ClearFocus(); |
| 2783 EXPECT_FALSE(textfield_->HasFocus()); | 2798 EXPECT_FALSE(textfield_->HasFocus()); |
| 2784 textfield_->OnMousePressed(middle); | 2799 textfield_->OnMousePressed(middle); |
| 2785 EXPECT_TRUE(textfield_->HasFocus()); | 2800 EXPECT_TRUE(textfield_->HasFocus()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2801 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); | 2816 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); |
| 2802 textfield_->SelectRange(gfx::Range(2, 6)); | 2817 textfield_->SelectRange(gfx::Range(2, 6)); |
| 2803 textfield_->OnMousePressed(middle); | 2818 textfield_->OnMousePressed(middle); |
| 2804 EXPECT_STR_EQ("012301230123", textfield_->text()); | 2819 EXPECT_STR_EQ("012301230123", textfield_->text()); |
| 2805 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); | 2820 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); |
| 2806 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); | 2821 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); |
| 2807 | 2822 |
| 2808 // Double and triple clicking should update the clipboard contents. | 2823 // Double and triple clicking should update the clipboard contents. |
| 2809 textfield_->SetText(ASCIIToUTF16("ab cd ef")); | 2824 textfield_->SetText(ASCIIToUTF16("ab cd ef")); |
| 2810 gfx::Point word(GetCursorPositionX(4), cursor_y); | 2825 gfx::Point word(GetCursorPositionX(4), cursor_y); |
| 2811 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, | 2826 ui::MouseEvent press_word( |
| 2812 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2827 ui::ET_MOUSE_PRESSED, word, word, ui::EventTimeForNow(), |
| 2813 ui::EF_LEFT_MOUSE_BUTTON); | 2828 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2829 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2814 textfield_->OnMousePressed(press_word); | 2830 textfield_->OnMousePressed(press_word); |
| 2815 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, | 2831 ui::MouseEvent release_word( |
| 2816 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2832 ui::ET_MOUSE_RELEASED, word, word, ui::EventTimeForNow(), |
| 2817 ui::EF_LEFT_MOUSE_BUTTON); | 2833 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2834 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2818 textfield_->OnMouseReleased(release_word); | 2835 textfield_->OnMouseReleased(release_word); |
| 2819 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, | 2836 ui::MouseEvent double_click( |
| 2820 ui::EventTimeForNow(), | 2837 ui::ET_MOUSE_PRESSED, word, word, ui::EventTimeForNow(), |
| 2821 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | 2838 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 2822 ui::EF_LEFT_MOUSE_BUTTON); | 2839 ui::EF_LEFT_MOUSE_BUTTON, |
| 2840 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2823 textfield_->OnMousePressed(double_click); | 2841 textfield_->OnMousePressed(double_click); |
| 2824 textfield_->OnMouseReleased(release_word); | 2842 textfield_->OnMouseReleased(release_word); |
| 2825 EXPECT_EQ(gfx::Range(3, 5), textfield_->GetSelectedRange()); | 2843 EXPECT_EQ(gfx::Range(3, 5), textfield_->GetSelectedRange()); |
| 2826 EXPECT_STR_EQ("cd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2844 EXPECT_STR_EQ("cd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2827 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2845 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2828 textfield_->OnMousePressed(press_word); | 2846 textfield_->OnMousePressed(press_word); |
| 2829 textfield_->OnMouseReleased(release_word); | 2847 textfield_->OnMouseReleased(release_word); |
| 2830 EXPECT_EQ(gfx::Range(0, 8), textfield_->GetSelectedRange()); | 2848 EXPECT_EQ(gfx::Range(0, 8), textfield_->GetSelectedRange()); |
| 2831 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2849 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2832 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2850 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 InitTextfield(); | 3135 InitTextfield(); |
| 3118 | 3136 |
| 3119 textfield_->SetCursorEnabled(false); | 3137 textfield_->SetCursorEnabled(false); |
| 3120 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3138 EXPECT_FALSE(test_api_->IsCursorVisible()); |
| 3121 | 3139 |
| 3122 textfield_->SetCursorEnabled(true); | 3140 textfield_->SetCursorEnabled(true); |
| 3123 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3141 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3124 } | 3142 } |
| 3125 | 3143 |
| 3126 } // namespace views | 3144 } // namespace views |
| OLD | NEW |