Commit bd36e178 authored by dzhioev@chromium.org's avatar dzhioev@chromium.org

InputDeviceSettings refactoring.

Standalone functions replaced with InputDeviceSettings interface and
singleton implementation InputDeviceSettingsImpl.
Changing of input device settings became more efficient for two reasons:
1) InputDeviceSettingsImpl caches previously set values and doesn't
call tpcontrol/mousecontrol if client tries to set same values twice.
2) New methods for changing several settings at a time was implemented. For
example, If client wants to change several touchpad settings at a time,
he can use UpdateTouchpadSettings method that will result in one (or
zero) invocation of tpcontrol.

Implemented FakeInputDeviceSettings for use in tests.

These changes are needed for upcoming changes in chromeos::Preferences.

BUG=325564
TEST=manually
TBR=scheib

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251399 0039d316-1c4b-4281-b951-d872f2087c98
parent 8aae9e05
......@@ -21,7 +21,8 @@ const int kModifierMask = ui::EF_SHIFT_DOWN;
bool ShouldStripModifiersForArrowKeysAndEnter() {
if (UserManager::IsInitialized() &&
!UserManager::Get()->IsUserLoggedIn()) {
return system::keyboard_settings::ForceKeyboardDrivenUINavigation();
return system::InputDeviceSettings::Get()
->ForceKeyboardDrivenUINavigation();
}
return false;
......
......@@ -958,7 +958,7 @@ void LoginDisplayHostImpl::InitLoginWindowAndView() {
if (login_window_)
return;
if (system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation()) {
views::FocusManager::set_arrow_key_traversal_enabled(true);
focus_ring_controller_.reset(new FocusRingController);
......@@ -1083,10 +1083,10 @@ void ShowLoginWizard(const std::string& first_screen_name) {
PrefService* prefs = g_browser_process->local_state();
// Apply owner preferences for tap-to-click and mouse buttons swap for
// login screen.
system::mouse_settings::SetPrimaryButtonRight(
system::InputDeviceSettings::Get()->SetPrimaryButtonRight(
prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight));
system::touchpad_settings::SetTapToClick(
prefs->GetBoolean(prefs::kOwnerTapToClickEnabled));
system::InputDeviceSettings::Get()->SetTapToClick(
prefs->GetBoolean(prefs::kOwnerTapToClickEnabled));
}
ui::SetNaturalScroll(CommandLine::ForCurrentProcess()->HasSwitch(
......
......@@ -407,6 +407,8 @@ void Preferences::OnPreferenceChanged(const std::string& pref_name) {
}
void Preferences::NotifyPrefChanged(const std::string* pref_name) {
system::TouchpadSettings touchpad_settings;
system::MouseSettings mouse_settings;
if (!pref_name || *pref_name == prefs::kPerformanceTracingEnabled) {
const bool enabled = performance_tracing_enabled_.GetValue();
if (enabled)
......@@ -417,7 +419,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kTapToClickEnabled)) {
const bool enabled = tap_to_click_enabled_.GetValue();
system::touchpad_settings::SetTapToClick(enabled);
touchpad_settings.SetTapToClick(enabled);
if (pref_name)
UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
else
......@@ -433,7 +435,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kTapDraggingEnabled)) {
const bool enabled = tap_dragging_enabled_.GetValue();
system::touchpad_settings::SetTapDragging(enabled);
touchpad_settings.SetTapDragging(enabled);
if (pref_name)
UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled);
else
......@@ -442,7 +444,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kEnableTouchpadThreeFingerClick)) {
const bool enabled = three_finger_click_enabled_.GetValue();
system::touchpad_settings::SetThreeFingerClick(enabled);
touchpad_settings.SetThreeFingerClick(enabled);
if (pref_name)
UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled);
else
......@@ -465,7 +467,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kMouseSensitivity)) {
const int sensitivity = mouse_sensitivity_.GetValue();
system::mouse_settings::SetSensitivity(sensitivity);
mouse_settings.SetSensitivity(sensitivity);
if (pref_name) {
UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Changed",
sensitivity,
......@@ -479,7 +481,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kTouchpadSensitivity)) {
const int sensitivity = touchpad_sensitivity_.GetValue();
system::touchpad_settings::SetSensitivity(sensitivity);
touchpad_settings.SetSensitivity(sensitivity);
if (pref_name) {
UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Changed",
sensitivity,
......@@ -493,7 +495,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
if ((!pref_name && is_primary_user_prefs_) ||
(pref_name && *pref_name == prefs::kPrimaryMouseButtonRight)) {
const bool right = primary_mouse_button_right_.GetValue();
system::mouse_settings::SetPrimaryButtonRight(right);
mouse_settings.SetPrimaryButtonRight(right);
if (pref_name)
UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right);
else
......@@ -556,6 +558,8 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
input_method_manager_->SetEnabledExtensionImes(&split_values);
}
system::InputDeviceSettings::Get()->UpdateTouchpadSettings(touchpad_settings);
system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
}
void Preferences::OnIsSyncingChanged() {
......
......@@ -4,11 +4,7 @@
#include "chrome/browser/chromeos/system/device_change_handler.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
namespace chromeos {
namespace system {
......@@ -27,55 +23,20 @@ DeviceChangeHandler::~DeviceChangeHandler() {
pointer_device_observer_->RemoveObserver(this);
}
// When we detect a touchpad is attached, apply touchpad settings of the
// primary profile.
// When we detect a touchpad is attached, apply touchpad settings that was
// cached inside InputDeviceSettings.
void DeviceChangeHandler::TouchpadExists(bool exists) {
if (!exists)
return;
// Using GetPrimaryUserProfile here because this is a system setting which can
// only be set by the user which starts the session.
PrefService* prefs = ProfileManager::GetPrimaryUserProfile()->GetPrefs();
const bool tap_dragging = prefs->GetBoolean(prefs::kTapDraggingEnabled);
system::touchpad_settings::SetTapDragging(tap_dragging);
const bool three_finger_click =
prefs->GetBoolean(prefs::kEnableTouchpadThreeFingerClick);
system::touchpad_settings::SetThreeFingerClick(three_finger_click);
const int sensitivity = prefs->GetInteger(prefs::kTouchpadSensitivity);
system::touchpad_settings::SetSensitivity(sensitivity);
// If we are not logged in, use owner preferences.
PrefService* local_prefs = g_browser_process->local_state();
const bool tap_to_click =
g_browser_process->profile_manager()->IsLoggedIn() ?
prefs->GetBoolean(prefs::kTapToClickEnabled) :
local_prefs->GetBoolean(prefs::kOwnerTapToClickEnabled);
system::touchpad_settings::SetTapToClick(tap_to_click);
system::InputDeviceSettings::Get()->ReapplyTouchpadSettings();
}
// When we detect a mouse is attached, apply mouse settings of the primary
// profile.
// When we detect a mouse is attached, apply mouse settings that was cached
// inside InputDeviceSettings.
void DeviceChangeHandler::MouseExists(bool exists) {
if (!exists)
return;
// Using GetPrimaryUserProfile here because this is the property which can
// only be set by the user which starts the session.
PrefService* prefs = ProfileManager::GetPrimaryUserProfile()->GetPrefs();
const int sensitivity = prefs->GetInteger(prefs::kMouseSensitivity);
system::mouse_settings::SetSensitivity(sensitivity);
// If we are not logged in, use owner preferences.
PrefService* local_prefs = g_browser_process->local_state();
const bool primary_button_right =
g_browser_process->profile_manager()->IsLoggedIn() ?
prefs->GetBoolean(prefs::kPrimaryMouseButtonRight) :
local_prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight);
system::mouse_settings::SetPrimaryButtonRight(primary_button_right);
system::InputDeviceSettings::Get()->ReapplyMouseSettings();
}
} // namespace system
......
......@@ -12,7 +12,7 @@ namespace chromeos {
namespace system {
// Observes changes in device hierarchy. When a new touchpad/mouse is attached,
// applies the last used profile's touchpad/mouse settings to the system.
// applies the last used touchpad/mouse settings to the system.
class DeviceChangeHandler : public PointerDeviceObserver::Observer {
public:
DeviceChangeHandler();
......@@ -27,7 +27,7 @@ class DeviceChangeHandler : public PointerDeviceObserver::Observer {
};
} // namespace system
} // namesspace chromeos
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_CHANGE_HANDLER_H_
// Copyright 2014 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 "chrome/browser/chromeos/system/fake_input_device_settings.h"
namespace chromeos {
namespace system {
FakeInputDeviceSettings::FakeInputDeviceSettings() {}
FakeInputDeviceSettings::~FakeInputDeviceSettings() {}
// Overriden from InputDeviceSettings.
void FakeInputDeviceSettings::TouchpadExists(
const DeviceExistsCallback& callback) {
callback.Run(true);
}
void FakeInputDeviceSettings::UpdateTouchpadSettings(
const TouchpadSettings& settings) {
current_touchpad_settings_.Update(settings, NULL);
}
void FakeInputDeviceSettings::SetTouchpadSensitivity(int value) {
TouchpadSettings settings;
settings.SetSensitivity(value);
UpdateTouchpadSettings(settings);
}
void FakeInputDeviceSettings::SetTapToClick(bool enabled) {
TouchpadSettings settings;
settings.SetTapToClick(enabled);
UpdateTouchpadSettings(settings);
}
void FakeInputDeviceSettings::SetThreeFingerClick(bool enabled) {
TouchpadSettings settings;
settings.SetThreeFingerClick(enabled);
UpdateTouchpadSettings(settings);
}
void FakeInputDeviceSettings::SetTapDragging(bool enabled) {
TouchpadSettings settings;
settings.SetTapDragging(enabled);
UpdateTouchpadSettings(settings);
}
void FakeInputDeviceSettings::MouseExists(
const DeviceExistsCallback& callback) {
callback.Run(false);
}
void FakeInputDeviceSettings::UpdateMouseSettings(
const MouseSettings& settings) {
current_mouse_settings_.Update(settings, NULL);
}
void FakeInputDeviceSettings::SetMouseSensitivity(int value) {
MouseSettings settings;
settings.SetSensitivity(value);
UpdateMouseSettings(settings);
}
void FakeInputDeviceSettings::SetPrimaryButtonRight(bool right) {
MouseSettings settings;
settings.SetPrimaryButtonRight(right);
UpdateMouseSettings(settings);
}
bool FakeInputDeviceSettings::ForceKeyboardDrivenUINavigation() {
return false;
}
void FakeInputDeviceSettings::ReapplyTouchpadSettings() {
}
void FakeInputDeviceSettings::ReapplyMouseSettings() {
}
} // namespace system
} // namespace chromeos
// Copyright 2014 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.
#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_FAKE_INPUT_DEVICE_SETTINGS_H_
#define CHROME_BROWSER_CHROMEOS_SYSTEM_FAKE_INPUT_DEVICE_SETTINGS_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
namespace chromeos {
namespace system {
// This fake just memorizes current values of input devices settings.
class FakeInputDeviceSettings : public InputDeviceSettings {
public:
FakeInputDeviceSettings();
virtual ~FakeInputDeviceSettings();
// Overridden from InputDeviceSettings.
virtual void TouchpadExists(const DeviceExistsCallback& callback) OVERRIDE;
virtual void UpdateTouchpadSettings(const TouchpadSettings& settings)
OVERRIDE;
virtual void SetTouchpadSensitivity(int value) OVERRIDE;
virtual void SetTapToClick(bool enabled) OVERRIDE;
virtual void SetThreeFingerClick(bool enabled) OVERRIDE;
virtual void SetTapDragging(bool enabled) OVERRIDE;
virtual void MouseExists(const DeviceExistsCallback& callback) OVERRIDE;
virtual void UpdateMouseSettings(const MouseSettings& settings) OVERRIDE;
virtual void SetMouseSensitivity(int value) OVERRIDE;
virtual void SetPrimaryButtonRight(bool right) OVERRIDE;
virtual bool ForceKeyboardDrivenUINavigation() OVERRIDE;
virtual void ReapplyTouchpadSettings() OVERRIDE;
virtual void ReapplyMouseSettings() OVERRIDE;
const TouchpadSettings& current_touchpad_settings() const {
return current_touchpad_settings_;
}
const MouseSettings& current_mouse_settings() const {
return current_mouse_settings_;
}
private:
TouchpadSettings current_touchpad_settings_;
MouseSettings current_mouse_settings_;
DISALLOW_COPY_AND_ASSIGN(FakeInputDeviceSettings);
};
} // namespace system
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_FAKE_INPUT_DEVICE_SETTINGS_H_
......@@ -4,10 +4,6 @@
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include <stdarg.h>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_util.h"
......@@ -34,6 +30,9 @@ namespace system {
namespace {
InputDeviceSettings* g_instance_;
InputDeviceSettings* g_test_instance_;
const char kTpControl[] = "/opt/google/touchpad/tpcontrol";
const char kMouseControl[] = "/opt/google/mouse/mousecontrol";
......@@ -63,15 +62,14 @@ void ExecuteScriptOnFileThread(const std::vector<std::string>& argv) {
base::EnsureProcessGetsReaped(handle);
}
void ExecuteScript(int argc, ...) {
void ExecuteScript(const std::vector<std::string>& argv) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
std::vector<std::string> argv;
va_list vl;
va_start(vl, argc);
for (int i = 0; i < argc; ++i) {
argv.push_back(va_arg(vl, const char*));
}
va_end(vl);
if (argv.size() == 1)
return;
VLOG(1) << "About to launch: \""
<< CommandLine(argv).GetCommandLineString() << "\"";
// Control scripts can take long enough to cause SIGART during shutdown
// (http://crbug.com/261426). Run the blocking pool task with
......@@ -83,15 +81,17 @@ void ExecuteScript(int argc, ...) {
runner->PostTask(FROM_HERE, base::Bind(&ExecuteScriptOnFileThread, argv));
}
void SetPointerSensitivity(const char* script, int value) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
void AddSensitivityArguments(int value, std::vector<std::string>* argv) {
DCHECK(value >= kMinPointerSensitivity && value <= kMaxPointerSensitivity);
ExecuteScript(
3, script, "sensitivity", base::StringPrintf("%d", value).c_str());
argv->push_back("sensitivity");
argv->push_back(base::StringPrintf("%d", value));
}
void SetTPControl(const char* control, bool enabled) {
ExecuteScript(3, kTpControl, control, enabled ? "on" : "off");
void AddTPControlArguments(const char* control,
bool enabled,
std::vector<std::string>* argv) {
argv->push_back(control);
argv->push_back(enabled ? "on" : "off");
}
void DeviceExistsBlockingPool(const char* script,
......@@ -111,14 +111,16 @@ void DeviceExistsBlockingPool(const char* script,
DVLOG(1) << "DeviceExistsBlockingPool:" << script << "=" << exists->data;
}
void RunCallbackUIThread(scoped_refptr<RefCountedBool> exists,
const DeviceExistsCallback& callback) {
void RunCallbackUIThread(
scoped_refptr<RefCountedBool> exists,
const InputDeviceSettings::DeviceExistsCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DVLOG(1) << "RunCallbackUIThread " << exists->data;
callback.Run(exists->data);
}
void DeviceExists(const char* script, const DeviceExistsCallback& callback) {
void DeviceExists(const char* script,
const InputDeviceSettings::DeviceExistsCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// One or both of the control scripts can apparently hang during shutdown
......@@ -134,62 +136,98 @@ void DeviceExists(const char* script, const DeviceExistsCallback& callback) {
base::Bind(&RunCallbackUIThread, exists, callback));
}
} // namespace
namespace touchpad_settings {
void TouchpadExists(const DeviceExistsCallback& callback) {
class InputDeviceSettingsImpl : public InputDeviceSettings {
public:
InputDeviceSettingsImpl();
private:
// Overridden from InputDeviceSettings.
virtual void TouchpadExists(const DeviceExistsCallback& callback) OVERRIDE;
virtual void UpdateTouchpadSettings(const TouchpadSettings& settings)
OVERRIDE;
virtual void SetTouchpadSensitivity(int value) OVERRIDE;
virtual void SetTapToClick(bool enabled) OVERRIDE;
virtual void SetThreeFingerClick(bool enabled) OVERRIDE;
virtual void SetTapDragging(bool enabled) OVERRIDE;
virtual void MouseExists(const DeviceExistsCallback& callback) OVERRIDE;
virtual void UpdateMouseSettings(const MouseSettings& update) OVERRIDE;
virtual void SetMouseSensitivity(int value) OVERRIDE;
virtual void SetPrimaryButtonRight(bool right) OVERRIDE;
virtual bool ForceKeyboardDrivenUINavigation() OVERRIDE;
virtual void ReapplyTouchpadSettings() OVERRIDE;
virtual void ReapplyMouseSettings() OVERRIDE;
private:
TouchpadSettings current_touchpad_settings_;
MouseSettings current_mouse_settings_;
DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImpl);
};
InputDeviceSettingsImpl::InputDeviceSettingsImpl() {}
void InputDeviceSettingsImpl::TouchpadExists(
const DeviceExistsCallback& callback) {
DeviceExists(kTpControl, callback);
}
// Sets the touchpad sensitivity in the range [1, 5].
void SetSensitivity(int value) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
SetPointerSensitivity(kTpControl, value);
void InputDeviceSettingsImpl::UpdateTouchpadSettings(
const TouchpadSettings& settings) {
std::vector<std::string> argv;
if (current_touchpad_settings_.Update(settings, &argv))
ExecuteScript(argv);
}
void SetTapToClick(bool enabled) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
SetTPControl("taptoclick", enabled);
void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) {
TouchpadSettings settings;
settings.SetSensitivity(value);
UpdateTouchpadSettings(settings);
}
void SetThreeFingerClick(bool enabled) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
void InputDeviceSettingsImpl::SetTapToClick(bool enabled) {
TouchpadSettings settings;
settings.SetTapToClick(enabled);
UpdateTouchpadSettings(settings);
}
void InputDeviceSettingsImpl::SetThreeFingerClick(bool enabled) {
// For Alex/ZGB.
SetTPControl("t5r2_three_finger_click", enabled);
TouchpadSettings settings;
settings.SetThreeFingerClick(enabled);
UpdateTouchpadSettings(settings);
}
void SetTapDragging(bool enabled) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
SetTPControl("tap_dragging", enabled);
void InputDeviceSettingsImpl::SetTapDragging(bool enabled) {
TouchpadSettings settings;
settings.SetTapDragging(enabled);
UpdateTouchpadSettings(settings);
}
} // namespace touchpad_settings
namespace mouse_settings {
void MouseExists(const DeviceExistsCallback& callback) {
void InputDeviceSettingsImpl::MouseExists(
const DeviceExistsCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DeviceExists(kMouseControl, callback);
}
// Sets the touchpad sensitivity in the range [1, 5].
void SetSensitivity(int value) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
SetPointerSensitivity(kMouseControl, value);
void InputDeviceSettingsImpl::UpdateMouseSettings(const MouseSettings& update) {
std::vector<std::string> argv;
if (current_mouse_settings_.Update(update, &argv))
ExecuteScript(argv);
}
void SetPrimaryButtonRight(bool right) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
ExecuteScript(3, kMouseControl, "swap_left_right", right ? "1" : "0");
void InputDeviceSettingsImpl::SetMouseSensitivity(int value) {
MouseSettings settings;
settings.SetSensitivity(value);
UpdateMouseSettings(settings);
}
} // namespace mouse_settings
namespace keyboard_settings {
void InputDeviceSettingsImpl::SetPrimaryButtonRight(bool right) {
MouseSettings settings;
settings.SetPrimaryButtonRight(right);
UpdateMouseSettings(settings);
}
bool ForceKeyboardDrivenUINavigation() {
bool InputDeviceSettingsImpl::ForceKeyboardDrivenUINavigation() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (!connector)
......@@ -207,14 +245,164 @@ bool ForceKeyboardDrivenUINavigation() {
bool keyboard_driven = false;
if (chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
kOemKeyboardDrivenOobeKey, &keyboard_driven)) {
kOemKeyboardDrivenOobeKey, &keyboard_driven)) {
return keyboard_driven;
}
return false;
}
} // namespace keyboard_settings
void InputDeviceSettingsImpl::ReapplyTouchpadSettings() {
TouchpadSettings settings = current_touchpad_settings_;
current_touchpad_settings_ = TouchpadSettings();
UpdateTouchpadSettings(settings);
}
void InputDeviceSettingsImpl::ReapplyMouseSettings() {
MouseSettings settings = current_mouse_settings_;
current_mouse_settings_ = MouseSettings();
UpdateMouseSettings(settings);
}
} // namespace
TouchpadSettings::TouchpadSettings() {}
TouchpadSettings& TouchpadSettings::operator=(const TouchpadSettings& other) {
if (&other != this) {
sensitivity_ = other.sensitivity_;
tap_to_click_ = other.tap_to_click_;
three_finger_click_ = other.three_finger_click_;
tap_dragging_ = other.tap_dragging_;
}
return *this;
}
void TouchpadSettings::SetSensitivity(int value) {
sensitivity_.Set(value);
}
int TouchpadSettings::GetSensitivity() const {
return sensitivity_.value();
}
void TouchpadSettings::SetTapToClick(bool enabled) {
tap_to_click_.Set(enabled);
}
bool TouchpadSettings::GetTapToClick() const {
return tap_to_click_.value();
}
void TouchpadSettings::SetThreeFingerClick(bool enabled) {
three_finger_click_.Set(enabled);
}
bool TouchpadSettings::GetThreeFingerClick() const {
return three_finger_click_.value();
}
void TouchpadSettings::SetTapDragging(bool enabled) {
tap_dragging_.Set(enabled);
}
bool TouchpadSettings::GetTapDragging() const {
return tap_dragging_.value();
}
bool TouchpadSettings::Update(const TouchpadSettings& settings,
std::vector<std::string>* argv) {
if (argv)
argv->push_back(kTpControl);
bool updated = false;
if (sensitivity_.Update(settings.sensitivity_)) {
updated = true;
if (argv)
AddSensitivityArguments(sensitivity_.value(), argv);
}
if (tap_to_click_.Update(settings.tap_to_click_)) {
updated = true;
if (argv)
AddTPControlArguments("taptoclick", tap_to_click_.value(), argv);
}
if (three_finger_click_.Update(settings.three_finger_click_)) {
updated = true;
if (argv)
AddTPControlArguments("t5r2_three_finger_click",
three_finger_click_.value(),
argv);
}
if (tap_dragging_.Update(settings.tap_dragging_)) {
updated = true;
if (argv)
AddTPControlArguments("tap_dragging", tap_dragging_.value(), argv);
}
return updated;
}
MouseSettings::MouseSettings() {}
MouseSettings& MouseSettings::operator=(const MouseSettings& other) {
if (&other != this) {
sensitivity_ = other.sensitivity_;
primary_button_right_ = other.primary_button_right_;
}
return *this;
}
void MouseSettings::SetSensitivity(int value) {
sensitivity_.Set(value);
}
int MouseSettings::GetSensitivity() const {
return sensitivity_.value();
}
void MouseSettings::SetPrimaryButtonRight(bool right) {
primary_button_right_.Set(right);
}
bool MouseSettings::GetPrimaryButtonRight() const {
return primary_button_right_.value();
}
bool MouseSettings::Update(const MouseSettings& settings,
std::vector<std::string>* argv) {
if (argv)
argv->push_back(kMouseControl);
bool updated = false;
if (sensitivity_.Update(settings.sensitivity_)) {
updated = true;
if (argv)
AddSensitivityArguments(sensitivity_.value(), argv);
}
if (primary_button_right_.Update(settings.primary_button_right_)) {
updated = true;
if (argv) {
argv->push_back("swap_left_right");
argv->push_back(settings.GetPrimaryButtonRight() ? "1" : "0");
}
}
return updated;
}
// static
InputDeviceSettings* InputDeviceSettings::Get() {
if (g_test_instance_)
return g_test_instance_;
if (!g_instance_)
g_instance_ = new InputDeviceSettingsImpl;
return g_instance_;
}
// static
void InputDeviceSettings::SetSettingsForTesting(
InputDeviceSettings* test_settings) {
if (g_test_instance_ == test_settings)
return;
delete g_test_instance_;
g_test_instance_ = test_settings;
}
} // namespace system
} // namespace chromeos
......@@ -5,57 +5,199 @@
#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_
#define CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/logging.h"
namespace chromeos {
namespace system {
namespace internal {
// Objects of this class are intended to store values of type T, but might have
// "unset" state. Object will be in "unset" state until Set is called first
// time.
template <typename T>
class Optional {
public:
Optional()
: value_(),
is_set_(false) {
}
Optional& operator=(const Optional& other) {
if (&other != this) {
value_ = other.value_;
is_set_ = other.is_set_;
}
return *this;
}
void Set(const T& value) {
is_set_ = true;
value_ = value;
}
bool is_set() const {
return is_set_;
}
T value() const {
DCHECK(is_set());
return value_;
}
// Tries to update |this| with |update|. If |update| is unset or has same
// value as |this| method returns false. Otherwise |this| takes value of
// |update| and returns true.
bool Update(const Optional& update) {
if (update.is_set_ && (!is_set_ || value_ != update.value_)) {
value_ = update.value_;
is_set_ = true;
return true;
}
return false;
}
private:
T value_;
bool is_set_;
};
} // namespace internal
// Min/max possible pointer sensitivity values. Defined in CrOS inputcontrol
// scripts (see kTpControl/kMouseControl in the source file).
const int kMinPointerSensitivity = 1;
const int kMaxPointerSensitivity = 5;
typedef base::Callback<void(bool)> DeviceExistsCallback;
namespace touchpad_settings {
// Calls |callback| asynchronously after determining if a touchpad is connected.
void TouchpadExists(const DeviceExistsCallback& callback);
// Sets the touchpad sensitivity in the range [1, 5].
void SetSensitivity(int value);
// Turns tap to click on/off.
void SetTapToClick(bool enabled);
// Switch for three-finger click.
void SetThreeFingerClick(bool enabled);
// Turns tap-dragging on/off.
void SetTapDragging(bool enabled);
} // namespace touchpad_settings
namespace mouse_settings {
// Calls |callback| asynchronously after determining if a mouse is connected.
void MouseExists(const DeviceExistsCallback& callback);
// Sets the mouse sensitivity in the range [1, 5].
void SetSensitivity(int value);
// Sets the primary mouse button to the right button if |right| is true.
void SetPrimaryButtonRight(bool right);
} // namespace mouse_settings
namespace keyboard_settings {
// Returns true if UI should implement enhanced keyboard support for cases where
// other input devices like mouse are absent.
bool ForceKeyboardDrivenUINavigation();
} // namespace keyboard_settings
// Auxiliary class used to update several touchpad settings at a time. User
// should set any number of settings and pass object to UpdateTouchpadSettings
// method of InputDeviceSettings.
// Objects of this class have no default values for settings, so it is error
// to call Get* method before calling corresponding Set* method at least
// once.
class TouchpadSettings {
public:
TouchpadSettings();
TouchpadSettings& operator=(const TouchpadSettings& other);
void SetSensitivity(int value);
int GetSensitivity() const;
void SetTapToClick(bool enabled);
bool GetTapToClick() const;
void SetThreeFingerClick(bool enabled);
bool GetThreeFingerClick() const;
void SetTapDragging(bool enabled);
bool GetTapDragging() 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
// to apply update. This argument is optional and could be NULL.
bool Update(const TouchpadSettings& settings, std::vector<std::string>* argv);
private:
internal::Optional<int> sensitivity_;
internal::Optional<bool> tap_to_click_;
internal::Optional<bool> three_finger_click_;
internal::Optional<bool> tap_dragging_;
};
// Auxiliary class used to update several mouse settings at a time. User
// should set any number of settings and pass object to UpdateMouseSettings
// method of InputDeviceSettings.
// Objects of this class have no default values for settings, so it is error
// to call Get* method before calling corresponding Set* method at least
// once.
class MouseSettings {
public:
MouseSettings();
MouseSettings& operator=(const MouseSettings& other);
void SetSensitivity(int value);
int GetSensitivity() const;
void SetPrimaryButtonRight(bool right);
bool GetPrimaryButtonRight() 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
// to apply update. This argument is optional and could be NULL.
bool Update(const MouseSettings& update, std::vector<std::string>* argv);
private:
internal::Optional<int> sensitivity_;
internal::Optional<bool> primary_button_right_;
};
class InputDeviceSettings {
public:
typedef base::Callback<void(bool)> DeviceExistsCallback;
virtual ~InputDeviceSettings() {}
// Returns current instance of InputDeviceSettings.
static InputDeviceSettings* Get();
// Replaces current instance with |test_settings|. Takes ownership of
// |test_settings|. Default implementation could be returned back by passing
// NULL to this method.
static void SetSettingsForTesting(InputDeviceSettings* test_settings);
// Calls |callback| asynchronously after determining if a touchpad is
// connected.
virtual void TouchpadExists(const DeviceExistsCallback& callback) = 0;
// Updates several touchpad settings at a time. Updates only settings that
// are set in |settings| object. It is more efficient to use this method to
// update several settings then calling Set* methods one by one.
virtual void UpdateTouchpadSettings(const TouchpadSettings& settings) = 0;
// Sets the touchpad sensitivity in the range [kMinPointerSensitivity,
// kMaxPointerSensitivity].
virtual void SetTouchpadSensitivity(int value) = 0;
// Turns tap to click on/off.
virtual void SetTapToClick(bool enabled) = 0;
// Switch for three-finger click.
virtual void SetThreeFingerClick(bool enabled) = 0;
// Turns tap-dragging on/off.
virtual void SetTapDragging(bool enabled) = 0;
// Calls |callback| asynchronously after determining if a mouse is connected.
virtual void MouseExists(const DeviceExistsCallback& callback) = 0;
// Updates several mouse settings at a time. Updates only settings that
// are set in |settings| object. It is more efficient to use this method to
// update several settings then calling Set* methods one by one.
virtual void UpdateMouseSettings(const MouseSettings& settings) = 0;
// Sets the mouse sensitivity in the range [kMinPointerSensitivity,
// kMaxPointerSensitivity].
virtual void SetMouseSensitivity(int value) = 0;
// Sets the primary mouse button to the right button if |right| is true.
virtual void SetPrimaryButtonRight(bool right) = 0;
// Returns true if UI should implement enhanced keyboard support for cases
// where other input devices like mouse are absent.
virtual bool ForceKeyboardDrivenUINavigation() = 0;
// Reapplies previously set touchpad settings.
virtual void ReapplyTouchpadSettings() = 0;
// Reapplies previously set mouse settings.
virtual void ReapplyMouseSettings() = 0;
};
} // namespace system
} // namespace chromeos
......
......@@ -48,13 +48,13 @@ void PointerDeviceObserver::DeviceHierarchyChanged() {
}
void PointerDeviceObserver::CheckTouchpadExists() {
touchpad_settings::TouchpadExists(
InputDeviceSettings::Get()->TouchpadExists(
base::Bind(&PointerDeviceObserver::OnTouchpadExists,
weak_factory_.GetWeakPtr()));
}
void PointerDeviceObserver::CheckMouseExists() {
mouse_settings::MouseExists(
InputDeviceSettings::Get()->MouseExists(
base::Bind(&PointerDeviceObserver::OnMouseExists,
weak_factory_.GetWeakPtr()));
}
......
......@@ -61,10 +61,12 @@ void LoadGaiaAuthExtension(Profile* profile) {
}
int manifest_resource_id = IDR_GAIA_AUTH_MANIFEST;
if (chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation())
if (chromeos::system::InputDeviceSettings::Get()
->ForceKeyboardDrivenUINavigation()) {
manifest_resource_id = IDR_GAIA_AUTH_KEYBOARD_MANIFEST;
else if (!command_line->HasSwitch(chromeos::switches::kDisableSamlSignin))
} else if (!command_line->HasSwitch(chromeos::switches::kDisableSamlSignin)) {
manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST;
}
#else
int manifest_resource_id = IDR_GAIA_AUTH_INLINE_MANIFEST;
#endif
......
......@@ -300,7 +300,7 @@ void CoreOobeHandler::UpdateOobeUIVisibility() {
}
CallJS("showVersion", should_show_version);
CallJS("showOobeUI", show_oobe_ui_);
if (system::keyboard_settings::ForceKeyboardDrivenUINavigation())
if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation())
CallJS("enableKeyboardFlow", true);
}
......
......@@ -127,7 +127,7 @@ void NetworkScreenHandler::EnableContinue(bool enabled) {
void NetworkScreenHandler::DeclareLocalizedValues(
LocalizedValuesBuilder* builder) {
if (system::keyboard_settings::ForceKeyboardDrivenUINavigation())
if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation())
builder->Add("networkScreenGreeting", IDS_REMORA_CONFIRM_MESSAGE);
else
builder->Add("networkScreenGreeting", IDS_WELCOME_SCREEN_GREETING);
......
......@@ -375,7 +375,7 @@ void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) {
}
bool keyboard_driven_oobe =
system::keyboard_settings::ForceKeyboardDrivenUINavigation();
system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation();
localized_strings->SetString("highlightStrength",
keyboard_driven_oobe ? "strong" : "normal");
......
......@@ -100,7 +100,7 @@ ProxySettingsUI::ProxySettingsUI(content::WebUI* web_ui)
proxy_handler_->GetLocalizedValues(localized_strings);
bool keyboard_driven_oobe =
system::keyboard_settings::ForceKeyboardDrivenUINavigation();
system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation();
localized_strings->SetString("highlightStrength",
keyboard_driven_oobe ? "strong" : "normal");
......
......@@ -69,7 +69,7 @@ void ProxyHandler::InitializePage() {
::options::OptionsPageUIHandler::InitializePage();
bool keyboard_driven_oobe =
system::keyboard_settings::ForceKeyboardDrivenUINavigation();
system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation();
if (keyboard_driven_oobe) {
web_ui()->CallJavascriptFunction(
"DetailsInternetPage.initializeKeyboardFlow");
......
......@@ -110,6 +110,8 @@
'browser/chromeos/settings/device_settings_test_helper.h',
'browser/chromeos/settings/mock_owner_key_util.cc',
'browser/chromeos/settings/mock_owner_key_util.h',
'browser/chromeos/system/fake_input_device_settings.cc',
'browser/chromeos/system/fake_input_device_settings.h',
# The only thing used from browser is Browser::Type.
'browser/download/download_test_file_activity_observer.cc',
'browser/download/download_test_file_activity_observer.h',
......
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