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

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 2. 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) 2011 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!
(...skipping 229 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.
269 this.updateIndicator(); 277 // https://bugs.webkit.org/show_bug.cgi?id=52256
270 }); 278 this.onchange = this.onChange_.bind(this);
279 this.onkeyup = this.onInputUp_.bind(this);
arv (Not doing code reviews) 2011/01/12 00:44:55 No need to bind twice this.onkeyup = this.onmouse
James Hawkins 2011/01/12 00:46:03 Done.
280 this.onmouseup = this.onInputUp_.bind(this);
271 }, 281 },
272 282
273 updateIndicator: function() { 283 /**
274 if ($(this.id + '-value')) { 284 * Event listener that updates the UI when the underlying pref changes.
275 $(this.id + '-value').textContent = this.value; 285 * @param {Event} event The event that details the pref change.
276 } 286 * @private
277 } 287 */
288 onPrefChange_: function(event) {
289 var value = event.value && event.value['value'] != undefined ?
290 event.value['value'] : event.value;
291 if (value != undefined)
292 this.value = this.valueMap ? this.valueMap.indexOf(value) : value;
293 },
294
295 /**
296 * onchange handler that sets the pref when the user changes the value of
297 * the input element.
298 * @private
299 */
300 onChange_: function(event) {
301 if (this.continuous)
302 this.setRangePref_();
303
304 this.notifyChange(this, this.mapValueToRange_(this.value));
305 },
306
307 /**
308 * Sets the integer value of |pref| to the value of this element.
309 * @private
310 */
311 setRangePref_: function() {
312 Preferences.setIntegerPref(
313 this.pref, this.mapValueToRange_(this.value), this.metric);
314 },
315
316 /**
317 * onkeyup/onmouseup handler that modifies the pref if |continuous| is
318 * false.
319 * @private
320 */
321 onInputUp_: function(event) {
322 if (!this.continuous)
323 this.setRangePref_();
324 },
325
326 /**
327 * Maps the value of this element into the range provided by the client,
328 * represented by |valueMap|.
329 * @param {number} value The value to map.
330 * @private
331 */
332 mapValueToRange_: function(value) {
333 return this.valueMap ? this.valueMap[value] : value;
334 },
335
336 /**
337 * Called when the client has specified non-continuous mode and the value of
338 * the range control changes.
339 * @param {Element} el This element.
340 * @param {number} value The value of this element.
341 */
342 notifyChange: function(el, value) {
343 },
278 }; 344 };
279 345
346 /**
347 * The preference name.
348 * @type {string}
349 */
350 cr.defineProperty(PrefRange, 'pref', cr.PropertyKind.ATTR);
351
352 /**
353 * The user metric string.
354 * @type {string}
355 */
356 cr.defineProperty(PrefRange, 'metric', cr.PropertyKind.ATTR);
357
280 ///////////////////////////////////////////////////////////////////////////// 358 /////////////////////////////////////////////////////////////////////////////
281 // PrefSelect class: 359 // PrefSelect class:
282 360
283 // Define a constructor that uses a select element as its underlying element. 361 // Define a constructor that uses a select element as its underlying element.
284 var PrefSelect = cr.ui.define('select'); 362 var PrefSelect = cr.ui.define('select');
285 363
286 PrefSelect.prototype = { 364 PrefSelect.prototype = {
287 // Set up the prototype chain 365 // Set up the prototype chain
288 __proto__: HTMLSelectElement.prototype, 366 __proto__: HTMLSelectElement.prototype,
289 367
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 case 'number': 416 case 'number':
339 Preferences.setIntegerPref(self.pref, 417 Preferences.setIntegerPref(self.pref,
340 self.options[self.selectedIndex].value, self.metric); 418 self.options[self.selectedIndex].value, self.metric);
341 break; 419 break;
342 case 'boolean': 420 case 'boolean':
343 var option = self.options[self.selectedIndex]; 421 var option = self.options[self.selectedIndex];
344 var value = (option.value == 'true') ? true : false; 422 var value = (option.value == 'true') ? true : false;
345 Preferences.setBooleanPref(self.pref, value, self.metric); 423 Preferences.setBooleanPref(self.pref, value, self.metric);
346 break; 424 break;
347 case 'string': 425 case 'string':
426 case undefined: // Assume the pref is a string.
348 Preferences.setStringPref(self.pref, 427 Preferences.setStringPref(self.pref,
349 self.options[self.selectedIndex].value, self.metric); 428 self.options[self.selectedIndex].value, self.metric);
350 break; 429 break;
351 } 430 }
352 }); 431 });
353 }, 432 },
354 }; 433 };
355 434
356 /** 435 /**
357 * The preference name. 436 * The preference name.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 PrefCheckbox: PrefCheckbox, 506 PrefCheckbox: PrefCheckbox,
428 PrefNumber: PrefNumber, 507 PrefNumber: PrefNumber,
429 PrefNumeric: PrefNumeric, 508 PrefNumeric: PrefNumeric,
430 PrefRadio: PrefRadio, 509 PrefRadio: PrefRadio,
431 PrefRange: PrefRange, 510 PrefRange: PrefRange,
432 PrefSelect: PrefSelect, 511 PrefSelect: PrefSelect,
433 PrefTextField: PrefTextField 512 PrefTextField: PrefTextField
434 }; 513 };
435 514
436 }); 515 });
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