1/* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31WebInspector.StatusBarButton = function(title, className, states) 32{ 33 this.element = document.createElement("button"); 34 this.element.className = className + " status-bar-item"; 35 this.element.addEventListener("click", this._clicked.bind(this), false); 36 37 this.glyph = document.createElement("div"); 38 this.glyph.className = "glyph"; 39 this.element.appendChild(this.glyph); 40 41 this.glyphShadow = document.createElement("div"); 42 this.glyphShadow.className = "glyph shadow"; 43 this.element.appendChild(this.glyphShadow); 44 45 this.states = states; 46 if (!states) 47 this.states = 2; 48 49 if (states == 2) 50 this._state = false; 51 else 52 this._state = 0; 53 54 this.title = title; 55 this.disabled = false; 56 this._visible = true; 57} 58 59WebInspector.StatusBarButton.prototype = { 60 _clicked: function() 61 { 62 this.dispatchEventToListeners("click"); 63 }, 64 65 get disabled() 66 { 67 return this._disabled; 68 }, 69 70 set disabled(x) 71 { 72 if (this._disabled === x) 73 return; 74 this._disabled = x; 75 this.element.disabled = x; 76 }, 77 78 get title() 79 { 80 return this._title; 81 }, 82 83 set title(x) 84 { 85 if (this._title === x) 86 return; 87 this._title = x; 88 this.element.title = x; 89 }, 90 91 get state() 92 { 93 return this._state; 94 }, 95 96 set state(x) 97 { 98 if (this._state === x) 99 return; 100 101 if (this.states === 2) { 102 if (x) 103 this.element.addStyleClass("toggled-on"); 104 else 105 this.element.removeStyleClass("toggled-on"); 106 } else { 107 if (x !== 0) { 108 this.element.removeStyleClass("toggled-" + this._state); 109 this.element.addStyleClass("toggled-" + x); 110 } else 111 this.element.removeStyleClass("toggled-" + this._state); 112 } 113 this._state = x; 114 }, 115 116 get toggled() 117 { 118 if (this.states !== 2) 119 throw("Only used toggled when there are 2 states, otherwise, use state"); 120 return this.state; 121 }, 122 123 set toggled(x) 124 { 125 if (this.states !== 2) 126 throw("Only used toggled when there are 2 states, otherwise, use state"); 127 this.state = x; 128 }, 129 130 get visible() 131 { 132 return this._visible; 133 }, 134 135 set visible(x) 136 { 137 if (this._visible === x) 138 return; 139 140 if (x) 141 this.element.removeStyleClass("hidden"); 142 else 143 this.element.addStyleClass("hidden"); 144 this._visible = x; 145 } 146} 147 148WebInspector.StatusBarButton.prototype.__proto__ = WebInspector.Object.prototype; 149