Skip to content

Commit

Permalink
Don't handle NaturalScroll in Chrome but pass it to CMT instead
Browse files Browse the repository at this point in the history
In order to support mice via CMT (Project Cobra) we will have to do
the natural scroll handling in the CMT driver instead of Chrome.

BUG=chromium:285663
TEST=test with touchpads and traditional mice. Everything should work as before,
touchpad should have natural scroll applied, scroll wheels should not.
Test changing the natural scroll property and see if it's applied correctly.
Also test if touch mice have natural scroll applied.

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=260926

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261478 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
denniskempin@chromium.org committed Apr 3, 2014
1 parent 336a094 commit 1587754
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 66 deletions.
9 changes: 0 additions & 9 deletions ash/sticky_keys/sticky_keys_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,6 @@ TEST_F(StickyKeysTest, MouseEventLocked) {
}

TEST_F(StickyKeysTest, ScrollEventOneshot) {
// Disable Australlian scrolling.
ui::DeviceDataManager::GetInstance()->set_natural_scroll_enabled(true);

scoped_ptr<ui::ScrollEvent> ev;
scoped_ptr<ui::KeyEvent> kev;
MockStickyKeysHandlerDelegate* mock_delegate =
Expand Down Expand Up @@ -670,9 +667,6 @@ TEST_F(StickyKeysTest, ScrollEventOneshot) {
}

TEST_F(StickyKeysTest, ScrollDirectionChanged) {
// Disable Australlian scrolling.
ui::DeviceDataManager::GetInstance()->set_natural_scroll_enabled(true);

scoped_ptr<ui::ScrollEvent> ev;
scoped_ptr<ui::KeyEvent> kev;
MockStickyKeysHandlerDelegate* mock_delegate =
Expand Down Expand Up @@ -707,9 +701,6 @@ TEST_F(StickyKeysTest, ScrollDirectionChanged) {
}

TEST_F(StickyKeysTest, ScrollEventLocked) {
// Disable Australlian scrolling.
ui::DeviceDataManager::GetInstance()->set_natural_scroll_enabled(true);

scoped_ptr<ui::ScrollEvent> ev;
scoped_ptr<ui::KeyEvent> kev;
MockStickyKeysHandlerDelegate* mock_delegate =
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/chrome_browser_main_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/owner_key_util.h"
#include "chrome/browser/chromeos/status/data_promo_notification.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/metrics/metrics_service.h"
Expand Down Expand Up @@ -714,7 +715,7 @@ void ChromeBrowserMainPartsChromeos::PreBrowserStart() {
if (ui::ShouldDefaultToNaturalScroll()) {
CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kNaturalScrollDefault);
ui::SetNaturalScroll(true);
system::InputDeviceSettings::Get()->SetTapToClick(true);
}

ChromeBrowserMainPartsLinux::PreBrowserStart();
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/login/login_display_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,9 @@ void ShowLoginWizard(const std::string& first_screen_name) {
system::InputDeviceSettings::Get()->SetTapToClick(
prefs->GetBoolean(prefs::kOwnerTapToClickEnabled));
}

ui::SetNaturalScroll(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNaturalScrollDefault));
system::InputDeviceSettings::Get()->SetNaturalScroll(
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNaturalScrollDefault));

gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void Preferences::ApplyPreferences(ApplyReason reason,
const bool enabled = natural_scroll_.GetValue();
DVLOG(1) << "Natural scroll set to " << enabled;
if (user_is_active)
ui::SetNaturalScroll(enabled);
touchpad_settings.SetNaturalScroll(enabled);
if (reason == REASON_PREF_CHANGED)
UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled);
else if (reason == REASON_INITIALIZATION)
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/chromeos/preferences_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class PreferencesTest : public LoginManagerTest {
EXPECT_EQ(prefs->GetBoolean(prefs::kEnableTouchpadThreeFingerClick),
input_settings_->current_touchpad_settings()
.GetThreeFingerClick());
EXPECT_EQ(prefs->GetBoolean(prefs::kNaturalScroll),
ui::IsNaturalScrollEnabled());
EXPECT_EQ(prefs->GetInteger(prefs::kMouseSensitivity),
input_settings_->current_mouse_settings().GetSensitivity());
EXPECT_EQ(prefs->GetInteger(prefs::kTouchpadSensitivity),
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/chromeos/system/fake_input_device_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ void FakeInputDeviceSettings::SetTapDragging(bool enabled) {
UpdateTouchpadSettings(settings);
}

void FakeInputDeviceSettings::SetNaturalScroll(bool enabled) {
TouchpadSettings settings;
settings.SetNaturalScroll(enabled);
UpdateTouchpadSettings(settings);
}

void FakeInputDeviceSettings::MouseExists(
const DeviceExistsCallback& callback) {
callback.Run(false);
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/system/fake_input_device_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class FakeInputDeviceSettings : public InputDeviceSettings {
virtual void UpdateMouseSettings(const MouseSettings& settings) OVERRIDE;
virtual void SetMouseSensitivity(int value) OVERRIDE;
virtual void SetPrimaryButtonRight(bool right) OVERRIDE;
virtual void SetNaturalScroll(bool enabled) OVERRIDE;

virtual bool ForceKeyboardDrivenUINavigation() OVERRIDE;
virtual void ReapplyTouchpadSettings() OVERRIDE;
virtual void ReapplyMouseSettings() OVERRIDE;
Expand Down
22 changes: 22 additions & 0 deletions chrome/browser/chromeos/system/input_device_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class InputDeviceSettingsImpl : public InputDeviceSettings {
virtual void SetTapToClick(bool enabled) OVERRIDE;
virtual void SetThreeFingerClick(bool enabled) OVERRIDE;
virtual void SetTapDragging(bool enabled) OVERRIDE;
virtual void SetNaturalScroll(bool enabled) OVERRIDE;
virtual void MouseExists(const DeviceExistsCallback& callback) OVERRIDE;
virtual void UpdateMouseSettings(const MouseSettings& update) OVERRIDE;
virtual void SetMouseSensitivity(int value) OVERRIDE;
Expand Down Expand Up @@ -186,6 +187,12 @@ void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) {
UpdateTouchpadSettings(settings);
}

void InputDeviceSettingsImpl::SetNaturalScroll(bool enabled) {
TouchpadSettings settings;
settings.SetNaturalScroll(enabled);
UpdateTouchpadSettings(settings);
}

void InputDeviceSettingsImpl::SetTapToClick(bool enabled) {
TouchpadSettings settings;
settings.SetTapToClick(enabled);
Expand Down Expand Up @@ -276,6 +283,7 @@ TouchpadSettings& TouchpadSettings::operator=(const TouchpadSettings& other) {
tap_to_click_ = other.tap_to_click_;
three_finger_click_ = other.three_finger_click_;
tap_dragging_ = other.tap_dragging_;
natural_scroll_ = other.natural_scroll_;
}
return *this;
}
Expand All @@ -296,6 +304,14 @@ bool TouchpadSettings::GetTapToClick() const {
return tap_to_click_.value();
}

void TouchpadSettings::SetNaturalScroll(bool enabled) {
natural_scroll_.Set(enabled);
}

bool TouchpadSettings::GetNaturalScroll() const {
return natural_scroll_.value();
}

void TouchpadSettings::SetThreeFingerClick(bool enabled) {
three_finger_click_.Set(enabled);
}
Expand Down Expand Up @@ -339,6 +355,12 @@ bool TouchpadSettings::Update(const TouchpadSettings& settings,
if (argv)
AddTPControlArguments("tapdrag", tap_dragging_.value(), argv);
}
if (natural_scroll_.Update(settings.natural_scroll_)) {
updated = true;
if (argv)
AddTPControlArguments("australian_scrolling", natural_scroll_.value(),
argv);
}
return updated;
}

Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/chromeos/system/input_device_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class TouchpadSettings {
void SetTapDragging(bool enabled);
bool GetTapDragging() const;

void SetNaturalScroll(bool enabled);
bool GetNaturalScroll() const;

// Updates |this| with |settings|. If at least one setting was updated returns
// true.
// |argv| is filled with arguments of script, that should be launched in order
Expand All @@ -107,6 +110,7 @@ class TouchpadSettings {
internal::Optional<bool> tap_to_click_;
internal::Optional<bool> three_finger_click_;
internal::Optional<bool> tap_dragging_;
internal::Optional<bool> natural_scroll_;
};

// Auxiliary class used to update several mouse settings at a time. User
Expand Down Expand Up @@ -173,6 +177,9 @@ class InputDeviceSettings {
// Turns tap-dragging on/off.
virtual void SetTapDragging(bool enabled) = 0;

// Turns natural scrolling on/off for all devices except wheel mice
virtual void SetNaturalScroll(bool enabled) = 0;

// Calls |callback| asynchronously after determining if a mouse is connected.
virtual void MouseExists(const DeviceExistsCallback& callback) = 0;

Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/ui/views/ash/tab_scrubber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) {
event->StopPropagation();

float x_offset = event->x_offset();
if (!ui::IsNaturalScrollEnabled())
x_offset = -x_offset;
int last_tab_index = highlighted_tab_ == -1 ?
browser->tab_strip_model()->active_index() : highlighted_tab_;
if (!scrubbing_) {
Expand Down
6 changes: 0 additions & 6 deletions ui/events/event_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
double* start_time,
double* end_time);

// Enable/disable natural scrolling for touchpads.
EVENTS_EXPORT void SetNaturalScroll(bool enabled);

// In natural scrolling enabled for touchpads?
EVENTS_EXPORT bool IsNaturalScrollEnabled();

// Returns whether natural scrolling should be used for touchpad.
EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();

Expand Down
33 changes: 9 additions & 24 deletions ui/events/x/device_data_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ DeviceDataManager* DeviceDataManager::GetInstance() {
}

DeviceDataManager::DeviceDataManager()
: natural_scroll_enabled_(false),
xi_opcode_(-1),
: xi_opcode_(-1),
atom_cache_(gfx::GetXDisplay(), kCachedAtoms),
button_map_count_(0) {
CHECK(gfx::GetXDisplay());
Expand Down Expand Up @@ -177,14 +176,6 @@ bool DeviceDataManager::IsXInput2Available() const {
return xi_opcode_ != -1;
}

float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const {
// Natural scroll is touchpad-only.
if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid])
return -1.0f;

return natural_scroll_enabled_ ? 1.0f : -1.0f;
}

void DeviceDataManager::UpdateDeviceList(Display* display) {
cmt_devices_.reset();
touchpads_.reset();
Expand Down Expand Up @@ -460,20 +451,17 @@ void DeviceDataManager::GetScrollOffsets(const base::NativeEvent& native_event,
*y_offset_ordinal = 0;
*finger_count = 2;

XIDeviceEvent* xiev =
static_cast<XIDeviceEvent*>(native_event->xcookie.data);
const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
EventData data;
GetEventRawData(*native_event, &data);

if (data.find(DT_CMT_SCROLL_X) != data.end())
*x_offset = data[DT_CMT_SCROLL_X] * natural_scroll_factor;
*x_offset = data[DT_CMT_SCROLL_X];
if (data.find(DT_CMT_SCROLL_Y) != data.end())
*y_offset = data[DT_CMT_SCROLL_Y] * natural_scroll_factor;
*y_offset = data[DT_CMT_SCROLL_Y];
if (data.find(DT_CMT_ORDINAL_X) != data.end())
*x_offset_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor;
*x_offset_ordinal = data[DT_CMT_ORDINAL_X];
if (data.find(DT_CMT_ORDINAL_Y) != data.end())
*y_offset_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor;
*y_offset_ordinal = data[DT_CMT_ORDINAL_Y];
if (data.find(DT_CMT_FINGER_COUNT) != data.end())
*finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
}
Expand All @@ -488,22 +476,19 @@ void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event,
*vy_ordinal = 0;
*is_cancel = false;

XIDeviceEvent* xiev =
static_cast<XIDeviceEvent*>(native_event->xcookie.data);
const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
EventData data;
GetEventRawData(*native_event, &data);

if (data.find(DT_CMT_FLING_X) != data.end())
*vx = data[DT_CMT_FLING_X] * natural_scroll_factor;
*vx = data[DT_CMT_FLING_X];
if (data.find(DT_CMT_FLING_Y) != data.end())
*vy = data[DT_CMT_FLING_Y] * natural_scroll_factor;
*vy = data[DT_CMT_FLING_Y];
if (data.find(DT_CMT_FLING_STATE) != data.end())
*is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]);
if (data.find(DT_CMT_ORDINAL_X) != data.end())
*vx_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor;
*vx_ordinal = data[DT_CMT_ORDINAL_X];
if (data.find(DT_CMT_ORDINAL_Y) != data.end())
*vy_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor;
*vy_ordinal = data[DT_CMT_ORDINAL_Y];
}

void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event,
Expand Down
10 changes: 0 additions & 10 deletions ui/events/x/device_data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,9 @@ class EVENTS_BASE_EXPORT DeviceDataManager {
// Returns the DeviceDataManager singleton.
static DeviceDataManager* GetInstance();

// Natural scroll setter/getter.
bool natural_scroll_enabled() const { return natural_scroll_enabled_; }
void set_natural_scroll_enabled(bool enabled) {
natural_scroll_enabled_ = enabled;
}

// Returns if XInput2 is available on the system.
bool IsXInput2Available() const;

// Get the natural scroll direction multiplier (1.0f or -1.0f).
float GetNaturalScrollFactor(int sourceid) const;

// Updates the list of devices.
void UpdateDeviceList(Display* display);

Expand Down Expand Up @@ -248,7 +239,6 @@ class EVENTS_BASE_EXPORT DeviceDataManager {
static const int kMaxDeviceNum = 128;
static const int kMaxXIEventType = XI_LASTEVENT + 1;
static const int kMaxSlotNum = 10;
bool natural_scroll_enabled_;

// Major opcode for the XInput extension. Used to identify XInput events.
int xi_opcode_;
Expand Down
8 changes: 0 additions & 8 deletions ui/events/x/events_x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,6 @@ bool GetGestureTimes(const base::NativeEvent& native_event,
return true;
}

void SetNaturalScroll(bool enabled) {
DeviceDataManager::GetInstance()->set_natural_scroll_enabled(enabled);
}

bool IsNaturalScrollEnabled() {
return DeviceDataManager::GetInstance()->natural_scroll_enabled();
}

bool IsTouchpadEvent(const base::NativeEvent& event) {
return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event);
}
Expand Down

0 comments on commit 1587754

Please sign in to comment.