-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
per_device_pointing_stick_subsection.ts
217 lines (191 loc) · 6.73 KB
/
per_device_pointing_stick_subsection.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* 'per-device-pointing-stick-subsection' allow users to configure their
* per-device-pointing-stick subsection settings in system settings.
*/
import '../../icons.html.js';
import '../../settings_shared.css.js';
import 'chrome://resources/cr_components/localized_link/localized_link.js';
import 'chrome://resources/cr_elements/cr_radio_button/cr_radio_button.js';
import 'chrome://resources/cr_elements/cr_shared_vars.css.js';
import '../../controls/settings_radio_group.js';
import '../../controls/settings_slider.js';
import '../../controls/settings_toggle_button.js';
import '../../settings_shared.css.js';
import 'chrome://resources/cr_elements/cr_slider/cr_slider.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
import {PolymerElementProperties} from 'chrome://resources/polymer/v3_0/polymer/interfaces.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {DeepLinkingMixin} from '../deep_linking_mixin.js';
import {Setting} from '../mojom-webui/setting.mojom-webui.js';
import {routes} from '../os_settings_routes.js';
import {RouteObserverMixin} from '../route_observer_mixin.js';
import {Route} from '../router.js';
import {getInputDeviceSettingsProvider} from './input_device_mojo_interface_provider.js';
import {InputDeviceSettingsProviderInterface, PointingStick} from './input_device_settings_types.js';
import {getTemplate} from './per_device_pointing_stick_subsection.html.js';
const SettingsPerDevicePointingStickSubsectionElementBase =
DeepLinkingMixin(RouteObserverMixin(I18nMixin(PolymerElement)));
export class SettingsPerDevicePointingStickSubsectionElement extends
SettingsPerDevicePointingStickSubsectionElementBase {
static get is(): string {
return 'settings-per-device-pointing-stick-subsection';
}
static get template(): HTMLTemplateElement {
return getTemplate();
}
static get properties(): PolymerElementProperties {
return {
primaryRightPref: {
type: Object,
value() {
return {
key: 'fakePrimaryRightPref',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: false,
};
},
},
accelerationPref: {
type: Object,
value() {
return {
key: 'fakeAccelerationPref',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: true,
};
},
},
sensitivityPref: {
type: Object,
value() {
return {
key: 'fakeSensitivityPref',
type: chrome.settingsPrivate.PrefType.NUMBER,
value: 3,
};
},
},
swapPrimaryOptions: {
readOnly: true,
type: Array,
value() {
return [
{
value: false,
name: loadTimeData.getString('primaryMouseButtonLeft'),
},
{
value: true,
name: loadTimeData.getString('primaryMouseButtonRight'),
},
];
},
},
/**
* TODO(michaelpg): settings-slider should optionally take a min and max
* so we don't have to generate a simple range of natural numbers
* ourselves. These values match the TouchpadSensitivity enum in
* enums.xml.
*/
sensitivityValues: {
type: Array,
value: [1, 2, 3, 4, 5],
readOnly: true,
},
pointingStick: {type: Object},
/**
* Used by DeepLinkingMixin to focus this page's deep links.
*/
supportedSettingIds: {
type: Object,
value: () => new Set<Setting>([
Setting.kPointingStickAcceleration,
Setting.kPointingStickSpeed,
Setting.kPointingStickSwapPrimaryButtons,
]),
},
pointingStickIndex: {
type: Number,
},
};
}
static get observers(): string[] {
return [
'onSettingsChanged(primaryRightPref.value,' +
'accelerationPref.value,' +
'sensitivityPref.value)',
'updateSettingsToCurrentPrefs(pointingStick)',
];
}
override currentRouteChanged(route: Route): void {
// Does not apply to this page.
if (route !== routes.PER_DEVICE_POINTING_STICK) {
return;
}
// If multiple pointing sticks are available, focus on the first one.
if (this.pointingStickIndex === 0) {
this.attemptDeepLink();
}
}
private pointingStick: PointingStick;
private sensitivityValues: number[];
private swapPrimaryOptions: number[];
private primaryRightPref: chrome.settingsPrivate.PrefObject;
private accelerationPref: chrome.settingsPrivate.PrefObject;
private sensitivityPref: chrome.settingsPrivate.PrefObject;
private isInitialized: boolean = false;
private inputDeviceSettingsProvider: InputDeviceSettingsProviderInterface =
getInputDeviceSettingsProvider();
private pointingStickIndex: number;
private updateSettingsToCurrentPrefs(): void {
this.set('primaryRightPref.value', this.pointingStick.settings.swapRight);
this.set(
'accelerationPref.value',
this.pointingStick.settings.accelerationEnabled);
this.set('sensitivityPref.value', this.pointingStick.settings.sensitivity);
this.isInitialized = true;
}
private onLearnMoreLinkClicked_(event: Event): void {
const path = event.composedPath();
if (!Array.isArray(path) || !path.length) {
return;
}
if ((path[0] as HTMLElement).tagName === 'A') {
// Do not toggle reverse scrolling if the contained link is clicked.
event.stopPropagation();
}
}
private onSettingsChanged(): void {
// TODO(wangdanny): Implement onSettingsChanged.
if (!this.isInitialized) {
return;
}
this.pointingStick.settings = {
...this.pointingStick.settings,
swapRight: this.primaryRightPref.value,
accelerationEnabled: this.accelerationPref.value,
sensitivity: this.sensitivityPref.value,
};
this.inputDeviceSettingsProvider.setPointingStickSettings(
this.pointingStick.id, this.pointingStick.settings);
}
private getPointingStickName(): string {
return this.pointingStick.isExternal ?
this.pointingStick.name :
this.i18n('builtInPointingStickName');
}
}
declare global {
interface HTMLElementTagNameMap {
'settings-per-device-pointing-stick-subsection':
SettingsPerDevicePointingStickSubsectionElement;
}
}
customElements.define(
SettingsPerDevicePointingStickSubsectionElement.is,
SettingsPerDevicePointingStickSubsectionElement);