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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 textfield_view_->OnGestureEvent(&scroll_end); | 1910 textfield_view_->OnGestureEvent(&scroll_end); |
1911 | 1911 |
1912 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); | 1912 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); |
1913 textfield_view_->OnGestureEvent(&end); | 1913 textfield_view_->OnGestureEvent(&end); |
1914 | 1914 |
1915 // In the end, part of text should have been selected and handles should have | 1915 // In the end, part of text should have been selected and handles should have |
1916 // appeared. | 1916 // appeared. |
1917 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); | 1917 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); |
1918 EXPECT_TRUE(GetTouchSelectionController()); | 1918 EXPECT_TRUE(GetTouchSelectionController()); |
1919 } | 1919 } |
| 1920 |
| 1921 TEST_F(NativeTextfieldViewsTest, TouchSelectionInDisabledTextfield) { |
| 1922 // Create a disabled textfield. |
| 1923 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1924 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1925 textfield_->SetEnabled(false); |
| 1926 EXPECT_FALSE(GetTouchSelectionController()); |
| 1927 |
| 1928 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 1929 |
| 1930 // Simulate a complete tap. |
| 1931 int touch_x = GetCursorPositionX(2); |
| 1932 int touch_y = 0; |
| 1933 |
| 1934 GestureEventForTest begin(ui::ET_GESTURE_BEGIN, touch_x, touch_y, 0.0f, 0.0f); |
| 1935 textfield_view_->OnGestureEvent(&begin); |
| 1936 |
| 1937 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, touch_x, touch_y, 0.0f, |
| 1938 0.0f); |
| 1939 textfield_view_->OnGestureEvent(&tap_down); |
| 1940 |
| 1941 GestureEventForTest show_press(ui::ET_GESTURE_SHOW_PRESS, touch_x, touch_y, |
| 1942 0.0f, 0.0f); |
| 1943 textfield_view_->OnGestureEvent(&show_press); |
| 1944 |
| 1945 GestureEventForTest tap(ui::ET_GESTURE_TAP, touch_x, touch_y, 1.0f, 0.0f); |
| 1946 textfield_view_->OnGestureEvent(&tap); |
| 1947 |
| 1948 GestureEventForTest end(ui::ET_GESTURE_END, touch_x, touch_y, 0.0f, 0.0f); |
| 1949 textfield_view_->OnGestureEvent(&end); |
| 1950 |
| 1951 // In the end, there should be no selection handles in the textfield. |
| 1952 EXPECT_FALSE(GetTouchSelectionController()); |
| 1953 } |
| 1954 |
| 1955 TEST_F(NativeTextfieldViewsTest, TouchSelectionInNonFocusableTextfield) { |
| 1956 // Create a non-focusable textfield. |
| 1957 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1958 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1959 textfield_->set_focusable(false); |
| 1960 textfield_->GetFocusManager()->ClearFocus(); |
| 1961 EXPECT_FALSE(GetTouchSelectionController()); |
| 1962 |
| 1963 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 1964 |
| 1965 // Simulate a complete tap. |
| 1966 int touch_x = GetCursorPositionX(2); |
| 1967 int touch_y = 0; |
| 1968 |
| 1969 GestureEventForTest begin(ui::ET_GESTURE_BEGIN, touch_x, touch_y, 0.0f, 0.0f); |
| 1970 textfield_view_->OnGestureEvent(&begin); |
| 1971 |
| 1972 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, touch_x, touch_y, 0.0f, |
| 1973 0.0f); |
| 1974 textfield_view_->OnGestureEvent(&tap_down); |
| 1975 |
| 1976 GestureEventForTest show_press(ui::ET_GESTURE_SHOW_PRESS, touch_x, touch_y, |
| 1977 0.0f, 0.0f); |
| 1978 textfield_view_->OnGestureEvent(&show_press); |
| 1979 |
| 1980 GestureEventForTest tap(ui::ET_GESTURE_TAP, touch_x, touch_y, 1.0f, 0.0f); |
| 1981 textfield_view_->OnGestureEvent(&tap); |
| 1982 |
| 1983 GestureEventForTest end(ui::ET_GESTURE_END, touch_x, touch_y, 0.0f, 0.0f); |
| 1984 textfield_view_->OnGestureEvent(&end); |
| 1985 |
| 1986 // In the end, the textfield should not be focused and there should be no |
| 1987 // selection handles in the textfield. |
| 1988 EXPECT_FALSE(textfield_->HasFocus()); |
| 1989 EXPECT_FALSE(GetTouchSelectionController()); |
| 1990 } |
1920 #endif | 1991 #endif |
1921 | 1992 |
1922 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. | 1993 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. |
1923 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { | 1994 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { |
1924 InitTextfield(Textfield::STYLE_DEFAULT); | 1995 InitTextfield(Textfield::STYLE_DEFAULT); |
1925 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1996 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
1926 | 1997 |
1927 // Ensure the textfield will provide selected text for drag data. | 1998 // Ensure the textfield will provide selected text for drag data. |
1928 textfield_->SelectRange(gfx::Range(6, 12)); | 1999 textfield_->SelectRange(gfx::Range(6, 12)); |
1929 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 2000 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
(...skipping 18 matching lines...) Expand all Loading... |
1948 // Set text which may fall back to a font which has taller baseline than | 2019 // Set text which may fall back to a font which has taller baseline than |
1949 // the default font. | 2020 // the default font. |
1950 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 2021 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
1951 const int new_baseline = textfield_->GetBaseline(); | 2022 const int new_baseline = textfield_->GetBaseline(); |
1952 | 2023 |
1953 // Regardless of the text, the baseline must be the same. | 2024 // Regardless of the text, the baseline must be the same. |
1954 EXPECT_EQ(new_baseline, old_baseline); | 2025 EXPECT_EQ(new_baseline, old_baseline); |
1955 } | 2026 } |
1956 | 2027 |
1957 } // namespace views | 2028 } // namespace views |
OLD | NEW |