| 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 | 812 |
| 813 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { | 813 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
| 814 InitTextfield(); | 814 InitTextfield(); |
| 815 textfield_->SetText(ASCIIToUTF16("hello string world")); | 815 textfield_->SetText(ASCIIToUTF16("hello string world")); |
| 816 | 816 |
| 817 // Ensure the textfield will provide selected text for drag data. | 817 // Ensure the textfield will provide selected text for drag data. |
| 818 base::string16 string; | 818 base::string16 string; |
| 819 ui::OSExchangeData data; | 819 ui::OSExchangeData data; |
| 820 const gfx::Range kStringRange(6, 12); | 820 const gfx::Range kStringRange(6, 12); |
| 821 textfield_->SelectRange(kStringRange); | 821 textfield_->SelectRange(kStringRange); |
| 822 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 822 const gfx::PointF kStringPoint(GetCursorPositionX(9), 0); |
| 823 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); | 823 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); |
| 824 EXPECT_TRUE(data.GetString(&string)); | 824 EXPECT_TRUE(data.GetString(&string)); |
| 825 EXPECT_EQ(textfield_->GetSelectedText(), string); | 825 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 826 | 826 |
| 827 // Ensure that disabled textfields do not support drag operations. | 827 // Ensure that disabled textfields do not support drag operations. |
| 828 textfield_->SetEnabled(false); | 828 textfield_->SetEnabled(false); |
| 829 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 829 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 830 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 830 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 831 textfield_->SetEnabled(true); | 831 textfield_->SetEnabled(true); |
| 832 // Ensure that textfields without selections do not support drag operations. | 832 // Ensure that textfields without selections do not support drag operations. |
| 833 textfield_->ClearSelection(); | 833 textfield_->ClearSelection(); |
| 834 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 834 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 835 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 835 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 836 textfield_->SelectRange(kStringRange); | 836 textfield_->SelectRange(kStringRange); |
| 837 // Ensure that password textfields do not support drag operations. | 837 // Ensure that password textfields do not support drag operations. |
| 838 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 838 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 839 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 839 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 840 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 840 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 841 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); | 841 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); |
| 842 // Ensure that textfields only initiate drag operations inside the selection. | 842 // Ensure that textfields only initiate drag operations inside the selection. |
| 843 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, | 843 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, |
| 844 ui::EF_LEFT_MOUSE_BUTTON, | 844 ui::EF_LEFT_MOUSE_BUTTON, |
| 845 ui::EF_LEFT_MOUSE_BUTTON); | 845 ui::EF_LEFT_MOUSE_BUTTON); |
| 846 textfield_->OnMousePressed(press_event); | 846 textfield_->OnMousePressed(press_event); |
| 847 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 847 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 848 textfield_->GetDragOperationsForView(NULL, gfx::Point())); | 848 textfield_->GetDragOperationsForView(NULL, gfx::Point())); |
| 849 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), | 849 EXPECT_FALSE( |
| 850 gfx::Point())); | 850 textfield_->CanStartDragForView(NULL, gfx::PointF(), gfx::PointF())); |
| 851 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 851 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
| 852 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 852 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 853 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, | 853 EXPECT_TRUE( |
| 854 gfx::Point())); | 854 textfield_->CanStartDragForView(NULL, kStringPoint, gfx::PointF())); |
| 855 // Ensure that textfields support local moves. | 855 // Ensure that textfields support local moves. |
| 856 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 856 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 857 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); | 857 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); |
| 858 } | 858 } |
| 859 | 859 |
| 860 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { | 860 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
| 861 InitTextfield(); | 861 InitTextfield(); |
| 862 textfield_->SetText(ASCIIToUTF16("hello world")); | 862 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 863 | 863 |
| 864 base::string16 string; | 864 base::string16 string; |
| 865 ui::OSExchangeData data; | 865 ui::OSExchangeData data; |
| 866 int formats = 0; | 866 int formats = 0; |
| 867 int operations = 0; | 867 int operations = 0; |
| 868 std::set<OSExchangeData::CustomFormat> custom_formats; | 868 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 869 | 869 |
| 870 // Start dragging "ello". | 870 // Start dragging "ello". |
| 871 textfield_->SelectRange(gfx::Range(1, 5)); | 871 textfield_->SelectRange(gfx::Range(1, 5)); |
| 872 gfx::Point point(GetCursorPositionX(3), 0); | 872 gfx::Point point(GetCursorPositionX(3), 0); |
| 873 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 873 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 874 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 874 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 875 textfield_->OnMousePressed(click_a); | 875 textfield_->OnMousePressed(click_a); |
| 876 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), | 876 EXPECT_TRUE(textfield_->CanStartDragForView( |
| 877 gfx::Point())); | 877 textfield_, click_a.location(), gfx::PointF())); |
| 878 operations = textfield_->GetDragOperationsForView(textfield_, | 878 operations = textfield_->GetDragOperationsForView(textfield_, |
| 879 click_a.location()); | 879 click_a.location()); |
| 880 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 880 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 881 operations); | 881 operations); |
| 882 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); | 882 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 883 EXPECT_TRUE(data.GetString(&string)); | 883 EXPECT_TRUE(data.GetString(&string)); |
| 884 EXPECT_EQ(textfield_->GetSelectedText(), string); | 884 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 885 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); | 885 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 886 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 886 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
| 887 EXPECT_TRUE(custom_formats.empty()); | 887 EXPECT_TRUE(custom_formats.empty()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 int formats = 0; | 919 int formats = 0; |
| 920 int operations = 0; | 920 int operations = 0; |
| 921 std::set<OSExchangeData::CustomFormat> custom_formats; | 921 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 922 | 922 |
| 923 // Start dragging " worl". | 923 // Start dragging " worl". |
| 924 textfield_->SelectRange(gfx::Range(5, 10)); | 924 textfield_->SelectRange(gfx::Range(5, 10)); |
| 925 gfx::Point point(GetCursorPositionX(7), 0); | 925 gfx::Point point(GetCursorPositionX(7), 0); |
| 926 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 926 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 927 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 927 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 928 textfield_->OnMousePressed(click_a); | 928 textfield_->OnMousePressed(click_a); |
| 929 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), | 929 EXPECT_TRUE(textfield_->CanStartDragForView( |
| 930 gfx::Point())); | 930 textfield_, click_a.location(), gfx::PointF())); |
| 931 operations = textfield_->GetDragOperationsForView(textfield_, | 931 operations = textfield_->GetDragOperationsForView(textfield_, |
| 932 click_a.location()); | 932 click_a.location()); |
| 933 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 933 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 934 operations); | 934 operations); |
| 935 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); | 935 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 936 EXPECT_TRUE(data.GetString(&string)); | 936 EXPECT_TRUE(data.GetString(&string)); |
| 937 EXPECT_EQ(textfield_->GetSelectedText(), string); | 937 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 938 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); | 938 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 939 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 939 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
| 940 EXPECT_TRUE(custom_formats.empty()); | 940 EXPECT_TRUE(custom_formats.empty()); |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 } | 1957 } |
| 1958 #endif | 1958 #endif |
| 1959 | 1959 |
| 1960 // Long_Press gesture in Textfield can initiate a drag and drop now. | 1960 // Long_Press gesture in Textfield can initiate a drag and drop now. |
| 1961 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { | 1961 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
| 1962 InitTextfield(); | 1962 InitTextfield(); |
| 1963 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1963 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
| 1964 | 1964 |
| 1965 // Ensure the textfield will provide selected text for drag data. | 1965 // Ensure the textfield will provide selected text for drag data. |
| 1966 textfield_->SelectRange(gfx::Range(6, 12)); | 1966 textfield_->SelectRange(gfx::Range(6, 12)); |
| 1967 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 1967 const gfx::PointF kStringPoint(GetCursorPositionX(9), 0); |
| 1968 | 1968 |
| 1969 // Enable touch-drag-drop to make long press effective. | 1969 // Enable touch-drag-drop to make long press effective. |
| 1970 CommandLine::ForCurrentProcess()->AppendSwitch( | 1970 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1971 switches::kEnableTouchDragDrop); | 1971 switches::kEnableTouchDragDrop); |
| 1972 | 1972 |
| 1973 // Create a long press event in the selected region should start a drag. | 1973 // Create a long press event in the selected region should start a drag. |
| 1974 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), | 1974 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), |
| 1975 kStringPoint.y(), 0.0f, 0.0f); | 1975 kStringPoint.y(), 0.0f, 0.0f); |
| 1976 textfield_->OnGestureEvent(&long_press); | 1976 textfield_->OnGestureEvent(&long_press); |
| 1977 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, | 1977 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
| 1978 kStringPoint)); | 1978 kStringPoint)); |
| 1979 } | 1979 } |
| 1980 | 1980 |
| 1981 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { | 1981 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { |
| 1982 InitTextfield(); | 1982 InitTextfield(); |
| 1983 textfield_->SetText(UTF8ToUTF16("abc")); | 1983 textfield_->SetText(UTF8ToUTF16("abc")); |
| 1984 const int old_baseline = textfield_->GetBaseline(); | 1984 const int old_baseline = textfield_->GetBaseline(); |
| 1985 | 1985 |
| 1986 // Set text which may fall back to a font which has taller baseline than | 1986 // Set text which may fall back to a font which has taller baseline than |
| 1987 // the default font. | 1987 // the default font. |
| 1988 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1988 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
| 1989 const int new_baseline = textfield_->GetBaseline(); | 1989 const int new_baseline = textfield_->GetBaseline(); |
| 1990 | 1990 |
| 1991 // Regardless of the text, the baseline must be the same. | 1991 // Regardless of the text, the baseline must be the same. |
| 1992 EXPECT_EQ(new_baseline, old_baseline); | 1992 EXPECT_EQ(new_baseline, old_baseline); |
| 1993 } | 1993 } |
| 1994 | 1994 |
| 1995 } // namespace views | 1995 } // namespace views |
| OLD | NEW |