Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 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.innerHTML = field.label; | |
|
flackr
2012/06/11 18:06:52
Prefer .textContent over .innerHTML (below as well
Kevin Greer
2012/06/11 19:56:32
Changed.
On 2012/06/11 18:06:52, flackr wrote:
| |
| 141 input.id = field.key; | |
| 142 input.min = field.min || 0; | |
| 143 input.title = "Default Value: " + field.default; | |
| 144 if (field.max) input.max = field.max; | |
| 145 if (field.step) input.step = field.step; | |
| 146 | |
| 147 $('gesture-form').appendChild(row); | |
| 148 if (field.units) | |
| 149 units.innerHTML = '(' + field.units + ')'; | |
| 150 } | |
| 151 | |
| 152 $('gesture-form-row').outerHTML = ''; | |
|
flackr
2012/06/11 18:06:52
Can you avoid having to delete this if you put 'ge
Kevin Greer
2012/06/11 19:56:32
I've changed it to the same design used by ntp4 an
| |
| 153 } | |
| 154 | |
| 155 /** | |
| 156 * Initialize the form by adding 'onChange' listeners to all fields. | |
| 157 */ | |
| 158 function initForm() { | |
| 159 for (var i = 0; i < FIELDS.length; i++) { | |
| 160 var field = FIELDS[i]; | |
| 161 $(field.key).onchange = (function(key) { | |
| 162 setPreferenceValue(key, $(key).value); | |
| 163 }).bind(null, field.key); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 /** | |
| 168 * Request a preference setting's value. | |
| 169 * This method is asynchronous; the result is provided by a call to | |
| 170 * getPreferenceValueResult. | |
| 171 * @param {string} prefName The name of the preference value being requested. | |
| 172 */ | |
| 173 function getPreferenceValue(prefName) { | |
| 174 chrome.send('getPreferenceValue', [GESTURE_PREFIX + prefName]); | |
| 175 } | |
| 176 | |
| 177 /** | |
| 178 * Handle callback from call to getPreferenceValue. | |
| 179 * @param {string} prefName The name of the requested preference value. | |
| 180 * @param {value} value The current value associated with prefName. | |
| 181 */ | |
| 182 function getPreferenceValueResult(prefName, value) { | |
| 183 prefName = prefName.substring(prefName.indexOf('.') + 1); | |
| 184 $(prefName).value = value; | |
| 185 } | |
| 186 | |
| 187 /** | |
| 188 * Set a preference setting's value. | |
| 189 * @param {string} prefName The name of the preference value being set. | |
| 190 * @param {value} value The value to be associated with prefName. | |
| 191 */ | |
| 192 function setPreferenceValue(prefName, value) { | |
| 193 chrome.send( | |
| 194 'setPreferenceValue', | |
| 195 [GESTURE_PREFIX + prefName, parseFloat(value)]); | |
| 196 } | |
| 197 | |
| 198 /** | |
| 199 * Handle processing of "Reset" button. | |
| 200 * Causes off form values to be updated based on current preference values. | |
| 201 */ | |
| 202 function onReset() { | |
| 203 for (var i = 0; i < FIELDS.length; i++) { | |
| 204 var field = FIELDS[i]; | |
| 205 $(field.key).value = field.default; | |
| 206 setPreferenceValue(field.key, field.default); | |
| 207 } | |
| 208 return false; | |
| 209 } | |
| 210 | |
| 211 function loadForm() { | |
| 212 for (var i = 0; i < FIELDS.length; i++) { | |
| 213 getPreferenceValue(FIELDS[i].key); | |
| 214 } | |
|
flackr
2012/06/11 18:06:52
nit: no braces necessary here.
Kevin Greer
2012/06/11 19:56:32
Removed.
On 2012/06/11 18:06:52, flackr wrote:
| |
| 215 } | |
| 216 | |
| 217 /** | |
| 218 * Build and initialize the gesture configuration form. | |
| 219 */ | |
| 220 function initialize() { | |
| 221 buildForm(); | |
| 222 loadForm(); | |
| 223 initForm(); | |
| 224 | |
| 225 $('resetButton').onclick = onReset.bind(this); | |
| 226 } | |
| 227 | |
| 228 return { | |
| 229 initialize: initialize, | |
| 230 getPreferenceValueResult: getPreferenceValueResult | |
| 231 }; | |
| 232 })(); | |
| 233 | |
| 234 document.addEventListener('DOMContentLoaded', gesture_config.initialize); | |
| OLD | NEW |