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

Side by Side Diff: chrome/browser/resources/options/pref_ui.js

Issue 6155008: DOMUI: Implement the new Fonts and Encoding page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 11 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
« no previous file with comments | « chrome/browser/resources/options/options.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('options', function() { 5 cr.define('options', function() {
6 6
7 var Preferences = options.Preferences; 7 var Preferences = options.Preferences;
8 ///////////////////////////////////////////////////////////////////////////// 8 /////////////////////////////////////////////////////////////////////////////
9 // PrefCheckbox class: 9 // PrefCheckbox class:
10 // TODO(jhawkins): Refactor all this copy-pasted code! 10 // TODO(jhawkins): Refactor all this copy-pasted code!
11 11
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 }; 240 };
241 241
242 ///////////////////////////////////////////////////////////////////////////// 242 /////////////////////////////////////////////////////////////////////////////
243 // PrefRange class: 243 // PrefRange class:
244 244
245 // Define a constructor that uses an input element as its underlying element. 245 // Define a constructor that uses an input element as its underlying element.
246 var PrefRange = cr.ui.define('input'); 246 var PrefRange = cr.ui.define('input');
247 247
248 PrefRange.prototype = { 248 PrefRange.prototype = {
249 // Set up the prototype chain 249 // Set up the prototype chain
250 __proto__: PrefNumeric.prototype, 250 __proto__: HTMLInputElement.prototype,
251
252 /**
253 * The map from input range value to the corresponding preference value.
254 */
255 valueMap: undefined,
256
257 /**
258 * If true, the associated pref will be modified on each onchange event;
259 * otherwise, the pref will only be modified on the onmouseup event after
260 * the drag.
261 */
262 continuous: true,
251 263
252 /** 264 /**
253 * Initialization function for the cr.ui framework. 265 * Initialization function for the cr.ui framework.
254 */ 266 */
255 decorate: function() { 267 decorate: function() {
256 this.type = 'range'; 268 this.type = 'range';
257 PrefNumeric.prototype.decorate.call(this);
258 var self = this;
259 269
260 // Additionally change the indicator as well. 270 // Update the UI when the pref changes.
261 Preferences.getInstance().addEventListener(this.pref, 271 Preferences.getInstance().addEventListener(
262 function(event) { 272 this.pref, this.onPrefChange_.bind(this));
263 self.updateIndicator();
264 });
265 273
266 // Listen to user events. 274 // Listen to user events.
267 this.addEventListener('input', 275 // TODO(jhawkins): Add onmousewheel handling once the associated WK bug is
268 function(e) { 276 // fixed.
arv (Not doing code reviews) 2011/01/12 00:26:45 Link to https://bugs.webkit.org/show_bug.cgi?id=52
James Hawkins 2011/01/12 00:40:07 Done.
269 this.updateIndicator(); 277 this.onchange = this.onChange_.bind(this);
270 }); 278 this.onkeyup = this.onKeyUp_.bind(this);
279 this.onmouseup = this.onMouseUp_.bind(this);
271 }, 280 },
272 281
273 updateIndicator: function() { 282 /**
274 if ($(this.id + '-value')) { 283 * Event listener that updates the UI when the underlying pref changes.
275 $(this.id + '-value').textContent = this.value; 284 * @param {Event} event The event that details the pref change.
276 } 285 * @private
277 } 286 */
287 onPrefChange_: function(event) {
288 var value = event.value && event.value['value'] != undefined ?
289 event.value['value'] : event.value;
290 if (value != undefined)
291 this.value = this.valueMap ? this.valueMap.indexOf(value) : value;
292 },
293
294 /**
295 * onchange handler that sets the pref when the user changes the value of
296 * the input element.
297 * @private
298 */
299 onChange_: function(event) {
300 if (this.continuous)
301 this.setRangePref_();
302
303 this.notifyChange(this, this.mapValueToRange_(this.value));
304 },
305
306 /**
307 * Sets the integer value of |pref| to the value of this element.
308 * @private
309 */
310 setRangePref_: function() {
311 Preferences.setIntegerPref(
312 this.pref, this.mapValueToRange_(this.value), this.metric);
313 },
314
315 /**
316 * onkeyup handler that modifies the pref if |continuous| is false and the
317 * key being released is the left or right arrow.
318 * @private
319 */
320 onKeyUp_: function(event) {
321 // Left, right arrow keys.
322 if (!this.continuous && (event.keyCode == 37 || event.keyCode == 39))
arv (Not doing code reviews) 2011/01/12 00:26:45 Can you use keyIdentifier instead?
arv (Not doing code reviews) 2011/01/12 00:26:45 This caused me to file another WebKit bug: https:
James Hawkins 2011/01/12 00:40:07 Per off-list discussion, changing this to set the
323 this.setRangePref_();
324 },
325
326 /**
327 * onmouseup handler that modifies the pref if |continuous| is false.
328 * @private
329 */
330 onMouseUp_: function() {
331 if (!this.continuous)
332 this.setRangePref_();
333 },
334
335 /**
336 * Maps the value of this element into the range provided by the client,
337 * represented by |valueMap|.
338 * @param {number} value The value to map.
339 * @private
340 */
341 mapValueToRange_: function(value) {
342 return this.valueMap ? this.valueMap[value] : value;
343 },
344
345 /**
346 * Called when the client has specified non-continuous mode and the value of
347 * the range control changes.
348 * @param {Element} el This element.
349 * @param {number} value The value of this element.
350 */
351 notifyChange: function(el, value) {
352 },
278 }; 353 };
279 354
355 /**
356 * The preference name.
357 * @type {string}
358 */
359 cr.defineProperty(PrefRange, 'pref', cr.PropertyKind.ATTR);
360
361 /**
362 * The user metric string.
363 * @type {string}
364 */
365 cr.defineProperty(PrefRange, 'metric', cr.PropertyKind.ATTR);
366
280 ///////////////////////////////////////////////////////////////////////////// 367 /////////////////////////////////////////////////////////////////////////////
281 // PrefSelect class: 368 // PrefSelect class:
282 369
283 // Define a constructor that uses an select element as its underlying element. 370 // Define a constructor that uses an select element as its underlying element.
284 var PrefSelect = cr.ui.define('select'); 371 var PrefSelect = cr.ui.define('select');
285 372
286 PrefSelect.prototype = { 373 PrefSelect.prototype = {
287 // Set up the prototype chain 374 // Set up the prototype chain
288 __proto__: HTMLSelectElement.prototype, 375 __proto__: HTMLSelectElement.prototype,
289 376
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 case 'number': 422 case 'number':
336 Preferences.setIntegerPref(self.pref, 423 Preferences.setIntegerPref(self.pref,
337 self.options[self.selectedIndex].value, self.metric); 424 self.options[self.selectedIndex].value, self.metric);
338 break; 425 break;
339 case 'boolean': 426 case 'boolean':
340 var option = self.options[self.selectedIndex]; 427 var option = self.options[self.selectedIndex];
341 var value = (option.value == 'true') ? true : false; 428 var value = (option.value == 'true') ? true : false;
342 Preferences.setBooleanPref(self.pref, value, self.metric); 429 Preferences.setBooleanPref(self.pref, value, self.metric);
343 break; 430 break;
344 case 'string': 431 case 'string':
432 case undefined: // Assume the pref is a string.
345 Preferences.setStringPref(self.pref, 433 Preferences.setStringPref(self.pref,
346 self.options[self.selectedIndex].value, self.metric); 434 self.options[self.selectedIndex].value, self.metric);
347 break; 435 break;
348 } 436 }
349 }); 437 });
350 }, 438 },
351 }; 439 };
352 440
353 /** 441 /**
354 * The preference name. 442 * The preference name.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 PrefCheckbox: PrefCheckbox, 512 PrefCheckbox: PrefCheckbox,
425 PrefNumber: PrefNumber, 513 PrefNumber: PrefNumber,
426 PrefNumeric: PrefNumeric, 514 PrefNumeric: PrefNumeric,
427 PrefRadio: PrefRadio, 515 PrefRadio: PrefRadio,
428 PrefRange: PrefRange, 516 PrefRange: PrefRange,
429 PrefSelect: PrefSelect, 517 PrefSelect: PrefSelect,
430 PrefTextField: PrefTextField 518 PrefTextField: PrefTextField
431 }; 519 };
432 520
433 }); 521 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/options.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698