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 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 } | 1924 } |
1925 #endif | 1925 #endif |
1926 | 1926 |
1927 // Touch selection and dragging currently only works for chromeos. | 1927 // Touch selection and dragging currently only works for chromeos. |
1928 #if defined(OS_CHROMEOS) | 1928 #if defined(OS_CHROMEOS) |
1929 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { | 1929 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { |
1930 InitTextfield(); | 1930 InitTextfield(); |
1931 textfield_->SetText(ASCIIToUTF16("hello world")); | 1931 textfield_->SetText(ASCIIToUTF16("hello world")); |
1932 EXPECT_FALSE(test_api_->touch_selection_controller()); | 1932 EXPECT_FALSE(test_api_->touch_selection_controller()); |
1933 const int x = GetCursorPositionX(2); | 1933 const int x = GetCursorPositionX(2); |
1934 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); | |
1935 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); | |
1936 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); | |
1937 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1934 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
1938 | 1935 |
1939 // Tapping on the textfield should turn on the TouchSelectionController. | 1936 // Tapping on the textfield should turn on the TouchSelectionController. |
| 1937 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); |
1940 textfield_->OnGestureEvent(&tap); | 1938 textfield_->OnGestureEvent(&tap); |
1941 EXPECT_TRUE(test_api_->touch_selection_controller()); | 1939 EXPECT_TRUE(test_api_->touch_selection_controller()); |
1942 | 1940 |
1943 // Un-focusing the textfield should reset the TouchSelectionController | 1941 // Un-focusing the textfield should reset the TouchSelectionController |
1944 textfield_->GetFocusManager()->ClearFocus(); | 1942 textfield_->GetFocusManager()->ClearFocus(); |
1945 EXPECT_FALSE(test_api_->touch_selection_controller()); | 1943 EXPECT_FALSE(test_api_->touch_selection_controller()); |
| 1944 textfield_->RequestFocus(); |
1946 | 1945 |
1947 // With touch editing enabled, long press should not show context menu. | 1946 // With touch editing enabled, long press should not show context menu. |
1948 // Instead, select word and invoke TouchSelectionController. | 1947 // Instead, select word and invoke TouchSelectionController. |
1949 textfield_->OnGestureEvent(&tap_down); | 1948 GestureEventForTest long_press_1(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1950 textfield_->OnGestureEvent(&long_press); | 1949 textfield_->OnGestureEvent(&long_press_1); |
1951 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1950 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1952 EXPECT_TRUE(test_api_->touch_selection_controller()); | 1951 EXPECT_TRUE(test_api_->touch_selection_controller()); |
| 1952 EXPECT_TRUE(long_press_1.handled()); |
1953 | 1953 |
1954 // With touch drag drop enabled, long pressing in the selected region should | 1954 // With touch drag drop enabled, long pressing in the selected region should |
1955 // start a drag and remove TouchSelectionController. | 1955 // start a drag and remove TouchSelectionController. |
1956 ASSERT_TRUE(switches::IsTouchDragDropEnabled()); | 1956 ASSERT_TRUE(switches::IsTouchDragDropEnabled()); |
1957 textfield_->OnGestureEvent(&tap_down); | 1957 GestureEventForTest long_press_2(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1958 textfield_->OnGestureEvent(&long_press); | 1958 textfield_->OnGestureEvent(&long_press_2); |
1959 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1959 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1960 EXPECT_FALSE(test_api_->touch_selection_controller()); | 1960 EXPECT_FALSE(test_api_->touch_selection_controller()); |
| 1961 EXPECT_FALSE(long_press_2.handled()); |
1961 | 1962 |
1962 // After disabling touch drag drop, long pressing again in the selection | 1963 // After disabling touch drag drop, long pressing again in the selection |
1963 // region should not do anything. | 1964 // region should not do anything. |
1964 CommandLine::ForCurrentProcess()->AppendSwitch( | 1965 CommandLine::ForCurrentProcess()->AppendSwitch( |
1965 switches::kDisableTouchDragDrop); | 1966 switches::kDisableTouchDragDrop); |
1966 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); | 1967 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); |
1967 textfield_->OnGestureEvent(&tap_down); | 1968 GestureEventForTest long_press_3(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1968 textfield_->OnGestureEvent(&long_press); | 1969 textfield_->OnGestureEvent(&long_press_3); |
1969 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1970 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1970 EXPECT_TRUE(test_api_->touch_selection_controller()); | |
1971 EXPECT_TRUE(long_press.handled()); | |
1972 } | |
1973 | |
1974 TEST_F(TextfieldTest, TouchScrubbingSelection) { | |
1975 InitTextfield(); | |
1976 textfield_->SetText(ASCIIToUTF16("hello world")); | |
1977 EXPECT_FALSE(test_api_->touch_selection_controller()); | 1971 EXPECT_FALSE(test_api_->touch_selection_controller()); |
1978 | 1972 EXPECT_FALSE(long_press_3.handled()); |
1979 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | |
1980 | |
1981 // Simulate touch-scrubbing. | |
1982 int scrubbing_start = GetCursorPositionX(1); | |
1983 int scrubbing_end = GetCursorPositionX(6); | |
1984 | |
1985 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, | |
1986 0.0f, 0.0f); | |
1987 textfield_->OnGestureEvent(&tap_down); | |
1988 | |
1989 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0, | |
1990 0.0f, 0.0f); | |
1991 textfield_->OnGestureEvent(&tap_cancel); | |
1992 | |
1993 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start, | |
1994 0, 0.0f, 0.0f); | |
1995 textfield_->OnGestureEvent(&scroll_begin); | |
1996 | |
1997 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end, | |
1998 0, scrubbing_end - scrubbing_start, 0.0f); | |
1999 textfield_->OnGestureEvent(&scroll_update); | |
2000 | |
2001 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0, | |
2002 0.0f, 0.0f); | |
2003 textfield_->OnGestureEvent(&scroll_end); | |
2004 | |
2005 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); | |
2006 textfield_->OnGestureEvent(&end); | |
2007 | |
2008 // In the end, part of text should have been selected and handles should have | |
2009 // appeared. | |
2010 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); | |
2011 EXPECT_TRUE(test_api_->touch_selection_controller()); | |
2012 } | 1973 } |
2013 #endif | 1974 #endif |
2014 | 1975 |
2015 // Long_Press gesture in Textfield can initiate a drag and drop now. | 1976 // Long_Press gesture in Textfield can initiate a drag and drop now. |
2016 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { | 1977 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
2017 InitTextfield(); | 1978 InitTextfield(); |
2018 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1979 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
2019 | 1980 |
2020 // Ensure the textfield will provide selected text for drag data. | 1981 // Ensure the textfield will provide selected text for drag data. |
2021 textfield_->SelectRange(gfx::Range(6, 12)); | 1982 textfield_->SelectRange(gfx::Range(6, 12)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 TextfieldDestroyerController controller(textfield_); | 2017 TextfieldDestroyerController controller(textfield_); |
2057 EXPECT_TRUE(controller.target()); | 2018 EXPECT_TRUE(controller.target()); |
2058 | 2019 |
2059 // Send a key to trigger OnKeyEvent(). | 2020 // Send a key to trigger OnKeyEvent(). |
2060 SendKeyEvent('X'); | 2021 SendKeyEvent('X'); |
2061 | 2022 |
2062 EXPECT_FALSE(controller.target()); | 2023 EXPECT_FALSE(controller.target()); |
2063 } | 2024 } |
2064 | 2025 |
2065 } // namespace views | 2026 } // namespace views |
OLD | NEW |