Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | <bindings id="numberboxBindings" |
michael@0 | 8 | xmlns="http://www.mozilla.org/xbl" |
michael@0 | 9 | xmlns:html="http://www.w3.org/1999/xhtml" |
michael@0 | 10 | xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 11 | xmlns:xbl="http://www.mozilla.org/xbl"> |
michael@0 | 12 | |
michael@0 | 13 | <binding id="numberbox" |
michael@0 | 14 | extends="chrome://global/content/bindings/textbox.xml#textbox"> |
michael@0 | 15 | |
michael@0 | 16 | <resources> |
michael@0 | 17 | <stylesheet src="chrome://global/skin/numberbox.css"/> |
michael@0 | 18 | </resources> |
michael@0 | 19 | |
michael@0 | 20 | <content> |
michael@0 | 21 | <xul:hbox class="textbox-input-box numberbox-input-box" flex="1" xbl:inherits="context,disabled,focused"> |
michael@0 | 22 | <html:input class="numberbox-input textbox-input" anonid="input" |
michael@0 | 23 | xbl:inherits="value,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey"/> |
michael@0 | 24 | </xul:hbox> |
michael@0 | 25 | <xul:spinbuttons anonid="buttons" xbl:inherits="disabled,hidden=hidespinbuttons"/> |
michael@0 | 26 | </content> |
michael@0 | 27 | |
michael@0 | 28 | <implementation> |
michael@0 | 29 | <field name="_valueEntered">false</field> |
michael@0 | 30 | <field name="_spinButtons">null</field> |
michael@0 | 31 | <field name="_value">0</field> |
michael@0 | 32 | <field name="decimalSymbol">"."</field> |
michael@0 | 33 | |
michael@0 | 34 | <property name="spinButtons" readonly="true"> |
michael@0 | 35 | <getter> |
michael@0 | 36 | <![CDATA[ |
michael@0 | 37 | if (!this._spinButtons) |
michael@0 | 38 | this._spinButtons = document.getAnonymousElementByAttribute(this, "anonid", "buttons"); |
michael@0 | 39 | return this._spinButtons; |
michael@0 | 40 | ]]> |
michael@0 | 41 | </getter> |
michael@0 | 42 | </property> |
michael@0 | 43 | |
michael@0 | 44 | <property name="value" onget="return '' + this.valueNumber" |
michael@0 | 45 | onset="return this.valueNumber = val;"/> |
michael@0 | 46 | |
michael@0 | 47 | <property name="valueNumber"> |
michael@0 | 48 | <getter> |
michael@0 | 49 | if (this._valueEntered) { |
michael@0 | 50 | var newval = this.inputField.value; |
michael@0 | 51 | newval = newval.replace(this.decimalSymbol, "."); |
michael@0 | 52 | this._validateValue(newval, false); |
michael@0 | 53 | } |
michael@0 | 54 | return this._value; |
michael@0 | 55 | </getter> |
michael@0 | 56 | <setter> |
michael@0 | 57 | this._validateValue(val, false); |
michael@0 | 58 | return val; |
michael@0 | 59 | </setter> |
michael@0 | 60 | </property> |
michael@0 | 61 | |
michael@0 | 62 | <property name="wrapAround"> |
michael@0 | 63 | <getter> |
michael@0 | 64 | <![CDATA[ |
michael@0 | 65 | return (this.getAttribute('wraparound') == 'true') |
michael@0 | 66 | ]]> |
michael@0 | 67 | </getter> |
michael@0 | 68 | <setter> |
michael@0 | 69 | <![CDATA[ |
michael@0 | 70 | if (val) |
michael@0 | 71 | this.setAttribute('wraparound', 'true'); |
michael@0 | 72 | else |
michael@0 | 73 | this.removeAttribute('wraparound'); |
michael@0 | 74 | this._enableDisableButtons(); |
michael@0 | 75 | return val; |
michael@0 | 76 | ]]> |
michael@0 | 77 | </setter> |
michael@0 | 78 | </property> |
michael@0 | 79 | |
michael@0 | 80 | <property name="min"> |
michael@0 | 81 | <getter> |
michael@0 | 82 | var min = this.getAttribute("min"); |
michael@0 | 83 | return min ? Number(min) : 0; |
michael@0 | 84 | </getter> |
michael@0 | 85 | <setter> |
michael@0 | 86 | <![CDATA[ |
michael@0 | 87 | if (typeof val == "number") { |
michael@0 | 88 | this.setAttribute("min", val); |
michael@0 | 89 | if (this.valueNumber < val) |
michael@0 | 90 | this._validateValue(val, false); |
michael@0 | 91 | } |
michael@0 | 92 | return val; |
michael@0 | 93 | ]]> |
michael@0 | 94 | </setter> |
michael@0 | 95 | </property> |
michael@0 | 96 | |
michael@0 | 97 | <property name="max"> |
michael@0 | 98 | <getter> |
michael@0 | 99 | var max = this.getAttribute("max"); |
michael@0 | 100 | return max ? Number(max) : Infinity; |
michael@0 | 101 | </getter> |
michael@0 | 102 | <setter> |
michael@0 | 103 | <![CDATA[ |
michael@0 | 104 | if (typeof val != "number") |
michael@0 | 105 | return val; |
michael@0 | 106 | var min = this.min; |
michael@0 | 107 | if (val < min) |
michael@0 | 108 | val = min; |
michael@0 | 109 | this.setAttribute("max", val); |
michael@0 | 110 | if (this.valueNumber > val) |
michael@0 | 111 | this._validateValue(val, false); |
michael@0 | 112 | return val; |
michael@0 | 113 | ]]> |
michael@0 | 114 | </setter> |
michael@0 | 115 | </property> |
michael@0 | 116 | |
michael@0 | 117 | <property name="decimalPlaces"> |
michael@0 | 118 | <getter> |
michael@0 | 119 | var places = this.getAttribute("decimalplaces"); |
michael@0 | 120 | return places ? Number(places) : 0; |
michael@0 | 121 | </getter> |
michael@0 | 122 | <setter> |
michael@0 | 123 | if (typeof val == "number") { |
michael@0 | 124 | this.setAttribute("decimalplaces", val); |
michael@0 | 125 | this._validateValue(this.valueNumber, false); |
michael@0 | 126 | } |
michael@0 | 127 | return val; |
michael@0 | 128 | </setter> |
michael@0 | 129 | </property> |
michael@0 | 130 | |
michael@0 | 131 | <property name="increment"> |
michael@0 | 132 | <getter> |
michael@0 | 133 | var increment = this.getAttribute("increment"); |
michael@0 | 134 | return increment ? Number(increment) : 1; |
michael@0 | 135 | </getter> |
michael@0 | 136 | <setter> |
michael@0 | 137 | <![CDATA[ |
michael@0 | 138 | if (typeof val == "number") |
michael@0 | 139 | this.setAttribute("increment", val); |
michael@0 | 140 | return val; |
michael@0 | 141 | ]]> |
michael@0 | 142 | </setter> |
michael@0 | 143 | </property> |
michael@0 | 144 | |
michael@0 | 145 | <method name="decrease"> |
michael@0 | 146 | <body> |
michael@0 | 147 | return this._validateValue(this.valueNumber - this.increment, true); |
michael@0 | 148 | </body> |
michael@0 | 149 | </method> |
michael@0 | 150 | |
michael@0 | 151 | <method name="increase"> |
michael@0 | 152 | <body> |
michael@0 | 153 | return this._validateValue(this.valueNumber + this.increment, true); |
michael@0 | 154 | </body> |
michael@0 | 155 | </method> |
michael@0 | 156 | |
michael@0 | 157 | <method name="_modifyUp"> |
michael@0 | 158 | <body> |
michael@0 | 159 | <![CDATA[ |
michael@0 | 160 | if (this.disabled || this.readOnly) |
michael@0 | 161 | return; |
michael@0 | 162 | var oldval = this.valueNumber; |
michael@0 | 163 | var newval = this.increase(); |
michael@0 | 164 | this.inputField.select(); |
michael@0 | 165 | if (oldval != newval) |
michael@0 | 166 | this._fireChange(); |
michael@0 | 167 | ]]> |
michael@0 | 168 | </body> |
michael@0 | 169 | </method> |
michael@0 | 170 | <method name="_modifyDown"> |
michael@0 | 171 | <body> |
michael@0 | 172 | <![CDATA[ |
michael@0 | 173 | if (this.disabled || this.readOnly) |
michael@0 | 174 | return; |
michael@0 | 175 | var oldval = this.valueNumber; |
michael@0 | 176 | var newval = this.decrease(); |
michael@0 | 177 | this.inputField.select(); |
michael@0 | 178 | if (oldval != newval) |
michael@0 | 179 | this._fireChange(); |
michael@0 | 180 | ]]> |
michael@0 | 181 | </body> |
michael@0 | 182 | </method> |
michael@0 | 183 | |
michael@0 | 184 | <method name="_enableDisableButtons"> |
michael@0 | 185 | <body> |
michael@0 | 186 | <![CDATA[ |
michael@0 | 187 | var buttons = this.spinButtons; |
michael@0 | 188 | if (this.wrapAround) { |
michael@0 | 189 | buttons.decreaseDisabled = buttons.increaseDisabled = false; |
michael@0 | 190 | } |
michael@0 | 191 | else if (this.disabled || this.readOnly) { |
michael@0 | 192 | buttons.decreaseDisabled = buttons.increaseDisabled = true; |
michael@0 | 193 | } |
michael@0 | 194 | else { |
michael@0 | 195 | buttons.decreaseDisabled = (this.valueNumber <= this.min); |
michael@0 | 196 | buttons.increaseDisabled = (this.valueNumber >= this.max); |
michael@0 | 197 | } |
michael@0 | 198 | ]]> |
michael@0 | 199 | </body> |
michael@0 | 200 | </method> |
michael@0 | 201 | |
michael@0 | 202 | <method name="_validateValue"> |
michael@0 | 203 | <parameter name="aValue"/> |
michael@0 | 204 | <parameter name="aIsIncDec"/> |
michael@0 | 205 | <body> |
michael@0 | 206 | <![CDATA[ |
michael@0 | 207 | aValue = Number(aValue) || 0; |
michael@0 | 208 | |
michael@0 | 209 | var min = this.min; |
michael@0 | 210 | var max = this.max; |
michael@0 | 211 | var wrapAround = this.wrapAround && |
michael@0 | 212 | min != -Infinity && max != Infinity; |
michael@0 | 213 | if (aValue < min) |
michael@0 | 214 | aValue = (aIsIncDec && wrapAround ? max : min); |
michael@0 | 215 | else if (aValue > max) |
michael@0 | 216 | aValue = (aIsIncDec && wrapAround ? min : max); |
michael@0 | 217 | |
michael@0 | 218 | var places = this.decimalPlaces; |
michael@0 | 219 | aValue = (places == Infinity) ? "" + aValue : aValue.toFixed(places); |
michael@0 | 220 | |
michael@0 | 221 | this._valueEntered = false; |
michael@0 | 222 | this._value = Number(aValue); |
michael@0 | 223 | this.inputField.value = aValue.replace(/\./, this.decimalSymbol); |
michael@0 | 224 | |
michael@0 | 225 | if (!wrapAround) |
michael@0 | 226 | this._enableDisableButtons(); |
michael@0 | 227 | |
michael@0 | 228 | return aValue; |
michael@0 | 229 | ]]> |
michael@0 | 230 | </body> |
michael@0 | 231 | </method> |
michael@0 | 232 | |
michael@0 | 233 | <method name="_fireChange"> |
michael@0 | 234 | <body> |
michael@0 | 235 | var evt = document.createEvent("Events"); |
michael@0 | 236 | evt.initEvent("change", true, true); |
michael@0 | 237 | this.dispatchEvent(evt); |
michael@0 | 238 | </body> |
michael@0 | 239 | </method> |
michael@0 | 240 | |
michael@0 | 241 | <constructor><![CDATA[ |
michael@0 | 242 | if (this.max < this.min) |
michael@0 | 243 | this.max = this.min; |
michael@0 | 244 | |
michael@0 | 245 | var dsymbol = (Number(5.4)).toLocaleString().match(/\D/); |
michael@0 | 246 | if (dsymbol != null) |
michael@0 | 247 | this.decimalSymbol = dsymbol[0]; |
michael@0 | 248 | |
michael@0 | 249 | var value = this.inputField.value || 0; |
michael@0 | 250 | this._validateValue(value, false); |
michael@0 | 251 | ]]></constructor> |
michael@0 | 252 | |
michael@0 | 253 | </implementation> |
michael@0 | 254 | |
michael@0 | 255 | <handlers> |
michael@0 | 256 | <handler event="input" phase="capturing"> |
michael@0 | 257 | this._valueEntered = true; |
michael@0 | 258 | </handler> |
michael@0 | 259 | |
michael@0 | 260 | <handler event="keypress"> |
michael@0 | 261 | <![CDATA[ |
michael@0 | 262 | if (!event.ctrlKey && !event.metaKey && !event.altKey && event.charCode) { |
michael@0 | 263 | if (event.charCode == this.decimalSymbol.charCodeAt(0) && |
michael@0 | 264 | this.decimalPlaces && |
michael@0 | 265 | String(this.inputField.value).indexOf(this.decimalSymbol) == -1) |
michael@0 | 266 | return; |
michael@0 | 267 | |
michael@0 | 268 | if (event.charCode == 45 && this.min < 0) |
michael@0 | 269 | return; |
michael@0 | 270 | |
michael@0 | 271 | if (event.charCode < 48 || event.charCode > 57) |
michael@0 | 272 | event.preventDefault(); |
michael@0 | 273 | } |
michael@0 | 274 | ]]> |
michael@0 | 275 | </handler> |
michael@0 | 276 | |
michael@0 | 277 | <handler event="keypress" keycode="VK_UP"> |
michael@0 | 278 | this._modifyUp(); |
michael@0 | 279 | </handler> |
michael@0 | 280 | |
michael@0 | 281 | <handler event="keypress" keycode="VK_DOWN"> |
michael@0 | 282 | this._modifyDown(); |
michael@0 | 283 | </handler> |
michael@0 | 284 | |
michael@0 | 285 | <handler event="up" preventdefault="true"> |
michael@0 | 286 | this._modifyUp(); |
michael@0 | 287 | </handler> |
michael@0 | 288 | |
michael@0 | 289 | <handler event="down" preventdefault="true"> |
michael@0 | 290 | this._modifyDown(); |
michael@0 | 291 | </handler> |
michael@0 | 292 | |
michael@0 | 293 | <handler event="change"> |
michael@0 | 294 | if (event.originalTarget == this.inputField) { |
michael@0 | 295 | var newval = this.inputField.value; |
michael@0 | 296 | newval = newval.replace(this.decimalSymbol, "."); |
michael@0 | 297 | this._validateValue(newval, false); |
michael@0 | 298 | } |
michael@0 | 299 | </handler> |
michael@0 | 300 | </handlers> |
michael@0 | 301 | |
michael@0 | 302 | </binding> |
michael@0 | 303 | |
michael@0 | 304 | </bindings> |