Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/resources/gesture_config.js

Issue 10532005: Initial check-in of gesture config WebUI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed all outstanding review comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Redefine '$' here rather than including 'cr.js', since this is
6 // the only function needed. This allows this file to be loaded
7 // in a browser directly for layout and some testing purposes.
8 var $ = function(id) { return document.getElementById(id); };
9
10 /**
11 * WebUI for configuring gesture.* preference values used by
12 * Chrome's gesture recognition system.
13 */
14 var gesture_config = (function() {
15 'use strict';
16
17 /** Common prefix of gesture preferences. **/
18 /** @const */ var GESTURE_PREFIX = 'gesture.';
19
20 /** List of fields used to dynamically build form. **/
21 var FIELDS = [
22 {
23 key: 'long_press_time_in_seconds',
24 label: 'Long Press Time',
25 units: 'seconds',
26 default: 1.0
27 },
28 {
29 key: 'max_seconds_between_double_click',
30 label: 'Maximum Double Click Interval',
31 units: 'seconds',
32 step: 0.1,
33 default: 0.7
34 },
35 {
36 key: 'max_separation_for_gesture_touches_in_pixels',
37 label: 'Maximum Separation for Gesture Touches',
38 units: 'pixels',
39 default: 150
40 },
41 {
42 key: 'max_swipe_deviation_ratio',
43 label: 'Maximum Swipe Deviation',
44 units: '',
45 default: 3
46 },
47 {
48 key: 'max_touch_down_duration_in_seconds_for_click',
49 label: 'Maximum Touch-Down Duration for Click',
50 units: 'seconds',
51 step: 0.1,
52 default: 0.8
53 },
54 {
55 key: 'max_touch_move_in_pixels_for_click',
56 label: 'Maximum Touch-Move for Click',
57 units: 'pixels',
58 default: 20
59 },
60 {
61 key: 'min_distance_for_pinch_scroll_in_pixels',
62 label: 'Minimum Distance for Pinch Scroll',
63 units: 'pixels',
64 default: 20
65 },
66 {
67 key: 'min_flick_speed_squared',
68 label: 'Minimum Flick Speed Squared',
69 units: '',
70 default: 550 * 550
71 },
72 {
73 key: 'min_pinch_update_distance_in_pixels',
74 label: 'Minimum Pinch Update Distance',
75 units: 'pixels',
76 default: 5
77 },
78 {
79 key: 'min_rail_break_velocity',
80 label: 'Minimum Rail-Break Velocity',
81 units: '',
82 default: 200
83 },
84 {
85 key: 'min_scroll_delta_squared',
86 label: 'Minimum Scroll Delta Squared',
87 units: '',
88 default: 5 * 5
89 },
90 {
91 key: 'min_swipe_speed',
92 label: 'Minimum Swipe Speed',
93 units: '',
94 default: 20
95 },
96 {
97 key: 'min_touch_down_duration_in_seconds_for_click',
98 label: 'Minimum Touch-Down Duration for Click',
99 units: 'seconds',
100 step: 0.01,
101 default: 0.01
102 },
103 {
104 key: 'points_buffered_for_velocity',
105 label: 'Points Buffered for Velocity',
106 units: '',
107 step: 1,
108 default: 3
109 },
110 {
111 key: 'rail_break_proportion',
112 label: 'Rail-Break Proportion',
113 units: '',
114 default: 15
115 },
116 {
117 key: 'rail_start_proportion',
118 label: 'Rail-Start Proportion',
119 units: '',
120 default: 2
121 }
122 ];
123
124 /**
125 * Dynamically builds web-form based on FIELDS list.
126 * @return {string} The form's HTML.
127 */
128 function buildForm() {
129 var buf = [];
130
131 for (var i = 0; i < FIELDS.length; i++) {
132 var field = FIELDS[i];
133
134 var row = $('gesture-form-row').cloneNode(true);
135 var label = row.querySelector('.row-label');
136 var input = row.querySelector('.row-input');
137 var units = row.querySelector('.row-units');
138
139 row.id = '';
140 label.setAttribute('for', field.key);
141 label.textContent = field.label;
142 input.id = field.key;
143 input.min = field.min || 0;
144 input.title = "Default Value: " + field.default;
145 if (field.max) input.max = field.max;
146 if (field.step) input.step = field.step;
147
148 $('gesture-form').appendChild(row);
149 if (field.units)
150 units.textContent = '(' + field.units + ')';
151 }
152 }
153
154 /**
155 * Initialize the form by adding 'onChange' listeners to all fields.
156 */
157 function initForm() {
158 for (var i = 0; i < FIELDS.length; i++) {
159 var field = FIELDS[i];
160 $(field.key).onchange = (function(key) {
161 setPreferenceValue(key, $(key).value);
162 }).bind(null, field.key);
163 }
164 }
165
166 /**
167 * Request a preference setting's value.
168 * This method is asynchronous; the result is provided by a call to
169 * getPreferenceValueResult.
170 * @param {string} prefName The name of the preference value being requested.
171 */
172 function getPreferenceValue(prefName) {
173 chrome.send('getPreferenceValue', [GESTURE_PREFIX + prefName]);
174 }
175
176 /**
177 * Handle callback from call to getPreferenceValue.
178 * @param {string} prefName The name of the requested preference value.
179 * @param {value} value The current value associated with prefName.
180 */
181 function getPreferenceValueResult(prefName, value) {
182 prefName = prefName.substring(prefName.indexOf('.') + 1);
183 $(prefName).value = value;
184 }
185
186 /**
187 * Set a preference setting's value.
188 * @param {string} prefName The name of the preference value being set.
189 * @param {value} value The value to be associated with prefName.
190 */
191 function setPreferenceValue(prefName, value) {
192 chrome.send(
193 'setPreferenceValue',
194 [GESTURE_PREFIX + prefName, parseFloat(value)]);
195 }
196
197 /**
198 * Handle processing of "Reset" button.
199 * Causes off form values to be updated based on current preference values.
200 */
201 function onReset() {
202 for (var i = 0; i < FIELDS.length; i++) {
203 var field = FIELDS[i];
204 $(field.key).value = field.default;
205 setPreferenceValue(field.key, field.default);
206 }
207 return false;
208 }
209
210 function loadForm() {
211 for (var i = 0; i < FIELDS.length; i++)
212 getPreferenceValue(FIELDS[i].key);
213 }
214
215 /**
216 * Build and initialize the gesture configuration form.
217 */
218 function initialize() {
219 buildForm();
220 loadForm();
221 initForm();
222
223 $('resetButton').onclick = onReset.bind(this);
224 }
225
226 return {
227 initialize: initialize,
228 getPreferenceValueResult: getPreferenceValueResult
229 };
230 })();
231
232 document.addEventListener('DOMContentLoaded', gesture_config.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698