Commit 67e23385 authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Enable UnadjustedMovement option in Chrome OS

This uses the InputControllerEvDev to allow application to turn off
mouse acceleration when using pointer lock on Chrome OS.

Bug: 982379
Change-Id: Ie3b9d5f67d7a5514b90b25d8b13e9f6f5b01e390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2188908
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781628}
parent a35682b6
...@@ -1907,6 +1907,7 @@ test("ash_unittests") { ...@@ -1907,6 +1907,7 @@ test("ash_unittests") {
"home_screen/home_launcher_gesture_handler_unittest.cc", "home_screen/home_launcher_gesture_handler_unittest.cc",
"home_screen/home_screen_controller_unittest.cc", "home_screen/home_screen_controller_unittest.cc",
"home_screen/swipe_home_to_overview_controller_unittest.cc", "home_screen/swipe_home_to_overview_controller_unittest.cc",
"host/ash_window_tree_host_platform_unittest.cc",
"ime/ime_controller_impl_unittest.cc", "ime/ime_controller_impl_unittest.cc",
"keyboard/keyboard_controller_impl_unittest.cc", "keyboard/keyboard_controller_impl_unittest.cc",
"keyboard/virtual_keyboard_controller_unittest.cc", "keyboard/virtual_keyboard_controller_unittest.cc",
...@@ -2289,6 +2290,7 @@ test("ash_unittests") { ...@@ -2289,6 +2290,7 @@ test("ash_unittests") {
"//ui/message_center", "//ui/message_center",
"//ui/message_center:test_support", "//ui/message_center:test_support",
"//ui/message_center/public/cpp", "//ui/message_center/public/cpp",
"//ui/ozone",
"//ui/ozone/testhelpers:mock_gesture_properties_service", "//ui/ozone/testhelpers:mock_gesture_properties_service",
"//ui/resources", "//ui/resources",
"//ui/snapshot", "//ui/snapshot",
......
...@@ -20,4 +20,7 @@ specific_include_rules = { ...@@ -20,4 +20,7 @@ specific_include_rules = {
# ozone. # ozone.
"+ui/events/ozone/chromeos/cursor_controller.h", "+ui/events/ozone/chromeos/cursor_controller.h",
], ],
"ash_window_tree_host_platform_unittest.cc" : [
"+ash/test/ash_test_base.h",
]
} }
...@@ -23,18 +23,36 @@ ...@@ -23,18 +23,36 @@
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/platform_window.h" #include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
namespace ash { namespace ash {
class ScopedEnableUnadjustedMouseEventsOzone
: public aura::ScopedEnableUnadjustedMouseEvents {
public:
explicit ScopedEnableUnadjustedMouseEventsOzone(
ui::InputController* input_controller) {
input_controller_ = input_controller;
input_controller_->SuspendMouseAcceleration();
}
~ScopedEnableUnadjustedMouseEventsOzone() override {
input_controller_->EndMouseAccelerationSuspension();
}
private:
ui::InputController* input_controller_;
};
AshWindowTreeHostPlatform::AshWindowTreeHostPlatform( AshWindowTreeHostPlatform::AshWindowTreeHostPlatform(
ui::PlatformWindowInitProperties properties) ui::PlatformWindowInitProperties properties)
: aura::WindowTreeHostPlatform(std::move(properties), : aura::WindowTreeHostPlatform(std::move(properties),
window_factory::NewWindow()), window_factory::NewWindow()),
transformer_helper_(this) { transformer_helper_(this),
input_controller_(
ui::OzonePlatform::GetInstance()->GetInputController()) {
CommonInit(); CommonInit();
} }
...@@ -157,6 +175,12 @@ void AshWindowTreeHostPlatform::SetTapToClickPaused(bool state) { ...@@ -157,6 +175,12 @@ void AshWindowTreeHostPlatform::SetTapToClickPaused(bool state) {
state); state);
} }
std::unique_ptr<aura::ScopedEnableUnadjustedMouseEvents>
AshWindowTreeHostPlatform::RequestUnadjustedMovement() {
return std::make_unique<ScopedEnableUnadjustedMouseEventsOzone>(
input_controller_);
}
void AshWindowTreeHostPlatform::DispatchEvent(ui::Event* event) { void AshWindowTreeHostPlatform::DispatchEvent(ui::Event* event) {
TRACE_EVENT0("input", "AshWindowTreeHostPlatform::DispatchEvent"); TRACE_EVENT0("input", "AshWindowTreeHostPlatform::DispatchEvent");
if (event->IsLocatedEvent()) if (event->IsLocatedEvent())
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/host/ash_window_tree_host.h" #include "ash/host/ash_window_tree_host.h"
#include "ash/host/transformer_helper.h" #include "ash/host/transformer_helper.h"
#include "ui/aura/window_tree_host_platform.h" #include "ui/aura/window_tree_host_platform.h"
#include "ui/ozone/public/input_controller.h"
namespace ui { namespace ui {
struct PlatformWindowInitProperties; struct PlatformWindowInitProperties;
...@@ -18,6 +19,7 @@ struct PlatformWindowInitProperties; ...@@ -18,6 +19,7 @@ struct PlatformWindowInitProperties;
namespace ash { namespace ash {
class ExtendedMouseWarpControllerTest; class ExtendedMouseWarpControllerTest;
class AshWindowTreeHostPlatformTest;
class ASH_EXPORT AshWindowTreeHostPlatform class ASH_EXPORT AshWindowTreeHostPlatform
: public AshWindowTreeHost, : public AshWindowTreeHost,
...@@ -32,6 +34,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform ...@@ -32,6 +34,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform
friend ExtendedMouseWarpControllerTest; friend ExtendedMouseWarpControllerTest;
FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest,
CheckHostPointToScreenInMouseWarpRegion); CheckHostPointToScreenInMouseWarpRegion);
friend AshWindowTreeHostPlatformTest;
FRIEND_TEST_ALL_PREFIXES(AshWindowTreeHostPlatformTest, UnadjustedMovement);
AshWindowTreeHostPlatform(); AshWindowTreeHostPlatform();
...@@ -57,6 +61,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform ...@@ -57,6 +61,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform
void OnCursorVisibilityChangedNative(bool show) override; void OnCursorVisibilityChangedNative(bool show) override;
void SetBoundsInPixels(const gfx::Rect& bounds) override; void SetBoundsInPixels(const gfx::Rect& bounds) override;
void DispatchEvent(ui::Event* event) override; void DispatchEvent(ui::Event* event) override;
std::unique_ptr<aura::ScopedEnableUnadjustedMouseEvents>
RequestUnadjustedMovement() override;
private: private:
// All constructors call into this. // All constructors call into this.
...@@ -67,6 +73,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform ...@@ -67,6 +73,8 @@ class ASH_EXPORT AshWindowTreeHostPlatform
TransformerHelper transformer_helper_; TransformerHelper transformer_helper_;
ui::InputController* input_controller_;
gfx::Rect last_cursor_confine_bounds_in_pixels_; gfx::Rect last_cursor_confine_bounds_in_pixels_;
DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostPlatform); DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostPlatform);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/host/ash_window_tree_host_platform.h"
#include "ash/test/ash_test_base.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h"
namespace ash {
class AshWindowTreeHostPlatformTest : public AshTestBase {
public:
AshWindowTreeHostPlatformTest() = default;
~AshWindowTreeHostPlatformTest() override = default;
};
class TestInputController : public ui::InputController {
public:
TestInputController() = default;
~TestInputController() override = default;
// InputController:
void SuspendMouseAcceleration() override { acceleration_suspended_ = true; }
void EndMouseAccelerationSuspension() override {
acceleration_suspended_ = false;
}
// these are all stubs that are not used yet in these tests
bool HasMouse() override { return false; }
bool HasTouchpad() override { return false; }
bool IsCapsLockEnabled() override { return false; }
void SetCapsLockEnabled(bool enabled) override {}
void SetNumLockEnabled(bool enabled) override {}
bool IsAutoRepeatEnabled() override { return true; }
void SetAutoRepeatEnabled(bool enabled) override {}
void SetAutoRepeatRate(const base::TimeDelta& delay,
const base::TimeDelta& interval) override {}
void GetAutoRepeatRate(base::TimeDelta* delay,
base::TimeDelta* interval) override {}
void SetCurrentLayoutByName(const std::string& layout_name) override {}
void SetTouchEventLoggingEnabled(bool enabled) override {
NOTIMPLEMENTED_LOG_ONCE();
}
void SetTouchpadSensitivity(int value) override {}
void SetTouchpadScrollSensitivity(int value) override {}
void SetTapToClick(bool enabled) override {}
void SetThreeFingerClick(bool enabled) override {}
void SetTapDragging(bool enabled) override {}
void SetNaturalScroll(bool enabled) override {}
void SetMouseSensitivity(int value) override {}
void SetMouseScrollSensitivity(int value) override {}
void SetPrimaryButtonRight(bool right) override {}
void SetMouseReverseScroll(bool enabled) override {}
void SetMouseAcceleration(bool enabled) override {}
void SetMouseScrollAcceleration(bool enabled) override {}
void SetTouchpadAcceleration(bool enabled) override {}
void SetTouchpadScrollAcceleration(bool enabled) override {}
void SetTapToClickPaused(bool state) override {}
void GetTouchDeviceStatus(GetTouchDeviceStatusReply reply) override {
std::move(reply).Run(std::string());
}
void GetTouchEventLog(const base::FilePath& out_dir,
GetTouchEventLogReply reply) override {
std::move(reply).Run(std::vector<base::FilePath>());
}
void SetInternalTouchpadEnabled(bool enabled) override {}
bool IsInternalTouchpadEnabled() const override { return false; }
void SetTouchscreensEnabled(bool enabled) override {}
void SetInternalKeyboardFilter(
bool enable_filter,
std::vector<ui::DomCode> allowed_keys) override {}
void GetGesturePropertiesService(
mojo::PendingReceiver<ui::ozone::mojom::GesturePropertiesService>
receiver) override {}
bool GetAccelerationSuspended() { return acceleration_suspended_; }
private:
// member variable used to keep track of mouse acceleration suspension
bool acceleration_suspended_ = false;
};
TEST_F(AshWindowTreeHostPlatformTest, UnadjustedMovement) {
AshWindowTreeHostPlatform host;
auto test_input_controller = std::make_unique<TestInputController>();
host.input_controller_ = test_input_controller.get();
std::unique_ptr<aura::ScopedEnableUnadjustedMouseEvents>
unadjusted_movement_context = host.RequestUnadjustedMovement();
EXPECT_TRUE(unadjusted_movement_context.get() != nullptr);
EXPECT_TRUE(test_input_controller->GetAccelerationSuspended());
unadjusted_movement_context.reset();
EXPECT_FALSE(test_input_controller->GetAccelerationSuspended());
}
} // namespace ash
...@@ -820,7 +820,7 @@ IN_PROC_BROWSER_TEST_F(PointerLockBrowserTestWithOptions, UnadjustedMovement) { ...@@ -820,7 +820,7 @@ IN_PROC_BROWSER_TEST_F(PointerLockBrowserTestWithOptions, UnadjustedMovement) {
#if defined(USE_AURA) #if defined(USE_AURA)
// TODO(https://crbug.com/982379): Remove failure test when fully implemented // TODO(https://crbug.com/982379): Remove failure test when fully implemented
#if defined(OS_WIN) #if defined(OS_WIN) || defined(OS_CHROMEOS)
#define MAYBE_ChangeUnadjustedMovementFailure \ #define MAYBE_ChangeUnadjustedMovementFailure \
DISABLED_ChangeUnadjustedMovementFailure DISABLED_ChangeUnadjustedMovementFailure
#else #else
......
...@@ -348,6 +348,10 @@ test("aura_unittests") { ...@@ -348,6 +348,10 @@ test("aura_unittests") {
"//ui/wm", "//ui/wm",
] ]
if (use_ozone) {
deps += [ "//ui/ozone" ]
}
data_deps = [ "//third_party/mesa_headers" ] data_deps = [ "//third_party/mesa_headers" ]
} }
......
...@@ -247,7 +247,10 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, ...@@ -247,7 +247,10 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
// Requests using unadjusted movement mouse events, i.e. WM_INPUT on Windows. // Requests using unadjusted movement mouse events, i.e. WM_INPUT on Windows.
// Returns a ScopedEnableUnadjustedMouseEvents instance which stops using // Returns a ScopedEnableUnadjustedMouseEvents instance which stops using
// unadjusted mouse events when destroyed, returns nullptr if unadjusted mouse // unadjusted mouse events when destroyed, returns nullptr if unadjusted mouse
// event is not not implemented or failed. // event is not not implemented or failed. On some platforms this function may
// temporarily affect the global state of mouse settings. This function is
// currently only intended to be used with PointerLock as it is not set up for
// multiple calls.
virtual std::unique_ptr<ScopedEnableUnadjustedMouseEvents> virtual std::unique_ptr<ScopedEnableUnadjustedMouseEvents>
RequestUnadjustedMovement(); RequestUnadjustedMovement();
......
...@@ -169,10 +169,29 @@ void InputControllerEvdev::SetMouseReverseScroll(bool enabled) { ...@@ -169,10 +169,29 @@ void InputControllerEvdev::SetMouseReverseScroll(bool enabled) {
} }
void InputControllerEvdev::SetMouseAcceleration(bool enabled) { void InputControllerEvdev::SetMouseAcceleration(bool enabled) {
if (mouse_acceleration_suspended_) {
stored_mouse_acceleration_setting_ = enabled;
return;
}
input_device_settings_.mouse_acceleration_enabled = enabled; input_device_settings_.mouse_acceleration_enabled = enabled;
ScheduleUpdateDeviceSettings(); ScheduleUpdateDeviceSettings();
} }
void InputControllerEvdev::SuspendMouseAcceleration() {
// multiple calls to suspend are currently not supported.
DCHECK(!mouse_acceleration_suspended_);
stored_mouse_acceleration_setting_ =
input_device_settings_.mouse_acceleration_enabled;
mouse_acceleration_suspended_ = true;
input_device_settings_.mouse_acceleration_enabled = false;
ScheduleUpdateDeviceSettings();
}
void InputControllerEvdev::EndMouseAccelerationSuspension() {
mouse_acceleration_suspended_ = false;
SetMouseAcceleration(stored_mouse_acceleration_setting_);
}
void InputControllerEvdev::SetMouseScrollAcceleration(bool enabled) { void InputControllerEvdev::SetMouseScrollAcceleration(bool enabled) {
input_device_settings_.mouse_scroll_acceleration_enabled = enabled; input_device_settings_.mouse_scroll_acceleration_enabled = enabled;
ScheduleUpdateDeviceSettings(); ScheduleUpdateDeviceSettings();
......
...@@ -62,6 +62,8 @@ class COMPONENT_EXPORT(EVDEV) InputControllerEvdev : public InputController { ...@@ -62,6 +62,8 @@ class COMPONENT_EXPORT(EVDEV) InputControllerEvdev : public InputController {
void SetPrimaryButtonRight(bool right) override; void SetPrimaryButtonRight(bool right) override;
void SetMouseReverseScroll(bool enabled) override; void SetMouseReverseScroll(bool enabled) override;
void SetMouseAcceleration(bool enabled) override; void SetMouseAcceleration(bool enabled) override;
void SuspendMouseAcceleration() override;
void EndMouseAccelerationSuspension() override;
void SetMouseScrollAcceleration(bool enabled) override; void SetMouseScrollAcceleration(bool enabled) override;
void SetTouchpadAcceleration(bool enabled) override; void SetTouchpadAcceleration(bool enabled) override;
void SetTouchpadScrollAcceleration(bool enabled) override; void SetTouchpadScrollAcceleration(bool enabled) override;
...@@ -91,6 +93,13 @@ class COMPONENT_EXPORT(EVDEV) InputControllerEvdev : public InputController { ...@@ -91,6 +93,13 @@ class COMPONENT_EXPORT(EVDEV) InputControllerEvdev : public InputController {
// Configuration that needs to be passed on to InputDeviceFactory. // Configuration that needs to be passed on to InputDeviceFactory.
InputDeviceSettingsEvdev input_device_settings_; InputDeviceSettingsEvdev input_device_settings_;
// Indicates when the mouse acceleration is turned off for PointerLock.
bool mouse_acceleration_suspended_ = false;
// Holds mouse acceleration setting while suspended.
// Should only be considered a valid setting while
// |mouse_acceleration_suspended| is true.
bool stored_mouse_acceleration_setting_ = false;
// Task to update config from input_device_settings_ is pending. // Task to update config from input_device_settings_ is pending.
bool settings_update_pending_ = false; bool settings_update_pending_ = false;
......
...@@ -46,6 +46,8 @@ class StubInputController : public InputController { ...@@ -46,6 +46,8 @@ class StubInputController : public InputController {
void SetPrimaryButtonRight(bool right) override {} void SetPrimaryButtonRight(bool right) override {}
void SetMouseReverseScroll(bool enabled) override {} void SetMouseReverseScroll(bool enabled) override {}
void SetMouseAcceleration(bool enabled) override {} void SetMouseAcceleration(bool enabled) override {}
void SuspendMouseAcceleration() override {}
void EndMouseAccelerationSuspension() override {}
void SetMouseScrollAcceleration(bool enabled) override {} void SetMouseScrollAcceleration(bool enabled) override {}
void SetTouchpadAcceleration(bool enabled) override {} void SetTouchpadAcceleration(bool enabled) override {}
void SetTouchpadScrollAcceleration(bool enabled) override {} void SetTouchpadScrollAcceleration(bool enabled) override {}
......
...@@ -73,6 +73,8 @@ class COMPONENT_EXPORT(OZONE_BASE) InputController { ...@@ -73,6 +73,8 @@ class COMPONENT_EXPORT(OZONE_BASE) InputController {
virtual void SetPrimaryButtonRight(bool right) = 0; virtual void SetPrimaryButtonRight(bool right) = 0;
virtual void SetMouseReverseScroll(bool enabled) = 0; virtual void SetMouseReverseScroll(bool enabled) = 0;
virtual void SetMouseAcceleration(bool enabled) = 0; virtual void SetMouseAcceleration(bool enabled) = 0;
virtual void SuspendMouseAcceleration() = 0;
virtual void EndMouseAccelerationSuspension() = 0;
virtual void SetMouseScrollAcceleration(bool enabled) = 0; virtual void SetMouseScrollAcceleration(bool enabled) = 0;
// Touch log collection. // Touch log collection.
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
namespace ui { namespace ui {
namespace { namespace {
OzonePlatform* g_instance = nullptr; OzonePlatform* g_instance = nullptr;
void EnsureInstance() { void EnsureInstance() {
......
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