Commit 41355a89 authored by mohsen's avatar mohsen Committed by Commit bot

Fix long press touch selection on empty text fields

Desired behavior when long press happens on an empty text field is to
activate touch selection and show the quick menu if there is anything
available to show in the quick menu. Otherwise, the regular context menu
should be shown. This was regressed due to changes in context menu
source type that added LONG_PRESS and LONG_TAP types. In addition to
fixing this regression, this CL fixes the regression on the new tab page
that shows an incorrectly placed quick menu instead of the context menu.

BUG=594101

Review-Url: https://codereview.chromium.org/2124913002
Cr-Commit-Position: refs/heads/master@{#407059}
parent ce88c0f9
......@@ -156,8 +156,11 @@ void TouchSelectionControllerClientAura::OnScrollCompleted() {
bool TouchSelectionControllerClientAura::HandleContextMenu(
const ContextMenuParams& params) {
if (params.source_type == ui::MENU_SOURCE_TOUCH && params.is_editable &&
params.selection_text.empty() && IsQuickMenuAvailable()) {
if (params.source_type == ui::MENU_SOURCE_LONG_PRESS &&
rwhva_->selection_controller()->insertion_active_or_requested() &&
IsQuickMenuAvailable()) {
DCHECK(params.is_editable);
DCHECK(params.selection_text.empty());
quick_menu_requested_ = true;
UpdateQuickMenu();
return true;
......
......@@ -151,7 +151,7 @@ class TouchSelectionControllerClientAuraTest : public ContentBrowserTest {
return false;
}
bool EmptyTextfield() { return ExecuteScript(shell(), "empty_textfield()"); }
bool ClearTextfield() { return ExecuteScript(shell(), "clear_textfield()"); }
RenderWidgetHostViewAura* GetRenderWidgetHostViewAura() {
return static_cast<RenderWidgetHostViewAura*>(
......@@ -282,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
// Clear textfield contents.
ASSERT_TRUE(EmptyTextfield());
ASSERT_TRUE(ClearTextfield());
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
......@@ -309,6 +309,43 @@ IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
// Tests that long-pressing on an empty textfield brings up the insertion handle
// and the quick menu.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
EmptyTextfieldInsertionOnLongPress) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
// Clear textfield contents.
ASSERT_TRUE(ClearTextfield());
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Long-press inside the textfield and wait for the insertion handle.
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideTextfield(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
// Check that insertion is active and the quick menu is showing.
EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
// Tests that the quick menu is hidden whenever a touch point is active.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
QuickMenuHiddenOnTouch) {
......
......@@ -37,7 +37,7 @@ function get_point_inside_textfield() {
get_point_inside(document.getElementById('textfield'));
}
function empty_textfield() {
function clear_textfield() {
document.getElementById('textfield').value = "";
}
......
......@@ -147,6 +147,10 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
ActiveStatus active_status() const { return active_status_; }
bool insertion_active_or_requested() const {
return activate_insertion_automatically_;
}
private:
friend class TouchSelectionControllerTestApi;
......
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