Commit 425b55b9 authored by mohsen@chromium.org's avatar mohsen@chromium.org

Show handles when marking text with touch in NativeTextfieldViews

In NativeTextfieldViews, part of text can be selected using touch
scrubbing. After touch scrubbing is finished, touch editing handles
should appear to allow more touch selection manipulation.

BUG=239111

Review URL: https://codereview.chromium.org/93433003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238444 0039d316-1c4b-4281-b951-d872f2087c98
parent c695f2c3
...@@ -180,6 +180,11 @@ void NativeTextfieldViews::OnGestureEvent(ui::GestureEvent* event) { ...@@ -180,6 +180,11 @@ void NativeTextfieldViews::OnGestureEvent(ui::GestureEvent* event) {
OnAfterUserAction(); OnAfterUserAction();
event->SetHandled(); event->SetHandled();
break; break;
case ui::ET_GESTURE_SCROLL_END:
case ui::ET_SCROLL_FLING_START:
CreateTouchSelectionControllerAndNotifyIt();
event->SetHandled();
break;
case ui::ET_GESTURE_TAP: case ui::ET_GESTURE_TAP:
if (event->details().tap_count() == 1) { if (event->details().tap_count() == 1) {
CreateTouchSelectionControllerAndNotifyIt(); CreateTouchSelectionControllerAndNotifyIt();
......
...@@ -99,9 +99,10 @@ class GetTextHelper { ...@@ -99,9 +99,10 @@ class GetTextHelper {
// Convenience to make constructing a GestureEvent simpler. // Convenience to make constructing a GestureEvent simpler.
class GestureEventForTest : public ui::GestureEvent { class GestureEventForTest : public ui::GestureEvent {
public: public:
GestureEventForTest(ui::EventType type, int x, int y, int flags) GestureEventForTest(ui::EventType type, int x, int y, float delta_x,
: GestureEvent(type, x, y, flags, base::TimeDelta(), float delta_y)
ui::GestureEventDetails(type, 0.0f, 0.0f), 0) { : GestureEvent(type, x, y, 0, base::TimeDelta(),
ui::GestureEventDetails(type, delta_x, delta_y), 0) {
} }
private: private:
...@@ -1836,9 +1837,7 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { ...@@ -1836,9 +1837,7 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) {
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
// Tapping on the textfield should turn on the TouchSelectionController. // Tapping on the textfield should turn on the TouchSelectionController.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, eventX, eventY, 0, base::TimeDelta(), GestureEventForTest tap(ui::ET_GESTURE_TAP, eventX, eventY, 1.0f, 0.0f);
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f),
0);
textfield_view_->OnGestureEvent(&tap); textfield_view_->OnGestureEvent(&tap);
EXPECT_TRUE(GetTouchSelectionController()); EXPECT_TRUE(GetTouchSelectionController());
...@@ -1848,9 +1847,11 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { ...@@ -1848,9 +1847,11 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) {
// With touch editing enabled, long press should not show context menu. // With touch editing enabled, long press should not show context menu.
// Instead, select word and invoke TouchSelectionController. // Instead, select word and invoke TouchSelectionController.
GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, eventX, eventY, 0); GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, eventX, eventY, 0.0f,
0.0f);
textfield_view_->OnGestureEvent(&tap_down); textfield_view_->OnGestureEvent(&tap_down);
GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, eventX, eventY,
0.0f, 0.0f);
textfield_view_->OnGestureEvent(&long_press); textfield_view_->OnGestureEvent(&long_press);
EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
EXPECT_TRUE(GetTouchSelectionController()); EXPECT_TRUE(GetTouchSelectionController());
...@@ -1870,11 +1871,52 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { ...@@ -1870,11 +1871,52 @@ TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) {
textfield_view_->OnGestureEvent(&tap_down); textfield_view_->OnGestureEvent(&tap_down);
// Create a new long press event since the previous one is not marked handled. // Create a new long press event since the previous one is not marked handled.
GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY,
0.0f, 0.0f);
textfield_view_->OnGestureEvent(&long_press2); textfield_view_->OnGestureEvent(&long_press2);
EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
EXPECT_FALSE(GetTouchSelectionController()); EXPECT_FALSE(GetTouchSelectionController());
} }
TEST_F(NativeTextfieldViewsTest, TouchScrubbingSelection) {
InitTextfield(Textfield::STYLE_DEFAULT);
textfield_->SetText(ASCIIToUTF16("hello world"));
EXPECT_FALSE(GetTouchSelectionController());
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
// Simulate touch-scrubbing.
int scrubbing_start = GetCursorPositionX(1);
int scrubbing_end = GetCursorPositionX(6);
GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0,
0.0f, 0.0f);
textfield_view_->OnGestureEvent(&tap_down);
GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0,
0.0f, 0.0f);
textfield_view_->OnGestureEvent(&tap_cancel);
GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start,
0, 0.0f, 0.0f);
textfield_view_->OnGestureEvent(&scroll_begin);
GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end,
0, scrubbing_end - scrubbing_start, 0.0f);
textfield_view_->OnGestureEvent(&scroll_update);
GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0,
0.0f, 0.0f);
textfield_view_->OnGestureEvent(&scroll_end);
GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f);
textfield_view_->OnGestureEvent(&end);
// In the end, part of text should have been selected and handles should have
// appeared.
EXPECT_STR_EQ("ello ", textfield_->GetSelectedText());
EXPECT_TRUE(GetTouchSelectionController());
}
#endif #endif
// Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now.
...@@ -1891,8 +1933,8 @@ TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { ...@@ -1891,8 +1933,8 @@ TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) {
switches::kEnableTouchDragDrop); switches::kEnableTouchDragDrop);
// Create a long press event in the selected region should start a drag. // Create a long press event in the selected region should start a drag.
GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(),
kStringPoint.x(), kStringPoint.y(), 0); kStringPoint.y(), 0.0f, 0.0f);
textfield_view_->OnGestureEvent(&long_press); textfield_view_->OnGestureEvent(&long_press);
EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL,
kStringPoint, kStringPoint)); kStringPoint, kStringPoint));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment