1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (c) 2009 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/preferences.h"
#include "base/string_util.h"
#include "chrome/browser/chromeos/cros/synaptics_library.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_member.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "unicode/timezone.h"
namespace chromeos {
// static
void Preferences::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterStringPref(prefs::kTimeZone, L"US/Pacific");
prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, false);
prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, false);
prefs->RegisterIntegerPref(prefs::kTouchpadSpeedFactor, 5);
prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, 5);
}
void Preferences::Init(PrefService* prefs) {
timezone_.Init(prefs::kTimeZone, prefs, this);
tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this);
speed_factor_.Init(prefs::kTouchpadSpeedFactor, prefs, this);
sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
// Initialize touchpad settings to what's saved in user preferences.
NotifyPrefChanged(NULL);
}
void Preferences::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::PREF_CHANGED)
NotifyPrefChanged(Details<std::wstring>(details).ptr());
}
void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
if (!pref_name || *pref_name == prefs::kTimeZone)
SetTimeZone(timezone_.GetValue());
if (!pref_name || *pref_name == prefs::kTapToClickEnabled)
SynapticsLibrary::Get()->SetBoolParameter(PARAM_BOOL_TAP_TO_CLICK,
tap_to_click_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kVertEdgeScrollEnabled)
SynapticsLibrary::Get()->SetBoolParameter(
PARAM_BOOL_VERTICAL_EDGE_SCROLLING,
vert_edge_scroll_enabled_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor)
SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_SPEED_SENSITIVITY,
speed_factor_.GetValue());
if (!pref_name || *pref_name == prefs::kTouchpadSensitivity)
SynapticsLibrary::Get()->SetRangeParameter(PARAM_RANGE_TOUCH_SENSITIVITY,
sensitivity_.GetValue());
}
void Preferences::SetTimeZone(const std::wstring& id) {
icu::TimeZone* timezone = icu::TimeZone::createTimeZone(
icu::UnicodeString::fromUTF8(WideToASCII(id)));
icu::TimeZone::adoptDefault(timezone);
}
} // namespace chromeos
|