| 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/native_textfield_views.h" | 5 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 gfx::Rect GetDisplayRect() { | 287 gfx::Rect GetDisplayRect() { |
| 288 return textfield_view_->GetRenderText()->display_rect(); | 288 return textfield_view_->GetRenderText()->display_rect(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and | 291 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and |
| 292 // y-axis is in the middle of |bound|'s vertical range. | 292 // y-axis is in the middle of |bound|'s vertical range. |
| 293 void MouseClick(const gfx::Rect bound, int x_offset) { | 293 void MouseClick(const gfx::Rect bound, int x_offset) { |
| 294 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); | 294 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); |
| 295 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 295 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
| 296 ui::EF_LEFT_MOUSE_BUTTON); | 296 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 297 textfield_view_->OnMousePressed(click); | 297 textfield_view_->OnMousePressed(click); |
| 298 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, | 298 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, |
| 299 ui::EF_LEFT_MOUSE_BUTTON); | 299 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 300 textfield_view_->OnMouseReleased(release); | 300 textfield_view_->OnMouseReleased(release); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // This is to avoid double/triple click. | 303 // This is to avoid double/triple click. |
| 304 void NonClientMouseClick() { | 304 void NonClientMouseClick() { |
| 305 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 305 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 306 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT); | 306 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 307 ui::EF_LEFT_MOUSE_BUTTON); |
| 307 textfield_view_->OnMousePressed(click); | 308 textfield_view_->OnMousePressed(click); |
| 308 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 309 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 309 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT); | 310 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 311 ui::EF_LEFT_MOUSE_BUTTON); |
| 310 textfield_view_->OnMouseReleased(release); | 312 textfield_view_->OnMouseReleased(release); |
| 311 } | 313 } |
| 312 | 314 |
| 313 // Wrap for visibility in test classes. | 315 // Wrap for visibility in test classes. |
| 314 ui::TextInputType GetTextInputType() { | 316 ui::TextInputType GetTextInputType() { |
| 315 return textfield_view_->GetTextInputType(); | 317 return textfield_view_->GetTextInputType(); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 320 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
| 319 bool can_undo, | 321 bool can_undo, |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 EXPECT_EQ(3, GetFocusedView()->id()); | 776 EXPECT_EQ(3, GetFocusedView()->id()); |
| 775 | 777 |
| 776 // Request focus should still work. | 778 // Request focus should still work. |
| 777 textfield_->RequestFocus(); | 779 textfield_->RequestFocus(); |
| 778 EXPECT_EQ(1, GetFocusedView()->id()); | 780 EXPECT_EQ(1, GetFocusedView()->id()); |
| 779 | 781 |
| 780 // Test if clicking on textfield view sets the focus to textfield_. | 782 // Test if clicking on textfield view sets the focus to textfield_. |
| 781 widget_->GetFocusManager()->AdvanceFocus(true); | 783 widget_->GetFocusManager()->AdvanceFocus(true); |
| 782 EXPECT_EQ(3, GetFocusedView()->id()); | 784 EXPECT_EQ(3, GetFocusedView()->id()); |
| 783 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 785 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 784 ui::EF_LEFT_MOUSE_BUTTON); | 786 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 785 textfield_view_->OnMousePressed(click); | 787 textfield_view_->OnMousePressed(click); |
| 786 EXPECT_EQ(1, GetFocusedView()->id()); | 788 EXPECT_EQ(1, GetFocusedView()->id()); |
| 787 } | 789 } |
| 788 | 790 |
| 789 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { | 791 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { |
| 790 InitTextfield(Textfield::STYLE_DEFAULT); | 792 InitTextfield(Textfield::STYLE_DEFAULT); |
| 791 EXPECT_TRUE(textfield_->context_menu_controller()); | 793 EXPECT_TRUE(textfield_->context_menu_controller()); |
| 792 textfield_->SetText(ASCIIToUTF16("hello world")); | 794 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 793 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); | 795 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 794 textfield_view_->ClearEditHistory(); | 796 textfield_view_->ClearEditHistory(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 806 | 808 |
| 807 // Exercise the "paste enabled?" check in the verifier. | 809 // Exercise the "paste enabled?" check in the verifier. |
| 808 SetClipboardText("Test"); | 810 SetClipboardText("Test"); |
| 809 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 811 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
| 810 } | 812 } |
| 811 | 813 |
| 812 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { | 814 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { |
| 813 InitTextfield(Textfield::STYLE_DEFAULT); | 815 InitTextfield(Textfield::STYLE_DEFAULT); |
| 814 textfield_->SetText(ASCIIToUTF16("hello world")); | 816 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 815 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 817 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 816 ui::EF_LEFT_MOUSE_BUTTON); | 818 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 817 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 819 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 818 ui::EF_LEFT_MOUSE_BUTTON); | 820 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 819 ui::MouseEvent double_click( | 821 ui::MouseEvent double_click( |
| 820 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 822 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 821 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK); | 823 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 824 ui::EF_LEFT_MOUSE_BUTTON); |
| 822 | 825 |
| 823 // Test for double click. | 826 // Test for double click. |
| 824 textfield_view_->OnMousePressed(click); | 827 textfield_view_->OnMousePressed(click); |
| 825 textfield_view_->OnMouseReleased(release); | 828 textfield_view_->OnMouseReleased(release); |
| 826 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 829 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
| 827 textfield_view_->OnMousePressed(double_click); | 830 textfield_view_->OnMousePressed(double_click); |
| 828 textfield_view_->OnMouseReleased(release); | 831 textfield_view_->OnMouseReleased(release); |
| 829 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 832 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 830 | 833 |
| 831 // Test for triple click. | 834 // Test for triple click. |
| 832 textfield_view_->OnMousePressed(click); | 835 textfield_view_->OnMousePressed(click); |
| 833 textfield_view_->OnMouseReleased(release); | 836 textfield_view_->OnMouseReleased(release); |
| 834 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 837 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
| 835 | 838 |
| 836 // Another click should reset back to double click. | 839 // Another click should reset back to double click. |
| 837 textfield_view_->OnMousePressed(click); | 840 textfield_view_->OnMousePressed(click); |
| 838 textfield_view_->OnMouseReleased(release); | 841 textfield_view_->OnMouseReleased(release); |
| 839 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 842 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 840 } | 843 } |
| 841 | 844 |
| 842 TEST_F(NativeTextfieldViewsTest, DragToSelect) { | 845 TEST_F(NativeTextfieldViewsTest, DragToSelect) { |
| 843 InitTextfield(Textfield::STYLE_DEFAULT); | 846 InitTextfield(Textfield::STYLE_DEFAULT); |
| 844 textfield_->SetText(ASCIIToUTF16("hello world")); | 847 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 845 const int kStart = GetCursorPositionX(5); | 848 const int kStart = GetCursorPositionX(5); |
| 846 const int kEnd = 500; | 849 const int kEnd = 500; |
| 847 gfx::Point start_point(kStart, 0); | 850 gfx::Point start_point(kStart, 0); |
| 848 gfx::Point end_point(kEnd, 0); | 851 gfx::Point end_point(kEnd, 0); |
| 849 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, | 852 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, |
| 850 ui::EF_LEFT_MOUSE_BUTTON); | 853 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 851 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, | 854 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, |
| 852 ui::EF_LEFT_MOUSE_BUTTON); | 855 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 853 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), | 856 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), |
| 854 ui::EF_LEFT_MOUSE_BUTTON); | 857 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 855 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, | 858 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, |
| 856 ui::EF_LEFT_MOUSE_BUTTON); | 859 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 857 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, | 860 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, |
| 858 ui::EF_LEFT_MOUSE_BUTTON); | 861 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 859 textfield_view_->OnMousePressed(click_a); | 862 textfield_view_->OnMousePressed(click_a); |
| 860 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 863 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
| 861 // Check that dragging left selects the beginning of the string. | 864 // Check that dragging left selects the beginning of the string. |
| 862 textfield_view_->OnMouseDragged(drag_left); | 865 textfield_view_->OnMouseDragged(drag_left); |
| 863 string16 text_left = textfield_->GetSelectedText(); | 866 string16 text_left = textfield_->GetSelectedText(); |
| 864 EXPECT_STR_EQ("hello", text_left); | 867 EXPECT_STR_EQ("hello", text_left); |
| 865 // Check that dragging right selects the rest of the string. | 868 // Check that dragging right selects the rest of the string. |
| 866 textfield_view_->OnMouseDragged(drag_right); | 869 textfield_view_->OnMouseDragged(drag_right); |
| 867 string16 text_right = textfield_->GetSelectedText(); | 870 string16 text_right = textfield_->GetSelectedText(); |
| 868 EXPECT_STR_EQ(" world", text_right); | 871 EXPECT_STR_EQ(" world", text_right); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 958 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 956 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 959 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 957 textfield_->SelectRange(kStringRange); | 960 textfield_->SelectRange(kStringRange); |
| 958 // Ensure that password textfields do not support drag operations. | 961 // Ensure that password textfields do not support drag operations. |
| 959 textfield_->SetObscured(true); | 962 textfield_->SetObscured(true); |
| 960 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 963 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 961 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 964 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 962 textfield_->SetObscured(false); | 965 textfield_->SetObscured(false); |
| 963 // Ensure that textfields only initiate drag operations inside the selection. | 966 // Ensure that textfields only initiate drag operations inside the selection. |
| 964 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, | 967 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, |
| 968 ui::EF_LEFT_MOUSE_BUTTON, |
| 965 ui::EF_LEFT_MOUSE_BUTTON); | 969 ui::EF_LEFT_MOUSE_BUTTON); |
| 966 textfield_view_->OnMousePressed(press_event); | 970 textfield_view_->OnMousePressed(press_event); |
| 967 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 971 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 968 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); | 972 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); |
| 969 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), | 973 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), |
| 970 gfx::Point())); | 974 gfx::Point())); |
| 971 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 975 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
| 972 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 976 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 973 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, | 977 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, |
| 974 gfx::Point())); | 978 gfx::Point())); |
| 975 // Ensure that textfields support local moves. | 979 // Ensure that textfields support local moves. |
| 976 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 980 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 977 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); | 981 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); |
| 978 } | 982 } |
| 979 | 983 |
| 980 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { | 984 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { |
| 981 InitTextfield(Textfield::STYLE_DEFAULT); | 985 InitTextfield(Textfield::STYLE_DEFAULT); |
| 982 textfield_->SetText(ASCIIToUTF16("hello world")); | 986 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 983 | 987 |
| 984 string16 string; | 988 string16 string; |
| 985 ui::OSExchangeData data; | 989 ui::OSExchangeData data; |
| 986 int formats = 0; | 990 int formats = 0; |
| 987 int operations = 0; | 991 int operations = 0; |
| 988 std::set<OSExchangeData::CustomFormat> custom_formats; | 992 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 989 | 993 |
| 990 // Start dragging "ello". | 994 // Start dragging "ello". |
| 991 textfield_->SelectRange(gfx::Range(1, 5)); | 995 textfield_->SelectRange(gfx::Range(1, 5)); |
| 992 gfx::Point point(GetCursorPositionX(3), 0); | 996 gfx::Point point(GetCursorPositionX(3), 0); |
| 993 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 997 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 994 ui::EF_LEFT_MOUSE_BUTTON); | 998 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 995 textfield_view_->OnMousePressed(click_a); | 999 textfield_view_->OnMousePressed(click_a); |
| 996 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 1000 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, |
| 997 click_a.location(), gfx::Point())); | 1001 click_a.location(), gfx::Point())); |
| 998 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 1002 operations = textfield_view_->GetDragOperationsForView(textfield_view_, |
| 999 click_a.location()); | 1003 click_a.location()); |
| 1000 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 1004 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 1001 operations); | 1005 operations); |
| 1002 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 1006 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 1003 EXPECT_TRUE(data.GetString(&string)); | 1007 EXPECT_TRUE(data.GetString(&string)); |
| 1004 EXPECT_EQ(textfield_->GetSelectedText(), string); | 1008 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 string16 string; | 1043 string16 string; |
| 1040 ui::OSExchangeData data; | 1044 ui::OSExchangeData data; |
| 1041 int formats = 0; | 1045 int formats = 0; |
| 1042 int operations = 0; | 1046 int operations = 0; |
| 1043 std::set<OSExchangeData::CustomFormat> custom_formats; | 1047 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 1044 | 1048 |
| 1045 // Start dragging " worl". | 1049 // Start dragging " worl". |
| 1046 textfield_->SelectRange(gfx::Range(5, 10)); | 1050 textfield_->SelectRange(gfx::Range(5, 10)); |
| 1047 gfx::Point point(GetCursorPositionX(7), 0); | 1051 gfx::Point point(GetCursorPositionX(7), 0); |
| 1048 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 1052 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 1049 ui::EF_LEFT_MOUSE_BUTTON); | 1053 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1050 textfield_view_->OnMousePressed(click_a); | 1054 textfield_view_->OnMousePressed(click_a); |
| 1051 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 1055 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, |
| 1052 click_a.location(), gfx::Point())); | 1056 click_a.location(), gfx::Point())); |
| 1053 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 1057 operations = textfield_view_->GetDragOperationsForView(textfield_view_, |
| 1054 click_a.location()); | 1058 click_a.location()); |
| 1055 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 1059 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 1056 operations); | 1060 operations); |
| 1057 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 1061 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 1058 EXPECT_TRUE(data.GetString(&string)); | 1062 EXPECT_TRUE(data.GetString(&string)); |
| 1059 EXPECT_EQ(textfield_->GetSelectedText(), string); | 1063 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1088 } | 1092 } |
| 1089 | 1093 |
| 1090 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { | 1094 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { |
| 1091 InitTextfield(Textfield::STYLE_DEFAULT); | 1095 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1092 textfield_->SetText(ASCIIToUTF16("hello world")); | 1096 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1093 | 1097 |
| 1094 // Start dragging "worl". | 1098 // Start dragging "worl". |
| 1095 textfield_->SelectRange(gfx::Range(6, 10)); | 1099 textfield_->SelectRange(gfx::Range(6, 10)); |
| 1096 gfx::Point point(GetCursorPositionX(8), 0); | 1100 gfx::Point point(GetCursorPositionX(8), 0); |
| 1097 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 1101 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
| 1098 ui::EF_LEFT_MOUSE_BUTTON); | 1102 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1099 textfield_view_->OnMousePressed(click); | 1103 textfield_view_->OnMousePressed(click); |
| 1100 ui::OSExchangeData data; | 1104 ui::OSExchangeData data; |
| 1101 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 1105 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); |
| 1102 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1106 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
| 1103 // Drag the text over somewhere valid, outside the current selection. | 1107 // Drag the text over somewhere valid, outside the current selection. |
| 1104 gfx::Point drop_point(GetCursorPositionX(2), 0); | 1108 gfx::Point drop_point(GetCursorPositionX(2), 0); |
| 1105 ui::DropTargetEvent drop(data, drop_point, drop_point, | 1109 ui::DropTargetEvent drop(data, drop_point, drop_point, |
| 1106 ui::DragDropTypes::DRAG_MOVE); | 1110 ui::DragDropTypes::DRAG_MOVE); |
| 1107 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 1111 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); |
| 1108 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 1112 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
| 1109 gfx::Point drag_point(GetCursorPositionX(9), 0); | 1113 gfx::Point drag_point(GetCursorPositionX(9), 0); |
| 1110 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, | 1114 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, |
| 1111 ui::EF_LEFT_MOUSE_BUTTON); | 1115 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1112 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1116 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
| 1113 ui::EF_LEFT_MOUSE_BUTTON); | 1117 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1114 textfield_view_->OnMouseDragged(drag); | 1118 textfield_view_->OnMouseDragged(drag); |
| 1115 textfield_view_->OnMouseReleased(release); | 1119 textfield_view_->OnMouseReleased(release); |
| 1116 textfield_view_->OnDragDone(); | 1120 textfield_view_->OnDragDone(); |
| 1117 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1121 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
| 1118 } | 1122 } |
| 1119 | 1123 |
| 1120 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 1124 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
| 1121 InitTextfield(Textfield::STYLE_DEFAULT); | 1125 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1122 textfield_->SetText(ASCIIToUTF16("read only")); | 1126 textfield_->SetText(ASCIIToUTF16("read only")); |
| 1123 textfield_->SetReadOnly(true); | 1127 textfield_->SetReadOnly(true); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 textfield_->SelectRange(gfx::Range(5, 5)); | 1847 textfield_->SelectRange(gfx::Range(5, 5)); |
| 1844 const gfx::Rect middle_cursor = GetCursorBounds(); | 1848 const gfx::Rect middle_cursor = GetCursorBounds(); |
| 1845 textfield_->SelectRange(gfx::Range(0, 0)); | 1849 textfield_->SelectRange(gfx::Range(0, 0)); |
| 1846 const gfx::Point beginning = GetCursorBounds().origin(); | 1850 const gfx::Point beginning = GetCursorBounds().origin(); |
| 1847 | 1851 |
| 1848 // Double click, but do not release the left button. | 1852 // Double click, but do not release the left button. |
| 1849 MouseClick(middle_cursor, 0); | 1853 MouseClick(middle_cursor, 0); |
| 1850 const gfx::Point middle(middle_cursor.x(), | 1854 const gfx::Point middle(middle_cursor.x(), |
| 1851 middle_cursor.y() + middle_cursor.height() / 2); | 1855 middle_cursor.y() + middle_cursor.height() / 2); |
| 1852 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, | 1856 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, |
| 1857 ui::EF_LEFT_MOUSE_BUTTON, |
| 1853 ui::EF_LEFT_MOUSE_BUTTON); | 1858 ui::EF_LEFT_MOUSE_BUTTON); |
| 1854 textfield_view_->OnMousePressed(press_event); | 1859 textfield_view_->OnMousePressed(press_event); |
| 1855 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 1860 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
| 1856 | 1861 |
| 1857 // Drag the mouse to the beginning of the textfield. | 1862 // Drag the mouse to the beginning of the textfield. |
| 1858 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, | 1863 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, |
| 1859 ui::EF_LEFT_MOUSE_BUTTON); | 1864 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1860 textfield_view_->OnMouseDragged(drag_event); | 1865 textfield_view_->OnMouseDragged(drag_event); |
| 1861 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 1866 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
| 1862 } | 1867 } |
| 1863 | 1868 |
| 1864 // Touch selection and draggin currently only works for chromeos. | 1869 // Touch selection and draggin currently only works for chromeos. |
| 1865 #if defined(OS_CHROMEOS) | 1870 #if defined(OS_CHROMEOS) |
| 1866 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { | 1871 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { |
| 1867 InitTextfield(Textfield::STYLE_DEFAULT); | 1872 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1868 textfield_->SetText(ASCIIToUTF16("hello world")); | 1873 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1869 EXPECT_FALSE(GetTouchSelectionController()); | 1874 EXPECT_FALSE(GetTouchSelectionController()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 // Set text which may fall back to a font which has taller baseline than | 1988 // Set text which may fall back to a font which has taller baseline than |
| 1984 // the default font. | 1989 // the default font. |
| 1985 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1990 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
| 1986 const int new_baseline = textfield_->GetBaseline(); | 1991 const int new_baseline = textfield_->GetBaseline(); |
| 1987 | 1992 |
| 1988 // Regardless of the text, the baseline must be the same. | 1993 // Regardless of the text, the baseline must be the same. |
| 1989 EXPECT_EQ(new_baseline, old_baseline); | 1994 EXPECT_EQ(new_baseline, old_baseline); |
| 1990 } | 1995 } |
| 1991 | 1996 |
| 1992 } // namespace views | 1997 } // namespace views |
| OLD | NEW |