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 // Since '$' is the only feature used from the standard 'cr.*' library, | |
| 6 // I just redefine it here. This allows this file to be loaded in a | |
| 7 // browser directly for layout and some testing purposes. | |
|
flackr
2012/06/06 14:50:54
Try to avoid personal pronouns. i.e. Redefine '$'
Kevin Greer
2012/06/06 20:26:20
Done.
| |
| 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', | |
|
flackr
2012/06/06 14:50:54
These labels will need to be localized.
Kevin Greer
2012/06/06 20:26:20
This is screen is meant to be an unsupported/inter
| |
| 25 units: 'seconds' | |
| 26 }, | |
| 27 { | |
| 28 key: 'max_seconds_between_double_click', | |
| 29 label: 'Max. Double Click Interval', | |
|
rjkroege
2012/06/06 15:10:28
why abbreviate Max, Min? Does it negatively effect
Kevin Greer
2012/06/06 20:26:20
Changed to the long forms.
On 2012/06/06 15:10:28,
| |
| 30 units: 'seconds' | |
| 31 }, | |
| 32 { | |
| 33 key: 'max_separation_for_gesture_touches_in_pixels', | |
| 34 label: 'Max. Separation for Gesture Touches', | |
| 35 units: 'pixels' | |
| 36 }, | |
| 37 { | |
| 38 key: 'max_swipe_deviation_ratio', | |
| 39 label: 'Max. Swipe Deviation', | |
| 40 units: '' | |
| 41 }, | |
| 42 { | |
| 43 key: 'max_touch_down_duration_in_seconds_for_click', | |
| 44 label: 'Max. Touch-Down Duration for Click', | |
| 45 units: 'seconds' | |
| 46 }, | |
| 47 { | |
| 48 key: 'max_touch_move_in_pixels_for_click', | |
| 49 label: 'Max. Touch-Move for Click', | |
| 50 units: 'pixels' | |
| 51 }, | |
| 52 { | |
| 53 key: 'min_distance_for_pinch_scroll_in_pixels', | |
| 54 label: 'Min. Distance for Pinch Scroll', | |
| 55 units: 'pixels' | |
| 56 }, | |
| 57 { | |
| 58 key: 'min_flick_speed_squared', | |
| 59 label: 'Min. Flick Speed Squared', | |
| 60 units: '' | |
| 61 }, | |
| 62 { | |
| 63 key: 'min_pinch_update_distance_in_pixels', | |
| 64 label: 'Min. Pinch Update Distance', | |
| 65 units: 'pixels' | |
| 66 }, | |
| 67 { | |
| 68 key: 'min_rail_break_velocity', | |
| 69 label: 'Min. Rail-Break Velocity', | |
| 70 units: '' | |
| 71 }, | |
| 72 { | |
| 73 key: 'min_scroll_delta_squared', | |
| 74 label: 'Min. Scroll Delta Squared', | |
| 75 units: '' | |
| 76 }, | |
| 77 { | |
| 78 key: 'min_swipe_speed', | |
| 79 label: 'Min. Swipe Speed', | |
| 80 units: '' | |
| 81 }, | |
| 82 { | |
| 83 key: 'min_touch_down_duration_in_seconds_for_click', | |
| 84 label: 'Min. Touch-Down Duration for Click', | |
| 85 units: 'seconds' | |
| 86 }, | |
| 87 { | |
| 88 key: 'points_buffered_for_velocity', | |
| 89 label: 'Points Buffered for Velocity', | |
| 90 units: '' | |
| 91 }, | |
| 92 { | |
| 93 key: 'rail_break_proportion', | |
| 94 label: 'Rail-Break Proportion', | |
| 95 units: '' | |
| 96 }, | |
| 97 { | |
| 98 key: 'rail_start_proportion', | |
| 99 label: 'Rail-Start Proportion', | |
| 100 units: '' | |
| 101 } | |
| 102 ]; | |
| 103 | |
| 104 /** | |
| 105 * Dynamically builds web-form based on FIELDS list. | |
| 106 * @return {string} The form's HTML. | |
| 107 */ | |
| 108 function buildForm() { | |
| 109 var buf = []; | |
| 110 | |
| 111 for (var i = 0; i < FIELDS.length; i++) { | |
| 112 var field = FIELDS[i]; | |
| 113 | |
| 114 buf.push('<div class="row">'); | |
| 115 buf.push('<label>'); | |
| 116 buf.push(field.label); | |
| 117 buf.push('</label>'); | |
| 118 buf.push('<input type="number" id="' + field.key + '" size=20 />'); | |
| 119 if (field.units) | |
| 120 buf.push('<div class="units">(' + field.units + ')</div>'); | |
| 121 buf.push('</div>'); | |
|
flackr
2012/06/06 14:50:54
Can you define and clone a template DOM node rathe
Kevin Greer
2012/06/07 19:07:00
Given all of the conditional logic in the formatti
flackr
2012/06/07 21:07:54
I don't think this should be that bad, you would j
Kevin Greer
2012/06/08 11:51:25
Will do in next CL.
On 2012/06/07 21:07:54, flackr
| |
| 122 } | |
| 123 | |
| 124 return buf.join(''); | |
| 125 } | |
| 126 | |
| 127 /** | |
| 128 * Request a preference setting's value. | |
| 129 * This method is asynchronous; the result is provided by a call to | |
| 130 * getPreferenceValueResult. | |
| 131 * @param {string} prefName The name of the preference value being requested. | |
| 132 */ | |
| 133 function getPreferenceValue(prefName) { | |
| 134 chrome.send('getPreferenceValue', [GESTURE_PREFIX + prefName]); | |
| 135 } | |
| 136 | |
| 137 /** | |
| 138 * Handle callback from call to getPreferenceValue. | |
| 139 * @param {string} prefName The name of the requested preference value. | |
| 140 * @param {value} value The current value associated with prefName. | |
| 141 */ | |
| 142 function getPreferenceValueResult(prefName, value) { | |
| 143 prefName = prefName.substring(prefName.indexOf('.') + 1); | |
| 144 $(prefName).value = value; | |
| 145 } | |
| 146 | |
| 147 /** | |
| 148 * Set a preference setting's value. | |
| 149 * @param {string} prefName The name of the preference value being set. | |
| 150 * @param {value} value The value to be associated with prefName. | |
| 151 */ | |
| 152 function setPreferenceValue(prefName, value) { | |
| 153 chrome.send( | |
| 154 'setPreferenceValue', | |
| 155 [GESTURE_PREFIX + prefName, parseFloat(value)]); | |
| 156 } | |
| 157 | |
| 158 /** | |
| 159 * Handle processing of "Update" button. | |
| 160 * Causes all preference values to be updated based on current form values. | |
| 161 */ | |
| 162 function onUpdate() { | |
| 163 for (var i = 0; i < FIELDS.length; i++) { | |
| 164 var key = FIELDS[i].key; | |
| 165 setPreferenceValue(key, $(key).value); | |
| 166 } | |
| 167 return false; | |
| 168 } | |
| 169 | |
| 170 /** | |
| 171 * Handle processing of "Reset" button. | |
| 172 * Causes off form values to be updated based on current preference values. | |
| 173 */ | |
| 174 function onReset() { | |
| 175 for (var i = 0; i < FIELDS.length; i++) { | |
| 176 getPreferenceValue(FIELDS[i].key); | |
| 177 } | |
| 178 return false; | |
| 179 } | |
| 180 | |
| 181 /** | |
| 182 * Build and initialize the gesture configuration form. | |
| 183 */ | |
| 184 function initialize() { | |
| 185 $('gestureForm').innerHTML = buildForm(); | |
| 186 | |
| 187 // Load Current Values | |
| 188 onReset(); | |
| 189 | |
| 190 $('updateButton').onclick = onUpdate.bind(this); | |
| 191 $('resetButton').onclick = onReset.bind(this); | |
|
flackr
2012/06/06 14:50:54
On the settings page we update / fetch values imme
Kevin Greer
2012/06/06 20:26:20
Changed.
On 2012/06/06 14:50:54, flackr wrote:
| |
| 192 } | |
| 193 | |
| 194 return { | |
| 195 initialize: initialize, | |
| 196 getPreferenceValue: getPreferenceValue, | |
| 197 getPreferenceValueResult: getPreferenceValueResult, | |
| 198 setPreferenceValue: setPreferenceValue | |
| 199 }; | |
| 200 })(); | |
| 201 | |
| 202 document.addEventListener('DOMContentLoaded', gesture_config.initialize); | |
| OLD | NEW |