Commit 8df49a3b authored by Katie D's avatar Katie D Committed by Commit Bot

Fix autoclick cancel click with stabilization "off".

Movements greater than the movement threshold should cancel
autoclick with stabilization "off".

Bug: 957113
Change-Id: Ibce4a7f168241a16a169c5811692807556eb51bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584784Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654568}
parent bd78483a
...@@ -183,7 +183,9 @@ void AutoclickController::UpdateAutoclickRingWidget( ...@@ -183,7 +183,9 @@ void AutoclickController::UpdateAutoclickRingWidget(
} }
void AutoclickController::DoAutoclickAction() { void AutoclickController::DoAutoclickAction() {
aura::Window* root_window = wm::GetRootWindowAt(anchor_location_); // The gesture_anchor_location_ is the position at which the animation is
// anchored, and where the click should occur.
aura::Window* root_window = wm::GetRootWindowAt(gesture_anchor_location_);
DCHECK(root_window) << "Root window not found while attempting autoclick."; DCHECK(root_window) << "Root window not found while attempting autoclick.";
// But if the thing that would be acted upon is an autoclick menu button, do a // But if the thing that would be acted upon is an autoclick menu button, do a
...@@ -191,8 +193,9 @@ void AutoclickController::DoAutoclickAction() { ...@@ -191,8 +193,9 @@ void AutoclickController::DoAutoclickAction() {
// ensures that no matter the autoclick setting, users can always change to // ensures that no matter the autoclick setting, users can always change to
// another autoclick setting. By using a fake click we avoid closing dialogs // another autoclick setting. By using a fake click we avoid closing dialogs
// and menus, allowing autoclick users to interact with those items. // and menus, allowing autoclick users to interact with those items.
if (!DragInProgress() && AutoclickMenuContainsPoint(anchor_location_)) { if (!DragInProgress() &&
menu_bubble_controller_->ClickOnBubble(anchor_location_, AutoclickMenuContainsPoint(gesture_anchor_location_)) {
menu_bubble_controller_->ClickOnBubble(gesture_anchor_location_,
mouse_event_flags_); mouse_event_flags_);
// Reset UI. // Reset UI.
CancelAutoclickAction(); CancelAutoclickAction();
...@@ -204,7 +207,7 @@ void AutoclickController::DoAutoclickAction() { ...@@ -204,7 +207,7 @@ void AutoclickController::DoAutoclickAction() {
mojom::AutoclickEventType in_progress_event_type = event_type_; mojom::AutoclickEventType in_progress_event_type = event_type_;
RecordUserAction(in_progress_event_type); RecordUserAction(in_progress_event_type);
gfx::Point location_in_pixels(anchor_location_); gfx::Point location_in_pixels(gesture_anchor_location_);
::wm::ConvertPointFromScreen(root_window, &location_in_pixels); ::wm::ConvertPointFromScreen(root_window, &location_in_pixels);
aura::WindowTreeHost* host = root_window->GetHost(); aura::WindowTreeHost* host = root_window->GetHost();
host->ConvertDIPToPixels(&location_in_pixels); host->ConvertDIPToPixels(&location_in_pixels);
...@@ -283,7 +286,9 @@ void AutoclickController::StartAutoclickGesture() { ...@@ -283,7 +286,9 @@ void AutoclickController::StartAutoclickGesture() {
} }
// Otherwise, go ahead and start the gesture. // Otherwise, go ahead and start the gesture.
} }
// The anchor is always the point in the screen where the timer starts. // The anchor is always the point in the screen where the timer starts, and is
// used to determine when the cursor has moved far enough to cancel the
// autoclick.
anchor_location_ = gesture_anchor_location_; anchor_location_ = gesture_anchor_location_;
autoclick_ring_handler_->StartGesture( autoclick_ring_handler_->StartGesture(
delay_ - CalculateStartGestureDelay(delay_), anchor_location_, delay_ - CalculateStartGestureDelay(delay_), anchor_location_,
...@@ -428,7 +433,7 @@ void AutoclickController::OnMouseEvent(ui::MouseEvent* event) { ...@@ -428,7 +433,7 @@ void AutoclickController::OnMouseEvent(ui::MouseEvent* event) {
} else if (autoclick_timer_->IsRunning() && !stabilize_click_position_) { } else if (autoclick_timer_->IsRunning() && !stabilize_click_position_) {
// If we are not stabilizing the click position, update the gesture // If we are not stabilizing the click position, update the gesture
// center with each mouse move event. // center with each mouse move event.
anchor_location_ = point_in_screen; gesture_anchor_location_ = point_in_screen;
autoclick_ring_handler_->SetGestureCenter(point_in_screen, widget_.get()); autoclick_ring_handler_->SetGestureCenter(point_in_screen, widget_.get());
} }
} else if (event->type() == ui::ET_MOUSE_PRESSED || } else if (event->type() == ui::ET_MOUSE_PRESSED ||
......
...@@ -232,9 +232,20 @@ TEST_F(AutoclickTest, MovementThreshold) { ...@@ -232,9 +232,20 @@ TEST_F(AutoclickTest, MovementThreshold) {
aura::Window::Windows root_windows = Shell::GetAllRootWindows(); aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(2u, root_windows.size()); EXPECT_EQ(2u, root_windows.size());
// Try at a couple different thresholds. int animation_delay = 5;
for (int movement_threshold = 10; movement_threshold < 50;
movement_threshold += 10) { const struct {
int movement_threshold;
bool stabilize_click_position;
} kTestCases[] = {
{10, false}, {20, false}, {30, false}, {40, false}, {50, false},
{10, true}, {20, true}, {30, true}, {40, true}, {50, true},
};
for (const auto& test : kTestCases) {
GetAutoclickController()->set_stabilize_click_position(
test.stabilize_click_position);
int movement_threshold = test.movement_threshold;
GetAutoclickController()->SetMovementThreshold(movement_threshold); GetAutoclickController()->SetMovementThreshold(movement_threshold);
// Run test for the secondary display too to test fix for crbug.com/449870. // Run test for the secondary display too to test fix for crbug.com/449870.
...@@ -243,6 +254,7 @@ TEST_F(AutoclickTest, MovementThreshold) { ...@@ -243,6 +254,7 @@ TEST_F(AutoclickTest, MovementThreshold) {
GetAutoclickController()->SetEnabled(true); GetAutoclickController()->SetEnabled(true);
GetEventGenerator()->MoveMouseTo(center); GetEventGenerator()->MoveMouseTo(center);
ClearMouseEvents();
EXPECT_EQ(2u, WaitForMouseEvents().size()); EXPECT_EQ(2u, WaitForMouseEvents().size());
// Small mouse movements should not trigger an autoclick, i.e. movements // Small mouse movements should not trigger an autoclick, i.e. movements
...@@ -265,11 +277,28 @@ TEST_F(AutoclickTest, MovementThreshold) { ...@@ -265,11 +277,28 @@ TEST_F(AutoclickTest, MovementThreshold) {
center + center +
gfx::Vector2d(movement_threshold + 1, movement_threshold + 1)); gfx::Vector2d(movement_threshold + 1, movement_threshold + 1));
EXPECT_EQ(2u, WaitForMouseEvents().size()); EXPECT_EQ(2u, WaitForMouseEvents().size());
// Moving outside the threshold after the gesture begins should cancel
// the autoclick. Update the delay so we can do events between the initial
// trigger of the feature and the click.
int full_delay = UpdateAnimationDelayAndGetFullDelay(animation_delay);
GetEventGenerator()->MoveMouseTo(
center - gfx::Vector2d(movement_threshold, movement_threshold));
FastForwardBy(animation_delay + 1);
GetEventGenerator()->MoveMouseTo(center);
ClearMouseEvents();
FastForwardBy(full_delay);
EXPECT_EQ(0u, GetMouseEvents().size());
// Move it out of the way so the next cycle starts properly.
GetEventGenerator()->MoveMouseTo(gfx::Point(0, 0));
GetAutoclickController()->SetAutoclickDelay(base::TimeDelta());
} }
} }
// Reset to default threshold. // Reset to defaults.
GetAutoclickController()->SetMovementThreshold(20); GetAutoclickController()->SetMovementThreshold(20);
GetAutoclickController()->set_stabilize_click_position(false);
} }
TEST_F(AutoclickTest, MovementWithinThresholdWhileTimerRunning) { TEST_F(AutoclickTest, MovementWithinThresholdWhileTimerRunning) {
......
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