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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 320 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
321 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 321 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
322 ui::EF_LEFT_MOUSE_BUTTON); | 322 ui::EF_LEFT_MOUSE_BUTTON); |
323 textfield_->OnMousePressed(click); | 323 textfield_->OnMousePressed(click); |
324 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 324 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
325 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 325 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
326 ui::EF_LEFT_MOUSE_BUTTON); | 326 ui::EF_LEFT_MOUSE_BUTTON); |
327 textfield_->OnMouseReleased(release); | 327 textfield_->OnMouseReleased(release); |
328 } | 328 } |
329 | 329 |
| 330 // Simulates a complete tap. |
| 331 void Tap(const gfx::Point& point) { |
| 332 GestureEventForTest begin( |
| 333 ui::ET_GESTURE_BEGIN, point.x(), point.y(), 0.0f, 0.0f); |
| 334 textfield_->OnGestureEvent(&begin); |
| 335 |
| 336 GestureEventForTest tap_down( |
| 337 ui::ET_GESTURE_TAP_DOWN, point.x(), point.y(), 0.0f, 0.0f); |
| 338 textfield_->OnGestureEvent(&tap_down); |
| 339 |
| 340 GestureEventForTest show_press( |
| 341 ui::ET_GESTURE_SHOW_PRESS, point.x(), point.y(), 0.0f, 0.0f); |
| 342 textfield_->OnGestureEvent(&show_press); |
| 343 |
| 344 GestureEventForTest tap( |
| 345 ui::ET_GESTURE_TAP, point.x(), point.y(), 1.0f, 0.0f); |
| 346 textfield_->OnGestureEvent(&tap); |
| 347 |
| 348 GestureEventForTest end( |
| 349 ui::ET_GESTURE_END, point.x(), point.y(), 0.0f, 0.0f); |
| 350 textfield_->OnGestureEvent(&end); |
| 351 } |
| 352 |
330 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 353 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
331 bool can_undo, | 354 bool can_undo, |
332 ui::MenuModel* menu) { | 355 ui::MenuModel* menu) { |
333 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 356 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
334 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 357 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
335 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 358 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
336 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 359 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
337 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), | 360 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
338 menu->IsEnabledAt(4 /* PASTE */)); | 361 menu->IsEnabledAt(4 /* PASTE */)); |
339 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 362 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 switches::kDisableTouchDragDrop); | 1989 switches::kDisableTouchDragDrop); |
1967 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); | 1990 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); |
1968 GestureEventForTest long_press_3(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); | 1991 GestureEventForTest long_press_3(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1969 textfield_->OnGestureEvent(&long_press_3); | 1992 textfield_->OnGestureEvent(&long_press_3); |
1970 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1993 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1971 EXPECT_FALSE(test_api_->touch_selection_controller()); | 1994 EXPECT_FALSE(test_api_->touch_selection_controller()); |
1972 EXPECT_FALSE(long_press_3.handled()); | 1995 EXPECT_FALSE(long_press_3.handled()); |
1973 } | 1996 } |
1974 #endif | 1997 #endif |
1975 | 1998 |
| 1999 TEST_F(TextfieldTest, TouchSelectionInUnfocusableTextfield) { |
| 2000 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 2001 |
| 2002 InitTextfield(); |
| 2003 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 2004 gfx::Point touch_point(GetCursorPositionX(2), 0); |
| 2005 |
| 2006 // Disable textfield and tap on it. Touch text selection should not get |
| 2007 // activated. |
| 2008 textfield_->SetEnabled(false); |
| 2009 Tap(touch_point); |
| 2010 EXPECT_FALSE(test_api_->touch_selection_controller()); |
| 2011 textfield_->SetEnabled(true); |
| 2012 |
| 2013 // Make textfield unfocusable and tap on it. Touch text selection should not |
| 2014 // get activated. |
| 2015 textfield_->SetFocusable(false); |
| 2016 Tap(touch_point); |
| 2017 EXPECT_FALSE(textfield_->HasFocus()); |
| 2018 EXPECT_FALSE(test_api_->touch_selection_controller()); |
| 2019 textfield_->SetFocusable(true); |
| 2020 } |
| 2021 |
1976 // Long_Press gesture in Textfield can initiate a drag and drop now. | 2022 // Long_Press gesture in Textfield can initiate a drag and drop now. |
1977 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { | 2023 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
1978 InitTextfield(); | 2024 InitTextfield(); |
1979 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 2025 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
1980 | 2026 |
1981 // Ensure the textfield will provide selected text for drag data. | 2027 // Ensure the textfield will provide selected text for drag data. |
1982 textfield_->SelectRange(gfx::Range(6, 12)); | 2028 textfield_->SelectRange(gfx::Range(6, 12)); |
1983 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 2029 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
1984 | 2030 |
1985 // Enable touch-drag-drop to make long press effective. | 2031 // Enable touch-drag-drop to make long press effective. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 TextfieldDestroyerController controller(textfield_); | 2063 TextfieldDestroyerController controller(textfield_); |
2018 EXPECT_TRUE(controller.target()); | 2064 EXPECT_TRUE(controller.target()); |
2019 | 2065 |
2020 // Send a key to trigger OnKeyEvent(). | 2066 // Send a key to trigger OnKeyEvent(). |
2021 SendKeyEvent('X'); | 2067 SendKeyEvent('X'); |
2022 | 2068 |
2023 EXPECT_FALSE(controller.target()); | 2069 EXPECT_FALSE(controller.target()); |
2024 } | 2070 } |
2025 | 2071 |
2026 } // namespace views | 2072 } // namespace views |
OLD | NEW |