1 // Copyright (c) 2013 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 'use strict'; 6 7 /** 8 * @fileoverview A text widget for monitoring ValueBar value and previewValue. 9 */ 10 base.require('ui'); 11 base.require('base.properties'); 12 base.require('ui.mouse_tracker'); 13 14 base.exportTo('ui', function() { 15 16 /** 17 * @constructor 18 */ 19 var ValueDisplay = ui.define('value-display'); 20 21 ValueDisplay.prototype = { 22 __proto__: HTMLDivElement.prototype, 23 24 decorate: function() { 25 this.className = 'value-display'; 26 this.currentValueDisplay_ = ui.createDiv({ 27 className: 'value-value', 28 parent: this 29 }); 30 this.previewValueDisplay_ = ui.createDiv({ 31 className: 'value-set-to', 32 parent: this 33 }); 34 this.setValueText_ = this.setValueText_.bind(this); 35 this.setPreviewValueText_ = this.setPreviewValueText_.bind(this); 36 }, 37 38 get valueBar() { 39 return this.valueBar_; 40 }, 41 42 set valueBar(newValue) { 43 if (this.valueBar_) 44 this.detach_(); 45 this.valueBar_ = newValue; 46 if (this.valueBar_) 47 this.attach_(); 48 }, 49 50 attach_: function() { 51 this.valueBar_.addEventListener('valueChange', 52 this.setValueText_); 53 this.valueBar_.addEventListener('previewValueChange', 54 this.setPreviewValueText_); 55 }, 56 57 dettach_: function() { 58 this.valueBar_.removeEventListener('valueChange', 59 this.setValueText_); 60 this.valueBar_.removeEventListener('previewValueChange', 61 this.setPreviewValueText_); 62 }, 63 64 setValueText_: function(event) { 65 if (typeof event.newValue === undefined) 66 return; 67 this.currentValueDisplay_.textContent = event.newValue.toFixed(2); 68 this.setPreviewValueText_(event); 69 }, 70 71 setPreviewValueText_: function(event) { 72 this.previewValueDisplay_.textContent = 73 ' (\u2192 ' + event.newValue.toFixed(2) + ')'; 74 } 75 76 }; 77 78 return { 79 ValueDisplay: ValueDisplay 80 }; 81 }); 82